NetSurf
|
Interface to Write-Once hash table for string to string mapping. More...
#include <stdbool.h>
Go to the source code of this file.
Functions | |
struct hash_table * | hash_create (unsigned int chains) |
Create a new hash table. More... | |
void | hash_destroy (struct hash_table *ht) |
Destroys a hash table. More... | |
bool | hash_add (struct hash_table *ht, const char *key, const char *value) |
Adds a key/value pair to a hash table. More... | |
const char * | hash_get (struct hash_table *ht, const char *key) |
Looks up a the value associated with with a key from a specific hash table. More... | |
nserror | hash_add_file (struct hash_table *ht, const char *path) |
Add key/value pairs to a hash table with data from a file. More... | |
nserror | hash_add_inline (struct hash_table *ht, const uint8_t *data, size_t size) |
Add key/value pairs to a hash table with data from a memory buffer. More... | |
Interface to Write-Once hash table for string to string mapping.
Definition in file hashtable.h.
bool hash_add | ( | struct hash_table * | ht, |
const char * | key, | ||
const char * | value | ||
) |
Adds a key/value pair to a hash table.
If the key you're adding is already in the hash table, it does not replace it, but it does take precedent over it. The old key/value pair will be inaccessable but still in memory until hash_destroy() is called on the hash table.
ht | The hash table context to add the key/value pair to. |
key | The key to associate the value with. A copy is made. |
value | The value to associate the key with. A copy is made. |
Definition at line 303 of file hashtable.c.
References hash_table::chain, hash_string_fnv(), hash_entry::key_length, hash_table::nchains, hash_entry::next, NSLOG, and hash_entry::pairing.
Referenced by gtk_fetch_filetype_init(), messages_create_ctx(), monkey_fetch_filetype_init(), and process_line().
nserror hash_add_file | ( | struct hash_table * | ht, |
const char * | path | ||
) |
Add key/value pairs to a hash table with data from a file.
The file should be formatted as a series of lines terminated with newline character. Each line should contain a key/value pair separated by a colon. If a line is empty or starts with a # character it will be ignored.
The file may be optionally gzip compressed.
ht | The hash table context to add the key/value pairs to. |
path | Path to file with key/value pairs in. |
Definition at line 363 of file hashtable.c.
References LINE_BUFFER_SIZE, NSERROR_BAD_PARAMETER, NSERROR_NOT_FOUND, NSERROR_OK, NSLOG, path(), and process_line().
Referenced by messages_load_ctx(), and nsgtk_accelerator_init().
nserror hash_add_inline | ( | struct hash_table * | ht, |
const uint8_t * | data, | ||
size_t | size | ||
) |
Add key/value pairs to a hash table with data from a memory buffer.
The data format is the same as in hash_add_file() but held in memory
The data may optionally be gzip compressed.
ht | The hash table context to add the key/value pairs to. |
data | Source of key/value pairs |
size | length of data |
Definition at line 399 of file hashtable.c.
References hash_add_inline_gzip(), and hash_add_inline_plain().
Referenced by messages_add_from_inline(), and nsgtk_accelerator_init().
struct hash_table * hash_create | ( | unsigned int | chains | ) |
Create a new hash table.
Allocate a new hash table and return a context for it. The memory consumption of a hash table is approximately 8 + (nchains * 12) bytes if it is empty.
chains | Number of chains/buckets this hash table will have. This should be a prime number, and ideally a prime number just over a power of two, for best performance and distribution. |
Definition at line 254 of file hashtable.c.
References hash_table::chain, hash_table::nchains, and NSLOG.
Referenced by gtk_fetch_filetype_init(), messages_create_ctx(), monkey_fetch_filetype_init(), and nsgtk_accelerator_init().
void hash_destroy | ( | struct hash_table * | ht | ) |
Destroys a hash table.
Destroy a hash table freeing all memory associated with it.
ht | Hash table to destroy. After the function returns, this will no longer be valid. |
Definition at line 278 of file hashtable.c.
References hash_table::chain, hash_table::nchains, hash_entry::next, and hash_entry::pairing.
Referenced by gtk_fetch_filetype_fin(), messages_destroy_ctx(), messages_load_ctx(), and monkey_fetch_filetype_fin().
const char * hash_get | ( | struct hash_table * | ht, |
const char * | key | ||
) |
Looks up a the value associated with with a key from a specific hash table.
ht | The hash table context to look up the key in. |
key | The key to search for. |
Definition at line 339 of file hashtable.c.
References hash_table::chain, hash_string_fnv(), hash_entry::key_length, hash_table::nchains, hash_entry::next, and hash_entry::pairing.
Referenced by fetch_filetype(), messages_get_buff(), messages_get_ctx(), monkey_fetch_filetype(), and nsgtk_accelerator_get_desc().