Cp_hashtable


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_hashtablecp_hashtable_create (unsigned long size_hint, cp_hashfunction hash_fn, cp_compare_fn compare_fn)
cp_hashtablecp_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_hashtablecp_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_entrycp_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)

Detailed Description


Define Documentation

#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)

creates a new cp_hashtable with the specified mode.

Definition at line 290 of file hashtable.h.

Referenced by cp_log_init().

#define cp_hashtable_is_empty ( table   )     (cp_hashtable_count(table) == 0)

Check if the collection is empty.

Return values:
true/1 if the collection is empty
false/0 if the collection has entries

Definition at line 557 of file hashtable.h.

#define cp_hashtable_rdlock ( table   )     cp_hashtable_lock((table), COLLECTION_LOCK_READ)

macro to get a read lock on the table

Definition at line 391 of file hashtable.h.

#define cp_hashtable_wrlock ( table   )     cp_hashtable_lock((table), COLLECTION_LOCK_WRITE)

macro to get a write lock on the table

Definition at line 394 of file hashtable.h.

#define HASH_SEED   1000000001L

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().


Typedef Documentation

typedef unsigned long(*) cp_hashfunction(void *)

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.

typedef CPROPS_DLL struct _cp_hashtable cp_hashtable

data structure of generic synchronized cp_hashtable

typedef CPROPS_DLL struct _cp_hashtable_entry cp_hashtable_entry

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.


Function Documentation

CPROPS_DLL unsigned long cp_hash_addr ( void *  addr  ) 

hash function for pointer keys

Definition at line 1156 of file hashtable.c.

Referenced by cp_httpclient_ctl_create(), cp_multimap_create_by_option(), and cp_multimap_create_index().

CPROPS_DLL int cp_hash_compare_addr ( void *  key1,
void *  key2 
)

comparator for pointer keys

Parameters:
key1 pointer the first pointer
key2 pointer the second pointer
Return values:
0 if key1 equals key2;
<0 if key1 is less than key2;
>0 if key1 is greater than key2

Definition at line 1161 of file hashtable.c.

Referenced by cp_httpclient_ctl_create(), cp_multimap_create_by_option(), and cp_multimap_create_index().

CPROPS_DLL int cp_hash_compare_int ( void *  key1,
void *  key2 
)

comparator for int keys

Parameters:
key1 pointer the first int
key2 pointer the second int
Return values:
0 if key1 equals key2;
<0 if key1 is less than key2;
>0 if key1 is greater than key2

Definition at line 1139 of file hashtable.c.

Referenced by cp_http_init(), cp_log_init(), cp_socket_create(), cp_socket_init(), and cp_socket_select_callback_impl().

CPROPS_DLL int cp_hash_compare_istring ( void *  key1,
void *  key2 
)

comparator for (char *) keys

Parameters:
key1 pointer to the first cp_string
key2 pointer to the second cp_string
Return values:
0 if key1 equals key2
<>0 otherwise

Definition at line 1206 of file hashtable.c.

CPROPS_DLL int cp_hash_compare_long ( void *  key1,
void *  key2 
)

comparator for long keys

Parameters:
key1 pointer the first long
key2 pointer the second long
Return values:
0 if key1 equals key2;
<0 if key1 is less than key2;
>0 if key1 is greater than key2

Definition at line 1150 of file hashtable.c.

Referenced by cp_log_init(), and cp_thread_pool_create().

CPROPS_DLL int cp_hash_compare_string ( void *  key1,
void *  key2 
)

comparator for (char *) keys

Parameters:
key1 pointer to the first cp_string
key2 pointer to the second cp_string
Return values:
0 if key1 equals key2
<>0 otherwise

Definition at line 1182 of file hashtable.c.

Referenced by cp_http_response_create(), cp_http_thread_fn(), and cp_httpclient_set_parameter().

CPROPS_DLL void * cp_hash_copy_string ( void *  element  ) 

copy function for cp_string copy tables

