libcute 0.1
Loading...
Searching...
No Matches
Classes | Typedefs | Enumerations | Functions
hashmap.h File Reference
#include "hash/hash.h"
#include "macro.h"
#include "memory/allocator.h"
#include "object/optional.h"
#include "object/result.h"
#include "state.h"
#include "utility.h"
#include <stdbool.h>
#include <stddef.h>
Include dependency graph for hashmap.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Classes

struct  cu_HashMap_Bucket
 
struct  cu_HashMap
 

Typedefs

typedef uint64_t(* cu_HashMap_HashFn) (const void *key, size_t key_size)
 
typedef bool(* cu_HashMap_EqualsFn) (const void *a, const void *b, size_t key_size)
 

Enumerations

enum  cu_HashMap_Error { CU_HASHMAP_ERROR_NONE = 0 , CU_HASHMAP_ERROR_OOM , CU_HASHMAP_ERROR_INVALID_LAYOUT , CU_HASHMAP_ERROR_INVALID }
 

Functions

cu_HashMap_Result cu_HashMap_create (cu_Allocator allocator, cu_Layout key_layout, cu_Layout value_layout, Size_Optional initial_capacity, cu_HashMap_HashFn_Optional hash_fn, cu_HashMap_EqualsFn_Optional equals_fn, cu_State state)
 Create a new hashmap.
 
void cu_HashMap_destroy (cu_HashMap *map)
 
cu_HashMap_Error_Optional cu_HashMap_insert (cu_HashMap *map, void *key, void *value)
 Insert a new key-value pair.
 
Ptr_Optional cu_HashMap_get (const cu_HashMap *map, const void *key)
 Retrieve the value stored for key.
 
bool cu_HashMap_iter (const cu_HashMap *map, size_t *index, void **key, void **value)
 Iterate over all stored pairs.
 

Detailed Description

Simple hashmap container.

Enumeration Type Documentation

◆ cu_HashMap_Error

Possible error codes returned by hashmap operations.

Function Documentation

◆ cu_HashMap_create()

cu_HashMap_Result cu_HashMap_create ( cu_Allocator  allocator,
cu_Layout  key_layout,
cu_Layout  value_layout,
Size_Optional  initial_capacity,
cu_HashMap_HashFn_Optional  hash_fn,
cu_HashMap_EqualsFn_Optional  equals_fn,
cu_State  state 
)

Create a new hashmap.

Parameters
allocatorallocator used for storage
key_layoutlayout describing the key type
value_layoutlayout describing the value type
initial_capacityoptional initial bucket count
hash_fnhashing function, defaults to FNV-1a when none
equals_fnequality predicate, defaults to bytewise compare
staterandomization source used to seed hashes and mitigate collision attacks
Here is the call graph for this function:
Here is the caller graph for this function:

◆ cu_HashMap_destroy()

void cu_HashMap_destroy ( cu_HashMap map)

Release resources held by map.

Here is the call graph for this function:
Here is the caller graph for this function: