18 #ifndef _ASTERISK_HASHTAB_H_ 19 #define _ASTERISK_HASHTAB_H_ 20 #define __USE_UNIX98 1 92 unsigned int (*
hash) (
const void *obj);
255 int (*
compare)(
const void *
a,
const void *
b),
258 unsigned int (*
hash)(
const void *obj),
260 const char *
file,
int lineno,
const char *
function);
261 #define ast_hashtab_create(initial_buckets, compare, resize, newsize, hash, do_locking) \ 262 _ast_hashtab_create(initial_buckets, compare, resize, newsize, hash, do_locking, __FILE__, __LINE__, __PRETTY_FUNCTION__) 291 #define ast_hashtab_insert_immediate(tab, obj) \ 292 _ast_hashtab_insert_immediate(tab, obj, __FILE__, __LINE__, __PRETTY_FUNCTION__) 305 #define ast_hashtab_insert_immediate_bucket(tab, obj, h) \ 306 _ast_hashtab_insert_immediate_bucket(tab, obj, h, __FILE__, __LINE__, __PRETTY_FUNCTION__) 315 #define ast_hashtab_insert_safe(tab, obj) \ 316 _ast_hashtab_insert_safe(tab, obj, __FILE__, __LINE__, __PRETTY_FUNCTION__) 350 #define ast_hashtab_dup(tab, obj_dup_func) \ 351 _ast_hashtab_dup(tab, obj_dup_func, __FILE__, __LINE__, __PRETTY_FUNCTION__) 355 #define ast_hashtab_start_traversal(tab) \ 356 _ast_hashtab_start_traversal(tab, __FILE__, __LINE__, __PRETTY_FUNCTION__) 377 #define ast_hashtab_start_write_traversal(tab) \ 378 _ast_hashtab_start_write_traversal(tab, __FILE__, __LINE__, __PRETTY_FUNCTION__) struct ast_hashtab_bucket * tnext
int ast_hashtab_resize_none(struct ast_hashtab *tab)
Effectively disables resizing by always returning 0, regardless of of load factor.
int ast_hashtab_capacity(struct ast_hashtab *tab)
Returns the size of the bucket array in the hashtab.
Asterisk locking-related definitions:
int ast_hashtab_compare_strings_nocase(const void *a, const void *b)
Compares two strings for equality, ignoring case.
void * ast_hashtab_lookup(struct ast_hashtab *tab, const void *obj)
Lookup this object in the hash table.
int ast_hashtab_newsize_java(struct ast_hashtab *tab)
Create a prime number roughly 2x the current table size.
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...
void ast_hashtab_destroylock(struct ast_hashtab *tab)
Call this before you destroy the table.
int ast_hashtab_newsize_none(struct ast_hashtab *tab)
always return current size – no resizing
struct ast_hashtab_bucket * tprev
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)
Return a copy of the hash table.
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.
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 ...
struct ast_hashtab_bucket * prev
int ast_hashtab_compare_ints(const void *a, const void *b)
Compares two integers for equality.
struct ast_hashtab_iter * _ast_hashtab_start_traversal(struct ast_hashtab *tab, const char *file, int lineno, const char *func)
Gives an iterator to hastable.
int _ast_hashtab_insert_immediate_bucket(struct ast_hashtab *tab, const void *obj, unsigned int h, const char *file, int lineno, const char *func)
Insert without checking, hashing or locking.
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...
struct ast_hashtab_bucket * next
void * ast_hashtab_remove_object_via_lookup_nolock(struct ast_hashtab *tab, void *obj)
Looks up the object, removes the corresponding bucket.
unsigned int ast_hashtab_hash_string_sax(const void *obj)
Hashes a string to a number using a modified Shift-And-XOR algorithm.
void ast_hashtab_end_traversal(struct ast_hashtab_iter *it)
end the traversal, free the iterator, unlock if necc.
struct ast_hashtab_bucket ** array
void * ast_hashtab_remove_object_via_lookup(struct ast_hashtab *tab, void *obj)
Looks up the object, removes the corresponding bucket.
int ast_hashtab_compare_shorts(const void *a, const void *b)
Compares two shorts for equality.
int(* resize)(struct ast_hashtab *tab)
struct ast_hashtab_bucket * tlist
void ast_hashtab_rdlock(struct ast_hashtab *tab)
Request a read-lock on the table – don't change anything!
an iterator for traversing the buckets
void ast_hashtab_wrlock(struct ast_hashtab *tab)
Request a write-lock on the table.
int ast_hashtab_newsize_tight(struct ast_hashtab *tab)
unsigned int ast_hashtab_hash_string(const void *obj)
Hashes a string to a number.
unsigned int(* hash)(const void *obj)
int ast_hashtab_compare_strings(const void *a, const void *b)
Compares two strings for equality.
struct ast_hashtab_iter * _ast_hashtab_start_write_traversal(struct ast_hashtab *tab, const char *file, int lineno, const char *func)
Gives an iterator to hastable.
unsigned int ast_hashtab_hash_int(const int num)
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.
Structure for rwlock and tracking information.
struct ast_hashtab_bucket * next
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.
int _ast_hashtab_insert_safe(struct ast_hashtab *tab, const void *obj, const char *file, int lineno, const char *func)
Check and insert new object only if it is not there.
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.
unsigned int ast_hashtab_hash_string_nocase(const void *obj)
Hashes a string to a number ignoring case.
int(* newsize)(struct ast_hashtab *tab)
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, const char *file, int lineno, const char *function)
Create the hashtable list.
int ast_hashtab_size(struct ast_hashtab *tab)
Returns the number of elements stored in the hashtab.
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.
unsigned int ast_hashtab_hash_short(const short num)
int ast_is_prime(int num)
Determines if the specified number is prime.
int _ast_hashtab_insert_immediate(struct ast_hashtab *tab, const void *obj, const char *file, int lineno, const char *func)
Insert without checking.
void ast_hashtab_unlock(struct ast_hashtab *tab)
release a read- or write- lock.
void ast_hashtab_destroy(struct ast_hashtab *tab, void(*objdestroyfunc)(void *obj))
This func will free the hash table and all its memory.
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...