|
AquilaOS documentation
How it works, and its code
|
Go to the source code of this file.
Data Structures | |
| struct | hashmap |
| A hash table. More... | |
| struct | hashmap_node |
| A hash table's node: an entry, with its key's hash. More... | |
Macros | |
| #define | HASHMAP_DEFAULT 20 |
| #define | HASHMAP_LOAD 2 |
| #define | hashmap_for(n, h) |
Typedefs | |
| typedef uintptr_t | hash_t |
Functions | |
| static struct hashmap * | hashmap_new (size_t n, int(*eq)(void *, void *)) |
| Makes a new, empty hash table of n buckets (0: HASHMAP_DEFAULT). | |
| static hash_t | hashmap_digest (const void *_id, size_t size) |
| Returns the hash of a key of size bytes. | |
| static void | hashmap_grow (struct hashmap *hashmap) |
| Doubles a table's buckets, and moves each entry to its new bucket. | |
| static int | hashmap_insert (struct hashmap *hashmap, hash_t hash, void *entry) |
| Adds an entry to a hash table. | |
| static struct hashmap_node * | hashmap_lookup (struct hashmap *hashmap, hash_t hash, void *key) |
| Finds the node of the entry for a key, or returns NULL if there's none. | |
| static int | hashmap_replace (struct hashmap *hashmap, hash_t hash, void *key, void *entry) |
| Replaces the entry for a key, or adds it if there's none. | |
| static void | hashmap_node_remove (struct hashmap *hashmap, struct hashmap_node *node) |
| Removes a node from a hash table, and frees it (not its entry). | |
| static void | hashmap_free (struct hashmap *hashmap) |
| Frees a hash table and its nodes (not their entries). | |
| #define HASHMAP_DEFAULT 20 |
Definition at line 25 of file hashmap.h.
Referenced by hashmap_new().
| #define hashmap_for | ( | n, | |
| h ) |
Definition at line 51 of file hashmap.h.
Referenced by vm_anon_copy_arefs(), vm_anon_destroy(), and vnode_pages_free().
| #define HASHMAP_LOAD 2 |
Definition at line 29 of file hashmap.h.
Referenced by hashmap_insert().
|
inlinestatic |
Frees a hash table and its nodes (not their entries).
Definition at line 235 of file hashmap.h.
References hashmap::buckets, hashmap::buckets_nr, and kfree().
|
inlinestatic |
Doubles a table's buckets, and moves each entry to its new bucket.
The queue nodes are relinked rather than made anew. If there's no memory for the new buckets, the table stays as it is.
Definition at line 110 of file hashmap.h.
References buckets, hashmap::buckets, hashmap::buckets_nr, queue::count, hashmap_node::hash, hashmap_grow(), queue::head, kfree(), kmalloc(), M_ZERO, qnode::next, NULL, qnode::prev, queue::tail, and qnode::value.
Referenced by hashmap_grow(), and hashmap_insert().
Adds an entry to a hash table.
Returns 0, -EINVAL for a bad table, or -ENOMEM if there was no memory for its node.
Definition at line 148 of file hashmap.h.
References hashmap::buckets, hashmap::buckets_nr, hashmap::count, hashmap_node::entry, hashmap_node::hash, hashmap_grow(), HASHMAP_LOAD, kfree(), kmalloc(), and hashmap_node::qnode.
Referenced by hashmap_replace().
|
inlinestatic |
Finds the node of the entry for a key, or returns NULL if there's none.
Definition at line 181 of file hashmap.h.
References hashmap::buckets, hashmap::buckets_nr, hashmap::count, hashmap_node::entry, hashmap::eq, hashmap_node::hash, NULL, and queue_for.
Makes a new, empty hash table of n buckets (0: HASHMAP_DEFAULT).
Returns it, or NULL if there was no memory for it.
Definition at line 57 of file hashmap.h.
References hashmap::buckets, hashmap::buckets_nr, hashmap::eq, HASHMAP_DEFAULT, kfree(), kmalloc(), memset(), and NULL.
|
inlinestatic |
Removes a node from a hash table, and frees it (not its entry).
Definition at line 220 of file hashmap.h.
References hashmap::buckets, hashmap::buckets_nr, hashmap::count, hashmap_node::hash, kfree(), and hashmap_node::qnode.
|
inlinestatic |
Replaces the entry for a key, or adds it if there's none.
Returns 0, or what hashmap_insert() returned.
Definition at line 200 of file hashmap.h.
References hashmap::buckets, hashmap::buckets_nr, hashmap::count, hashmap_node::entry, hashmap::eq, hashmap_node::hash, hashmap_insert(), hashmap_replace(), and queue_for.
Referenced by hashmap_replace().