Trailing whitespace, minor coding guideline fixes, and start beefing up the

hashtab documentation a bit.


git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@177884 65c4cc65-6c06-0410-ace0-fbb531ad65f3
1.6.2
Sean Bright 17 years ago
parent 7dc56a0c27
commit 935185ce8a

@ -108,47 +108,87 @@ struct ast_hashtab_iter
/* some standard, default routines for general use */
/*! \brief For sizing the hash table, tells if num is prime or not */
/*!
* \brief Determines if the specified number is prime.
*
* \param num the number to test
* \retval 0 if the number is not prime
* \retval 1 if the number is prime
*/
int ast_is_prime(int num);
/*!
* \brief assumes a and b are char *
* \return 0 if they match
*/
* \brief Compares two strings for equality.
*
* \param a a character string
* \param b a character string
* \retval 0 if the strings match
* \retval <0 if string a is less than string b
* \retval >0 if string a is greather than string b
*/
int ast_hashtab_compare_strings(const void *a, const void *b);
/*!
* \brief assumes a & b are strings
* \return 0 if they match (strcasecmp)
*/
* \brief Compares two strings for equality, ignoring case.
*
* \param a a character string
* \param b a character string
* \retval 0 if the strings match
* \retval <0 if string a is less than string b
* \retval >0 if string a is greather than string b
*/
int ast_hashtab_compare_strings_nocase(const void *a, const void *b);
/*!
* \brief assumes a & b are int *
* \retval 0 if match
* \retval 1 a > b
* \retval -1 a < b
*/
* \brief Compares two integers for equality.
*
* \param a an integer pointer (int *)
* \param b an integer pointer (int *)
* \retval 0 if the integers pointed to are equal
* \retval 1 if a is greater than b
* \retval -1 if a is less than b
*/
int ast_hashtab_compare_ints(const void *a, const void *b);
/*!
* \brief assumes a & b are short *
* \retval 0 if match
* \retval 1 a > b
* \retval -1 a < b
*/
* \brief Compares two shorts for equality.
*
* \param a a short pointer (short *)
* \param b a short pointer (short *)
* \retval 0 if the shorts pointed to are equal
* \retval 1 if a is greater than b
* \retval -1 if a is less than b
*/
int ast_hashtab_compare_shorts(const void *a, const void *b);
/*!
* \brief determine if resize should occur
* \returns 1 if the table is 75% full or more
*/
* \brief Determines if a table resize should occur using the Java algorithm
* (if the table load factor is 75% or higher).
*
* \param tab the hash table to operate on
* \retval 0 if the table load factor is less than or equal to 75%
* \retval 1 if the table load factor is greater than 75%
*/
int ast_hashtab_resize_java(struct ast_hashtab *tab);
/*! \brief no resizing; always return 0 */
/*! \brief Causes a resize whenever the number of elements stored in the table
* exceeds the number of buckets in the table.
*
* \param tab the hash table to operate on
* \retval 0 if the number of elements in the table is less than or equal to
* the number of buckets
* \retval 1 if the number of elements in the table exceeds the number of
* buckets
*/
int ast_hashtab_resize_tight(struct ast_hashtab *tab);
/*! \brief no resizing; always return 0 */
/*!
* \brief Effectively disables resizing by always returning 0, regardless of
* of load factor.
*
* \param tab the hash table to operate on
* \return 0 is always returned
*/
int ast_hashtab_resize_none(struct ast_hashtab *tab);
/*! \brief Create a prime number roughly 2x the current table size */
@ -162,16 +202,35 @@ int ast_hashtab_newsize_none(struct ast_hashtab *tab);
/*!
* \brief Hashes a string to a number
* \param obj
* \note A modulus is applied so it in the range 0 to mod-1
*/
*
* \param obj the string to hash
* \return Integer hash of the specified string
* \sa ast_hashtable_hash_string_nocase
* \sa ast_hashtab_hash_string_sax
* \note A modulus will be applied to the return value of this function
*/
unsigned int ast_hashtab_hash_string(const void *obj);
/*! \brief Upperases each char before using them for a hash */
/*!
* \brief Hashes a string to a number ignoring case
*
* \param obj the string to hash
* \return Integer hash of the specified string
* \sa ast_hashtable_hash_string
* \sa ast_hashtab_hash_string_sax
* \note A modulus will be applied to the return value of this function
*/
unsigned int ast_hashtab_hash_string_nocase(const void *obj);
unsigned int ast_hashtab_hash_string_sax(const void *obj); /* from Josh */
/*!
* \brief Hashes a string to a number using a modified Shift-And-XOR algorithm
*
* \param obj the string to hash
* \return Integer has of the specified string
* \sa ast_hastable_hash_string
* \sa ast_hastable_hash_string_nocase
*/
unsigned int ast_hashtab_hash_string_sax(const void *obj);
unsigned int ast_hashtab_hash_int(const int num); /* right now, both these funcs are just result = num%modulus; */

