VSF Documented
argtable3_private.h
Go to the documentation of this file.
1/*
2 * SPDX-FileCopyrightText: 2013-2019 Tom G. Huang
3 *
4 * SPDX-License-Identifier: BSD-3-Clause
5 */
6/*******************************************************************************
7 * argtable3_private: Declares private types, constants, and interfaces
8 *
9 * This file is part of the argtable3 library.
10 *
11 * Copyright (C) 2013-2019 Tom G. Huang
12 * <tomghuang@gmail.com>
13 * All rights reserved.
14 *
15 * Redistribution and use in source and binary forms, with or without
16 * modification, are permitted provided that the following conditions are met:
17 * * Redistributions of source code must retain the above copyright
18 * notice, this list of conditions and the following disclaimer.
19 * * Redistributions in binary form must reproduce the above copyright
20 * notice, this list of conditions and the following disclaimer in the
21 * documentation and/or other materials provided with the distribution.
22 * * Neither the name of STEWART HEITMANN nor the names of its contributors
23 * may be used to endorse or promote products derived from this software
24 * without specific prior written permission.
25 *
26 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
27 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
28 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
29 * ARE DISCLAIMED. IN NO EVENT SHALL STEWART HEITMANN BE LIABLE FOR ANY DIRECT,
30 * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
31 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
32 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
33 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
34 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
35 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
36 ******************************************************************************/
37
38#ifndef ARG_UTILS_H
39#define ARG_UTILS_H
40
41#include <stdlib.h>
42
43#define ARG_ENABLE_TRACE 0
44#define ARG_ENABLE_LOG 0
45
46#ifdef __cplusplus
47extern "C" {
48#endif
49
51
52typedef void(arg_panicfn)(const char* fmt, ...);
53
54#if defined(_MSC_VER)
55#define ARG_TRACE(x) \
56 __pragma(warning(push)) __pragma(warning(disable : 4127)) do { \
57 if (ARG_ENABLE_TRACE) \
58 dbg_printf x; \
59 } \
60 while (0) \
61 __pragma(warning(pop))
62
63#define ARG_LOG(x) \
64 __pragma(warning(push)) __pragma(warning(disable : 4127)) do { \
65 if (ARG_ENABLE_LOG) \
66 dbg_printf x; \
67 } \
68 while (0) \
69 __pragma(warning(pop))
70#else
71#define ARG_TRACE(x) \
72 do { \
73 if (ARG_ENABLE_TRACE) \
74 dbg_printf x; \
75 } while (0)
76
77#define ARG_LOG(x) \
78 do { \
79 if (ARG_ENABLE_LOG) \
80 dbg_printf x; \
81 } while (0)
82#endif
83
84/*
85 * Rename a few generic names to unique names.
86 * They can be a problem for the platforms like NuttX, where
87 * the namespace is flat for everything including apps and libraries.
88 */
89#define xmalloc argtable3_xmalloc
90#define xcalloc argtable3_xcalloc
91#define xrealloc argtable3_xrealloc
92#define xfree argtable3_xfree
93
94extern void dbg_printf(const char* fmt, ...);
95extern void arg_set_panic(arg_panicfn* proc);
96extern void* xmalloc(size_t size);
97extern void* xcalloc(size_t count, size_t size);
98extern void* xrealloc(void* ptr, size_t size);
99extern void xfree(void* ptr);
100
102 void *k, *v;
103 unsigned int h;
105};
106
107typedef struct arg_hashtable {
108 unsigned int tablelength;
110 unsigned int entrycount;
111 unsigned int loadlimit;
112 unsigned int primeindex;
113 unsigned int (*hashfn)(const void* k);
114 int (*eqfn)(const void* k1, const void* k2);
116
125arg_hashtable_t* arg_hashtable_create(unsigned int minsize, unsigned int (*hashfn)(const void*), int (*eqfn)(const void*, const void*));
126
142void arg_hashtable_insert(arg_hashtable_t* h, void* k, void* v);
143
144#define ARG_DEFINE_HASHTABLE_INSERT(fnname, keytype, valuetype) \
145 int fnname(arg_hashtable_t* h, keytype* k, valuetype* v) { return arg_hashtable_insert(h, k, v); }
146
154void* arg_hashtable_search(arg_hashtable_t* h, const void* k);
155
156#define ARG_DEFINE_HASHTABLE_SEARCH(fnname, keytype, valuetype) \
157 valuetype* fnname(arg_hashtable_t* h, keytype* k) { return (valuetype*)(arg_hashtable_search(h, k)); }
158
165void arg_hashtable_remove(arg_hashtable_t* h, const void* k);
166
167#define ARG_DEFINE_HASHTABLE_REMOVE(fnname, keytype, valuetype) \
168 void fnname(arg_hashtable_t* h, keytype* k) { arg_hashtable_remove(h, k); }
169
177
190int arg_hashtable_change(arg_hashtable_t* h, void* k, void* v);
191
198void arg_hashtable_destroy(arg_hashtable_t* h, int free_values);
199
200typedef struct arg_hashtable_itr {
204 unsigned int index;
206
208
210
215
220
225
230
237
238#define ARG_DEFINE_HASHTABLE_ITERATOR_SEARCH(fnname, keytype) \
239 int fnname(arg_hashtable_itr_t* i, arg_hashtable_t* h, keytype* k) { return (arg_hashtable_iterator_search(i, h, k)); }
240
241#ifdef __cplusplus
242}
243#endif
244
245#endif
int arg_hashtable_itr_search(arg_hashtable_itr_t *itr, arg_hashtable_t *h, void *k)
Search and overwrite the supplied iterator, to point to the entry matching the supplied key.
Definition arg_hashtable.c:384
void arg_hashtable_destroy(arg_hashtable_t *h, int free_values)
Free the hash table and the memory allocated for each key-value pair.
Definition arg_hashtable.c:253
void arg_set_panic(arg_panicfn *proc)
Definition arg_utils.c:91
int arg_hashtable_change(arg_hashtable_t *h, void *k, void *v)
Definition arg_hashtable.c:410
#define xfree
Definition argtable3_private.h:92
#define xrealloc
Definition argtable3_private.h:91
struct arg_hashtable arg_hashtable_t
void * arg_hashtable_itr_value(arg_hashtable_itr_t *i)
Return the value of the (key,value) pair at the current position.
Definition arg_hashtable.c:314
int arg_hashtable_itr_remove(arg_hashtable_itr_t *itr)
Remove current element and advance the iterator to the next element.
Definition arg_hashtable.c:355
struct arg_hashtable_itr arg_hashtable_itr_t
#define xmalloc
Definition argtable3_private.h:89
int arg_hashtable_itr_advance(arg_hashtable_itr_t *itr)
Advance the iterator to the next element. Returns zero if advanced to end of table.
Definition arg_hashtable.c:318
@ ARG_ERR_BADINT
Definition argtable3_private.h:50
@ ARG_ERR_BADDOUBLE
Definition argtable3_private.h:50
@ ARG_ERR_BADDATE
Definition argtable3_private.h:50
@ ARG_ERR_OVERFLOW
Definition argtable3_private.h:50
@ ARG_ERR_MAXCOUNT
Definition argtable3_private.h:50
@ ARG_ERR_MINCOUNT
Definition argtable3_private.h:50
@ ARG_ERR_REGNOMATCH
Definition argtable3_private.h:50
void * arg_hashtable_itr_key(arg_hashtable_itr_t *i)
Return the value of the (key,value) pair at the current position.
Definition arg_hashtable.c:310
arg_hashtable_itr_t * arg_hashtable_itr_create(arg_hashtable_t *h)
Definition arg_hashtable.c:283
unsigned int arg_hashtable_count(arg_hashtable_t *h)
Return the number of keys in the hash table.
Definition arg_hashtable.c:179
arg_hashtable_t * arg_hashtable_create(unsigned int minsize, unsigned int(*hashfn)(const void *), int(*eqfn)(const void *, const void *))
Create a hash table.
Definition arg_hashtable.c:111
void arg_hashtable_itr_destroy(arg_hashtable_itr_t *itr)
Definition arg_hashtable.c:306
void arg_hashtable_remove(arg_hashtable_t *h, const void *k)
Remove the specified key from the hash table.
Definition arg_hashtable.c:223
void() arg_panicfn(const char *fmt,...)
Definition argtable3_private.h:52
void dbg_printf(const char *fmt,...)
Definition arg_utils.c:52
#define xcalloc
Definition argtable3_private.h:90
void * arg_hashtable_search(arg_hashtable_t *h, const void *k)
Search the specified key in the hash table.
Definition arg_hashtable.c:206
void arg_hashtable_insert(arg_hashtable_t *h, void *k, void *v)
This function will cause the table to expand if the insertion would take the ratio of entries to tabl...
Definition arg_hashtable.c:183
Definition argtable3_private.h:101
void * k
Definition argtable3_private.h:102
unsigned int h
Definition argtable3_private.h:103
void * v
Definition argtable3_private.h:102
struct arg_hashtable_entry * next
Definition argtable3_private.h:104
Definition argtable3_private.h:200
unsigned int index
Definition argtable3_private.h:204
struct arg_hashtable_entry * e
Definition argtable3_private.h:202
struct arg_hashtable_entry * parent
Definition argtable3_private.h:203
arg_hashtable_t * h
Definition argtable3_private.h:201
Definition argtable3_private.h:107
unsigned int loadlimit
Definition argtable3_private.h:111
int(* eqfn)(const void *k1, const void *k2)
Definition argtable3_private.h:114
unsigned int tablelength
Definition argtable3_private.h:108
unsigned int entrycount
Definition argtable3_private.h:110
unsigned int primeindex
Definition argtable3_private.h:112
struct arg_hashtable_entry ** table
Definition argtable3_private.h:109
unsigned int(* hashfn)(const void *k)
Definition argtable3_private.h:113
uint32_t size
Definition vsf_memfs.h:50
Generated from commit: vsfteam/vsf@c3767bf