NVMLib  very early alpha
A library to optimally use a Hybrid RAM setup.
hashmap_tx.h File Reference
#include <stddef.h>
#include <stdint.h>
#include <libpmemobj.h>
#include "malloc.h"
Include dependency graph for hashmap_tx.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Data Structures

struct  hashmap_args
 
struct  entry
 
struct  buckets
 
struct  hashmap_tx
 

Macros

#define HASHMAP_TX_TYPE_OFFSET   1004
 

Typedefs

typedef struct entry entry
 
typedef struct buckets buckets
 
typedef struct hashmap_tx hashmap_tx
 

Enumerations

enum  hashmap_cmd { HASHMAP_CMD_REBUILD, HASHMAP_CMD_DEBUG }
 

Functions

 POBJ_LAYOUT_BEGIN (types_tab)
 
 POBJ_LAYOUT_ROOT (types_tab, struct hashmap_tx)
 
 POBJ_LAYOUT_TOID (types_tab, struct buckets)
 
 POBJ_LAYOUT_TOID (types_tab, struct entry)
 
 POBJ_LAYOUT_END (types_tab)
 
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_create (PMEMobjpool *pop, TOID(struct hashmap_tx) *map, void *arg)
 Allocates a new hashmap. More...
 
int hm_tx_init (PMEMobjpool *pop, TOID(struct hashmap_tx) hashmap)
 Recovers hashmap state. 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...
 
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...
 
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...
 
size_t hm_tx_count (PMEMobjpool *pop, TOID(struct hashmap_tx) hashmap)
 Returns number of elements in the hashmap. More...
 
int hm_tx_cmd (PMEMobjpool *pop, TOID(struct hashmap_tx) hashmap, unsigned cmd, uint64_t arg)
 Executes a command for hashmap. More...
 
void hm_tx_debug (PMEMobjpool *pop, TOID(struct hashmap_tx) hashmap, FILE *out)
 Prints complete hashmap state. More...
 

Macro Definition Documentation

◆ HASHMAP_TX_TYPE_OFFSET

#define HASHMAP_TX_TYPE_OFFSET   1004

Definition at line 20 of file hashmap_tx.h.

Typedef Documentation

◆ buckets

typedef struct buckets buckets

◆ entry

typedef struct entry entry

◆ hashmap_tx

typedef struct hashmap_tx hashmap_tx

Enumeration Type Documentation

◆ hashmap_cmd

Enumerator
HASHMAP_CMD_REBUILD 
HASHMAP_CMD_DEBUG 

Definition at line 13 of file hashmap_tx.h.

Function Documentation

◆ hm_tx_check()

