|
Electroneum
|
#include "util/storage/lruhash.h"

Go to the source code of this file.
Classes | |
| struct | slabhash |
| struct | slabhash_testkey |
| struct | slabhash_testdata |
Macros | |
| #define | HASH_DEFAULT_SLABS 4 |
Functions | |
| struct slabhash * | slabhash_create (size_t numtables, size_t start_size, size_t maxmem, lruhash_sizefunc_type sizefunc, lruhash_compfunc_type compfunc, lruhash_delkeyfunc_type delkeyfunc, lruhash_deldatafunc_type deldatafunc, void *arg) |
| void | slabhash_delete (struct slabhash *table) |
| void | slabhash_clear (struct slabhash *table) |
| void | slabhash_insert (struct slabhash *table, hashvalue_type hash, struct lruhash_entry *entry, void *data, void *cb_override) |
| struct lruhash_entry * | slabhash_lookup (struct slabhash *table, hashvalue_type hash, void *key, int wr) |
| void | slabhash_remove (struct slabhash *table, hashvalue_type hash, void *key) |
| void | slabhash_status (struct slabhash *table, const char *id, int extended) |
| size_t | slabhash_get_size (struct slabhash *table) |
| size_t | slabhash_get_mem (struct slabhash *table) |
| struct lruhash * | slabhash_gettable (struct slabhash *table, hashvalue_type hash) |
| void | slabhash_setmarkdel (struct slabhash *table, lruhash_markdelfunc_type md) |
| void | slabhash_traverse (struct slabhash *table, int wr, void(*func)(struct lruhash_entry *, void *), void *arg) |
| size_t | count_slabhash_entries (struct slabhash *table) |
| size_t | test_slabhash_sizefunc (void *, void *) |
| int | test_slabhash_compfunc (void *, void *) |
| void | test_slabhash_delkey (void *, void *) |
| void | test_slabhash_deldata (void *, void *) |
Hash table that consists of smaller hash tables. It cannot grow, but that gives it the ability to have multiple locks. Also this means there are multiple LRU lists.
Definition in file slabhash.h.
| #define HASH_DEFAULT_SLABS 4 |
default number of slabs
Definition at line 49 of file slabhash.h.
| size_t count_slabhash_entries | ( | struct slabhash * | table | ) |
| void slabhash_clear | ( | struct slabhash * | table | ) |
Clear hash table. Entries are all deleted.
| table | to make empty. |
| struct slabhash* slabhash_create | ( | size_t | numtables, |
| size_t | start_size, | ||
| size_t | maxmem, | ||
| lruhash_sizefunc_type | sizefunc, | ||
| lruhash_compfunc_type | compfunc, | ||
| lruhash_delkeyfunc_type | delkeyfunc, | ||
| lruhash_deldatafunc_type | deldatafunc, | ||
| void * | arg | ||
| ) |
Create new slabbed hash table.
| numtables | number of hash tables to use, other parameters used to initialize these smaller hashtables. |
| start_size | size of hashtable array at start, must be power of 2. |
| maxmem | maximum amount of memory this table is allowed to use. so every table gets maxmem/numtables to use for itself. |
| sizefunc | calculates memory usage of entries. |
| compfunc | compares entries, 0 on equality. |
| delkeyfunc | deletes key. |
| deldatafunc | deletes data. |
| arg | user argument that is passed to user function calls. |
| void slabhash_delete | ( | struct slabhash * | table | ) |
Delete hash table. Entries are all deleted.
| table | to delete. |
| size_t slabhash_get_mem | ( | struct slabhash * | table | ) |
Retrieve slab hash current memory use.
| table | hash table. |
| size_t slabhash_get_size | ( | struct slabhash * | table | ) |
Retrieve slab hash total size.
| table | hash table. |
| struct lruhash* slabhash_gettable | ( | struct slabhash * | table, |
| hashvalue_type | hash | ||
| ) |
Get lruhash table for a given hash value
| table | slabbed hash table. |
| hash | hash value. |
| void slabhash_insert | ( | struct slabhash * | table, |
| hashvalue_type | hash, | ||
| struct lruhash_entry * | entry, | ||
| void * | data, | ||
| void * | cb_override | ||
| ) |
Insert a new element into the hashtable, uses lruhash_insert. If key is already present data pointer in that entry is updated.
| table | hash table. |
| hash | hash value. User calculates the hash. |
| entry | identifies the entry. If key already present, this entry->key is deleted immediately. But entry->data is set to NULL before deletion, and put into the existing entry. The data is then freed. |
| data | the data. |
| cb_override | if not NULL overrides the cb_arg for deletefunc. |
| struct lruhash_entry* slabhash_lookup | ( | struct slabhash * | table, |
| hashvalue_type | hash, | ||
| void * | key, | ||
| int | wr | ||
| ) |
Lookup an entry in the hashtable. Uses lruhash_lookup. At the end of the function you hold a (read/write)lock on the entry. The LRU is updated for the entry (if found).
| table | hash table. |
| hash | hash of key. |
| key | what to look for, compared against entries in overflow chain. the hash value must be set, and must work with compare function. |
| wr | set to true if you desire a writelock on the entry. with a writelock you can update the data part. |
| void slabhash_remove | ( | struct slabhash * | table, |
| hashvalue_type | hash, | ||
| void * | key | ||
| ) |
Remove entry from hashtable. Does nothing if not found in hashtable. Delfunc is called for the entry. Uses lruhash_remove.
| table | hash table. |
| hash | hash of key. |
| key | what to look for. |
| void slabhash_setmarkdel | ( | struct slabhash * | table, |
| lruhash_markdelfunc_type | md | ||
| ) |
Set markdel function
| table | slabbed hash table. |
| md | markdel function ptr. |
| void slabhash_status | ( | struct slabhash * | table, |
| const char * | id, | ||
| int | extended | ||
| ) |
Output debug info to the log as to state of the hash table.
| table | hash table. |
| id | string printed with table to identify the hash table. |
| extended | set to true to print statistics on overflow bin lengths. |
| void slabhash_traverse | ( | struct slabhash * | table, |
| int | wr, | ||
| void(*)(struct lruhash_entry *, void *) | func, | ||
| void * | arg | ||
| ) |
Traverse a slabhash.
| table | slabbed hash table. |
| wr | if true, writelock is obtained, otherwise readlock. |
| func | function to call for every element. |
| arg | user argument to function. |
| int test_slabhash_compfunc | ( | void * | , |
| void * | |||
| ) |
test comparefunc for lruhash
| void test_slabhash_deldata | ( | void * | , |
| void * | |||
| ) |
test deldata for lruhash
| void test_slabhash_delkey | ( | void * | , |
| void * | |||
| ) |
test delkey for lruhash
| size_t test_slabhash_sizefunc | ( | void * | , |
| void * | |||
| ) |
test sizefunc for lruhash