trafilo 0.1.0
Streaming event-handler framework in C
Loading...
Searching...
No Matches
hashmap.c File Reference
#include "headers/hashmap.h"
#include "headers/window.h"

Functions

hashmap_thashmap_create (size_t num_buckets)
 Create a hashmap.
static uint64_t fnv1a (const char *key)
 FNV1A Hashing function.
static size_t bucket_index (const hashmap_t *m, const char *key)
 Bucket Indexing.
static bucket_nodebucket_create (const char *key)
bucket_nodehashmap_find_or_create (hashmap_t *hashmap, const char *key)
 Find bucket for key; create if absent. Returns with bucket->bucket_lock LOCKED.
void hashmap_destroy (hashmap_t *hashmap, trafilo_state_free_fn state_free)
 Graceful cleanup of the hashmap.
void hashmap_for_each (hashmap_t *hashmap, void(*fn)(bucket_node *bucket, void *arg), void *arg)
 For each iteration for operations, calls passed function within lock protection.
void hashmap_unlock_bucket (hashmap_t *hashmap, const char *key)
 Helper to unlock a locked node.

Function Documentation

◆ bucket_create()

bucket_node * bucket_create ( const char * key)
static

◆ bucket_index()

size_t bucket_index ( const hashmap_t * m,
const char * key )
static

Bucket Indexing.

Parameters
mPointer to the hashmap
keyPointer to the event key

◆ fnv1a()

uint64_t fnv1a ( const char * key)
static

FNV1A Hashing function.

Parameters
constchar * key to be hashed

◆ hashmap_create()

hashmap_t * hashmap_create ( size_t num_buckets)

Create a hashmap.

Parameters
num_bucketsNumber of buckets in the hashmap.
Returns
Pointer to the newly created hashmap.

◆ hashmap_destroy()

void hashmap_destroy ( hashmap_t * hashmap,
trafilo_state_free_fn state_free )

Graceful cleanup of the hashmap.

Parameters
hashmapPointer to the hashmap.
state_freeUser specified state_free function.

◆ hashmap_find_or_create()

bucket_node * hashmap_find_or_create ( hashmap_t * hashmap,
const char * key )

Find bucket for key; create if absent. Returns with bucket->bucket_lock LOCKED.

Parameters
hashmapTarget hashmap.
keyNUL-terminated string, bucket takes ownership.
Returns
Locked bucket, or NULL on alloc failure.

◆ hashmap_for_each()

void hashmap_for_each ( hashmap_t * hashmap,
void(* fn )(bucket_node *bucket, void *arg),
void * arg )

For each iteration for operations, calls passed function within lock protection.

Parameters
hashmapPointer to the hashmap.
fnFunction with bucket_node and arguments.
argArguments for the iterative function.

◆ hashmap_unlock_bucket()

void hashmap_unlock_bucket ( hashmap_t * hashmap,
const char * key )

Helper to unlock a locked node.

Parameters
hashmapPointer to the hashmap.
keyThe key that belongs to the node.