![]() |
#include <pthread.h>
#include <stdbool.h>
#include <stddef.h>
#include <stdint.h>
#include <citrusleaf/cf_types.h>
Go to the source code of this file.
Data Structures | |
struct | shash_elem |
struct | shash |
Macros | |
#define | SHASH_CR_GRAB 0x02 |
#define | SHASH_CR_MT_BIGLOCK 0x04 |
#define | SHASH_CR_MT_MANYLOCK 0x08 |
#define | SHASH_CR_RESIZE 0x01 |
#define | SHASH_CR_UNTRACKED 0x10 |
#define | SHASH_ELEM_KEY_PTR(_h, _e) ( (void *) _e->data ) |
#define | SHASH_ELEM_SZ(_h) ( sizeof(shash_elem) + (_h->key_len) + (_h->value_len) ) |
#define | SHASH_ELEM_VALUE_PTR(_h, _e) ( (void *) (_e->data + _h->key_len) ) |
#define | SHASH_ERR -1 |
#define | SHASH_ERR_BUFSZ -2 |
#define | SHASH_ERR_FOUND -4 |
#define | SHASH_ERR_NOTFOUND -3 |
#define | SHASH_OK 0 |
#define | SHASH_REDUCE_DELETE (1) |
Typedefs | |
typedef uint32_t(* | shash_hash_fn )(void *key) |
typedef int(* | shash_reduce_fn )(void *key, void *data, void *udata) |
typedef void(* | shash_update_fn )(void *key, void *value_old, void *value_new, void *udata) |
Functions | |
int | shash_create (shash **h, shash_hash_fn h_fn, uint32_t key_len, uint32_t value_len, uint32_t sz, uint flags) |
int | shash_delete (shash *h, void *key) |
int | shash_delete_lockfree (shash *h, void *key) |
void | shash_deleteall_lockfree (shash *h) |
void | shash_destroy (shash *h) |
int | shash_get (shash *h, void *key, void *value) |
int | shash_get_and_delete (shash *h, void *key, void *value) |
uint32_t | shash_get_size (shash *h) |
int | shash_get_vlock (shash *h, void *key, void **value, pthread_mutex_t **vlock) |
int | shash_grab (shash *h, void *key, uint32_t key_len, void **value, uint32_t *value_len) |
int | shash_put (shash *h, void *key, void *value) |
int | shash_put_duplicate (shash *h, void *key, void *value) |
int | shash_put_unique (shash *h, void *key, void *value) |
int | shash_reduce (shash *h, shash_reduce_fn reduce_fn, void *udata) |
int | shash_reduce_delete (shash *h, shash_reduce_fn reduce_fn, void *udata) |
int | shash_return (shash *h, void *value) |
int | shash_update (shash *h, void *key, void *value_old, void *value_new, shash_update_fn update_fn, void *udata) |
#define SHASH_CR_GRAB 0x02 |
support 'grab' call (requires more memory)
Definition at line 60 of file src/include/citrusleaf/cf_shash.h.
#define SHASH_CR_MT_BIGLOCK 0x04 |
support multithreaded access with a single big lock
Definition at line 65 of file src/include/citrusleaf/cf_shash.h.
#define SHASH_CR_MT_MANYLOCK 0x08 |
support multithreaded access with a pool of object loccks
Definition at line 70 of file src/include/citrusleaf/cf_shash.h.
#define SHASH_CR_RESIZE 0x01 |
support resizes (will sometimes hang for long periods)
Definition at line 55 of file src/include/citrusleaf/cf_shash.h.
#define SHASH_CR_UNTRACKED 0x10 |
Do not track memory allocations in this hash table. (Used only when creating the hash table tracking memory allocations....)
Definition at line 76 of file src/include/citrusleaf/cf_shash.h.
#define SHASH_ELEM_KEY_PTR | ( | _h, | |
_e | |||
) | ( (void *) _e->data ) |
Definition at line 256 of file src/include/citrusleaf/cf_shash.h.
#define SHASH_ELEM_SZ | ( | _h) | ( sizeof(shash_elem) + (_h->key_len) + (_h->value_len) ) |
Definition at line 258 of file src/include/citrusleaf/cf_shash.h.
#define SHASH_ELEM_VALUE_PTR | ( | _h, | |
_e | |||
) | ( (void *) (_e->data + _h->key_len) ) |
Definition at line 257 of file src/include/citrusleaf/cf_shash.h.
#define SHASH_ERR -1 |
Definition at line 49 of file src/include/citrusleaf/cf_shash.h.
#define SHASH_ERR_BUFSZ -2 |
Definition at line 48 of file src/include/citrusleaf/cf_shash.h.
#define SHASH_ERR_FOUND -4 |
Definition at line 46 of file src/include/citrusleaf/cf_shash.h.
#define SHASH_ERR_NOTFOUND -3 |
Definition at line 47 of file src/include/citrusleaf/cf_shash.h.
#define SHASH_OK 0 |
Definition at line 50 of file src/include/citrusleaf/cf_shash.h.
#define SHASH_REDUCE_DELETE (1) |
indicate that a delete should be done during the reduction
Definition at line 81 of file src/include/citrusleaf/cf_shash.h.
typedef uint32_t(* shash_hash_fn)(void *key) |
A generic call for hash functions the user can create
Definition at line 90 of file src/include/citrusleaf/cf_shash.h.
Typedef for a "reduce" fuction that is called on every node (Note about return value: some kinds of reduces can manipulate the hash table, allowing deletion. See the particulars of the reduce call.)
Definition at line 105 of file src/include/citrusleaf/cf_shash.h.
typedef void(* shash_update_fn)(void *key, void *value_old, void *value_new, void *udata) |
Type for a function to be called under the hash table locks to atomically update a hash table entry. The old value is the current value of the key, or NULL if non-existent. The new value is allocated by the caller. User data can be anything.
Definition at line 98 of file src/include/citrusleaf/cf_shash.h.
int shash_create | ( | shash ** | h, |
shash_hash_fn | h_fn, | ||
uint32_t | key_len, | ||
uint32_t | value_len, | ||
uint32_t | sz, | ||
uint | flags | ||
) |
Create a hash table Pass in the hash function (required) the key length if static (if not static pass 0 the value length if static (if not static pass 0 The initial table size a set of flags
int shash_delete | ( | shash * | h, |
void * | key | ||
) |
Got a key you want removed - this is the function to call
int shash_delete_lockfree | ( | shash * | h, |
void * | key | ||
) |
Special function you can call when you already have the lock - such as a vlock get
void shash_deleteall_lockfree | ( | shash * | h) |
Delete all the data from the entire hash - complete cleanup
void shash_destroy | ( | shash * | h) |
Destroy the entire hash - all memory will be freed
int shash_get | ( | shash * | h, |
void * | key, | ||
void * | value | ||
) |
call with the buffer you want filled; if you just want to check for existence, call with value set to NULL
int shash_get_and_delete | ( | shash * | h, |
void * | key, | ||
void * | value | ||
) |
Does a get and delete at the same time so you can make sure only one person gets what was inserted
uint32_t shash_get_size | ( | shash * | h) |
Get the number of elements currently in the hash
int shash_get_vlock | ( | shash * | h, |
void * | key, | ||
void ** | value, | ||
pthread_mutex_t ** | vlock | ||
) |
Returns the pointer to the internal item, and a locked-lock which allows the touching of internal state. If non-lock hash table, vlock param will be ignored
Note that the vlock is passed back only when the return code is BB_OK. In the case where nothing is found, no lock is held. It might be better to do it the other way, but you can change it later if you want
int shash_grab | ( | shash * | h, |
void * | key, | ||
uint32_t | key_len, | ||
void ** | value, | ||
uint32_t * | value_len | ||
) |
An interesting idea: readv / writev for these functions? Find / get a value from the hash But take the reference count on the object; must be returned with the return call
int shash_put | ( | shash * | h, |
void * | key, | ||
void * | value | ||
) |
Place a value into the hash Value will be copied into the hash
int shash_put_duplicate | ( | shash * | h, |
void * | key, | ||
void * | value | ||
) |
Place a duplicate value into the hash Value will be copied into the hash
int shash_put_unique | ( | shash * | h, |
void * | key, | ||
void * | value | ||
) |
Place a unique value into the hash Value will be copied into the hash
int shash_reduce | ( | shash * | h, |
shash_reduce_fn | reduce_fn, | ||
void * | udata | ||
) |
Map/Reduce pattern - call the callback on every element in the hash Warning: the entire traversal can hold the lock in the 'biglock' case, so make the reduce_fn lightweight! Consider queuing or soemthing if you want to do something fancy
int shash_reduce_delete | ( | shash * | h, |
shash_reduce_fn | reduce_fn, | ||
void * | udata | ||
) |
Map/Reduce pattern - call the callback on every element in the hash This instance allows deletion of hash elements during the reduce: return -1 to cause the deletion of the element visisted
int shash_return | ( | shash * | h, |
void * | value | ||
) |
Return a value that has been gotten
int shash_update | ( | shash * | h, |
void * | key, | ||
void * | value_old, | ||
void * | value_new, | ||
shash_update_fn | update_fn, | ||
void * | udata | ||
) |
Atomically update an entry in the hash table using a user-supplied update function and user data. The update function performs the merge of the old and new values, with respect to the user data and returns the new value.