OPIC
Object Persistence In C
|
An opaque object that manage associations of fixed length key-value pairs. More...
Related Functions | |
(Note that these are not member functions.) | |
OPHashTable * | HTNew (OPHeap *heap, uint64_t num_objects, double load, size_t keysize, size_t valsize) |
Constructor for OPHashTable. More... | |
void | HTDestroy (OPHashTable *table) |
Destructor for OPHashTable. More... | |
bool | HTInsertCustom (OPHashTable *table, OPHash hasher, void *key, void *val) |
Associates the specified key with the specified value in OPHashTable with specified hash function. More... | |
bool | HTUpsertCustom (OPHashTable *table, OPHash hasher, void *key, void **val_ref, bool *is_duplicate) |
Update or insert depends on whether the key already exists in the hash table using custom hash function. More... | |
void * | HTGetCustom (OPHashTable *table, OPHash hasher, void *key) |
Obtain the value associated with the specified key and hash function. Returns NULL if the key was not found. More... | |
void * | HTDeleteCustom (OPHashTable *table, OPHash hasher, void *key) |
Deletes the key-value entry in hash table with specified hasher. More... | |
static bool | HTInsert (OPHashTable *table, void *key, void *val) |
Associates the specified key with the specified value in OPHashTable using the default hash function. More... | |
static bool | HTUpsert (OPHashTable *table, void *key, void **val_ref, bool *is_duplicate) |
Update or insert depends on whether the key already exists in the hash table. More... | |
static void * | HTGet (OPHashTable *table, void *key) |
Obtain the value associated with the specified key using the default hash function. Returns NULL if the key was not found. More... | |
static void * | HTDelete (OPHashTable *table, void *key) |
Deletes the key-value entry in hash table using the default hash function. More... | |
uint64_t | HTObjcnt (OPHashTable *table) |
Obtain the number of objects stored in this hash table. | |
uint64_t | HTCapacity (OPHashTable *table) |
Obtain the number of objects can be stored in this hash table. | |
size_t | HTKeySize (OPHashTable *table) |
Obtain the size of the key configured for this hash table. | |
size_t | HTValSize (OPHashTable *table) |
Obtain the size of the value configured for this hash table. | |
void | HTIterate (OPHashTable *table, OPHashIterator iterator, void *context) |
Iterates over all key-value pairs in this hash table with user specified context. More... | |
void | HTPrintStat (OPHashTable *table) |
Prints the accumulated count for each probing number. More... | |
An opaque object that manage associations of fixed length key-value pairs.
The size of key and value is configured at the construction time of OPHashTable, and can not be changed later. This design is similar to fixed length fields CHAR(30)
in SQL which improve both space and runtime efficiencies.
Note that user can spcify size of value to 0 to make OPHashTable as a hash set. Similarly, make value size sizeof(opref_t)
and store a opref_t referencing another container (binary serach tree or whatever), can turn OPHashTable into a hash-multiset.
This object is not thread safe.
|
related |
Constructor for OPHashTable.
heap | OPHeap instance. |
num_objects | number of objects we decided to put in. |
load | (0.0-1.0) how full the hash table could be before expansion. |
keysize | length of key measured in bytes. Cannot be zero. |
valsize | length of value measured in bytes. This vlaue can be zero and the hash table would work like a hash set. |
|
related |
Destructor for OPHashTable.
table | the OPHashTable instance to destory. |
|
related |
Associates the specified key with the specified value in OPHashTable with specified hash function.
table | OPHashTable instance. |
hasher | hash function. |
key | pointer to the key. |
val | pointer to the value. |
The content pointed by key and val will be copied into the hash table. If the value size were 0, only the key get copied. When there's a key collision, the coresponding value get replaced.
If the inserted key-value pairs exceeded the original size user configured, the hash table will resized with a larger capacity. If the resize failed, false is returned.
|
related |
Update or insert depends on whether the key already exists in the hash table using custom hash function.
table | OPHashTable instance. |
hasher | hash function. |
key | pointer to the key. |
val_ref | reference of value pointer. |
is_duplicate | reference of duplication boolean variable. |
This method does not insert the value automatically, instead it provides the pointer to the address where value can be inserted or overriden.
If the inserted key-value pairs exceeded the original size user configured, the hash table will resized with a larger capacity. If the resize failed, false is returned.
|
related |
Obtain the value associated with the specified key and hash function. Returns NULL if the key was not found.
table | OPHashTable instance. |
hasher | hash function. |
key | pointer to the key. |
If the value size were set to 0, HTGetCustom would still return a pointer to where it would store the value. User can still use the returned value to exam if the key were present in the hash table.
|
related |
Deletes the key-value entry in hash table with specified hasher.
table | OPHashTable instance. |
hasher | hash function. |
key | pointer to the key. |
The hash table may shrink if too many entries were deleted.
|
related |
Associates the specified key with the specified value in OPHashTable using the default hash function.
table | OPHashTable instance. |
key | pointer to the key. |
val | pointer to the value. |
The content pointed by key and val will be copied into the hash table. If the value size were 0, only the key get copied. When there's a key collision, the coresponding value get replaced.
If the inserted key-value pairs exceeded the original size user configured, the hash table will resized with a larger capacity. If the resize failed, false is returned.
Definition at line 200 of file op_hash_table.h.
|
related |
Update or insert depends on whether the key already exists in the hash table.
table | OPHashTable instance. |
key | pointer to the key. |
val_ref | reference of value pointer. |
is_duplicate | reference of duplication boolean variable. |
This method does not insert the value automatically, instead it provides the pointer to the address where value can be inserted or overriden.
If the inserted key-value pairs exceeded the original size user configured, the hash table will resized with a larger capacity. If the resize failed, false is returned.
Definition at line 241 of file op_hash_table.h.
|
related |
Obtain the value associated with the specified key using the default hash function. Returns NULL if the key was not found.
table | OPHashTable instance. |
key | pointer to the key. |
If the value size were set to 0, HTGetCustom would still return a pointer to where it would store the value. User can still use the returned value to exam if the key were present in the hash table.
Definition at line 260 of file op_hash_table.h.
|
related |
Deletes the key-value entry in hash table using the default hash function.
table | OPHashTable instance. |
key | pointer to the key. |
The hash table may shrink if too many entries were deleted.
Definition at line 277 of file op_hash_table.h.
|
related |
Iterates over all key-value pairs in this hash table with user specified context.
table | OPHashTable instance. |
iterator | function pointer to user defined iterator function. |
context | user defined context. |
|
related |
Prints the accumulated count for each probing number.
Deprecated. Use HTProbeStat instead.