Astaroth  3.1
Scalable Multi-GPU Stencil Computations
Loading...
Searching...
No Matches
hashtable.h File Reference
#include <stdlib.h>
#include <string.h>
#include "func_define.h"
#include <stdint.h>
Include dependency graph for hashtable.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Data Structures

struct  hashmap_create_options_t
struct  hashmap_element_t
struct  hashmap_t

Macros

#define HASHMAP_ALWAYS_INLINE   HASHMAP_WEAK
#define HASHMAP_ATTRIBUTE(a)
#define HASHMAP_CAST(type, x)
#define HASHMAP_LINEAR_PROBE_LENGTH   (8)
#define HASHMAP_NULL   0
#define HASHMAP_PTR_CAST(type, x)

Typedefs

typedef int(* hashmap_comparer_t) (const void *a, hashmap_uint32_t a_len, const void *b, hashmap_uint32_t b_len)
typedef hashmap_uint32_t(* hashmap_hasher_t) (hashmap_uint32_t seed, const void *key, hashmap_uint32_t key_len)
typedef uint32_t hashmap_uint32_t
typedef uint64_t hashmap_uint64_t
typedef uint8_t hashmap_uint8_t

Functions

HASHMAP_WEAK hashmap_uint32_t hashmap_capacity (const struct hashmap_s *const hashmap)
 Get the capacity of the hashmap.
HASHMAP_WEAK hashmap_uint32_t hashmap_clz (const hashmap_uint32_t x)
HASHMAP_WEAK int hashmap_create (const hashmap_uint32_t initial_capacity, struct hashmap_s *const out_hashmap)
 Create a hashmap.
HASHMAP_WEAK int hashmap_create_ex (struct hashmap_create_options_s options, struct hashmap_s *const out_hashmap)
 Create a hashmap.
HASHMAP_WEAK void hashmap_destroy (struct hashmap_s *const hashmap)
 Destroy the hashmap.
HASHMAP_WEAK void * hashmap_get (const struct hashmap_s *const hashmap, const void *const key, const hashmap_uint32_t len)
 Get an element from the hashmap.
HASHMAP_WEAK int hashmap_hash_helper (const struct hashmap_s *const m, const void *const key, const hashmap_uint32_t len, hashmap_uint32_t *const out_index)
HASHMAP_WEAK hashmap_uint32_t hashmap_hash_helper_int_helper (const struct hashmap_s *const m, const void *const key, const hashmap_uint32_t len)
HASHMAP_WEAK int hashmap_iterate (const struct hashmap_s *const hashmap, int(*iterator)(void *const context, void *const value), void *const context)
 Iterate over all the elements in a hashmap.
HASHMAP_WEAK int hashmap_iterate_pairs (struct hashmap_s *const hashmap, int(*iterator)(void *const, struct hashmap_element_s *const), void *const context)
 Iterate over all the elements in a hashmap.
HASHMAP_WEAK hashmap_uint32_t hashmap_num_entries (const struct hashmap_s *const hashmap)
 Get the size of the hashmap.
HASHMAP_WEAK int hashmap_put (struct hashmap_s *const hashmap, const void *const key, const hashmap_uint32_t len, void *const value)
 Put an element into the hashmap.
HASHMAP_WEAK int hashmap_rehash_helper (struct hashmap_s *const m)
HASHMAP_WEAK int hashmap_rehash_iterator (void *const new_hash, struct hashmap_element_s *const e)
HASHMAP_WEAK int hashmap_remove (struct hashmap_s *const hashmap, const void *const key, const hashmap_uint32_t len)
 Remove an element from the hashmap.
HASHMAP_WEAK const void * hashmap_remove_and_return_key (struct hashmap_s *const hashmap, const void *const key, const hashmap_uint32_t len)
 Remove an element from the hashmap.

Macro Definition Documentation

◆ HASHMAP_ALWAYS_INLINE

#define HASHMAP_ALWAYS_INLINE   HASHMAP_WEAK

◆ HASHMAP_ATTRIBUTE

#define HASHMAP_ATTRIBUTE ( a)
Value:
__attribute__((a))

◆ HASHMAP_CAST

#define HASHMAP_CAST ( type,
x )
Value:
((type)(x))

◆ HASHMAP_LINEAR_PROBE_LENGTH

#define HASHMAP_LINEAR_PROBE_LENGTH   (8)

◆ HASHMAP_NULL

#define HASHMAP_NULL   0

◆ HASHMAP_PTR_CAST

#define HASHMAP_PTR_CAST ( type,
x )
Value:
((type)(x))

Typedef Documentation

◆ hashmap_comparer_t

typedef int(* hashmap_comparer_t) (const void *a, hashmap_uint32_t a_len, const void *b, hashmap_uint32_t b_len)

◆ hashmap_hasher_t

typedef hashmap_uint32_t(* hashmap_hasher_t) (hashmap_uint32_t seed, const void *key, hashmap_uint32_t key_len)

◆ hashmap_uint32_t

typedef uint32_t hashmap_uint32_t

◆ hashmap_uint64_t

typedef uint64_t hashmap_uint64_t