@ -38,7 +38,7 @@ ASTERISK_FILE_VERSION(__FILE__, "$Revision$")
#include "asterisk/linkedlists.h"
#include "asterisk/hashtab.h"
static void ast_hashtab_resize( struct ast_hashtab *tab);
static void ast_hashtab_resize(struct ast_hashtab *tab);
static void *ast_hashtab_lookup_internal(struct ast_hashtab *tab, const void *obj, unsigned int h);
/* some standard, default routines for general use */
@ -115,7 +115,6 @@ int ast_is_prime(int num)
}
/* if we made it through the loop, the number is a prime */
return 1;
}
@ -150,8 +149,7 @@ unsigned int ast_hashtab_hash_string(const void *obj)
unsigned char *str = (unsigned char *) obj;
unsigned int total;
for (total = 0; *str; str++)
{
for (total = 0; *str; str++) {
unsigned int tmp = total;
total <<= 1; /* multiply by 2 */
total += tmp; /* multiply by 3 */
@ -363,7 +361,7 @@ void ast_hashtab_unlock(struct ast_hashtab *tab)
ast_rwlock_unlock(&tab->lock);
}
void ast_hashtab_destroy( struct ast_hashtab *tab, void (*objdestroyfunc)(void *obj))
void ast_hashtab_destroy(struct ast_hashtab *tab, void (*objdestroyfunc)(void *obj))
{
/* this func will free the hash table and all its memory. It
doesn't touch the objects stored in it */
@ -379,16 +377,21 @@ void ast_hashtab_destroy( struct ast_hashtab *tab, void (*objdestroyfunc)(void *
while (tab->tlist) {
t = tab->tlist;
if (t->object && objdestroyfunc)
(*objdestroyfunc)((void *) t->object); /* I cast this because I'm not going to MOD it, I'm going to DESTROY it */
if (t->object && objdestroyfunc) {
/* I cast this because I'm not going to MOD it, I'm going to DESTROY
* it.
*/
(*objdestroyfunc)((void *) t->object);
}
tlist_del_item(&(tab->tlist), tab->tlist);
free(t);
}
for (i = 0; i < tab->hash_tab_size; i++)
tab->array[i] = NULL; /* not totally necc., but best to destroy old ptrs */
for (i = 0; i < tab->hash_tab_size; i++) {
/* Not totally necessary, but best to destroy old pointers */
tab->array[i] = NULL;
}
free(tab->array);
}
if (tab->do_locking) {
@ -548,14 +551,15 @@ static void *ast_hashtab_lookup_internal(struct ast_hashtab *tab, const void *ob
for (b = tab->array[h]; b; b = b->next) {
if (!(*tab->compare)(obj,b->object)) {
return (void*) b->object; /* I can't touch obj in this func, but the outside world is welcome to */
/* I can't touch obj in this func, but the outside world is welcome to */
return (void*) b->object;
}
}
return NULL;
}
void ast_hashtab_get_stats( struct ast_hashtab *tab, int *biggest_bucket_size, int *resize_count, int *num_objects, int *num_buckets)
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 */
if (tab->do_locking)
@ -568,24 +572,21 @@ void ast_hashtab_get_stats( struct ast_hashtab *tab, int *biggest_bucket_size, i
ast_rwlock_unlock(&tab->lock);
}
/* this function returns the number of elements stored in the hashtab */
int ast_hashtab_size( struct ast_hashtab *tab)
/* this function returns the number of elements stored in the hashtab */
int ast_hashtab_size(struct ast_hashtab *tab)
{
return tab->hash_tab_elements;
}
/* this function returns the size of the bucket array in the hashtab */
/* this function returns the size of the bucket array in the hashtab */
int ast_hashtab_capacity( struct ast_hashtab *tab)
{
return tab->hash_tab_size;
}
/* the insert operation calls this, and is wrlock'd when it does. */
/* if you want to call it, you should set the wrlock yourself */
static void ast_hashtab_resize( struct ast_hashtab *tab)
{
/* this function is called either internally, when the resize func returns 1, or

Loading…
Cancel
Save