46 #if (defined(MALLOC_DEBUG) && !defined(STANDALONE))
47 static void _ast_hashtab_resize(
struct ast_hashtab *tab,
const char *file,
int lineno,
const char *func);
48 #define ast_hashtab_resize(a) _ast_hashtab_resize(a,__FILE__, __LINE__, __PRETTY_FUNCTION__)
63 return strcasecmp(a, b);
68 int ai = *((
int *) a);
69 int bi = *((
int *) b);
79 short as = *((
short *) a);
80 short bs = *((
short *) b);
92 return (loadfactor > 0.75);
116 while (tnum < limit) {
159 unsigned char *
str = (
unsigned char *) obj;
162 for (total = 0; *
str; str++) {
163 unsigned int tmp =
total;
169 total += ((
unsigned int)(*str));
176 const unsigned char *
str = obj;
177 unsigned int total = 0, c = 0;
180 total ^= (total << 5) + (total >> 2) + (total << 10) + c;
187 const unsigned char *
str = obj;
190 for (total = 0; *
str; str++) {
191 unsigned int tmp =
total;
192 unsigned int charval = toupper(*str);
221 #if (defined(MALLOC_DEBUG) && !defined(STANDALONE))
226 (
int initial_buckets,
227 int (*
compare)(
const void *a,
const void *b),
230 unsigned int (*
hash)(
const void *obj),
232 #
if (defined(MALLOC_DEBUG) && !defined(STANDALONE))
233 ,
const char *file,
int lineno,
const char *
function
239 #if (defined(MALLOC_DEBUG) && !defined(STANDALONE))
240 if (!(ht =
__ast_calloc(1,
sizeof(*ht), file, lineno,
function)))
249 #if (defined(MALLOC_DEBUG) && !defined(STANDALONE))
277 #if (defined(MALLOC_DEBUG) && !defined(STANDALONE))
278 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)
290 #
if (defined(MALLOC_DEBUG) && !defined(STANDALONE))
316 void *newobj = (*obj_dup_func)(b->
object);
318 #if (defined(MALLOC_DEBUG) && !defined(STANDALONE))
319 _ast_hashtab_insert_immediate_bucket(ht, newobj, i, file, lineno, func);
350 (*head)->
tprev = item;
404 if (t->
object && objdestroyfunc) {
408 (*objdestroyfunc)((
void *) t->
object);
417 tab->
array[i] = NULL;
429 #if (defined(MALLOC_DEBUG) && !defined(STANDALONE))
430 int _ast_hashtab_insert_immediate(
struct ast_hashtab *tab,
const void *obj,
const char *file,
int lineno,
const char *func)
446 #if (defined(MALLOC_DEBUG) && !defined(STANDALONE))
447 res = _ast_hashtab_insert_immediate_bucket(tab, obj, h, file, lineno, func);
458 #if (defined(MALLOC_DEBUG) && !defined(STANDALONE))
459 int _ast_hashtab_insert_immediate_bucket(
struct ast_hashtab *tab,
const void *obj,
unsigned int h,
const char *file,
int lineno,
const char *func)
470 for (c = 0, b = tab->
array[h]; b; b= b->
next)
477 #
if (defined(MALLOC_DEBUG) && !defined(STANDALONE))
500 #if (defined(MALLOC_DEBUG) && !defined(STANDALONE))
501 int _ast_hashtab_insert_safe(
struct ast_hashtab *tab,
const void *obj,
const char *file,
int lineno,
const char *func)
516 #if (defined(MALLOC_DEBUG) && !defined(STANDALONE))
517 int ret2 = _ast_hashtab_insert_immediate_bucket(tab, obj, bucket, file, lineno, func);
601 for (b = tab->
array[h]; b; b = b->
next) {
639 #if (defined(MALLOC_DEBUG) && !defined(STANDALONE))
640 static void _ast_hashtab_resize(
struct ast_hashtab *tab,
const char *file,
int lineno,
const char *func)
647 int newsize = (*tab->
newsize)(tab), i, c;
662 #
if (defined(MALLOC_DEBUG) && !defined(STANDALONE))
675 for (b = tab->
tlist; b; b = bn) {
686 for (c = 0, b = tab->
array[i]; b; b = b->
next)
693 #if (defined(MALLOC_DEBUG) && !defined(STANDALONE))
703 #
if (defined(MALLOC_DEBUG) && !defined(STANDALONE))
720 #if (defined(MALLOC_DEBUG) && !defined(STANDALONE))
721 struct ast_hashtab_iter *_ast_hashtab_start_write_traversal(
struct ast_hashtab *tab,
const char *file,
int lineno,
const char *func)
730 #
if (defined(MALLOC_DEBUG) && !defined(STANDALONE))
758 if (it && it->
next) {
761 return (
void *) retval->
object;
790 for (c2 = 0, b2 = tab->
tlist; b2; b2 = b2->
tnext) {
794 printf(
"Hey! we didn't delete right! there are %d elements in the list, and we expected %d\n",
797 for (c2 = 0, b2 = tab->
tlist; b2; b2 = b2->
tnext) {
798 unsigned int obj3 = (
unsigned long) obj2;
799 unsigned int b3 = (
unsigned long) b;
801 printf(
"Hey-- you've still got a bucket pointing at ht_element %x\n", obj3);
803 printf(
"Hey-- you've still got a bucket with next ptr pointing to deleted bucket %x\n", b3);
805 printf(
"Hey-- you've still got a bucket with prev ptr pointing to deleted bucket %x\n", b3);
807 printf(
"Hey-- you've still got a bucket with tprev ptr pointing to deleted bucket %x\n", b3);
809 printf(
"Hey-- you've still got a bucket with tnext ptr pointing to deleted bucket %x\n", b3);
813 return (
void *) obj2;
845 for (b = tab->
array[h]; b; b = b->
next) {
852 return (
void *) obj2;
892 for (b = tab->
array[h]; b; b = b->
next) {
898 return (
void *) obj2;
#define ast_rwlock_rdlock(a)
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:
Asterisk main include file. File version handling, generic pbx functions.
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...
#define ast_rwlock_destroy(rwlock)
void ast_hashtab_destroylock(struct ast_hashtab *tab)
Call this before you destroy the table.
int(* resize)(struct ast_hashtab *tab)
int ast_hashtab_newsize_none(struct ast_hashtab *tab)
always return current size – no resizing
struct ast_hashtab_bucket * tprev
Generic (perhaps overly so) hashtable implementation Hash Table support in Asterisk.
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.
struct ast_hashtab_iter * ast_hashtab_start_write_traversal(struct ast_hashtab *tab)
Gives an iterator to hastable.
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 ...
void * __ast_calloc(size_t nmemb, size_t size, const char *file, int lineno, const char *func)
struct ast_hashtab_iter * ast_hashtab_start_traversal(struct ast_hashtab *tab)
Gives an iterator to hastable.
int ast_hashtab_insert_immediate_bucket(struct ast_hashtab *tab, const void *obj, unsigned int h)
Insert without checking, hashing or locking.
struct ast_hashtab_bucket * prev
Definitions to aid in the use of thread local storage.
struct ast_hashtab * ast_hashtab_dup(struct ast_hashtab *tab, void *(*obj_dup_func)(const void *obj))
Return a copy of the hash table.
int ast_hashtab_compare_ints(const void *a, const void *b)
Compares two integers for equality.
#define ast_rwlock_unlock(a)
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
static void * ast_hashtab_lookup_internal(struct ast_hashtab *tab, const void *obj, unsigned int h)
void * ast_hashtab_remove_object_via_lookup_nolock(struct ast_hashtab *tab, void *obj)
Looks up the object, removes the corresponding bucket.
int(* compare)(const void *a, const void *b)
static void ast_hashtab_resize(struct ast_hashtab *tab)
unsigned int ast_hashtab_hash_string_sax(const void *obj)
Hashes a string to a number using a modified Shift-And-XOR algorithm.
General Asterisk PBX channel definitions.
Asterisk internal frame definitions.
int ast_hashtab_insert_immediate(struct ast_hashtab *tab, const void *obj)
Insert without checking.
A set of macros to manage forward-linked lists.
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.
void ast_hashtab_end_traversal(struct ast_hashtab_iter *it)
end the traversal, free the iterator, unlock if necc.
struct ast_hashtab_bucket ** array
int(* newsize)(struct ast_hashtab *tab)
static void tlist_del_item(struct ast_hashtab_bucket **head, struct ast_hashtab_bucket *item)
void * ast_hashtab_remove_object_via_lookup(struct ast_hashtab *tab, void *obj)
Looks up the object, removes the corresponding bucket.
unsigned int(* hash)(const void *obj)
#define ast_rwlock_init(rwlock)
wrapper for rwlock with tracking enabled
int ast_hashtab_compare_shorts(const void *a, const void *b)
Compares two shorts for equality.
static void tlist_add_head(struct ast_hashtab_bucket **head, struct ast_hashtab_bucket *item)
struct ast_hashtab_bucket * tlist
static void * ast_hashtab_remove_object_internal(struct ast_hashtab *tab, struct ast_hashtab_bucket *b, int h)
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.
if(yyss+yystacksize-1<=yyssp)
int ast_hashtab_compare_strings(const void *a, const void *b)
Compares two strings for equality.
#define ast_rwlock_wrlock(a)
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.
Standard Command Line Interface.
struct ast_hashtab_bucket * next
int ast_hashtab_insert_safe(struct ast_hashtab *tab, const void *obj)
Check and insert new object only if it is not there.
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.
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.
Handy terminal functions for vt* terms.
unsigned int ast_hashtab_hash_string_nocase(const void *obj)
Hashes a string to a number ignoring case.
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.
void ast_hashtab_unlock(struct ast_hashtab *tab)
release a read- or write- lock.
#define ASTERISK_FILE_VERSION(file, version)
Register/unregister a source code file with the core.
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...