|
Serene Runtime 1.0.0-dev
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 (const srn_context_t *ctx) |
| Create, initialize and return a new hashmap pinned to ctx. | |
| hmap_t | hmap_insert (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, 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 (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, 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 (const 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. | |
| hmap_key_t * | hmap_copy_key (const hmap_t *hmap, const hmap_key_t *k) |
| The default copy_key hook. | |
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 |
| hmap_key_t * hmap_copy_key | ( | const hmap_t * | hmap, |
| const hmap_key_t * | k ) |
The default copy_key hook.
Clone the key struct and its bytes into the map's map_ctx so the map never retains pointers into a caller's block.
Definition at line 678 of file hashmap.c.
|
nodiscard |
Create, initialize and return a new hashmap pinned to ctx.
The pinned context owns every allocation the map (and all of its future versions) retains, so pick a context that lives at least as long as the map.
Definition at line 655 of file hashmap.c.
| hmap_hash_t hmap_hash | ( | const 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 77 of file hashmap.c.
|
nodiscard |
Insert the given key k with the value v in the given hash hmap and return the new map.
The new map will share parts of its structure with the old map and never mutate the old map. All retained allocations go through the map's map_ctx. The control's copy_key clones the key into it, so k may point at stack or transient memory. The value v is stored as is and must outlive the map.
Definition at line 661 of file hashmap.c.
|
nodiscard |
Just like the hmap_insert function but, it receives a hmap_control_t to customize the comparison and hashing function.
Definition at line 594 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 665 of file hashmap.c.
| void * hmap_lookup_ctl | ( | const hmap_control_t * | ctl, |
| 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 638 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 669 of file hashmap.c.
|
extern |
Definition at line 690 of file hashmap.c.