Definition at line 1213 of file hashtable.c.

CPROPS_DLL unsigned long cp_hash_int ( void *  key  ) 

hash function for int keys

Parameters:
key pointer to the int
Returns:
hash code of the key

Definition at line 1133 of file hashtable.c.

Referenced by cp_http_init(), cp_log_init(), cp_socket_create(), cp_socket_init(), and cp_socket_select_callback_impl().

CPROPS_DLL unsigned long cp_hash_istring ( void *  key  ) 

case insensitive hash function for (char *) keys

Parameters:
key pointer to the cp_string
Returns:
hash code of the key

Definition at line 1191 of file hashtable.c.

References CP_CHAR_UC, and HASH_SEED.

CPROPS_DLL unsigned long cp_hash_long ( void *  key  ) 

hash function for long keys

Definition at line 1144 of file hashtable.c.

Referenced by cp_log_init(), and cp_thread_pool_create().

CPROPS_DLL unsigned long cp_hash_string ( void *  key  ) 

hash function for (char *) keys

Parameters:
key pointer to the cp_string
Returns:
hash code of the key

Definition at line 1166 of file hashtable.c.

References HASH_SEED.

Referenced by cp_http_response_create(), cp_http_thread_fn(), and cp_httpclient_set_parameter().

CPROPS_DLL unsigned long cp_hashtable_choose_size ( unsigned long  size_request  ) 

Returns:
a prime greater than size_request

Definition at line 59 of file hashtable.c.

Referenced by cp_hashlist_create_by_option(), cp_hashlist_resize_nosync(), cp_hashtable_create_by_option(), cp_hashtable_put_by_option(), cp_hashtable_remove_by_mode(), cp_hashtable_resize_nosync(), and cp_sorted_hash_create_by_option().

CPROPS_DLL int cp_hashtable_contains ( cp_hashtable table,
void *  key 
)

Check if there is an entry with matching key.

Parameters:
table the object
key Key to search for.
Returns:
1 if table contains key, 0 otherwise

Definition at line 989 of file hashtable.c.

References COLLECTION_LOCK_READ, cp_hashtable_txlock(), cp_hashtable_txunlock(), cp_list_destroy(), and lookup_internal().

CPROPS_DLL unsigned long cp_hashtable_count ( cp_hashtable table  ) 

Get the number of entries in the collection.

Returns:
the number of key mappings currently in the table.

Definition at line 1076 of file hashtable.c.

Referenced by cp_http_request_dump(), cp_http_response_get_header_names(), and cp_http_response_write().

CPROPS_DLL cp_hashtable * cp_hashtable_create ( unsigned long  size_hint,
cp_hashfunction  hashfn,
cp_compare_fn  compare_fn 
)

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%.

Parameters:
size_hint an estimate for the initial storage requirements. The table
handles the storage appropriately when items become too tight.
Parameters:
hashfn a hash code function. This should ideally produce different results for different keys.
compare_fn the comparator for your key type.
Returns:
a pointer to the newly created cp_hashtable.

Definition at line 90 of file hashtable.c.

References cp_hashtable_create_by_option().

Referenced by cp_http_init(), and cp_socket_select_callback_impl().

CPROPS_DLL 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.

Parameters:
size_hint initial capacity
hash_fn hash function
compare_fn key comparison function
copy_key function to return new copies of keys
copy_value function to return new copies of values
mode mode flags
Returns:
new created cp_hashtable. Returns NULL case of error.

Definition at line 120 of file hashtable.c.

References cp_hashtable_choose_size(), CP_HASHTABLE_DEFAULT_MAX_FILL_FACTOR, CP_HASHTABLE_DEFAULT_MIN_FILL_FACTOR, and _cp_hashtable::table_size.

Referenced by cp_hashtable_create(), cp_hashtable_create_copy_mode(), cp_http_response_create(), cp_httpclient_set_parameter(), and cp_log_init().

CPROPS_DLL 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.

