libpulsar
A modular compiler for the pulsar programming language
Loading...
Searching...
No Matches
Data Structures | Typedefs | Functions
hashmap.h File Reference

Hash map data structure. More...

#include "def.h"
#include "hash.h"

Go to the source code of this file.

Data Structures

struct  ps_hash_map
 A hash map. More...
 
struct  ps_hash_map::ps_hash_map_entry
 

Typedefs

typedef void(* free_fn_t) (void *ptr)
 Function that destroys an object and its owned resources.
 

Functions

struct ps_hash_mapps_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.
 
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_insert (struct ps_hash_map **map_ptr, void *key, void *value)
 Inserts a new key-value pair into the hash map.
 
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.
 

Detailed Description

Hash map data structure.

Author
Ethan Uppal

Definition in file hashmap.h.

Typedef Documentation

◆ free_fn_t

typedef void(* free_fn_t) (void *ptr)

Function that destroys an object and its owned resources.

Definition at line 13 of file hashmap.h.

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_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 
)

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

Parameters
map_ptrA pointer to the hash map.
keyThe key.
valueThe value.

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

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

Parameters
is_equalThe comparison function (for the keys).
hasherThe hash function (for the keys).
free_fnThe free function (for the objects).

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

Definition at line 43 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.