NVMLib  very early alpha
A library to optimally use a Hybrid RAM setup.
hashmap_tx.h
Go to the documentation of this file.
1 #ifndef __NVM_HASHMAP_TX_H
2 #define __NVM_HASHMAP_TX_H
3 
4 #include <stddef.h>
5 #include <stdint.h>
6 #include <libpmemobj.h>
7 #include "malloc.h"
8 
9 struct hashmap_args {
11 };
12 
16 };
17 
18 #ifndef HASHMAP_TX_TYPE_OFFSET
19 #define HASHMAP_TX_TYPE_OFFSET 1004
20 #endif
21 
22 
23 /* layout definition */
24 //TOID_DECLARE(struct hashmap_tx, HASHMAP_TX_TYPE_OFFSET + 0);
25 //TOID_DECLARE(struct buckets, HASHMAP_TX_TYPE_OFFSET + 1);
26 //TOID_DECLARE(struct entry, HASHMAP_TX_TYPE_OFFSET + 2);
27 POBJ_LAYOUT_BEGIN(types_tab);
28 POBJ_LAYOUT_ROOT(types_tab, struct hashmap_tx);
29 POBJ_LAYOUT_TOID(types_tab, struct buckets);
30 POBJ_LAYOUT_TOID(types_tab, struct entry);
31 POBJ_LAYOUT_END(types_tab);
32 
33 typedef struct entry {
36 
37  /* next entry list pointer */
38  TOID(struct entry) next;
40 
41 typedef struct buckets {
42  /* number of buckets */
43  size_t nbuckets;
44  /* array of lists */
45  TOID(struct entry) bucket[];
47 
48 typedef struct hashmap_tx {
49  /* random number generator seed */
51 
52  /* hash function coefficients */
56 
57  /* number of values inserted */
59 
60  /* buckets */
61  TOID(struct buckets) buckets;
63 
64 int hm_tx_check(PMEMobjpool *pop, TOID(struct hashmap_tx) hashmap);
65 int hm_tx_create(PMEMobjpool *pop, TOID(struct hashmap_tx) *map, void *arg);
66 int hm_tx_init(PMEMobjpool *pop, TOID(struct hashmap_tx) hashmap);
67 int hm_tx_insert(PMEMobjpool *pop, TOID(struct hashmap_tx) hashmap,
68  uint64_t key, MEMoid value);
69 MEMoid hm_tx_remove(PMEMobjpool *pop, TOID(struct hashmap_tx) hashmap,
70  uint64_t key);
71 MEMoid hm_tx_get(PMEMobjpool *pop, TOID(struct hashmap_tx) hashmap,
72  uint64_t key);
73 int hm_tx_lookup(PMEMobjpool *pop, TOID(struct hashmap_tx) hashmap,
74  uint64_t key);
75 int hm_tx_foreach(PMEMobjpool *pop, TOID(struct hashmap_tx) hashmap,
76  int (*cb)(uint64_t key, MEMoid value, void *arg), void *arg);
77 size_t hm_tx_count(PMEMobjpool *pop, TOID(struct hashmap_tx) hashmap);
78 int hm_tx_cmd(PMEMobjpool *pop, TOID(struct hashmap_tx) hashmap,
79  unsigned cmd, uint64_t arg);
80 void hm_tx_debug(PMEMobjpool *pop, TOID(struct hashmap_tx) hashmap, FILE *out);
81 #endif // !__NVM_HASHMAP_TX_H
hashmap_tx::hash_fun_a
uint32_t hash_fun_a
Definition: hashmap_tx.h:53
hm_tx_remove
MEMoid hm_tx_remove(PMEMobjpool *pop, TOID(struct hashmap_tx) hashmap, uint64_t key)
Removes specified value from the hashmap.
Definition: hashmap_tx.c:224
POBJ_LAYOUT_BEGIN
POBJ_LAYOUT_BEGIN(types_tab)
entry::TOID
TOID(struct entry) next
hashmap_tx
Definition: hashmap_tx.h:48
hm_tx_check
int hm_tx_check(PMEMobjpool *pop, TOID(struct hashmap_tx) hashmap)
Checks if specified persistent object is an instance of hashmap.
Definition: hashmap_tx.c:463
hashmap_tx::TOID
TOID(struct buckets) buckets
hashmap_tx::hash_fun_b
uint32_t hash_fun_b
Definition: hashmap_tx.h:54
hashmap_tx::seed
uint32_t seed
Definition: hashmap_tx.h:50
hashmap_args
Definition: hashmap_tx.h:9
hashmap_tx::hash_fun_p
uint64_t hash_fun_p
Definition: hashmap_tx.h:55
hashmap_tx
struct hashmap_tx hashmap_tx
pop
PMEMobjpool * pop
Definition: types.c:7
buckets
struct buckets buckets
MEMoid_st
The struct that stores the memptr for the object.
Definition: malloc.h:29
hm_tx_debug
void hm_tx_debug(PMEMobjpool *pop, TOID(struct hashmap_tx) hashmap, FILE *out)
Prints complete hashmap state.
Definition: hashmap_tx.c:314
hm_tx_cmd
int hm_tx_cmd(PMEMobjpool *pop, TOID(struct hashmap_tx) hashmap, unsigned cmd, uint64_t arg)
Executes a command for hashmap.
Definition: hashmap_tx.c:480
POBJ_LAYOUT_TOID
POBJ_LAYOUT_TOID(types_tab, struct buckets)
POBJ_LAYOUT_END
POBJ_LAYOUT_END(types_tab)
hm_tx_count
size_t hm_tx_count(PMEMobjpool *pop, TOID(struct hashmap_tx) hashmap)
Returns number of elements in the hashmap.
Definition: hashmap_tx.c:401
entry::key
uint64_t key
Definition: hashmap_tx.h:34
uint64_t
__uint64_t uint64_t
Definition: globals.h:51
hm_tx_get
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.
Definition: hashmap_tx.c:349
HASHMAP_CMD_REBUILD
@ HASHMAP_CMD_REBUILD
Definition: hashmap_tx.h:14
buckets::TOID
TOID(struct entry) bucket[]
hm_tx_create
int hm_tx_create(PMEMobjpool *pop, TOID(struct hashmap_tx) *map, void *arg)
Allocates a new hashmap.
Definition: hashmap_tx.c:433
malloc.h
hashmap_cmd
hashmap_cmd
Definition: hashmap_tx.h:13
hm_tx_lookup
int hm_tx_lookup(PMEMobjpool *pop, TOID(struct hashmap_tx) hashmap, uint64_t key)
Checks whether specified key exists in the hashmap.
Definition: hashmap_tx.c:377
hashmap_tx::count
uint64_t count
Definition: hashmap_tx.h:58
hm_tx_init
int hm_tx_init(PMEMobjpool *pop, TOID(struct hashmap_tx) hashmap)
Recovers hashmap state.
Definition: hashmap_tx.c:415
buckets::nbuckets
size_t nbuckets
Definition: hashmap_tx.h:43
TOID
TOID(struct hashmap_tx)
Definition: types.c:11
POBJ_LAYOUT_ROOT
POBJ_LAYOUT_ROOT(types_tab, struct hashmap_tx)
HASHMAP_CMD_DEBUG
@ HASHMAP_CMD_DEBUG
Definition: hashmap_tx.h:15
hm_tx_foreach
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.
Definition: hashmap_tx.c:281
hm_tx_insert
int hm_tx_insert(PMEMobjpool *pop, TOID(struct hashmap_tx) hashmap, uint64_t key, MEMoid value)
Inserts the specified value into the hashmap.
Definition: hashmap_tx.c:164
entry
Definition: hashmap_tx.h:33
entry
struct entry entry
hashmap_args::seed
uint32_t seed
Definition: hashmap_tx.h:10
buckets
Definition: hashmap_tx.h:41
uint32_t
__uint32_t uint32_t
Definition: globals.h:52
entry::value
MEMoid value
Definition: hashmap_tx.h:35