Parameters:
size_hint an estimate for the initial storage requirements. The table handles the storage appropriately when items become too tight.
hashfn a hash code function. This should ideally produce different results for different keys.
compare_fn the comparator for your key type.
Returns:
a pointer to the newly created cp_hashtable.

Definition at line 100 of file hashtable.c.

References COLLECTION_MODE_COPY, COLLECTION_MODE_DEEP, and cp_hashtable_create_by_option().

CPROPS_DLL void cp_hashtable_destroy ( cp_hashtable table  ) 

deletes a cp_hashtable according to the current mode settings

Parameters:
table object to delete

Definition at line 216 of file hashtable.c.

References COLLECTION_MODE_DEEP, and COLLECTION_MODE_NORESIZE.

Referenced by cp_db_shutdown(), cp_hashtable_destroy_shallow(), cp_http_request_delete(), cp_http_response_delete(), cp_http_shutdown(), cp_httpclient_destroy(), and cp_log_close().

CPROPS_DLL 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. NULL function pointers are not invoked.

Definition at line 262 of file hashtable.c.

Referenced by cp_hashtable_destroy_deep(), and cp_socket_select_callback_impl().

CPROPS_DLL void cp_hashtable_destroy_deep ( cp_hashtable table  ) 

deletes a cp_hashtable. Keys and values entered in the cp_hashtable are released.

Parameters:
table object to delete

Definition at line 256 of file hashtable.c.

References COLLECTION_MODE_DEEP, cp_hashtable_destroy_custom(), and cp_hashtable_set_mode().

CPROPS_DLL void cp_hashtable_destroy_shallow ( cp_hashtable table  ) 

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.

Parameters:
table object to delete

Definition at line 296 of file hashtable.c.

References COLLECTION_MODE_DEEP, cp_hashtable_destroy(), and cp_hashtable_unset_mode().

CPROPS_DLL void * cp_hashtable_get ( cp_hashtable table,
void *  key 
)

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.

Return values:
(void*)value to the value if found
NULL otherwise

Definition at line 1022 of file hashtable.c.

References cp_hashtable_get_by_option().

Referenced by cp_dbms_mysql_get_data_source_prm(), cp_dbms_postgres_get_data_source_prm(), 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(), cp_perror(), and cp_socket_select_callback_impl().

CPROPS_DLL void * cp_hashtable_get_by_option ( cp_hashtable table,
void *  key,
int  mode 
)

Retrieves the value by key.

Parameters:
table the object
key Key to search for.
option operation mode
Return values:
value of the entry with key.
NULL otherwise (no entry with given key or key == NULL)

Definition at line 481 of file hashtable.c.

References COLLECTION_LOCK_READ, cp_hashtable_txlock(), cp_hashtable_txunlock(), and lookup_internal().

Referenced by cp_hashtable_get().

CPROPS_DLL void ** cp_hashtable_get_keys ( cp_hashtable table  ) 

get an array containing all keys mapped in table table.

Note:
It is the responsibility of the caller to free the returned array.

The keys themselves must not be changed or deleted (read-only).

Definition at line 1027 of file hashtable.c.

References COLLECTION_LOCK_READ, cp_hashtable_txlock(), cp_hashtable_txunlock(), and _cp_hashtable_entry::key.

Referenced by cp_http_request_dump(), cp_http_request_get_headers(), cp_http_response_get_header_names(), and cp_http_response_write().

CPROPS_DLL int cp_hashtable_get_mode ( cp_hashtable table  ) 

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.

CPROPS_DLL void ** cp_hashtable_get_values ( cp_hashtable table  ) 

get an array containing all values in the table.

Note:
It is the responsibility of the caller to free the returned array.

The values themselves must not be changed or deleted (read-only).

Definition at line 1082 of file hashtable.c.

References COLLECTION_LOCK_READ, cp_hashtable_txlock(), and _cp_hashtable_entry::value.

CPROPS_DLL 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. 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:

