Implementation of generic synchronized cp_hashtable. More...
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <errno.h>
#include "hashtable.h"
#include "linked_list.h"
#include "log.h"
#include "common.h"
#include "collection.h"
#include "thread.h"
#include "util.h"
#include "config.h"
Defines | |
#define | CP_HASHTABLE_MULTIPLE_VALUES 1 |
#define | CP_CHAR_UC(x) ((x) >= 'a' && (x) <= 'z' ? ((x) - 'a' + 'A') : (x)) |
Functions | |
unsigned long | cp_hashtable_choose_size (unsigned long size_request) |
cp_hashtable * | cp_hashtable_create (unsigned long size_hint, cp_hashfunction hashfn, cp_compare_fn compare_fn) |
creates a new cp_hashtable. | |
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) |
creates a new cp_hashtable with COLLECTION_MODE_DEEP | COLLECTION_MODE_COPY. | |
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) |
create a new table, fully specifying all parameters. | |
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) |
deletes a cp_hashtable according to the current mode settings | |
void | cp_hashtable_destroy_deep (cp_hashtable *table) |
deletes a cp_hashtable. | |
void | cp_hashtable_destroy_custom (cp_hashtable *table, cp_destructor_fn dk, cp_destructor_fn dv) |
Deep destroy with custom destructors for keys and values. | |
void | cp_hashtable_destroy_shallow (cp_hashtable *table) |
deletes a cp_hashtable. | |
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) |
by default the get, put and remove functions as well as set and unset mode perform their own locking. | |
int | cp_hashtable_unlock (cp_hashtable *table) |
unlock the table | |
int | cp_hashtable_set_mode (cp_hashtable *table, int mode) |
set the operation mode as a bit set of the following options: | |
int | cp_hashtable_get_mode (cp_hashtable *table) |
returns the current operation mode. | |
int | cp_hashtable_unset_mode (cp_hashtable *table, int mode) |
unset the mode bits defined by mode | |
void * | lookup_internal (cp_hashtable *table, void *key, long code, int option, int resize) |
Retrieves the value by key from normal or resizing table. | |
void * | cp_hashtable_get_by_option (cp_hashtable *table, void *key, int option) |
Retrieves the value by key. | |
void * | cp_hashtable_resize_thread (void *tbl) |
<<Thread>> resize a cp_hashtable. | |
int | cp_hashtable_set_min_size (cp_hashtable *table, int min_size) |
the internal table will not be resized to less than min_size | |
int | cp_hashtable_set_max_fill_factor (cp_hashtable *table, int fill_factor) |
a resize is triggered when the table contains more items than table_size * fill_factor / 100 | |
int | cp_hashtable_set_min_fill_factor (cp_hashtable *table, int fill_factor) |
a resize is triggered when the table contains less items than table_size * fill_factor / 100 | |
void * | cp_hashtable_resize (cp_hashtable *table, long new_size) |
Initiates a resize of the cp_hashtable which is executed in the background. | |
void * | cp_hashtable_resize_nosync (cp_hashtable *table, unsigned long new_size) |
Resizes the table to a new size. | |
static cp_hashtable_entry ** | cp_hashtable_replace_internal (cp_hashtable *table, void *key, void *value, unsigned long code, int option, int resize) |
Internal replace an existing entry with a new key, value pair. | |
void * | cp_hashtable_put (cp_hashtable *table, void *key, void *value) |
the key 'key' will be assigned to the value 'value'. | |
void * | cp_hashtable_put_safe (cp_hashtable *table, void *key, void *value) |
same as cp_hashtable_put(table, key, value) except that an old value is released if it exists. | |
void * | cp_hashtable_put_copy (cp_hashtable *table, void *key, void *value) |
same as cp_hashtable_put(table, key, value) except that it inserts a copy of the key and the value object. | |
void * | cp_hashtable_put_by_option (cp_hashtable *table, void *key, void *value, int mode) |
Internal put method. | |
void * | cp_hashtable_remove_internal (cp_hashtable *table, void *key, long code, int mode, int resize) |
Internal remove an entry from the table by key. | |
void * | cp_hashtable_remove_by_mode (cp_hashtable *table, void *key, int mode) |
Remove an entry from the table by key with locking mode. | |
int | cp_hashtable_remove_all (cp_hashtable *table) |
remove all entries with current mode | |
void * | cp_hashtable_remove (cp_hashtable *table, void *key) |
Attempts to remove the mapping for key from the table. | |
int | cp_hashtable_remove_deep (cp_hashtable *table, void *key) |
Remove with COLLECTION_MODE_DEEP set. | |
int | cp_hashtable_contains (cp_hashtable *table, void *key) |
Check if there is an entry with matching key. | |
void * | cp_hashtable_get (cp_hashtable *table, void *key) |
attempts to retrieve the value assigned to the key 'key'. | |
void ** | cp_hashtable_get_keys (cp_hashtable *table) |
get an array containing all keys mapped in table table. | |
unsigned long | cp_hashtable_count (cp_hashtable *table) |
Get the number of entries in the collection. | |
void ** | cp_hashtable_get_values (cp_hashtable *table) |
get an array containing all values in the table. | |
unsigned long | cp_hash_int (void *key) |
hash function for int keys | |
int | cp_hash_compare_int (void *key1, void *key2) |
comparator for int keys | |
unsigned long | cp_hash_long (void *key) |
hash function for long keys | |
int | cp_hash_compare_long (void *key1, void *key2) |
comparator for long keys | |
unsigned long | cp_hash_addr (void *addr) |
hash function for pointer keys | |
int | cp_hash_compare_addr (void *key1, void *key2) |
comparator for pointer keys | |
unsigned long | cp_hash_string (void *key) |
hash function for (char *) keys | |
int | cp_hash_compare_string (void *key1, void *key2) |
comparator for (char *) keys | |
unsigned long | cp_hash_istring (void *key) |
case insensitive hash function for (char *) keys | |
int | cp_hash_compare_istring (void *key1, void *key2) |
comparator for (char *) keys | |
void * | cp_hash_copy_string (void *element) |
copy function for cp_string copy tables | |
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) |
Variables | |
static int | table_sizes [] |
static int | table_sizes_len = 40 |
Implementation of generic synchronized cp_hashtable.
The elements are stored in cp_list_entry objects.