libpulsar
A modular compiler for the pulsar programming language
Loading...
Searching...
No Matches
Macros | Functions
hashmap.c File Reference
#include <stdio.h>
#include <stdlib.h>
#include "hashmap.h"
#include "util/abort.h"
#include "util/mtrack.h"

Go to the source code of this file.

Macros

#define PS_HASH_MAP_INITIAL_CAPACITY   16
 

Functions

void ps_hash_map_assert_inv (const struct ps_hash_map *map)
 Asserts the invariants of the data structure implementation.
 
struct ps_hash_mapps_hash_map_new (is_equal_t is_equal, hasher_t hasher, free_fn_t free_fn)
 Initializes a new hash map with the given comparison and memory functions.
 
struct ps_hash_map_ps_hash_map_new (is_equal_t is_equal, hasher_t hasher, free_fn_t free_fn, u64 capacity)
 
void ps_hash_map_free (struct ps_hash_map *map)
 Destroys all data owned by the hash map.
 
void ps_hash_map_redistribute (struct ps_hash_map **map_ptr)
 
void ps_hash_map_insert (struct ps_hash_map **map_ptr, void *key, void *value)
 Sets the object associated with the given key in the hash map, overwriting any existing value for that key.
 
void * ps_hash_map_get (struct ps_hash_map *map, void *key)
 Gets the value associated with the given key.
 
void ps_hash_map_remove (struct ps_hash_map *map, void *key)
 Removes the key-value pair associated with the given key.
 
bool ps_hash_map_contains (struct ps_hash_map *map, void *key)
 Checks if the hash map contains the given key-value pair.
 
u64 ps_hash_map_count (const struct ps_hash_map *map)
 Gets the number of key-value pairs in the hash map.
 

Macro Definition Documentation

◆ PS_HASH_MAP_INITIAL_CAPACITY

#define PS_HASH_MAP_INITIAL_CAPACITY   16

Definition at line 9 of file hashmap.c.

Function Documentation

◆ _ps_hash_map_new()

struct ps_hash_map * _ps_hash_map_new ( is_equal_t  is_equal,
hasher_t  hasher,
free_fn_t  free_fn,
u64  capacity 
)

Definition at line 49 of file hashmap.c.

◆ ps_hash_map_assert_inv()

void ps_hash_map_assert_inv ( const struct ps_hash_map map)

Asserts the invariants of the data structure implementation.

Definition at line 12 of file hashmap.c.

◆ ps_hash_map_contains()

bool ps_hash_map_contains ( struct ps_hash_map map,
void *  key 
)

Checks if the hash map contains the given key-value pair.

Parameters
mapThe hash map.
keyThe key.

Definition at line 240 of file hashmap.c.

◆ ps_hash_map_count()

u64 ps_hash_map_count ( const struct ps_hash_map map)

Gets the number of key-value pairs in the hash map.

Parameters
mapThe hash map.
Returns
The number of key-value pairs in the hash map.

Definition at line 244 of file hashmap.c.

◆ ps_hash_map_free()

void ps_hash_map_free ( struct ps_hash_map map)

Destroys all data owned by the hash map.

Parameters
mapThe hash map to destroy.

Definition at line 78 of file hashmap.c.

◆ ps_hash_map_get()

void * ps_hash_map_get ( struct ps_hash_map map,
void *  key 
)

Gets the value associated with the given key.

Parameters
mapThe hash map.
keyThe key.
Returns
The value associated with the key, or NULL if the key is not in the hash map.

Definition at line 174 of file hashmap.c.

◆ ps_hash_map_insert()

void ps_hash_map_insert ( struct ps_hash_map **  map_ptr,
void *  key,
void *  value 
)

Sets the object associated with the given key in the hash map, overwriting any existing value for that key.

Inserts a new key-value pair into the hash map.

Definition at line 119 of file hashmap.c.

◆ ps_hash_map_new()

struct ps_hash_map * ps_hash_map_new ( is_equal_t  is_equal,
hasher_t  hasher,
free_fn_t  free_fn 
)
inline

Initializes a new hash map with the given comparison and memory functions.

Creates a new hash map with the given comparison and memory functions.

Definition at line 43 of file hashmap.c.

◆ ps_hash_map_redistribute()

void ps_hash_map_redistribute ( struct ps_hash_map **  map_ptr)

Definition at line 94 of file hashmap.c.

◆ ps_hash_map_remove()

void ps_hash_map_remove ( struct ps_hash_map map,
void *  key 
)

Removes the key-value pair associated with the given key.

Parameters
mapThe hash map.
keyThe key.

Definition at line 193 of file hashmap.c.