Parameters:
table cp_hashtable to lock
type COLLECTION_LOCK_READ or COLLECTION_LOCK_WRITE

Definition at line 358 of file hashtable.c.

References COLLECTION_MODE_IN_TRANSACTION, COLLECTION_MODE_NOSYNC, and cp_hashtable_lock_internal().

CPROPS_DLL void * cp_hashtable_put ( cp_hashtable table,
void *  key,
void *  value 
)

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(), cp_httpclient_set_user_agent(), cp_log_init(), and cp_socket_select_callback_impl().

CPROPS_DLL void * cp_hashtable_put_by_option ( cp_hashtable table,
void *  key,
void *  value,
int  mode 
)

Internal put method.

Definition at line 763 of file hashtable.c.

References COLLECTION_LOCK_WRITE, COLLECTION_MODE_NORESIZE, COLLECTION_MODE_NOSYNC, cp_hashtable_choose_size(), cp_hashtable_create_entry(), cp_hashtable_resize(), cp_hashtable_resize_nosync(), cp_hashtable_txlock(), and cp_hashtable_txunlock().

Referenced by cp_hashtable_put(), cp_hashtable_put_copy(), and cp_hashtable_put_safe().

CPROPS_DLL 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.

Definition at line 756 of file hashtable.c.

References COLLECTION_MODE_COPY, and cp_hashtable_put_by_option().

CPROPS_DLL 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.

Definition at line 751 of file hashtable.c.

References cp_hashtable_put_by_option().

CPROPS_DLL void * cp_hashtable_remove ( cp_hashtable table,
void *  key 
)

Attempts to remove the mapping for key from the table.

Parameters:
table the object
key Key to search for.
Return values:
value retrieved by the key (that was removed)
NULL if the table does not contain the requested key.

Definition at line 971 of file hashtable.c.

References cp_hashtable_remove_by_mode().

Referenced by cp_httpclient_set_header(), and cp_httpclient_set_parameter().

CPROPS_DLL int cp_hashtable_remove_all ( cp_hashtable table  ) 

remove all entries with current mode

Definition at line 918 of file hashtable.c.

References COLLECTION_LOCK_WRITE, and cp_hashtable_txlock().

Referenced by cp_httpclient_drop_headers(), and cp_httpclient_drop_parameters().

void* cp_hashtable_remove_by_mode ( cp_hashtable table,
void *  key,
int  mode 
)

Remove an entry from the table by key with locking mode.

Get the value by key and destroy the entry.

Parameters:
table the object
key Key to search for.
mode operation/locking mode
Return values:
value of the entry with key.
NULL otherwise (no entry with given key)

Definition at line 881 of file hashtable.c.

References COLLECTION_LOCK_WRITE, COLLECTION_MODE_NORESIZE, COLLECTION_MODE_NOSYNC, cp_hashtable_choose_size(), cp_hashtable_remove_internal(), cp_hashtable_resize(), cp_hashtable_resize_nosync(), cp_hashtable_txlock(), and cp_hashtable_txunlock().

Referenced by cp_hashtable_remove(), and cp_hashtable_remove_deep().

CPROPS_DLL int cp_hashtable_remove_deep ( cp_hashtable table,
void *  key 
)

Remove with COLLECTION_MODE_DEEP set

Note:
here cp_hashtable_remove_by_mode returns an invalid pointer on success, since the item has just been released. We can not use it but we can tell it isn't null.

Definition at line 983 of file hashtable.c.

References cp_hashtable_remove_by_mode().

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.

Get the value by key and destroy the entry.

Parameters:
table the object
key Key to search for.
code Hash code of the Key (saves recalculating it)
mode operation mode
resize 0: search in the normal table, 1: search in the resize table
Return values:
value of the entry with key.
NULL otherwise (no entry with given key)

Definition at line 829 of file hashtable.c.

References _cp_hashtable_entry::next, and _cp_hashtable_entry::value.

Referenced by cp_hashtable_remove_by_mode().

