![]() |
NVMLib
very early alpha
A library to optimally use a Hybrid RAM setup.
|
#include <stdlib.h>#include <stdio.h>#include <errno.h>#include <inttypes.h>#include "hashmap_tx.h"
Go to the source code of this file.
Macros | |
| #define | HASH_FUNC_COEFF_P 32212254719ULL |
| #define | INIT_BUCKETS_NUM 10 |
| #define | MIN_HASHSET_THRESHOLD 5 |
| #define | MAX_HASHSET_THRESHOLD 10 |
Functions | |
| static void | create_hashmap (PMEMobjpool *pop, TOID(struct hashmap_tx) hashmap, uint32_t seed) |
| Hashmap initializer. More... | |
| static uint64_t | hash (const TOID(struct hashmap_tx) *hashmap, const TOID(struct buckets) *buckets, uint64_t value) |
| The hash function. More... | |
| static void | hm_tx_rebuild (PMEMobjpool *pop, TOID(struct hashmap_tx) hashmap, size_t new_len) |
| Rebuilds the hashmap when the hashmap size threshold is reached. More... | |
| int | hm_tx_insert (PMEMobjpool *pop, TOID(struct hashmap_tx) hashmap, uint64_t key, MEMoid value) |
Inserts the specified value into the hashmap. More... | |
| MEMoid | hm_tx_remove (PMEMobjpool *pop, TOID(struct hashmap_tx) hashmap, uint64_t key) |
Removes specified value from the hashmap. More... | |
| int | hm_tx_foreach (PMEMobjpool *pop, TOID(struct hashmap_tx) hashmap, int(*cb)(uint64_t key, MEMoid value, void *arg), void *arg) |
Calls a given callback for every element in the hashmap. More... | |
| void | hm_tx_debug (PMEMobjpool *pop, TOID(struct hashmap_tx) hashmap, FILE *out) |
| Prints complete hashmap state. More... | |
| MEMoid | hm_tx_get (PMEMobjpool *pop, TOID(struct hashmap_tx) hashmap, uint64_t key) |
Checks whether specified key is in the hashmap and retries the value associated with it. More... | |
| int | hm_tx_lookup (PMEMobjpool *pop, TOID(struct hashmap_tx) hashmap, uint64_t key) |
Checks whether specified key exists in the hashmap. More... | |
| size_t | hm_tx_count (PMEMobjpool *pop, TOID(struct hashmap_tx) hashmap) |
Returns number of elements in the hashmap. More... | |
| int | hm_tx_init (PMEMobjpool *pop, TOID(struct hashmap_tx) hashmap) |
Recovers hashmap state. More... | |
| int | hm_tx_create (PMEMobjpool *pop, TOID(struct hashmap_tx) *map, void *arg) |
Allocates a new hashmap. More... | |
| int | hm_tx_check (PMEMobjpool *pop, TOID(struct hashmap_tx) hashmap) |
Checks if specified persistent object is an instance of hashmap. More... | |
| int | hm_tx_cmd (PMEMobjpool *pop, TOID(struct hashmap_tx) hashmap, unsigned cmd, uint64_t arg) |
Executes a command for hashmap. More... | |
The implemantation of a Persistent Hashmap using only transaction APIs of libpmemobj
Definition in file hashmap_tx.c.
| #define HASH_FUNC_COEFF_P 32212254719ULL |
Definition at line 15 of file hashmap_tx.c.
| #define INIT_BUCKETS_NUM 10 |
Definition at line 18 of file hashmap_tx.c.
| #define MAX_HASHSET_THRESHOLD 10 |
Definition at line 24 of file hashmap_tx.c.
| #define MIN_HASHSET_THRESHOLD 5 |
Definition at line 21 of file hashmap_tx.c.
|
static |
Hashmap initializer.
This is the function called by hm_tx_create() for creation of the hashmap.
| PMEMobjpool | the pool where the hashmap would be stored. |
| hashmap | the typed hashmap which needs to be initialised. |
| seed | the seed for initialising hashing varaibles. |
Definition at line 38 of file hashmap_tx.c.

|
static |
The hash function.
Its the simplest hashing function.
This function is used to get the hash for a key in the hashmap.
| hashmap | the hashmap which is being accessed |
| buckets | the pointer to the buckets in the hashmap |
| value | the value that needs to be hashed. * |
Definition at line 76 of file hashmap_tx.c.
| int hm_tx_check | ( | PMEMobjpool * | pop, |
| TOID(struct hashmap_tx) | hashmap | ||
| ) |
Checks if specified persistent object is an instance of hashmap.
| PMEMobjpool | the pool where the hashmap is stored. |
| hashmap | the typed hashmap which needs to be initialised. |
hashmap Definition at line 463 of file hashmap_tx.c.
| int hm_tx_cmd | ( | PMEMobjpool * | pop, |
| TOID(struct hashmap_tx) | hashmap, | ||
| unsigned | cmd, | ||
| uint64_t | arg | ||
| ) |
Executes a command for hashmap.
Available commands are: HASHMAP_CMD_REBUILD and HASHMAP_CMD_DEBUG
| PMEMobjpool | the pool where the hashmap is stored. |
| hashmap | the typed hashmap which needs to be initialised. |
| cmd | the command to be executed. |
| arg | the arguments for the command. |
EINVAL: otherwise Definition at line 480 of file hashmap_tx.c.

