Go to the source code of this file.
Data Structures | |
| struct | Hash_Entry_t |
| Hash table entry. More... | |
| struct | Hash_Generator_t |
| Used for traversing entries in a table. More... | |
| struct | Hash_t |
| Hash table. More... | |
Defines | |
| #define | HASH_DEFAULT_MAX_DENSITY 5 |
| #define | HASH_DEFAULT_INIT_TABLE_SIZE 11 |
| #define | HASH_DEFAULT_GROW_FACTOR 2.0 |
| #define | HASH_DEFAULT_REORDER_FLAG 0 |
| #define | ST_DEFAULT_MAX_DENSITY HASH_DEFAULT_MAX_DENSITY |
| #define | ST_DEFAULT_INIT_TABLE_SIZE HASH_DEFAULT_INIT_TABLE_SIZE |
| #define | ST_DEFAULT_GROW_FACTOR HASH_DEFAULT_GROW_FACTOR |
| #define | ST_DEFAULT_REORDER_FLAG HASH_DEFAULT_REORDER_FLAG |
| #define | Hash_ForEachItem(table, gen, key, value) for(gen=st_init_gen(table); st_gen(gen,key,value) || (st_free_gen(gen),0);) |
| An iteration macro which loops over all the entries in `table'. | |
| #define | st_foreach_item(table, gen, key, value) Hash_ForEachItem(table, gen, key, value) |
| #define | Hash_ForEachItemNew(table, key, value) for(table->gen=st_init_gen(table); st_gen(table->gen,key,value) || (st_free_gen(table->gen),0);) |
| #define | st_foreach_item_new(table, key, value) Hash_ForEachItemNew(table, key, value) |
| #define | st_foreach_item_int(table, gen, key, value) for(gen=st_init_gen(table); st_gen_int(gen,key,value) || (st_free_gen(gen),0);) |
| An iteration macro which loops over all the entries in `table'. | |
| #define | HASH_OUT_OF_MEM -10000 |
| #define | ST_OUT_OF_MEM -10000 |
Typedefs | |
| typedef Hash_Entry_t | Hash_Entry_t |
| typedef Hash_Entry_t | st_table_entry |
| typedef Hash_t | Hash_t |
| typedef Hash_Generator_t | Hash_Generator_t |
| typedef Hash_Generator_t | st_generator |
| typedef int(*) | Hash_GenericFunctionPointer_t () |
| typedef Hash_t | st_table |
| typedef int(*) | ST_PFI () |
Enumerations | |
| enum | st_retval { ST_CONTINUE, ST_STOP, ST_DELETE } |
Functions | |
| void | Hash_Test () |
| Simple test of the hash package. | |
| Hash_t * | Hash_InitTableWithParams (ST_PFI, ST_PFI, int, int, double, int) |
| Hash_t * | Hash_InitTable (ST_PFI a, ST_PFI b) |
| void | Hash_FreeTable (Hash_t *) |
| Free any internal storage associated with table. | |
| int | Hash_Lookup (Hash_t *, char *, char **) |
| Lookup up `key' in `table'. | |
| int | Hash_LookupInt (Hash_t *, char *, int *) |
| Lookup up int `key' in `table'. | |
| int | Hash_Insert (Hash_t *, char *, char *) |
| Insert value in table under the key 'key'. | |
| int | Hash_AddDirect (Hash_t *, char *, char *) |
| Place 'value' in 'table' under the key 'key'. This is done without checking if 'key' is in 'table' already. | |
| int | Hash_FindOrAdd (Hash_t *, char *, char ***) |
| Lookup `key' in `table'. If not found, create an entry.In either case set slot to point to the field in the entry where the value is stored. The value associated with `key' may then be changed by accessing directly through slot. Returns 1 if an entry already existed, 0 otherwise. | |
| int | Hash_Find (Hash_t *a, char *b, char ***c) |
Like Hash_FindOrAdd, but does not create an entry if one is not found. | |
| Hash_t * | Hash_Copy (Hash_t *) |
| Return a copy of old_table and all its members. | |
| int | Hash_Delete (Hash_t *, char **, char **) |
| Delete the entry with the key pointed to by `key_ptr'. | |
| int | Hash_DeleteInt (Hash_t *, int *, char **) |
| Delete the entry with the key pointed to by `key_ptr'. | |
| int | Hash_ForEach (Hash_t *, ST_PFSR, char *) |
| int | Hash_StrHash (char *, int) |
| Hash function for strings. | |
| int | st_strhash (char *, int) |
| int | Hash_NumHash (char *, int) |
| Hash function for numbers. | |
| int | st_numhash (char *, int) |
| int | Hash_PtrHash (char *, int) |
| Hash function for pointers. | |
| int | st_ptrhash (char *, int) |
| int | Hash_NumCmp (int, int) |
| Compare function for numbers. | |
| int | st_numcmp (int, int) |
| int | Hash_PtrCmp (char *, char *) |
| Compare function for pointers. | |
| int | st_ptrcmp (char *, char *) |
| Hash_Generator_t * | Hash_InitGen (Hash_t *) |
| Returns a generator handle which when used with Hash_Gen() will progressively return each (key, value) record in `table'. | |
| Hash_Generator_t * | st_init_gen (Hash_t *a) |
| int | Hash_Gen (Hash_Generator_t *, char **, char **) |
| Given a generator returned by Hash_InitGen(), this routine returns the next (key, value) pair in the generation sequence. | |
| int | st_gen (Hash_Generator_t *a, char **b, char **c) |
| int | Hash_GenInt (Hash_Generator_t *, char **, int *) |
| Given a generator returned by Hash_InitGen(), this routine returns the next (key, value) pair in the generation sequence. | |
| int | st_gen_int (Hash_Generator_t *a, char **b, int *c) |
| void | Hash_FreeGen (Hash_Generator_t *) |
| After generating all items in a generation sequence, this routine must be called to reclaim the resources associated with `gen'. | |
| void | st_free_gen (Hash_Generator_t *a) |
Variables | |
| enum st_retval(*) | ST_PFSR () |
Definition in file st.h.
| #define Hash_ForEachItem | ( | table, | |||
| gen, | |||||
| key, | |||||
| value | ) | for(gen=st_init_gen(table); st_gen(gen,key,value) || (st_free_gen(gen),0);) |
An iteration macro which loops over all the entries in `table'.
It sets `key_p' to point to the key and `value_p' to the associated value (if it is not nil). `gen' is a generator variable used internally.
Sample usage:
char *key, *value;
st_generator *gen;
st_foreach_item(table, gen, &key, &value) { process_item(value); }
| #define Hash_ForEachItemNew | ( | table, | |||
| key, | |||||
| value | ) | for(table->gen=st_init_gen(table); st_gen(table->gen,key,value) || (st_free_gen(table->gen),0);) |
| #define ST_DEFAULT_INIT_TABLE_SIZE HASH_DEFAULT_INIT_TABLE_SIZE |
| #define st_foreach_item | ( | table, | |||
| gen, | |||||
| key, | |||||
| value | ) | Hash_ForEachItem(table, gen, key, value) |
| #define st_foreach_item_int | ( | table, | |||
| gen, | |||||
| key, | |||||
| value | ) | for(gen=st_init_gen(table); st_gen_int(gen,key,value) || (st_free_gen(gen),0);) |
An iteration macro which loops over all the entries in `table'.
It sets `key_p' to point to the key and `value_p' to the associated value (if it is not nil). `value_p' is assumed to be a pointer to an integer. `gen' is a generator variable used internally.
Sample usage:
char *key;
int *value;
st_generator *gen;
st_foreach_item_int(table, gen, &key, &value) { process_item(value); }
| #define st_foreach_item_new | ( | table, | |||
| key, | |||||
| value | ) | Hash_ForEachItemNew(table, key, value) |
| typedef struct Hash_Entry_t Hash_Entry_t |
| typedef struct Hash_Generator_t Hash_Generator_t |
| typedef int(*) Hash_GenericFunctionPointer_t() |
| typedef Hash_Generator_t st_generator |
| typedef Hash_Entry_t st_table_entry |
| int Hash_AddDirect | ( | Hash_t * | table, | |
| char * | key, | |||
| char * | value | |||
| ) |
Place 'value' in 'table' under the key 'key'. This is done without checking if 'key' is in 'table' already.
This should only be used if you are sure there is not already an entry for 'key', since it is undefined which entry you would later get from Hash_Lookup or Hash_FindOrAdd.
| int Hash_Delete | ( | Hash_t * | table, | |
| char ** | keyp, | |||
| char ** | value | |||
| ) |
Delete the entry with the key pointed to by `key_ptr'.
If the entry is found, 1 is returned and `key_ptr' is set to the actual key and `entry_ptr' is set to the corresponding entry (This allows the freeing of the associated storage). If the entry is not found, then 0 is returned and nothing is changed.
| int Hash_DeleteInt | ( | Hash_t * | table, | |
| int * | keyp, | |||
| char ** | value | |||
| ) |
Delete the entry with the key pointed to by `key_ptr'.
`key_ptr' should be specifically a pointer to an integer. If the entry is found, 1 is returned and `key_ptr' is set to the actual key and `entry_ptr' is set to the corresponding entry (This allows the freeing of the associated storage). If the entry is not found, then 0 is returned and nothing is changed.
| int Hash_Find | ( | Hash_t * | a, | |
| char * | b, | |||
| char *** | c | |||
| ) |
| int Hash_FindOrAdd | ( | Hash_t * | table, | |
| char * | key, | |||
| char *** | slot | |||
| ) |
Lookup `key' in `table'. If not found, create an entry.In either case set slot to point to the field in the entry where the value is stored. The value associated with `key' may then be changed by accessing directly through slot. Returns 1 if an entry already existed, 0 otherwise.
As an example:
char **slot;
char *key;
char *value = (char *) item_ptr // ptr to a malloc'd structure
if (Hash_FindOrAdd(table, key, &slot)) {
FREE(*slot); // free the old value of the record
}
slot = value; // attach the new value to the record
This replaces the equivelent code:
if (Hash_Lookup(table, key, &ovalue)) {
FREE(ovalue);
}
Hash_Insert(table, key, value);
| void Hash_FreeGen | ( | Hash_Generator_t * | ) |
| void Hash_FreeTable | ( | Hash_t * | table | ) |
| int Hash_Gen | ( | Hash_Generator_t * | gen, | |
| char ** | key_p, | |||
| char ** | value_p | |||
| ) |
Given a generator returned by Hash_InitGen(), this routine returns the next (key, value) pair in the generation sequence.
The pointer `value_p' can be zero which means no value will be returned. When there are no more items in the generation sequence, the routine returns 0.
While using a generation sequence, deleting any (key, value) pair other than the one just generated may cause a fatal error when Hash_Gen() is called later in the sequence and is therefore not recommended.
| int Hash_GenInt | ( | Hash_Generator_t * | gen, | |
| char ** | key_p, | |||
| int * | value_p | |||
| ) |
Given a generator returned by Hash_InitGen(), this routine returns the next (key, value) pair in the generation sequence.
`value' must be a pointer to an integer. The pointer `value_p' can be zero which means no value will be returned. When there are no more items in the generation sequence, the routine returns 0.
| Hash_Generator_t* Hash_InitGen | ( | Hash_t * | ) |
Returns a generator handle which when used with Hash_Gen() will progressively return each (key, value) record in `table'.
| int Hash_Insert | ( | Hash_t * | table, | |
| char * | key, | |||
| char * | value | |||
| ) |
| int Hash_Lookup | ( | Hash_t * | table, | |
| char * | key, | |||
| char ** | value | |||
| ) |
| int Hash_LookupInt | ( | Hash_t * | table, | |
| char * | key, | |||
| int * | value | |||
| ) |
| int Hash_PtrCmp | ( | char * | , | |
| char * | ||||
| ) |
| void st_free_gen | ( | Hash_Generator_t * | a | ) |
| int st_gen | ( | Hash_Generator_t * | a, | |
| char ** | b, | |||
| char ** | c | |||
| ) |
| int st_gen_int | ( | Hash_Generator_t * | a, | |
| char ** | b, | |||
| int * | c | |||
| ) |
| Hash_Generator_t* st_init_gen | ( | Hash_t * | a | ) |