|
Serene Runtime 1.0.0
C runtime for the Serene programming language
|
This is an implementation of Compressed Hash-Array Mapped Prefix-tree, which is a bit-partitioned, persistent, immutable Hashed array mapped trie. More...
Go to the source code of this file.
Data Structures | |
| struct | hmap_key_t |
| Note: For key equality we use the memcpy function. More... | |
| struct | hmap_kv_entry_t |
| struct | hmap_node_t |
| struct | hmap_t |
| struct | hmap_control_t |
| If we ever want to modify some of these behaviours for a new instance of hashmap, we should use this control type. More... | |
Macros | |
| #define | HMAP_BR 32u |
| branching factor (power of two) | |
| #define | HMAP_SHIFT 5u |
| #define | HMAP_MASK (HMAP_BR - 1u) |
| #define | HMAP_HASH_SIZE 32u |
| By default we use 32bit hashes. | |
| #define | HMAP_HASH_TYPE uint32_t |
| #define | HMAP_BITMAP_TYPE uint32_t |
Typedefs | |
| typedef HMAP_HASH_TYPE | hmap_hash_t |
| typedef HMAP_BITMAP_TYPE | hmap_bitmap_t |
| typedef void * | hmap_data_t |
| typedef struct hmap_key_t | hmap_key_t |
| Note: For key equality we use the memcpy function. | |
| typedef struct hmap_kv_entry_t | hmap_kv_entry_t |
| typedef struct hmap_node_t | hmap_node_t |
| typedef struct hmap_t | hmap_t |
| typedef struct hmap_control_t | hmap_control_t |
| If we ever want to modify some of these behaviours for a new instance of hashmap, we should use this control type. | |
Functions | |
| hmap_t | hmap_empty (srn_context_t *ctx) |
| Create, initialize and return a new hashmap. | |
| hmap_t | hmap_insert (srn_context_t *ctx, const hmap_t *hmap, hmap_key_t *k, void *v) |
Insert the given key k with the value v in the given hash hmap and return the new map. | |
| hmap_t | hmap_insert_ctl (const hmap_control_t *ctl, srn_context_t *ctx, const hmap_t *hmap, hmap_key_t *k, void *v) |
Just like the hmap_insert function but, it receives a hmap_control_t to customize the comparison and hashing function. | |
| void * | hmap_lookup (srn_context_t *ctx, const hmap_t *hmap, const hmap_key_t *k, void *default_value) |
Lookup the given k in the given hmap and return the value if it's been found. | |
| void * | hmap_lookup_ctl (const hmap_control_t *ctl, srn_context_t *ctx, const hmap_t *hmap, const hmap_key_t *k, void *default_value) |
Just like the hmap_lookup function but, it receives a hmap_control_t to customize the comparison and hashing function. | |
| hmap_hash_t | hmap_hash (srn_context_t *ctx, const void *data, size_t len) |
| This is a simple hack to mock the hash function during tests to force a high collision hashing function. | |
| hmap_key_t * | hmap_make_key (srn_context_t *ctx, void *data, size_t len) |
Create a new key out of the given data, with the given len. | |
Variables | |
| hmap_control_t | hmap_default_control |
This is an implementation of Compressed Hash-Array Mapped Prefix-tree, which is a bit-partitioned, persistent, immutable Hashed array mapped trie.
For more information, have a look at the Optimizing Hash-Array Mapped Tries / for Fast and Lean Immutable JVM Collections paper.
TL;DR:
Definition in file hashmap.h.
| typedef HMAP_BITMAP_TYPE hmap_bitmap_t |
| typedef struct hmap_control_t hmap_control_t |
If we ever want to modify some of these behaviours for a new instance of hashmap, we should use this control type.
| typedef void* hmap_data_t |
| typedef HMAP_HASH_TYPE hmap_hash_t |
| typedef struct hmap_key_t hmap_key_t |
Note: For key equality we use the memcpy function.
| typedef struct hmap_kv_entry_t hmap_kv_entry_t |
| typedef struct hmap_node_t hmap_node_t |
| typedef struct hmap_t hmap_t |
|
nodiscard |
Create, initialize and return a new hashmap.
Definition at line 612 of file hashmap.c.
| hmap_hash_t hmap_hash | ( | srn_context_t * | ctx, |
| const void * | data, | ||
| size_t | len ) |
This is a simple hack to mock the hash function during tests to force a high collision hashing function.
Outside of tests, this will be a wrapper around srn_hash.
Definition at line 78 of file hashmap.c.
|
nodiscard |
|
nodiscard |
Just like the hmap_insert function but, it receives a hmap_control_t to customize the comparison and hashing function.
Definition at line 559 of file hashmap.c.
|
nodiscard |
Lookup the given k in the given hmap and return the value if it's been found.
Otherwise return the default_value value. Since a nullptr is a valid value for any keys, returning a nullptr is not a good option to indicate that the key does not exist, So it's safer to use explicit values to differenciate between a missing key and a legit nullptr as a value.
Definition at line 622 of file hashmap.c.
| void * hmap_lookup_ctl | ( | const hmap_control_t * | ctl, |
| srn_context_t * | ctx, | ||
| const hmap_t * | hmap, | ||
| const hmap_key_t * | k, | ||
| void * | default_value ) |
Just like the hmap_lookup function but, it receives a hmap_control_t to customize the comparison and hashing function.
Definition at line 597 of file hashmap.c.
| hmap_key_t * hmap_make_key | ( | srn_context_t * | ctx, |
| void * | data, | ||
| size_t | len ) |
Create a new key out of the given data, with the given len.
Definition at line 627 of file hashmap.c.
|
extern |
Definition at line 636 of file hashmap.c.