void* cp_hashtable_resize ( cp_hashtable table,
long  new_size 
)

Initiates a resize of the cp_hashtable which is executed in the background.

Returns:
NULL

Definition at line 603 of file hashtable.c.

References cp_hashtable_resize_thread().

Referenced by cp_hashtable_put_by_option(), and cp_hashtable_remove_by_mode().

void* cp_hashtable_resize_nosync ( cp_hashtable table,
unsigned long  new_size 
)

Resizes the table to a new size.

This is invoked by the insertion code if the load * factor goes over the fill factor limits.

Parameters:
table the object
new_size desired size. The system trys to optmize the actual size for good distribution.

Definition at line 638 of file hashtable.c.

References cp_hashtable_choose_size(), and DEBUGMSG.

Referenced by cp_hashtable_put_by_option(), and cp_hashtable_remove_by_mode().

void* cp_hashtable_resize_thread ( void *  tbl  ) 

<<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.

Postcondition:
All items moved to the new table which replaces the old table The old table is destroyed.
Note:
The cp_thread locks and unlocks the table for each item. This creates some overhead, but ensures that the table can still be used during resizing.

Definition at line 516 of file hashtable.c.

References COLLECTION_LOCK_WRITE, cp_hashtable_txlock(), cp_hashtable_txunlock(), DEBUGMSG, and _cp_hashtable::table_size.

Referenced by cp_hashtable_resize().

CPROPS_DLL 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

Definition at line 581 of file hashtable.c.

References COLLECTION_LOCK_WRITE, cp_hashtable_txlock(), and cp_hashtable_txunlock().

CPROPS_DLL 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

Definition at line 589 of file hashtable.c.

References COLLECTION_LOCK_WRITE, cp_hashtable_txlock(), and cp_hashtable_txunlock().

CPROPS_DLL int cp_hashtable_set_min_size ( cp_hashtable table,
int  min_size 
)

the internal table will not be resized to less than min_size

Definition at line 572 of file hashtable.c.

References COLLECTION_LOCK_WRITE, cp_hashtable_txlock(), and cp_hashtable_txunlock().

CPROPS_DLL int cp_hashtable_set_mode ( cp_hashtable table,
int  mode 
)

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, COLLECTION_MODE_IN_TRANSACTION, COLLECTION_MODE_NOSYNC, cp_hashtable_txlock(), and cp_hashtable_txunlock().

Referenced by cp_hashtable_destroy_deep().

CPROPS_DLL int cp_hashtable_unlock ( cp_hashtable table  ) 

unlock the table

Definition at line 370 of file hashtable.c.

References COLLECTION_LOCK_WRITE, COLLECTION_MODE_IN_TRANSACTION, and cp_hashtable_unlock_internal().

CPROPS_DLL int cp_hashtable_unset_mode ( cp_hashtable table,
int  mode 
)

unset the mode bits defined by mode

Definition at line 408 of file hashtable.c.

References COLLECTION_LOCK_WRITE, COLLECTION_MODE_NOSYNC, cp_hashtable_txlock(), and cp_hashtable_txunlock().

Referenced by cp_hashtable_destroy_shallow().

void* lookup_internal ( cp_hashtable table,
void *  key,
long  code,
int  option,
int  resize 
)

Retrieves the value by key from normal or resizing table.

Parameters:
table the object
key Key to search for.
code Hash code of the Key (saves recalculating it)
option operation mode
resize 0: search in the normal table, 1: search in the resize table
Return values:
value of the entry with key.
NULL otherwise (no entry with given key)

Definition at line 430 of file hashtable.c.

References COLLECTION_MODE_MULTIPLE_VALUES, cp_list_append(), cp_list_create_view(), cp_list_insert(), and _cp_hashtable_entry::next.

Referenced by cp_hashtable_contains(), and cp_hashtable_get_by_option().


Generated on Mon Dec 5 23:00:23 2011 for cprops by  doxygen 1.4.7