◆ hashmap_uint8_t

typedef uint8_t hashmap_uint8_t

Function Documentation

◆ hashmap_capacity()

HASHMAP_WEAK hashmap_uint32_t hashmap_capacity ( const struct hashmap_s *const hashmap)

Get the capacity of the hashmap.

Parameters
hashmapThe hashmap to get the size of.
Returns
The capacity of the hashmap.

◆ hashmap_clz()

HASHMAP_WEAK hashmap_uint32_t hashmap_clz ( const hashmap_uint32_t x)

◆ hashmap_create()

int hashmap_create ( const hashmap_uint32_t initial_capacity,
struct hashmap_s *const out_hashmap )

Create a hashmap.

Parameters
initial_capacityThe initial capacity of the hashmap.
out_hashmapThe storage for the created hashmap.
Returns
On success 0 is returned.

◆ hashmap_create_ex()

int hashmap_create_ex ( struct hashmap_create_options_s options,
struct hashmap_s *const out_hashmap )

Create a hashmap.

Parameters
optionsThe options to create the hashmap with.
out_hashmapThe storage for the created hashmap.
Returns
On success 0 is returned.

The options members work as follows:

  • initial_capacity The initial capacity of the hashmap.
  • hasher Which hashing function to use with the hashmap (by default the

◆ hashmap_destroy()

void hashmap_destroy ( struct hashmap_s *const hashmap)

Destroy the hashmap.

Parameters
hashmapThe hashmap to destroy.

◆ hashmap_get()

void * hashmap_get ( const struct hashmap_s *const hashmap,
const void *const key,
const hashmap_uint32_t len )

Get an element from the hashmap.

Parameters
hashmapThe hashmap to get from.
keyThe string key to use.
lenThe length of the string key.
Returns
The previously set element, or NULL if none exists.

◆ hashmap_hash_helper()

HASHMAP_WEAK int hashmap_hash_helper ( const struct hashmap_s *const m,
const void *const key,
const hashmap_uint32_t len,
hashmap_uint32_t *const out_index )

◆ hashmap_hash_helper_int_helper()

HASHMAP_WEAK hashmap_uint32_t hashmap_hash_helper_int_helper ( const struct hashmap_s *const m,
const void *const key,
const hashmap_uint32_t len )

◆ hashmap_iterate()

int hashmap_iterate ( const struct hashmap_s *const hashmap,
int(* iterator )(void *const context, void *const value),
void *const context )

Iterate over all the elements in a hashmap.

Parameters
hashmapThe hashmap to iterate over.
iteratorThe function pointer to call on each element.
contextThe context to pass as the first argument to f.
Returns
If the entire hashmap was iterated then 0 is returned. Otherwise if the callback function f returned non-zero then non-zero is returned.

◆ hashmap_iterate_pairs()

int hashmap_iterate_pairs ( struct hashmap_s *const hashmap,
int(* iterator )(void *const, struct hashmap_element_s *const),
void *const context )

Iterate over all the elements in a hashmap.

Parameters
hashmapThe hashmap to iterate over.
iteratorThe function pointer to call on each element.
contextThe context to pass as the first argument to f.
Returns
If the entire hashmap was iterated then 0 is returned. Otherwise if the callback function f returned positive then the positive value is returned. If the callback function returns -1, the current item is removed and iteration continues.

◆ hashmap_num_entries()

HASHMAP_WEAK hashmap_uint32_t hashmap_num_entries ( const struct hashmap_s *const hashmap)

Get the size of the hashmap.

Parameters
hashmapThe hashmap to get the size of.
Returns
The size of the hashmap.

◆ hashmap_put()

int hashmap_put ( struct hashmap_s *const hashmap,
const void *const key,
const hashmap_uint32_t len,
void *const value )

Put an element into the hashmap.

Parameters
hashmapThe hashmap to insert into.
keyThe string key to use.
lenThe length of the string key.
valueThe value to insert.
Returns
On success 0 is returned.

The key string slice is not copied when creating the hashmap entry, and thus must remain a valid pointer until the hashmap entry is removed or the hashmap is destroyed.

◆ hashmap_rehash_helper()

HASHMAP_WEAK int hashmap_rehash_helper ( struct hashmap_s *const m)

◆ hashmap_rehash_iterator()

int hashmap_rehash_iterator ( void *const new_hash,
struct hashmap_element_s *const e )

◆ hashmap_remove()

int hashmap_remove ( struct hashmap_s *const hashmap,
const void *const key,
const hashmap_uint32_t len )

Remove an element from the hashmap.

Parameters
hashmapThe hashmap to remove from.
keyThe string key to use.
lenThe length of the string key.
Returns
On success 0 is returned.

◆ hashmap_remove_and_return_key()

const void * hashmap_remove_and_return_key ( struct hashmap_s *const hashmap,
const void *const key,
const hashmap_uint32_t len )

Remove an element from the hashmap.

Parameters
hashmapThe hashmap to remove from.
keyThe string key to use.
lenThe length of the string key.
Returns
On success the original stored key pointer is returned, on failure NULL is returned.