MentOS  0.8.0
The Mentoring Operating System
hashmap.h
Go to the documentation of this file.
1 
6 #pragma once
7 
8 #include "klib/list.h"
9 
10 // == OPAQUE TYPES ============================================================
12 typedef struct hashmap_entry_t hashmap_entry_t;
14 typedef struct hashmap_t hashmap_t;
15 
16 // == HASHMAP FUNCTIONS =======================================================
18 typedef unsigned int (*hashmap_hash_t)(const void *key);
20 typedef int (*hashmap_comp_t)(const void *a, const void *b);
22 typedef void *(*hashmap_dupe_t)(const void *);
24 typedef void (*hashmap_free_t)(void *);
25 
26 // == HASHMAP KEY MANAGEMENT FUNCTIONS ========================================
30 unsigned int hashmap_int_hash(const void *key);
31 
36 int hashmap_int_comp(const void *a, const void *b);
37 
41 unsigned int hashmap_str_hash(const void *key);
42 
47 int hashmap_str_comp(const void *a, const void *b);
48 
52 void *hashmap_do_not_duplicate(const void *value);
53 
56 void hashmap_do_not_free(void *value);
57 
58 // == HASHMAP CREATION AND DESTRUCTION ========================================
70  unsigned int size,
71  hashmap_hash_t hash_fun,
72  hashmap_comp_t comp_fun,
73  hashmap_dupe_t dupe_fun,
74  hashmap_free_t key_free_fun);
75 
83 
91 
94 void hashmap_free(hashmap_t *map);
95 
96 // == HASHMAP ACCESS FUNCTIONS ================================================
102 void *hashmap_set(hashmap_t *map, const void *key, void *value);
103 
108 void *hashmap_get(hashmap_t *map, const void *key);
109 
114 void *hashmap_remove(hashmap_t *map, const void *key);
115 
119 int hashmap_is_empty(hashmap_t *map);
120 
125 int hashmap_has(hashmap_t *map, const void *key);
126 
131 
int(* hashmap_comp_t)(const void *a, const void *b)
Comparison function, used to compare hash keys.
Definition: hashmap.h:20
void *(* hashmap_dupe_t)(const void *)
Key duplication function, used to duplicate hash keys.
Definition: hashmap.h:22
void hashmap_free(hashmap_t *map)
Frees the memory of the hashmap.
Definition: hashmap.c:139
unsigned int hashmap_str_hash(const void *key)
Transforms a string key into a hash key.
Definition: hashmap.c:91
int hashmap_int_comp(const void *a, const void *b)
Compares two integer hash keys.
Definition: hashmap.c:86
int hashmap_str_comp(const void *a, const void *b)
Compares two string hash keys.
Definition: hashmap.c:104
void * hashmap_remove(hashmap_t *map, const void *key)
Removes the entry with the given key.
Definition: hashmap.c:203
unsigned int(* hashmap_hash_t)(const void *key)
Hashing function, used to generate hash keys.
Definition: hashmap.h:18
unsigned int hashmap_int_hash(const void *key)
Transforms an integer key into a hash key.
Definition: hashmap.c:81
void hashmap_do_not_free(void *value)
This function can be passed as hashmap_free_t, it does nothing.
Definition: hashmap.c:114
void * hashmap_do_not_duplicate(const void *value)
This function can be passed as hashmap_dupe_t, it does nothing.
Definition: hashmap.c:109
void * hashmap_get(hashmap_t *map, const void *key)
Access the value for the given key.
Definition: hashmap.c:190
int hashmap_is_empty(hashmap_t *map)
Checks if the hashmap is empty.
Definition: hashmap.c:236
list_t * hashmap_values(hashmap_t *map)
Provides access to all the values.
Definition: hashmap.c:268
void(* hashmap_free_t)(void *)
Key deallocation function, used to free the memory occupied by hash keys.
Definition: hashmap.h:24
hashmap_t * hashmap_create_int(unsigned int size)
Standard hashmap with keys of type (char *).
hashmap_t * hashmap_create_str(unsigned int size)
Standard hashmap with keys of type (char *).
void * hashmap_set(hashmap_t *map, const void *key, void *value)
Sets the value for the given key in the hashmap map.
Definition: hashmap.c:153
list_t * hashmap_keys(hashmap_t *map)
Provides access to all the keys.
Definition: hashmap.c:257
hashmap_t * hashmap_create(unsigned int size, hashmap_hash_t hash_fun, hashmap_comp_t comp_fun, hashmap_dupe_t dupe_fun, hashmap_free_t key_free_fun)
User-defined hashmap.
Definition: hashmap.c:119
int hashmap_has(hashmap_t *map, const void *key)
Checks if the hashmap contains an entry with the given key.
Definition: hashmap.c:246
An implementation for generic list.
Stores information of an entry of the hashmap.
Definition: hashmap.c:12
Stores information of a hashmap.
Definition: hashmap.c:22
unsigned int size
Size of the hashmap.
Definition: hashmap.c:32
Represent the list.
Definition: list.h:19