Wed Jan 8 2020 09:49:48

Asterisk developer's documentation


hashtab.h
Go to the documentation of this file.
1 /*
2  * Asterisk -- An open source telephony toolkit.
3  *
4  * Copyright (C) 2006, Digium, Inc.
5  *
6  * Steve Murphy <murf@digium.com>
7  *
8  * See http://www.asterisk.org for more information about
9  * the Asterisk project. Please do not directly contact
10  * any of the maintainers of this project for assistance;
11  * the project provides a web site, mailing lists and IRC
12  * channels for your use.
13  *
14  * This program is free software, distributed under the terms of
15  * the GNU General Public License Version 2. See the LICENSE file
16  * at the top of the source tree.
17  */
18 #ifndef _ASTERISK_HASHTAB_H_
19 #define _ASTERISK_HASHTAB_H_
20 #define __USE_UNIX98 1 /* to get the MUTEX_RECURSIVE stuff */
21 
22 /*! \file
23  * \brief Generic (perhaps overly so) hashtable implementation
24  * \ref AstHash
25  */
26 
27 #include "asterisk/lock.h"
28 
29 /*! \page AstHash Hash Table support in Asterisk
30 
31 A hash table is a structure that allows for an exact-match search
32 in O(1) (or close to that) time.
33 
34 The method: given: a set of {key,val} pairs. (at a minimum).
35  given: a hash function, which, given a key,
36  will return an integer. Ideally, each key in the
37  set will have its own unique associated hash value.
38  This hash number will index into an array. "buckets"
39  are what the elements of this array are called. To
40  handle possible collisions in hash values, buckets can form a list.
41 
42 The key for a value must be contained in the value, or we won't
43 be able to find it in the bucket list.
44 
45 This implementation is pretty generic, because:
46 
47  1. The value and key are expected to be in a structure
48  (along with other data, perhaps) and it's address is a "void *".
49  2. The pointer to a compare function must be passed in at the
50  time of creation, and is stored in the hashtable.
51  3. The pointer to a resize function, which returns 1 if the
52  hash table is to be grown. A default routine is provided
53  if the pointer is NULL, and uses the java hashtable metric
54  of a 75% load factor.
55  4. The pointer to a "new size" function, which returns a preferable
56  new size for the hash table bucket array. By default, a function
57  is supplied which roughly doubles the size of the array, is provided.
58  This size should ideally be a prime number.
59  5. The hashing function pointer must also be supplied. This function
60  must be written by the user to access the keys in the objects being
61  stored. Some helper functions that use a simple "mult by prime, add
62  the next char", sort of string hash, or a simple modulus of the hash
63  table size for ints, is provided; the user can use these simple
64  algorithms to generate a hash, or implement any other algorithms they
65  wish.
66  6. Recently updated the hash routines to use Doubly-linked lists for buckets,
67  and added a doubly-linked list that threads thru every bucket in the table.
68  The list of all buckets is on the HashTab struct. The Traversal was modified
69  to go thru this list instead of searching the bucket array for buckets.
70  This also should make it safe to remove a bucket during the traversal.
71  Removal and destruction routines will work faster.
72 */
73 
75 {
76  const void *object; /*!< whatever it is we are storing in this table */
77  struct ast_hashtab_bucket *next; /*!< a DLL of buckets in hash collision */
78  struct ast_hashtab_bucket *prev; /*!< a DLL of buckets in hash collision */
79  struct ast_hashtab_bucket *tnext; /*!< a DLL of all the hash buckets for traversal */
80  struct ast_hashtab_bucket *tprev; /*!< a DLL of all the hash buckets for traversal */
81 };
82 
84 {
86  struct ast_hashtab_bucket *tlist; /*!< the head of a DLList of all the hashbuckets in the table (for traversal). */
87 
88  int (*compare) (const void *a, const void *b); /*!< a ptr to func that returns int, and take two void* ptrs, compares them,
89  rets -1 if a < b; rets 0 if a==b; rets 1 if a>b */
90  int (*newsize) (struct ast_hashtab *tab); /*!< a ptr to func that returns int, a new size for hash tab, based on curr_size */
91  int (*resize) (struct ast_hashtab *tab); /*!< a function to decide whether this hashtable should be resized now */
92  unsigned int (*hash) (const void *obj); /*!< a hash func ptr for this table. Given a raw ptr to an obj,
93  it calcs a hash.*/
94  int hash_tab_size; /*!< the size of the bucket array */
95  int hash_tab_elements; /*!< the number of objects currently stored in the table */
96  int largest_bucket_size; /*!< a stat on the health of the table */
97  int resize_count; /*!< a count of the number of times this table has been
98  resized */
99  int do_locking; /*!< if 1 use locks to guarantee safety of insertions/deletions */
100  /* this spot reserved for the proper lock storage */
101  ast_rwlock_t lock; /* is this as good as it sounds? */
102 };
103 
104 /*! \brief an iterator for traversing the buckets */
106 {
107  struct ast_hashtab *tab;
109 };
110 
111 
112 /* some standard, default routines for general use */
113 
114 /*!
115  * \brief Determines if the specified number is prime.
116  *
117  * \param num the number to test
118  * \retval 0 if the number is not prime
119  * \retval 1 if the number is prime
120  */
121 int ast_is_prime(int num);
122 
123 /*!
124  * \brief Compares two strings for equality.
125  *
126  * \param a a character string
127  * \param b a character string
128  * \retval 0 if the strings match
129  * \retval <0 if string a is less than string b
130  * \retval >0 if string a is greather than string b
131  */
132 int ast_hashtab_compare_strings(const void *a, const void *b);
133 
134 /*!
135  * \brief Compares two strings for equality, ignoring case.
136  *
137  * \param a a character string
138  * \param b a character string
139  * \retval 0 if the strings match
140  * \retval <0 if string a is less than string b
141  * \retval >0 if string a is greather than string b
142  */
143 int ast_hashtab_compare_strings_nocase(const void *a, const void *b);
144 
145 /*!
146  * \brief Compares two integers for equality.
147  *
148  * \param a an integer pointer (int *)
149  * \param b an integer pointer (int *)
150  * \retval 0 if the integers pointed to are equal
151  * \retval 1 if a is greater than b
152  * \retval -1 if a is less than b
153  */
154 int ast_hashtab_compare_ints(const void *a, const void *b);
155 
156 /*!
157  * \brief Compares two shorts for equality.
158  *
159  * \param a a short pointer (short *)
160  * \param b a short pointer (short *)
161  * \retval 0 if the shorts pointed to are equal
162  * \retval 1 if a is greater than b
163  * \retval -1 if a is less than b
164  */
165 int ast_hashtab_compare_shorts(const void *a, const void *b);
166 
167 /*!
168  * \brief Determines if a table resize should occur using the Java algorithm
169  * (if the table load factor is 75% or higher).
170  *
171  * \param tab the hash table to operate on
172  * \retval 0 if the table load factor is less than or equal to 75%
173  * \retval 1 if the table load factor is greater than 75%
174  */
175 int ast_hashtab_resize_java(struct ast_hashtab *tab);
176 
177 /*! \brief Causes a resize whenever the number of elements stored in the table
178  * exceeds the number of buckets in the table.
179  *
180  * \param tab the hash table to operate on
181  * \retval 0 if the number of elements in the table is less than or equal to
182  * the number of buckets
183  * \retval 1 if the number of elements in the table exceeds the number of
184  * buckets
185  */
186 int ast_hashtab_resize_tight(struct ast_hashtab *tab);
187 
188 /*!
189  * \brief Effectively disables resizing by always returning 0, regardless of
190  * of load factor.
191  *
192  * \param tab the hash table to operate on
193  * \return 0 is always returned
194  */
195 int ast_hashtab_resize_none(struct ast_hashtab *tab);
196 
197 /*! \brief Create a prime number roughly 2x the current table size */
198 int ast_hashtab_newsize_java(struct ast_hashtab *tab);
199 
200 /* not yet specified, probably will return 1.5x the current table size */
201 int ast_hashtab_newsize_tight(struct ast_hashtab *tab);
202 
203 /*! \brief always return current size -- no resizing */
204 int ast_hashtab_newsize_none(struct ast_hashtab *tab);
205 
206 /*!
207  * \brief Hashes a string to a number
208  *
209  * \param obj the string to hash
210  * \return Integer hash of the specified string
211  * \sa ast_hashtable_hash_string_nocase
212  * \sa ast_hashtab_hash_string_sax
213  * \note A modulus will be applied to the return value of this function
214  */
215 unsigned int ast_hashtab_hash_string(const void *obj);
216 
217 /*!
218  * \brief Hashes a string to a number ignoring case
219  *
220  * \param obj the string to hash
221  * \return Integer hash of the specified string
222  * \sa ast_hashtable_hash_string
223  * \sa ast_hashtab_hash_string_sax
224  * \note A modulus will be applied to the return value of this function
225  */
226 unsigned int ast_hashtab_hash_string_nocase(const void *obj);
227 
228 /*!
229  * \brief Hashes a string to a number using a modified Shift-And-XOR algorithm
230  *
231  * \param obj the string to hash
232  * \return Integer has of the specified string
233  * \sa ast_hastable_hash_string
234  * \sa ast_hastable_hash_string_nocase
235  */
236 unsigned int ast_hashtab_hash_string_sax(const void *obj);
237 
238 
239 unsigned int ast_hashtab_hash_int(const int num); /* right now, both these funcs are just result = num%modulus; */
240 
241 
242 unsigned int ast_hashtab_hash_short(const short num);
243 
244 
245 /*!
246  * \brief Create the hashtable list
247  * \param initial_buckets starting number of buckets
248  * \param compare a func ptr to compare two elements in the hash -- cannot be null
249  * \param resize a func ptr to decide if the table needs to be resized, a NULL ptr here will cause a default to be used
250  * \param newsize a func ptr that returns a new size of the array. A NULL will cause a default to be used
251  * \param hash a func ptr to do the hashing
252  * \param do_locking use locks to guarantee safety of iterators/insertion/deletion -- real simpleminded right now
253 */
254 #if (defined(MALLOC_DEBUG) && !defined(STANDALONE))
255 struct ast_hashtab * _ast_hashtab_create(int initial_buckets,
256  int (*compare)(const void *a, const void *b),
257  int (*resize)(struct ast_hashtab *),
258  int (*newsize)(struct ast_hashtab *tab),
259  unsigned int (*hash)(const void *obj),
260  int do_locking, const char *file, int lineno, const char *function);
261 #define ast_hashtab_create(a,b,c,d,e,f) _ast_hashtab_create(a,b,c,d,e,f,__FILE__,__LINE__,__PRETTY_FUNCTION__)
262 #else
263 struct ast_hashtab * ast_hashtab_create(int initial_buckets,
264  int (*compare)(const void *a, const void *b),
265  int (*resize)(struct ast_hashtab *),
266  int (*newsize)(struct ast_hashtab *tab),
267  unsigned int (*hash)(const void *obj),
268  int do_locking );
269 #endif
270 
271 /*!
272  * \brief This func will free the hash table and all its memory.
273  * \note It doesn't touch the objects stored in it, unless you
274  * specify a destroy func; it will call that func for each
275  * object in the hashtab, remove all the objects, and then
276  * free the hashtab itself. If no destroyfunc is specified
277  * then the routine will assume you will free it yourself.
278  * \param tab
279  * \param objdestroyfunc
280 */
281 void ast_hashtab_destroy( struct ast_hashtab *tab, void (*objdestroyfunc)(void *obj));
282 
283 
284 /*!
285  * \brief Insert without checking
286  * \param tab
287  * \param obj
288  *
289  * Normally, you'd insert "safely" by checking to see if the element is
290  * already there; in this case, you must already have checked. If an element
291  * is already in the hashtable, that matches this one, most likely this one
292  * will be found first.
293  * \note will force a resize if the resize func returns 1
294  * \retval 1 on success
295  * \retval 0 if there's a problem
296 */
297 #if (defined(MALLOC_DEBUG) && !defined(STANDALONE))
298 int _ast_hashtab_insert_immediate(struct ast_hashtab *tab, const void *obj, const char *file, int lineno, const char *func);
299 #define ast_hashtab_insert_immediate(a,b) _ast_hashtab_insert_immediate(a, b, __FILE__, __LINE__, __PRETTY_FUNCTION__)
300 #else
301 int ast_hashtab_insert_immediate(struct ast_hashtab *tab, const void *obj);
302 #endif
303 
304 /*!
305  * \brief Insert without checking, hashing or locking
306  * \param tab
307  * \param obj
308  * \param h hashed index value
309  *
310  * \note Will force a resize if the resize func returns 1
311  * \retval 1 on success
312  * \retval 0 if there's a problem
313 */
314 #if (defined(MALLOC_DEBUG) && !defined(STANDALONE))
315 int _ast_hashtab_insert_immediate_bucket(struct ast_hashtab *tab, const void *obj, unsigned int h, const char *file, int lineno, const char *func);
316 #define ast_hashtab_insert_immediate_bucket(a,b,c) _ast_hashtab_insert_immediate_bucket(a, b, c, __FILE__, __LINE__, __PRETTY_FUNCTION__)
317 #else
318 int ast_hashtab_insert_immediate_bucket(struct ast_hashtab *tab, const void *obj, unsigned int h);
319 #endif
320 
321 /*!
322  * \brief Check and insert new object only if it is not there.
323  * \note Will force a resize if the resize func returns 1
324  * \retval 1 on success
325  * \retval 0 if there's a problem, or it's already there.
326 */
327 #if (defined(MALLOC_DEBUG) && !defined(STANDALONE))
328 int _ast_hashtab_insert_safe(struct ast_hashtab *tab, const void *obj, const char *file, int lineno, const char *func);
329 #define ast_hashtab_insert_safe(a,b) _ast_hashtab_insert_safe(a,b,__FILE__, __LINE__, __PRETTY_FUNCTION__)
330 #else
331 int ast_hashtab_insert_safe(struct ast_hashtab *tab, const void *obj);
332 #endif
333 
334 /*!
335  * \brief Lookup this object in the hash table.
336  * \param tab
337  * \param obj
338  * \retval a ptr if found
339  * \retval NULL if not found
340 */
341 void * ast_hashtab_lookup(struct ast_hashtab *tab, const void *obj);
342 
343 /*!
344  * \brief Use this if have the hash val for the object
345  * \note This and avoid the recalc of the hash (the modulus (table_size) is not applied)
346 */
347 void * ast_hashtab_lookup_with_hash(struct ast_hashtab *tab, const void *obj, unsigned int hashval);
348 
349 /*!
350  * \brief Similar to ast_hashtab_lookup but sets h to the key hash value if the lookup fails.
351  * \note This has the modulus applied, and will not be useful for long term storage if the table is resizable.
352 */
353 void * ast_hashtab_lookup_bucket(struct ast_hashtab *tab, const void *obj, unsigned int *h);
354 
355 /*! \brief Returns key stats for the table */
356 void ast_hashtab_get_stats( struct ast_hashtab *tab, int *biggest_bucket_size, int *resize_count, int *num_objects, int *num_buckets);
357 
358 /*! \brief Returns the number of elements stored in the hashtab */
359 int ast_hashtab_size( struct ast_hashtab *tab);
360 
361 /*! \brief Returns the size of the bucket array in the hashtab */
362 int ast_hashtab_capacity( struct ast_hashtab *tab);
363 
364 /*! \brief Return a copy of the hash table */
365 #if (defined(MALLOC_DEBUG) && !defined(STANDALONE))
366 struct ast_hashtab *_ast_hashtab_dup(struct ast_hashtab *tab, void *(*obj_dup_func)(const void *obj), const char *file, int lineno, const char *func);
367 #define ast_hashtab_dup(a,b) _ast_hashtab_dup(a,b,__FILE__,__LINE__,__PRETTY_FUNCTION__)
368 #else
369 struct ast_hashtab *ast_hashtab_dup(struct ast_hashtab *tab, void *(*obj_dup_func)(const void *obj));
370 #endif
371 
372 /*! \brief Gives an iterator to hastable */
373 #if (defined(MALLOC_DEBUG) && !defined(STANDALONE))
374 struct ast_hashtab_iter *_ast_hashtab_start_traversal(struct ast_hashtab *tab, const char *file, int lineno, const char *func);
375 #define ast_hashtab_start_traversal(a) _ast_hashtab_start_traversal(a,__FILE__,__LINE__,__PRETTY_FUNCTION__)
376 #else
378 #endif
379 
380 /*! \brief end the traversal, free the iterator, unlock if necc. */
382 
383 /*! \brief Gets the next object in the list, advances iter one step returns null on end of traversal */
384 void *ast_hashtab_next(struct ast_hashtab_iter *it);
385 
386 /*! \brief Looks up the object, removes the corresponding bucket */
387 void *ast_hashtab_remove_object_via_lookup(struct ast_hashtab *tab, void *obj);
388 
389 /*! \brief Hash the object and then compare ptrs in bucket list instead of
390  calling the compare routine, will remove the bucket */
391 void *ast_hashtab_remove_this_object(struct ast_hashtab *tab, void *obj);
392 
393 /* ------------------ */
394 /* for lock-enabled traversals with ability to remove an object during the traversal*/
395 /* ------------------ */
396 
397 /*! \brief Gives an iterator to hastable */
398 #if (defined(MALLOC_DEBUG) && !defined(STANDALONE))
399 struct ast_hashtab_iter *_ast_hashtab_start_write_traversal(struct ast_hashtab *tab, const char *file, int lineno, const char *func);
400 #define ast_hashtab_start_write_traversal(a) _ast_hashtab_start_write_traversal(a,__FILE__,__LINE__,__PRETTY_FUNCTION__)
401 #else
403 #endif
404 
405 /*! \brief Looks up the object, removes the corresponding bucket */
406 void *ast_hashtab_remove_object_via_lookup_nolock(struct ast_hashtab *tab, void *obj);
407 
408 /*! \brief Hash the object and then compare ptrs in bucket list instead of
409  calling the compare routine, will remove the bucket */
410 void *ast_hashtab_remove_this_object_nolock(struct ast_hashtab *tab, void *obj);
411 
412 /* ------------------ */
413 /* ------------------ */
414 
415 /* user-controlled hashtab locking. Create a hashtab without locking, then call the
416  following locking routines yourself to lock the table between threads. */
417 
418 /*! \brief Call this after you create the table to init the lock */
419 void ast_hashtab_initlock(struct ast_hashtab *tab);
420 /*! \brief Request a write-lock on the table. */
421 void ast_hashtab_wrlock(struct ast_hashtab *tab);
422 /*! \brief Request a read-lock on the table -- don't change anything! */
423 void ast_hashtab_rdlock(struct ast_hashtab *tab);
424 /*! \brief release a read- or write- lock. */
425 void ast_hashtab_unlock(struct ast_hashtab *tab);
426 /*! \brief Call this before you destroy the table. */
427 void ast_hashtab_destroylock(struct ast_hashtab *tab);
428 
429 
430 #endif
struct ast_hashtab_bucket * tnext
Definition: hashtab.h:79
int ast_hashtab_resize_none(struct ast_hashtab *tab)
Effectively disables resizing by always returning 0, regardless of of load factor.
Definition: hashtab.c:100
int ast_hashtab_capacity(struct ast_hashtab *tab)
Returns the size of the bucket array in the hashtab.
Definition: hashtab.c:631
Asterisk locking-related definitions:
int ast_hashtab_compare_strings_nocase(const void *a, const void *b)
Compares two strings for equality, ignoring case.
Definition: hashtab.c:61
void * ast_hashtab_lookup(struct ast_hashtab *tab, const void *obj)
Lookup this object in the hash table.
Definition: hashtab.c:534
int ast_hashtab_newsize_java(struct ast_hashtab *tab)
Create a prime number roughly 2x the current table size.
Definition: hashtab.c:131
int hash_tab_size
Definition: hashtab.h:94
void * ast_hashtab_remove_this_object_nolock(struct ast_hashtab *tab, void *obj)
Hash the object and then compare ptrs in bucket list instead of calling the compare routine...
Definition: hashtab.c:880
int largest_bucket_size
Definition: hashtab.h:96
void ast_hashtab_destroylock(struct ast_hashtab *tab)
Call this before you destroy the table.
Definition: hashtab.c:378
ast_rwlock_t lock
Definition: hashtab.h:101
int(* resize)(struct ast_hashtab *tab)
Definition: hashtab.h:91
int ast_hashtab_newsize_none(struct ast_hashtab *tab)
always return current size – no resizing
Definition: hashtab.c:152
struct ast_hashtab_bucket * tprev
Definition: hashtab.h:80
void * ast_hashtab_next(struct ast_hashtab_iter *it)
Gets the next object in the list, advances iter one step returns null on end of traversal.
Definition: hashtab.c:753
struct ast_hashtab_iter * ast_hashtab_start_write_traversal(struct ast_hashtab *tab)
Gives an iterator to hastable.
Definition: hashtab.c:723
int resize_count
Definition: hashtab.h:97
int ast_hashtab_resize_tight(struct ast_hashtab *tab)
Causes a resize whenever the number of elements stored in the table exceeds the number of buckets in ...
Definition: hashtab.c:95
struct ast_hashtab_iter * ast_hashtab_start_traversal(struct ast_hashtab *tab)
Gives an iterator to hastable.
Definition: hashtab.c:696
int ast_hashtab_insert_immediate_bucket(struct ast_hashtab *tab, const void *obj, unsigned int h)
Insert without checking, hashing or locking.
Definition: hashtab.c:461
struct ast_hashtab_bucket * prev
Definition: hashtab.h:78
struct ast_hashtab * ast_hashtab_dup(struct ast_hashtab *tab, void *(*obj_dup_func)(const void *obj))
Return a copy of the hash table.
Definition: hashtab.c:280
int ast_hashtab_compare_ints(const void *a, const void *b)
Compares two integers for equality.
Definition: hashtab.c:66
int ast_hashtab_resize_java(struct ast_hashtab *tab)
Determines if a table resize should occur using the Java algorithm (if the table load factor is 75% o...
Definition: hashtab.c:88
struct ast_hashtab_bucket * next
Definition: hashtab.h:108
void * ast_hashtab_remove_object_via_lookup_nolock(struct ast_hashtab *tab, void *obj)
Looks up the object, removes the corresponding bucket.
Definition: hashtab.c:835
int(* compare)(const void *a, const void *b)
Definition: hashtab.h:88
int do_locking
Definition: hashtab.h:99
unsigned int ast_hashtab_hash_string_sax(const void *obj)
Hashes a string to a number using a modified Shift-And-XOR algorithm.
Definition: hashtab.c:174
int ast_hashtab_insert_immediate(struct ast_hashtab *tab, const void *obj)
Insert without checking.
Definition: hashtab.c:432
struct ast_hashtab * ast_hashtab_create(int initial_buckets, int(*compare)(const void *a, const void *b), int(*resize)(struct ast_hashtab *), int(*newsize)(struct ast_hashtab *tab), unsigned int(*hash)(const void *obj), int do_locking)
Create the hashtable list.
Definition: hashtab.c:226
void ast_hashtab_end_traversal(struct ast_hashtab_iter *it)
end the traversal, free the iterator, unlock if necc.
Definition: hashtab.c:746
struct ast_hashtab_bucket ** array
Definition: hashtab.h:85
int(* newsize)(struct ast_hashtab *tab)
Definition: hashtab.h:90
struct ast_hashtab * tab
Definition: hashtab.h:107
void * ast_hashtab_remove_object_via_lookup(struct ast_hashtab *tab, void *obj)
Looks up the object, removes the corresponding bucket.
Definition: hashtab.c:816
unsigned int(* hash)(const void *obj)
Definition: hashtab.h:92
int ast_hashtab_compare_shorts(const void *a, const void *b)
Compares two shorts for equality.
Definition: hashtab.c:77
struct ast_hashtab_bucket * tlist
Definition: hashtab.h:86
void ast_hashtab_rdlock(struct ast_hashtab *tab)
Request a read-lock on the table – don&#39;t change anything!
Definition: hashtab.c:368
an iterator for traversing the buckets
Definition: hashtab.h:105
void ast_hashtab_wrlock(struct ast_hashtab *tab)
Request a write-lock on the table.
Definition: hashtab.c:363
int ast_hashtab_newsize_tight(struct ast_hashtab *tab)
Definition: hashtab.c:141
unsigned int ast_hashtab_hash_string(const void *obj)
Hashes a string to a number.
Definition: hashtab.c:157
int ast_hashtab_compare_strings(const void *a, const void *b)
Compares two strings for equality.
Definition: hashtab.c:56
unsigned int ast_hashtab_hash_int(const int num)
Definition: hashtab.c:209
const void * object
Definition: hashtab.h:76
void * ast_hashtab_lookup_bucket(struct ast_hashtab *tab, const void *obj, unsigned int *h)
Similar to ast_hashtab_lookup but sets h to the key hash value if the lookup fails.
Definition: hashtab.c:579
Structure for rwlock and tracking information.
Definition: lock.h:133
struct ast_hashtab_bucket * next
Definition: hashtab.h:77
int ast_hashtab_insert_safe(struct ast_hashtab *tab, const void *obj)
Check and insert new object only if it is not there.
Definition: hashtab.c:503
static int compare(const char *text, const char *template)
void ast_hashtab_initlock(struct ast_hashtab *tab)
Call this after you create the table to init the lock.
Definition: hashtab.c:373
void * ast_hashtab_lookup_with_hash(struct ast_hashtab *tab, const void *obj, unsigned int hashval)
Use this if have the hash val for the object.
Definition: hashtab.c:557
unsigned int ast_hashtab_hash_string_nocase(const void *obj)
Hashes a string to a number ignoring case.
Definition: hashtab.c:185
int ast_hashtab_size(struct ast_hashtab *tab)
Returns the number of elements stored in the hashtab.
Definition: hashtab.c:625
void ast_hashtab_get_stats(struct ast_hashtab *tab, int *biggest_bucket_size, int *resize_count, int *num_objects, int *num_buckets)
Returns key stats for the table.
Definition: hashtab.c:611
unsigned int ast_hashtab_hash_short(const short num)
Definition: hashtab.c:214
int ast_is_prime(int num)
Determines if the specified number is prime.
Definition: hashtab.c:105
void ast_hashtab_unlock(struct ast_hashtab *tab)
release a read- or write- lock.
Definition: hashtab.c:383
int hash_tab_elements
Definition: hashtab.h:95
void ast_hashtab_destroy(struct ast_hashtab *tab, void(*objdestroyfunc)(void *obj))
This func will free the hash table and all its memory.
Definition: hashtab.c:388
void * ast_hashtab_remove_this_object(struct ast_hashtab *tab, void *obj)
Hash the object and then compare ptrs in bucket list instead of calling the compare routine...
Definition: hashtab.c:859