MentOS
0.8.0
The Mentoring Operating System
|
Functions for managing a structure that can map keys to values. More...
Go to the source code of this file.
Typedefs | |
typedef struct hashmap_entry_t | hashmap_entry_t |
Stores information of an entry of the hashmap. | |
typedef struct hashmap_t | hashmap_t |
Stores information of a hashmap. | |
typedef unsigned int(* | hashmap_hash_t) (const void *key) |
Hashing function, used to generate hash keys. | |
typedef int(* | hashmap_comp_t) (const void *a, const void *b) |
Comparison function, used to compare hash keys. | |
typedef void *(* | hashmap_dupe_t) (const void *) |
Key duplication function, used to duplicate hash keys. | |
typedef void(* | hashmap_free_t) (void *) |
Key deallocation function, used to free the memory occupied by hash keys. | |
Functions | |
unsigned int | hashmap_int_hash (const void *key) |
Transforms an integer key into a hash key. More... | |
int | hashmap_int_comp (const void *a, const void *b) |
Compares two integer hash keys. More... | |
unsigned int | hashmap_str_hash (const void *key) |
Transforms a string key into a hash key. More... | |
int | hashmap_str_comp (const void *a, const void *b) |
Compares two string hash keys. More... | |
void * | hashmap_do_not_duplicate (const void *value) |
This function can be passed as hashmap_dupe_t, it does nothing. More... | |
void | hashmap_do_not_free (void *value) |
This function can be passed as hashmap_free_t, it does nothing. More... | |
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. More... | |
hashmap_t * | hashmap_create_str (unsigned int size) |
Standard hashmap with keys of type (char *). More... | |
hashmap_t * | hashmap_create_int (unsigned int size) |
Standard hashmap with keys of type (char *). More... | |
void | hashmap_free (hashmap_t *map) |
Frees the memory of the hashmap. More... | |
void * | hashmap_set (hashmap_t *map, const void *key, void *value) |
Sets the value for the given key in the hashmap map . More... | |
void * | hashmap_get (hashmap_t *map, const void *key) |
Access the value for the given key. More... | |
void * | hashmap_remove (hashmap_t *map, const void *key) |
Removes the entry with the given key. More... | |
int | hashmap_is_empty (hashmap_t *map) |
Checks if the hashmap is empty. More... | |
int | hashmap_has (hashmap_t *map, const void *key) |
Checks if the hashmap contains an entry with the given key. More... | |
list_t * | hashmap_keys (hashmap_t *map) |
Provides access to all the keys. More... | |
list_t * | hashmap_values (hashmap_t *map) |
Provides access to all the values. More... | |
Functions for managing a structure that can map keys to values.
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.
size | Dimension of the hashmap. |
hash_fun | The hashing function. |
comp_fun | The hash compare function. |
dupe_fun | The key duplication function. |
key_free_fun | The function used to free memory of keys. |
(key_free_fun) : No free function. (val_free_fun) : Standard free
function.
hashmap_t* hashmap_create_int | ( | unsigned int | size | ) |
Standard hashmap with keys of type (char *).
size | Dimension of the hashmap. |
(key_free_fun) : No free function. (val_free_fun) : Standard free
function.
hashmap_t* hashmap_create_str | ( | unsigned int | size | ) |
Standard hashmap with keys of type (char *).
size | Dimension of the hashmap. |
(key_free_fun) : Standard free
function. (val_free_fun) : Standard free
function.
void* hashmap_do_not_duplicate | ( | const void * | value | ) |
This function can be passed as hashmap_dupe_t, it does nothing.
value | The value to duplicate. |
void hashmap_do_not_free | ( | void * | value | ) |
This function can be passed as hashmap_free_t, it does nothing.
value | The value to free. |
void hashmap_free | ( | hashmap_t * | map | ) |
Frees the memory of the hashmap.
map | A pointer to the hashmap. |
void* hashmap_get | ( | hashmap_t * | map, |
const void * | key | ||
) |
Access the value for the given key.
map | The hashmap. |
key | The key of the entry we are searching. |
int hashmap_has | ( | hashmap_t * | map, |
const void * | key | ||
) |
Checks if the hashmap contains an entry with the given key.
map | The hashmap. |
key | The key of the entry we are searching. |
int hashmap_int_comp | ( | const void * | a, |
const void * | b | ||
) |
Compares two integer hash keys.
a | The first hash key. |
b | The second hash key. |
unsigned int hashmap_int_hash | ( | const void * | key | ) |
Transforms an integer key into a hash key.
key | The integer key. |
int hashmap_is_empty | ( | hashmap_t * | map | ) |
Checks if the hashmap is empty.
map | The hashmap. |
Provides access to all the keys.
map | The hashmap. |
void* hashmap_remove | ( | hashmap_t * | map, |
const void * | key | ||
) |
Removes the entry with the given key.
map | The hashmap. |
key | The key of the entry we are searching. |
void* hashmap_set | ( | hashmap_t * | map, |
const void * | key, | ||
void * | value | ||
) |
Sets the value
for the given key
in the hashmap map
.
map | The hashmap. |
key | The entry key. |
value | The entry value. |
int hashmap_str_comp | ( | const void * | a, |
const void * | b | ||
) |
Compares two string hash keys.
a | The first hash key. |
b | The second hash key. |
unsigned int hashmap_str_hash | ( | const void * | key | ) |
Transforms a string key into a hash key.
key | The string key. |