int hm_tx_check ( PMEMobjpool *  pop,
TOID(struct hashmap_tx hashmap 
)

Checks if specified persistent object is an instance of hashmap.

Parameters
PMEMobjpoolthe pool where the hashmap is stored.
hashmapthe typed hashmap which needs to be initialised.
Returns
0: if it is a hashmap
1: otherwise

Definition at line 463 of file hashmap_tx.c.

◆ hm_tx_cmd()

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

Parameters
PMEMobjpoolthe pool where the hashmap is stored.
hashmapthe typed hashmap which needs to be initialised.
cmdthe command to be executed.
argthe arguments for the command.
Returns
0: on successful execution
-EINVAL: otherwise

Definition at line 480 of file hashmap_tx.c.

Here is the call graph for this function:

◆ hm_tx_count()

size_t hm_tx_count ( PMEMobjpool *  pop,
TOID(struct hashmap_tx hashmap 
)

Returns number of elements in the hashmap.

Parameters
PMEMobjpoolthe pool where the hashmap is stored.
hashmapthe typed hashmap which needs to be initialised.
Returns
Number of elements in the hashmap.

Definition at line 401 of file hashmap_tx.c.

◆ hm_tx_create()

int hm_tx_create ( PMEMobjpool *  pop,
TOID(struct hashmap_tx) *  map,
void *  arg 
)

Allocates a new hashmap.

Parameters
PMEMobjpoolthe pool where the hashmap would be stored.
hashmapthe typed hashmap which needs to be initialised.
argadditional arguments if necessary
Returns
0: on successful creation
-1: on failure.
See also
create_hashmap()

Definition at line 433 of file hashmap_tx.c.

Here is the call graph for this function:

◆ hm_tx_debug()

void hm_tx_debug ( PMEMobjpool *  pop,
TOID(struct hashmap_tx hashmap,
FILE *  out 
)

Prints complete hashmap state.

This function is used for debugging purposes.

Parameters
PMEMobjpoolthe pool where the hashmap would be stored.
hashmapthe typed hashmap which needs to be initialised.
outthe file desciptor for where the output needs to be recorded.
Returns
Nothing
Note
The out paramater can be stdout and stderr too.

Definition at line 314 of file hashmap_tx.c.

Here is the call graph for this function:

◆ hm_tx_foreach()

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.

Parameters
PMEMobjpoolthe pool where the hashmap is stored.
hashmapthe typed hashmap which needs to be initialised.
cbthe calback function.
argadditional arguments for the callback function
Returns
The return value of the callback function.

Definition at line 281 of file hashmap_tx.c.

Here is the call graph for this function:

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

Parameters
PMEMobjpoolthe pool where the hashmap is stored.
hashmapthe typed hashmap which needs to be initialised.
keythe key for the value being inserted. It will be used to calculate the hash.
Returns
the value associated with the key.
MEMOID_NULL upon failure or if not such key existed

Definition at line 349 of file hashmap_tx.c.

Here is the call graph for this function:

◆ hm_tx_init()

int hm_tx_init ( PMEMobjpool *  pop,
TOID(struct hashmap_tx hashmap 
)

Recovers hashmap state.

Called after pmemobj_open().

Parameters
PMEMobjpoolthe pool where the hashmap is stored.
hashmapthe typed hashmap which needs to be initialised.
See also
init_types_table()

Definition at line 415 of file hashmap_tx.c.

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

Parameters
PMEMobjpoolthe pool where the hashmap is stored.
hashmapthe typed hashmap which needs to be initialised.
keythe key for the value being inserted. It will be used to calculate the hash.
valuethe value that is supposed to be inserted.
Returns
0: if successful
1: if value already existed
-1: if the insertion failed
Warning
If the key already exists in the hashmap, then the value provided is not inserted.

Definition at line 164 of file hashmap_tx.c.

Here is the call graph for this function:

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

Parameters
PMEMobjpoolthe pool where the hashmap is stored.
hashmapthe typed hashmap which needs to be initialised.
keythe key for the value being inserted. It will be used to calculate the hash.
Returns
1: if the key exists
0: otherwise
See also
hm_tx_get()

Definition at line 377 of file hashmap_tx.c.

Here is the call graph for this function:

◆ hm_tx_remove()

MEMoid hm_tx_remove ( PMEMobjpool *  pop,
TOID(struct hashmap_tx hashmap,
uint64_t  key 
)

Removes specified value from the hashmap.

Parameters
PMEMobjpoolthe pool where the hashmap is stored.
hashmapthe typed hashmap which needs to be initialised.
keythe key for the value being inserted. It will be used to calculate the hash.
Returns
the value associated with the key deleted upon success
MEMOID_NULL upon failure or if not such key existed
Note
This function does call hm_tx_rebuild() if the the number of elements in the hashmap are less that number of buckets.

Definition at line 224 of file hashmap_tx.c.

Here is the call graph for this function:

◆ POBJ_LAYOUT_BEGIN()

POBJ_LAYOUT_BEGIN ( types_tab  )

◆ POBJ_LAYOUT_END()

POBJ_LAYOUT_END ( types_tab  )

◆ POBJ_LAYOUT_ROOT()

POBJ_LAYOUT_ROOT ( types_tab  ,
struct hashmap_tx   
)

◆ POBJ_LAYOUT_TOID() [1/2]

POBJ_LAYOUT_TOID ( types_tab  ,
struct buckets   
)

◆ POBJ_LAYOUT_TOID() [2/2]

POBJ_LAYOUT_TOID ( types_tab  ,
struct entry   
)