libpulsar
A modular compiler for the pulsar programming language
Loading...
Searching...
No Matches
hashmap.h
Go to the documentation of this file.
1
8#pragma once
9#include "def.h"
10#include "hash.h"
11
13typedef void (*free_fn_t)(void* ptr);
14
31
40
42 free_fn_t free_fn, u64 capacity);
43
48void ps_hash_map_free(struct ps_hash_map* map);
49
56void ps_hash_map_insert(struct ps_hash_map** map_ptr, void* key, void* value);
57
65void* ps_hash_map_get(struct ps_hash_map* map, void* key);
66
72void ps_hash_map_remove(struct ps_hash_map* map, void* key);
73
79bool ps_hash_map_contains(struct ps_hash_map* map, void* key);
80
86u64 ps_hash_map_count(const struct ps_hash_map* map);
Base definitions.
#define u64
Definition def.h:48
Hashing and equality functions for common data types.
u64(* hasher_t)(void *)
Function that hashes an object.
Definition hash.h:15
bool(* is_equal_t)(void *, void *)
Function that compares whether two objects are equal.
Definition hash.h:18
void * ps_hash_map_get(struct ps_hash_map *map, void *key)
Gets the value associated with the given key.
Definition hashmap.c:174
struct ps_hash_map * _ps_hash_map_new(is_equal_t is_equal, hasher_t hasher, free_fn_t free_fn, u64 capacity)
Definition hashmap.c:49
struct ps_hash_map * ps_hash_map_new(is_equal_t is_equal, hasher_t hasher, free_fn_t free_fn)
Creates a new hash map with the given comparison and memory functions.
Definition hashmap.c:43
void(* free_fn_t)(void *ptr)
Function that destroys an object and its owned resources.
Definition hashmap.h:13
u64 ps_hash_map_count(const struct ps_hash_map *map)
Gets the number of key-value pairs in the hash map.
Definition hashmap.c:244
void ps_hash_map_free(struct ps_hash_map *map)
Destroys all data owned by the hash map.
Definition hashmap.c:78
void ps_hash_map_insert(struct ps_hash_map **map_ptr, void *key, void *value)
Inserts a new key-value pair into the hash map.
Definition hashmap.c:119
bool ps_hash_map_contains(struct ps_hash_map *map, void *key)
Checks if the hash map contains the given key-value pair.
Definition hashmap.c:240
void ps_hash_map_remove(struct ps_hash_map *map, void *key)
Removes the key-value pair associated with the given key.
Definition hashmap.c:193
Definition hashmap.h:25
void * key
Definition hashmap.h:26
void * value
Definition hashmap.h:27
struct ps_hash_map_entry * next
Definition hashmap.h:28
A hash map.
Definition hashmap.h:18
u64 length
Number of first-node entries.
Definition hashmap.h:19
is_equal_t is_equal
Definition hashmap.h:22
hasher_t hasher
Definition hashmap.h:23
u64 count
Number of total entries: load factor = count / length.
Definition hashmap.h:20
struct ps_hash_map::ps_hash_map_entry entries[]
free_fn_t free_fn
Definition hashmap.h:24