NetSurf
|
#include <stdint.h>
#include <stdbool.h>
Go to the source code of this file.
Data Structures | |
struct | hashmap_parameters_t |
Parameters for hashmaps. More... | |
Typedefs | |
typedef struct hashmap_s | hashmap_t |
Generic hashmap. More... | |
typedef void *(* | hashmap_key_clone_t) (void *) |
Key cloning function type. More... | |
typedef void(* | hashmap_key_destroy_t) (void *) |
Key destructor function type. More... | |
typedef uint32_t(* | hashmap_key_hash_t) (void *) |
Key hashing function type. More... | |
typedef bool(* | hashmap_key_eq_t) (void *, void *) |
Key comparison function type. More... | |
typedef void *(* | hashmap_value_alloc_t) (void *) |
Value allocation function type. More... | |
typedef void(* | hashmap_value_destroy_t) (void *) |
Value destructor function type. More... | |
typedef bool(* | hashmap_iteration_cb_t) (void *, void *, void *) |
Hashmap iteration callback function type. More... | |
Functions | |
hashmap_t * | hashmap_create (hashmap_parameters_t *params) |
Create a hashmap. More... | |
void | hashmap_destroy (hashmap_t *hashmap) |
Destroy a hashmap. More... | |
void * | hashmap_lookup (hashmap_t *hashmap, void *key) |
Look up a key in a hashmap. More... | |
void * | hashmap_insert (hashmap_t *hashmap, void *key) |
Create an entry in a hashmap. More... | |
bool | hashmap_remove (hashmap_t *hashmap, void *key) |
Remove an entry from the hashmap. More... | |
bool | hashmap_iterate (hashmap_t *hashmap, hashmap_iteration_cb_t cb, void *ctx) |
Iterate the hashmap. More... | |
size_t | hashmap_count (hashmap_t *hashmap) |
Get the number of entries in this map. More... | |
typedef bool(* hashmap_iteration_cb_t) (void *, void *, void *) |
typedef void *(* hashmap_key_clone_t) (void *) |
typedef void(* hashmap_key_destroy_t) (void *) |
typedef bool(* hashmap_key_eq_t) (void *, void *) |
typedef uint32_t(* hashmap_key_hash_t) (void *) |
typedef void *(* hashmap_value_alloc_t) (void *) |
typedef void(* hashmap_value_destroy_t) (void *) |
size_t hashmap_count | ( | hashmap_t * | hashmap | ) |
Get the number of entries in this map.
hashmap | The hashmap to retrieve the entry count from |
Definition at line 252 of file hashmap.c.
References hashmap_s::entry_count.
Referenced by store_evict().
hashmap_t * hashmap_create | ( | hashmap_parameters_t * | params | ) |
Create a hashmap.
The provided hashmap parameter table will be used for map operations which need to allocate/free etc.
params | The hashmap parameters for this map |
Definition at line 67 of file hashmap.c.
References hashmap_s::bucket_count, hashmap_s::buckets, DEFAULT_HASHMAP_BUCKETS, hashmap_s::entry_count, and hashmap_s::params.
Referenced by fetch_curl_register(), and read_entries().
void hashmap_destroy | ( | hashmap_t * | hashmap | ) |
Destroy a hashmap.
After this, all keys and values will have been destroyed and all memory associated with this hashmap will be invalidated.
hashmap | The hashmap to destroy |
Definition at line 91 of file hashmap.c.
References hashmap_s::bucket_count, hashmap_s::buckets, hashmap_entry_s::key, hashmap_parameters_t::key_destroy, hashmap_entry_s::next, hashmap_s::params, hashmap_entry_s::value, and hashmap_parameters_t::value_destroy.
Referenced by fetch_curl_finalise(), finalise(), and initialise().
void * hashmap_insert | ( | hashmap_t * | hashmap, |
void * | key | ||
) |
Create an entry in a hashmap.
This creates a blank value using the parameters and then associates it with a clone of the given key, inserting it into the hashmap. If a value was present for the given key already, then it is destroyed first.
NOTE: If allocation of the new value object fails, then any existing entry will be left alone, but NULL will be returned.
hashmap | The hashmap to insert into |
key | The key to insert an entry for |
Definition at line 131 of file hashmap.c.
References hashmap_s::bucket_count, hashmap_s::buckets, hashmap_s::entry_count, hashmap_entry_s::key, hashmap_parameters_t::key_clone, hashmap_parameters_t::key_destroy, hashmap_parameters_t::key_eq, hashmap_entry_s::key_hash, hashmap_parameters_t::key_hash, hashmap_entry_s::next, hashmap_s::params, hashmap_entry_s::prevptr, hashmap_entry_s::value, hashmap_parameters_t::value_alloc, and hashmap_parameters_t::value_destroy.
Referenced by read_entries(), and set_store_entry().
bool hashmap_iterate | ( | hashmap_t * | hashmap, |
hashmap_iteration_cb_t | cb, | ||
void * | ctx | ||
) |
Iterate the hashmap.
For each key/value pair in the hashmap, call the callback passing in the key and value. During iteration you MUST NOT mutate the hashmap.
hashmap | The hashmap to iterate |
cb | The callback for each key,value pair |
ctx | The callback context |
Definition at line 233 of file hashmap.c.
References hashmap_s::bucket_count, hashmap_s::buckets, and hashmap_entry_s::next.
Referenced by store_evict(), and write_entries().
void * hashmap_lookup | ( | hashmap_t * | hashmap, |
void * | key | ||
) |
Look up a key in a hashmap.
If the key has an associated value in the hashmap then the pointer to it is returned, otherwise NULL.
hashmap | The hashmap to look up the key inside |
key | The key to look up in the hashmap |
Definition at line 113 of file hashmap.c.
References hashmap_s::bucket_count, hashmap_s::buckets, hashmap_entry_s::key, hashmap_parameters_t::key_eq, hashmap_entry_s::key_hash, hashmap_parameters_t::key_hash, hashmap_entry_s::next, hashmap_s::params, and hashmap_entry_s::value.
Referenced by fetch_curl_report_certs_upstream(), get_store_entry(), and set_store_entry().
bool hashmap_remove | ( | hashmap_t * | hashmap, |
void * | key | ||
) |
Remove an entry from the hashmap.
This will remove the entry for the given key from the hashmap If there is no such entry, this will safely do nothing. The value associated with the entry will be destroyed and so should not be used beyond calling this function.
hashmap | The hashmap to remove the entry from |
key | The key to remove the entry for |
Definition at line 206 of file hashmap.c.
References hashmap_s::bucket_count, hashmap_s::buckets, hashmap_s::entry_count, hashmap_entry_s::key, hashmap_parameters_t::key_destroy, hashmap_parameters_t::key_eq, hashmap_entry_s::key_hash, hashmap_parameters_t::key_hash, hashmap_entry_s::next, hashmap_s::params, hashmap_entry_s::prevptr, hashmap_entry_s::value, and hashmap_parameters_t::value_destroy.
Referenced by invalidate_entry().