Files | |
| file | hashtable.c |
| file | hashtable.h |
Data Structures | |
| struct | _cp_hashtable_entry |
| struct | _cp_hashtable |
Defines | |
| #define | CP_HASHTABLE_MULTIPLE_VALUES 1 |
| #define | CP_CHAR_UC(x) ((x) >= 'a' && (x) <= 'z' ? ((x) - 'a' + 'A') : (x)) |
| #define | HASH_SEED 1000000001L |
| #define | CP_HASHTABLE_DEFAULT_MIN_FILL_FACTOR 5 |
| #define | CP_HASHTABLE_DEFAULT_MAX_FILL_FACTOR 70 |
| #define | cp_hashtable_create_by_mode(mode, size_hint, cp_hashfn, compare_fn) cp_hashtable_create_by_option((mode), (size_hint), (cp_hashfn), (compare_fn), NULL, NULL, NULL, NULL) |
| #define | cp_hashtable_rdlock(table) cp_hashtable_lock((table), COLLECTION_LOCK_READ) |
| #define | cp_hashtable_wrlock(table) cp_hashtable_lock((table), COLLECTION_LOCK_WRITE) |
| #define | cp_hashtable_is_empty(table) (cp_hashtable_count(table) == 0) |
Typedefs | |
| typedef unsigned long(* | cp_hashfunction )(void *) |
| typedef CPROPS_DLL struct _cp_hashtable_entry | cp_hashtable_entry |
| typedef CPROPS_DLL struct _cp_hashtable | cp_hashtable |
Functions | |
| unsigned long | cp_hashtable_choose_size (unsigned long size_request) |
| cp_hashtable * | cp_hashtable_create (unsigned long size_hint, cp_hashfunction hash_fn, cp_compare_fn compare_fn) |
| cp_hashtable * | cp_hashtable_create_copy_mode (unsigned long size_hint, cp_hashfunction hash_fn, cp_compare_fn compare_fn, cp_copy_fn copy_key, cp_destructor_fn free_key, cp_copy_fn copy_value, cp_destructor_fn free_value) |
| cp_hashtable * | cp_hashtable_create_by_option (int mode, unsigned long size_hint, cp_hashfunction hash_fn, cp_compare_fn compare_fn, cp_copy_fn copy_key, cp_destructor_fn free_key, cp_copy_fn copy_value, cp_destructor_fn free_value) |
| cp_hashtable_entry * | cp_hashtable_create_entry (cp_hashtable *table, int mode, void *key, void *value, long hashcode) |
| void | cp_hashtable_destroy (cp_hashtable *table) |
| void | cp_hashtable_destroy_deep (cp_hashtable *table) |
| void | cp_hashtable_destroy_custom (cp_hashtable *table, cp_destructor_fn dk, cp_destructor_fn dv) |
| void | cp_hashtable_destroy_shallow (cp_hashtable *table) |
| int | cp_hashtable_lock_internal (cp_hashtable *table, int type) |
| int | cp_hashtable_unlock_internal (cp_hashtable *table) |
| int | cp_hashtable_txlock (cp_hashtable *table, int type) |
| int | cp_hashtable_txunlock (cp_hashtable *table) |
| int | cp_hashtable_lock (cp_hashtable *table, int type) |
| int | cp_hashtable_unlock (cp_hashtable *table) |
| int | cp_hashtable_set_mode (cp_hashtable *table, int mode) |
| int | cp_hashtable_get_mode (cp_hashtable *table) |
| int | cp_hashtable_unset_mode (cp_hashtable *table, int mode) |
| void * | lookup_internal (cp_hashtable *table, void *key, long code, int option, int resize) |
| void * | cp_hashtable_get_by_option (cp_hashtable *table, void *key, int option) |
| void * | cp_hashtable_resize_thread (void *tbl) |
| int | cp_hashtable_set_min_size (cp_hashtable *table, int min_size) |
| int | cp_hashtable_set_max_fill_factor (cp_hashtable *table, int fill_factor) |
| int | cp_hashtable_set_min_fill_factor (cp_hashtable *table, int fill_factor) |
| void * | cp_hashtable_resize (cp_hashtable *table, long new_size) |
| void * | cp_hashtable_resize_nosync (cp_hashtable *table, unsigned long new_size) |
| void * | cp_hashtable_put (cp_hashtable *table, void *key, void *value) |
| void * | cp_hashtable_put_safe (cp_hashtable *table, void *key, void *value) |
| void * | cp_hashtable_put_copy (cp_hashtable *table, void *key, void *value) |
| void * | cp_hashtable_put_by_option (cp_hashtable *table, void *key, void *value, int option) |
| void * | cp_hashtable_remove_internal (cp_hashtable *table, void *key, long code, int mode, int resize) |
| void * | cp_hashtable_remove_by_mode (cp_hashtable *table, void *key, int mode) |
| int | cp_hashtable_remove_all (cp_hashtable *table) |
| void * | cp_hashtable_remove (cp_hashtable *table, void *key) |
| int | cp_hashtable_remove_deep (cp_hashtable *table, void *key) |
| int | cp_hashtable_contains (cp_hashtable *table, void *key) |
| void * | cp_hashtable_get (cp_hashtable *table, void *key) |
| void ** | cp_hashtable_get_keys (cp_hashtable *table) |
| unsigned long | cp_hashtable_count (cp_hashtable *table) |
| void ** | cp_hashtable_get_values (cp_hashtable *table) |
| unsigned long | cp_hash_int (void *i) |
| int | cp_hash_compare_int (void *i, void *j) |
| unsigned long | cp_hash_long (void *l) |
| int | cp_hash_compare_long (void *i, void *j) |
| unsigned long | cp_hash_addr (void *addr) |
| int | cp_hash_compare_addr (void *a1, void *a2) |
| unsigned long | cp_hash_string (void *str) |
| int | cp_hash_compare_string (void *s1, void *s2) |
| unsigned long | cp_hash_istring (void *str) |
| int | cp_hash_compare_istring (void *s1, void *s2) |
| void * | cp_hash_copy_string (void *element) |
| unsigned long | cp_hash_float (void *addr) |
| int | cp_hash_compare_float (void *a1, void *a2) |
| unsigned long | cp_hash_double (void *d) |
| int | cp_hash_compare_double (void *a1, void *a2) |
|
|
creates a new cp_hashtable with the specified mode. Definition at line 290 of file hashtable.h. |
|
|
Check if the collection is empty.
Definition at line 557 of file hashtable.h. |
|
|
macro to get a read lock on the table Definition at line 391 of file hashtable.h. |
|
|
macro to get a write lock on the table Definition at line 394 of file hashtable.h. |
|
|
1000000001 is a prime. HASH_SEED is used by cp_hash_string(). Definition at line 87 of file hashtable.h. Referenced by cp_hash_istring(), and cp_hash_string(). |
|
|
the hash function takes (void *) and returns unsigned long. Create a function with the name <class_name>_hash_code() Definition at line 105 of file hashtable.h. |
|
|
data structure of generic synchronized cp_hashtable Referenced by cp_hashtable_create(), cp_hashtable_create_by_option(), and cp_hashtable_resize_thread(). |
|
|
Internal object that implements a key, value pair plus linked list. Entries which are stored under the same index in the hashtable are stored in a linked list. The algorithm of the hashtable has to ensure that the lists do not get too long. Referenced by cp_hashtable_create_by_option(), cp_hashtable_destroy(), cp_hashtable_destroy_custom(), cp_hashtable_get_keys(), cp_hashtable_get_values(), cp_hashtable_put_by_option(), cp_hashtable_remove_all(), cp_hashtable_remove_internal(), cp_hashtable_resize(), cp_hashtable_resize_nosync(), cp_hashtable_resize_thread(), and lookup_internal(). |
|
|
hash function for pointer keys Definition at line 1153 of file hashtable.c. Referenced by cp_httpclient_ctl_create(). |
|
||||||||||||
|
comparator for pointer keys
Definition at line 1158 of file hashtable.c. Referenced by cp_httpclient_ctl_create(). |
|
||||||||||||
|
comparator for int keys
Definition at line 1136 of file hashtable.c. Referenced by cp_http_init(), cp_socket_create(), and cp_socket_init(). |
|
||||||||||||
|
comparator for (char *) keys
Definition at line 1205 of file hashtable.c. |
|
||||||||||||
|
comparator for long keys
Definition at line 1147 of file hashtable.c. Referenced by cp_thread_pool_create(). |
|
||||||||||||
|
comparator for (char *) keys
Definition at line 1180 of file hashtable.c. Referenced by cp_http_response_create(), and cp_httpclient_set_parameter(). |
|
|
copy function for cp_string copy tables Definition at line 1212 of file hashtable.c. |
|
|
hash function for int keys
Definition at line 1130 of file hashtable.c. Referenced by cp_http_init(), cp_socket_create(), and cp_socket_init(). |
|
|
case insensitive hash function for (char *) keys
Definition at line 1189 of file hashtable.c. References HASH_SEED. |
|
|
hash function for long keys Definition at line 1141 of file hashtable.c. Referenced by cp_thread_pool_create(). |
|
|
hash function for (char *) keys
Definition at line 1163 of file hashtable.c. References HASH_SEED. Referenced by cp_http_response_create(), and cp_httpclient_set_parameter(). |
|
|
Definition at line 59 of file hashtable.c. Referenced by cp_hashlist_create_by_option(), cp_hashtable_create_by_option(), cp_hashtable_put_by_option(), cp_hashtable_remove_by_mode(), and cp_hashtable_resize_nosync(). |
|
||||||||||||
|
Check if there is an entry with matching key.
Definition at line 986 of file hashtable.c. References COLLECTION_LOCK_READ, cp_list_destroy(), and lookup_internal(). |
|
|
Get the number of entries in the collection.
Definition at line 1073 of file hashtable.c. Referenced by cp_http_request_dump(), cp_http_response_get_header_names(), and cp_http_response_write(). |
|
||||||||||||||||
|
creates a new cp_hashtable. by default there is no memory management for table content; insertion, removal and retrieval operations are synchronized; and the table will automatically resize when the fill factor goes over 70% or under 5%.
Definition at line 90 of file hashtable.c. References cp_hashtable, and cp_hashtable_create_by_option(). Referenced by cp_http_init(). |
|
||||||||||||||||||||||||||||||||||||
|
create a new table, fully specifying all parameters.
Definition at line 120 of file hashtable.c. References _cp_hashtable::compare_fn, _cp_hashtable::copy_key, _cp_hashtable::copy_value, cp_hashtable, cp_hashtable_choose_size(), cp_hashtable_entry, _cp_hashtable::fill_factor_max, _cp_hashtable::fill_factor_min, _cp_hashtable::free_key, _cp_hashtable::free_value, _cp_hashtable::hash_fn, _cp_hashtable::items, _cp_hashtable::lock, _cp_hashtable::min_size, _cp_hashtable::mode, _cp_hashtable::resizing, _cp_hashtable::table, and _cp_hashtable::table_size. Referenced by cp_hashtable_create(), cp_hashtable_create_copy_mode(), cp_http_response_create(), and cp_httpclient_set_parameter(). |
|
||||||||||||||||||||||||||||||||
|
creates a new cp_hashtable with COLLECTION_MODE_DEEP | COLLECTION_MODE_COPY.
Definition at line 100 of file hashtable.c. References COLLECTION_MODE_COPY, COLLECTION_MODE_DEEP, and cp_hashtable_create_by_option(). |
|
|
deletes a cp_hashtable according to the current mode settings
Definition at line 216 of file hashtable.c. References cp_hashtable_entry, and _cp_hashtable_entry::next. Referenced by cp_db_shutdown(), cp_hashtable_destroy_shallow(), cp_http_request_delete(), cp_http_response_delete(), cp_http_shutdown(), and cp_httpclient_destroy(). |
|
||||||||||||||||
|
Deep destroy with custom destructors for keys and values. NULL function pointers are not invoked. Definition at line 262 of file hashtable.c. References cp_hashtable_entry, and _cp_hashtable_entry::next. Referenced by cp_hashtable_destroy_deep(). |
|
|
deletes a cp_hashtable. Keys and values entered in the cp_hashtable are released.
Definition at line 256 of file hashtable.c. References COLLECTION_MODE_DEEP, cp_hashtable_destroy_custom(), and cp_hashtable_set_mode(). |
|
|
deletes a cp_hashtable. Pointers to the keys and values are not released. Use table if the keys and values you entered in the table should not be released by the cp_hashtable.
Definition at line 296 of file hashtable.c. References COLLECTION_MODE_DEEP, cp_hashtable_destroy(), and cp_hashtable_unset_mode(). |
|
||||||||||||
|
attempts to retrieve the value assigned to the key 'key'. To return multiple values the table mode must be set to COLLECTION_MODE_MULTIPLE_VALUES, otherwise the only first value for the given key will be returned.
Definition at line 1019 of file hashtable.c. References cp_hashtable_get_by_option(). Referenced by cp_error(), cp_http_request_dump(), cp_http_request_get_header(), cp_http_request_get_parameter(), cp_http_response_get_content_type(), cp_http_response_get_header(), cp_http_response_report_error(), cp_http_response_write(), cp_httpclient_fetch(), and cp_perror(). |
|
||||||||||||||||
|
Retrieves the value by key.
Definition at line 481 of file hashtable.c. References COLLECTION_LOCK_READ, and lookup_internal(). Referenced by cp_hashtable_get(). |
|
|
get an array containing all keys mapped in table table.
Definition at line 1024 of file hashtable.c. References COLLECTION_LOCK_READ, cp_hashtable_entry, _cp_hashtable_entry::key, and _cp_hashtable_entry::next. Referenced by cp_http_request_dump(), cp_http_request_get_headers(), cp_http_response_get_header_names(), and cp_http_response_write(). |
|
|
returns the current operation mode. See cp_hashtable_set_mode for a list of mode bits and their effects. Definition at line 403 of file hashtable.c. |
|
|
get an array containing all values in the table.
Definition at line 1079 of file hashtable.c. References COLLECTION_LOCK_READ, cp_hashtable_entry, _cp_hashtable_entry::next, and _cp_hashtable_entry::value. |
|
||||||||||||
|
by default the get, put and remove functions as well as set and unset mode perform their own locking. Other functions do not synchronize, since it is assumed they would be called in a single cp_thread context - the initialization * and deletion functions in particular. You can of course set COLLECTION_MODE_NOSYNC and perform your own synchronization. The current implementation uses a queued read/write lock where blocked cp_threads are guaranteed to be woken by the order in which they attempted the following macros are defined for convenience:
Definition at line 358 of file hashtable.c. |
|
||||||||||||||||
|
the key 'key' will be assigned to the value 'value'. The new value will override an old value if one exists. The old value will not be deallocated. If you would need the old value to be released call cp_hashtable_put_safe instead. Definition at line 746 of file hashtable.c. References cp_hashtable_put_by_option(). Referenced by cp_http_init(), cp_http_response_set_header(), cp_httpclient_set_header(), cp_httpclient_set_parameter(), and cp_httpclient_set_user_agent(). |
|
||||||||||||||||||||
|
Internal put method. Definition at line 763 of file hashtable.c. References COLLECTION_LOCK_WRITE, cp_hashtable_choose_size(), cp_hashtable_entry, cp_hashtable_resize(), cp_hashtable_resize_nosync(), and _cp_hashtable_entry::value. Referenced by cp_hashtable_put(), cp_hashtable_put_copy(), and cp_hashtable_put_safe(). |
|
||||||||||||||||
|
same as cp_hashtable_put(table, key, value) except that it inserts a copy of the key and the value object. Definition at line 756 of file hashtable.c. References COLLECTION_MODE_COPY, and cp_hashtable_put_by_option(). |
|
||||||||||||||||
|
same as cp_hashtable_put(table, key, value) except that an old value is released if it exists. Definition at line 751 of file hashtable.c. References COLLECTION_MODE_DEEP, and cp_hashtable_put_by_option(). |
|
||||||||||||
|
Attempts to remove the mapping for key from the table.
Definition at line 968 of file hashtable.c. References cp_hashtable_remove_by_mode(). Referenced by cp_httpclient_set_header(), and cp_httpclient_set_parameter(). |
|
|
remove all entries with current mode Definition at line 918 of file hashtable.c. References COLLECTION_LOCK_WRITE, cp_destructor_fn, cp_hashtable_entry, and _cp_hashtable_entry::next. Referenced by cp_httpclient_drop_headers(), and cp_httpclient_drop_parameters(). |
|
||||||||||||||||
|
Remove an entry from the table by key with locking mode. Get the value by key and destroy the entry.
Definition at line 881 of file hashtable.c. References COLLECTION_LOCK_WRITE, cp_hashtable_choose_size(), cp_hashtable_remove_internal(), cp_hashtable_resize(), and cp_hashtable_resize_nosync(). Referenced by cp_hashtable_remove(), and cp_hashtable_remove_deep(). |
|
||||||||||||
|
Remove with COLLECTION_MODE_DEEP set
Definition at line 980 of file hashtable.c. References COLLECTION_MODE_DEEP, and cp_hashtable_remove_by_mode(). |
|
||||||||||||||||||||||||
|
Internal remove an entry from the table by key. Get the value by key and destroy the entry.
Definition at line 829 of file hashtable.c. References cp_hashtable_entry, _cp_hashtable_entry::next, and _cp_hashtable_entry::value. Referenced by cp_hashtable_remove_by_mode(). |
|
||||||||||||
|
Initiates a resize of the cp_hashtable which is executed in the background.
Definition at line 603 of file hashtable.c. References cp_hashtable_entry, and cp_hashtable_resize_thread(). Referenced by cp_hashtable_put_by_option(), and cp_hashtable_remove_by_mode(). |
|
||||||||||||
|
Resizes the table to a new size. This is invoked by the insertion code if the load * factor goes over the fill factor limits.
Definition at line 638 of file hashtable.c. References cp_hashtable_choose_size(), cp_hashtable_entry, _cp_hashtable_entry::hashcode, and _cp_hashtable_entry::next. Referenced by cp_hashtable_put_by_option(), and cp_hashtable_remove_by_mode(). |
|
|
<<Thread>> resize a cp_hashtable. This cp_thread does a background resize of the table. It creates a new table and moves the entries to the new table.
Definition at line 516 of file hashtable.c. References COLLECTION_LOCK_WRITE, cp_hashtable, cp_hashtable_entry, _cp_hashtable::resize_len, _cp_hashtable::resize_table, _cp_hashtable::resizing, _cp_hashtable::table, and _cp_hashtable::table_size. Referenced by cp_hashtable_resize(). |
|
||||||||||||
|
a resize is triggered when the table contains more items than table_size * fill_factor / 100 Definition at line 581 of file hashtable.c. References COLLECTION_LOCK_WRITE, and _cp_hashtable::fill_factor_max. |
|
||||||||||||
|
a resize is triggered when the table contains less items than table_size * fill_factor / 100 Definition at line 589 of file hashtable.c. References COLLECTION_LOCK_WRITE, and _cp_hashtable::fill_factor_min. |
|
||||||||||||
|
the internal table will not be resized to less than min_size Definition at line 572 of file hashtable.c. References COLLECTION_LOCK_WRITE, and _cp_hashtable::min_size. |
|
||||||||||||
|
set the operation mode as a bit set of the following options:
The parameter bits are flipped on. If the current mode is COLLECTION_MODE_DEEP and you want to change it, call cp_hashtable_unset_mode(table, COLLECTION_MODE_DEEP). Definition at line 386 of file hashtable.c. References COLLECTION_LOCK_WRITE. Referenced by cp_hashtable_destroy_deep(). |
|
|
unlock the table Definition at line 370 of file hashtable.c. |
|
||||||||||||
|
unset the mode bits defined by mode Definition at line 408 of file hashtable.c. References COLLECTION_LOCK_WRITE. Referenced by cp_hashtable_destroy_shallow(). |
|
||||||||||||||||||||||||
|
Retrieves the value by key from normal or resizing table.
Definition at line 430 of file hashtable.c. References cp_hashtable_entry, cp_list, cp_list_append(), cp_list_insert(), and _cp_hashtable_entry::next. Referenced by cp_hashtable_contains(), and cp_hashtable_get_by_option(). |
1.3.9.1