Electroneum
Loading...
Searching...
No Matches
slabhash.h File Reference
Include dependency graph for slabhash.h:
This graph shows which files directly or indirectly include this file:

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

Detailed Description

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.

Macro Definition Documentation

◆ HASH_DEFAULT_SLABS

#define HASH_DEFAULT_SLABS   4

default number of slabs

Definition at line 49 of file slabhash.h.

Function Documentation

◆ count_slabhash_entries()

size_t count_slabhash_entries ( struct slabhash * table)
Here is the call graph for this function:
Here is the caller graph for this function:

◆ slabhash_clear()

void slabhash_clear ( struct slabhash * table)

Clear hash table. Entries are all deleted.

Parameters
tableto make empty.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ slabhash_create()

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.

Parameters
numtablesnumber of hash tables to use, other parameters used to initialize these smaller hashtables.
start_sizesize of hashtable array at start, must be power of 2.
maxmemmaximum amount of memory this table is allowed to use. so every table gets maxmem/numtables to use for itself.
sizefunccalculates memory usage of entries.
compfunccompares entries, 0 on equality.
delkeyfuncdeletes key.
deldatafuncdeletes data.
arguser argument that is passed to user function calls.
Returns
: new hash table or NULL on malloc failure.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ slabhash_delete()

void slabhash_delete ( struct slabhash * table)

Delete hash table. Entries are all deleted.

Parameters
tableto delete.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ slabhash_get_mem()

size_t slabhash_get_mem ( struct slabhash * table)

Retrieve slab hash current memory use.

Parameters
tablehash table.
Returns
memory in use.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ slabhash_get_size()

size_t slabhash_get_size ( struct slabhash * table)

Retrieve slab hash total size.

Parameters
tablehash table.
Returns
size configured as max.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ slabhash_gettable()

struct lruhash * slabhash_gettable ( struct slabhash * table,
hashvalue_type hash )

Get lruhash table for a given hash value

Parameters
tableslabbed hash table.
hashhash value.
Returns
the lru hash table.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ slabhash_insert()

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.

Parameters
tablehash table.
hashhash value. User calculates the hash.
entryidentifies 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.
datathe data.
cb_overrideif not NULL overrides the cb_arg for deletefunc.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ slabhash_lookup()

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

Parameters
tablehash table.
hashhash of key.
keywhat to look for, compared against entries in overflow chain. the hash value must be set, and must work with compare function.
wrset to true if you desire a writelock on the entry. with a writelock you can update the data part.
Returns
: pointer to the entry or NULL. The entry is locked. The user must unlock the entry when done.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ slabhash_remove()

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.

Parameters
tablehash table.
hashhash of key.
keywhat to look for.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ slabhash_setmarkdel()

void slabhash_setmarkdel ( struct slabhash * table,
lruhash_markdelfunc_type md )

Set markdel function

Parameters
tableslabbed hash table.
mdmarkdel function ptr.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ slabhash_status()

void slabhash_status ( struct slabhash * table,
const char * id,
int extended )

Output debug info to the log as to state of the hash table.

Parameters
tablehash table.
idstring printed with table to identify the hash table.
extendedset to true to print statistics on overflow bin lengths.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ slabhash_traverse()

void slabhash_traverse ( struct slabhash * table,
int wr,
void(* func )(struct lruhash_entry *, void *),
void * arg )

Traverse a slabhash.

Parameters
tableslabbed hash table.
wrif true, writelock is obtained, otherwise readlock.
funcfunction to call for every element.
arguser argument to function.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ test_slabhash_compfunc()

int test_slabhash_compfunc ( void * ,
void *  )

test comparefunc for lruhash

Here is the call graph for this function:
Here is the caller graph for this function:

◆ test_slabhash_deldata()

void test_slabhash_deldata ( void * ,
void *  )

test deldata for lruhash

Here is the call graph for this function:
Here is the caller graph for this function:

◆ test_slabhash_delkey()

void test_slabhash_delkey ( void * ,
void *  )

test delkey for lruhash

Here is the call graph for this function:
Here is the caller graph for this function:

◆ test_slabhash_sizefunc()

size_t test_slabhash_sizefunc ( void * ,
void *  )

test sizefunc for lruhash

Here is the call graph for this function:
Here is the caller graph for this function: