trafilo 0.1.0
Streaming event-handler framework in C
Loading...
Searching...
No Matches
hashmap.h File Reference
#include <pthread.h>
#include <time.h>
#include <stdlib.h>
#include <string.h>
#include "window.h"
#include "../../include/trafilo.h"

Go to the source code of this file.

Data Structures

struct  bucket_node
 A bucket node of the hashtable. More...
struct  hashmap_t
 The hashmap structure. More...

Functions

hashmap_thashmap_create (size_t num_buckets)
 Create a hashmap.
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

◆ 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.