| size_t hm_tx_count | ( | PMEMobjpool * | pop, |
| TOID(struct hashmap_tx) | hashmap | ||
| ) |
Returns number of elements in the hashmap.
| PMEMobjpool | the pool where the hashmap is stored. |
| hashmap | the typed hashmap which needs to be initialised. |
hashmap. Definition at line 401 of file hashmap_tx.c.
| int hm_tx_create | ( | PMEMobjpool * | pop, |
| TOID(struct hashmap_tx) * | map, | ||
| void * | arg | ||
| ) |
Allocates a new hashmap.
| PMEMobjpool | the pool where the hashmap would be stored. |
| hashmap | the typed hashmap which needs to be initialised. |
| arg | additional arguments if necessary |
Definition at line 433 of file hashmap_tx.c.

| void hm_tx_debug | ( | PMEMobjpool * | pop, |
| TOID(struct hashmap_tx) | hashmap, | ||
| FILE * | out | ||
| ) |
Prints complete hashmap state.
This function is used for debugging purposes.
| PMEMobjpool | the pool where the hashmap would be stored. |
| hashmap | the typed hashmap which needs to be initialised. |
| out | the file desciptor for where the output needs to be recorded. |
out paramater can be stdout and stderr too. Definition at line 314 of file hashmap_tx.c.

| int hm_tx_foreach | ( | PMEMobjpool * | pop, |
| TOID(struct hashmap_tx) | hashmap, | ||
| int(*)(uint64_t key, MEMoid value, void *arg) | cb, | ||
| void * | arg | ||
| ) |
Calls a given callback for every element in the hashmap.
| PMEMobjpool | the pool where the hashmap is stored. |
| hashmap | the typed hashmap which needs to be initialised. |
| cb | the calback function. |
| arg | additional arguments for the callback function |
callback function. Definition at line 281 of file hashmap_tx.c.

| MEMoid hm_tx_get | ( | PMEMobjpool * | pop, |
| TOID(struct hashmap_tx) | hashmap, | ||
| uint64_t | key | ||
| ) |
Checks whether specified key is in the hashmap and retries the value associated with it.
| PMEMobjpool | the pool where the hashmap is stored. |
| hashmap | the typed hashmap which needs to be initialised. |
| key | the key for the value being inserted. It will be used to calculate the hash. |
value associated with the key. key existed Definition at line 349 of file hashmap_tx.c.

| int hm_tx_init | ( | PMEMobjpool * | pop, |
| TOID(struct hashmap_tx) | hashmap | ||
| ) |
Recovers hashmap state.
Called after pmemobj_open().
| PMEMobjpool | the pool where the hashmap is stored. |
| hashmap | the typed hashmap which needs to be initialised. |
Definition at line 415 of file hashmap_tx.c.
| int hm_tx_insert | ( | PMEMobjpool * | pop, |
| TOID(struct hashmap_tx) | hashmap, | ||
| uint64_t | key, | ||
| MEMoid | value | ||
| ) |
Inserts the specified value into the hashmap.
| PMEMobjpool | the pool where the hashmap is stored. |
| hashmap | the typed hashmap which needs to be initialised. |
| key | the key for the value being inserted. It will be used to calculate the hash. |
| value | the value that is supposed to be inserted. |
value already existed key already exists in the hashmap, then the value provided is not inserted. Definition at line 164 of file hashmap_tx.c.

| int hm_tx_lookup | ( | PMEMobjpool * | pop, |
| TOID(struct hashmap_tx) | hashmap, | ||
| uint64_t | key | ||
| ) |
Checks whether specified key exists in the hashmap.
| PMEMobjpool | the pool where the hashmap is stored. |
| hashmap | the typed hashmap which needs to be initialised. |
| key | the key for the value being inserted. It will be used to calculate the hash. |
key exists Definition at line 377 of file hashmap_tx.c.

|
static |
Rebuilds the hashmap when the hashmap size threshold is reached.
The hashmap is rebuilt, i.e its size is increased/decreased, when its size exceeds the MAX_HASHSET_THRESHOLD or when the number of elements in the hashmap are less than the number of buckets in the hashmap.
| PMEMobjpool | the pool where the hashmap is stored. |
| hashmap | the typed hashmap which needs to be initialised. |
| new_len | the length of the resulting hashmap after resizing. |
Definition at line 102 of file hashmap_tx.c.

| MEMoid hm_tx_remove | ( | PMEMobjpool * | pop, |
| TOID(struct hashmap_tx) | hashmap, | ||
| uint64_t | key | ||
| ) |
Removes specified value from the hashmap.
| PMEMobjpool | the pool where the hashmap is stored. |
| hashmap | the typed hashmap which needs to be initialised. |
| key | the key for the value being inserted. It will be used to calculate the hash. |
value associated with the key deleted upon success key existedhashmap are less that number of buckets. Definition at line 224 of file hashmap_tx.c.
