objc

hashtable.h
Go to the documentation of this file.
1 
13 #pragma once
14 
15 #define SYS_HASHTABLE_KEY_SIZE 24
16 
17 
24 typedef struct sys_hashtable sys_hashtable_t;
25 
35 typedef struct sys_hashtable_iterator {
37  size_t index;
39 
50 typedef struct {
51  uintptr_t hash;
52  uintptr_t value;
53  uint8_t flags;
54  void *keyptr;
55  char keybuf[SYS_HASHTABLE_KEY_SIZE];
59 
67 typedef bool (*sys_hashtable_keyequals_t)(void *keyptr, void *other_keyptr);
68 
70 // LIFECYCLE
71 
80  sys_hashtable_keyequals_t keyequals);
81 
88 
90 // PUBLIC METHODS
91 
101  uintptr_t hash, void *keyptr);
102 
111  uintptr_t value);
112 
129  void *keyptr, bool *samekey);
130 
140  uintptr_t hash, void *keyptr);
141 
149  uintptr_t value);
150 
159  sys_hashtable_iterator_t **iterator);
160 
168 
void * keyptr
Pointer to key data.
Definition: hashtable.h:54
struct sys_hashtable_iterator sys_hashtable_iterator_t
Iterator state for hash table traversal.
void sys_hashtable_finalize(sys_hashtable_t *table)
Free all the hash tables in the chain.
size_t index
Current index within table.
Definition: hashtable.h:37
bool(* sys_hashtable_keyequals_t)(void *keyptr, void *other_keyptr)
Compare entry with a key.
Definition: hashtable.h:67
sys_hashtable_entry_t * sys_hashtable_get_key(sys_hashtable_t *table, uintptr_t hash, void *keyptr)
Search for an entry in the hash table by hash key.
sys_hashtable_t * sys_hashtable_init(size_t size, sys_hashtable_keyequals_t keyequals)
Initialize a new hash table.
#define SYS_HASHTABLE_KEY_SIZE
Maximum key size in bytes.
Definition: hashtable.h:15
Iterator state for hash table traversal.
Definition: hashtable.h:35
sys_hashtable_entry_t * sys_hashtable_delete_key(sys_hashtable_t *table, uintptr_t hash, void *keyptr)
Delete an entry into the hash table by key.
sys_hashtable_t * table
Current table being iterated.
Definition: hashtable.h:36
Hash table entry.
Definition: hashtable.h:50
uint8_t flags
Entry flags (implementation-specific)
Definition: hashtable.h:53
sys_hashtable_entry_t * sys_hashtable_iterator_next(sys_hashtable_t *table, sys_hashtable_iterator_t **iterator)
Get the next entry from the iterator.
uintptr_t value
Value associated with the entry.
Definition: hashtable.h:52
struct sys_hashtable sys_hashtable_t
Opaque type for hash table.
Definition: hashtable.h:24
sys_hashtable_entry_t * sys_hashtable_get_value(sys_hashtable_t *table, uintptr_t value)
Search for an entry in the hash table by hash value.
size_t sys_hashtable_capacity(sys_hashtable_t *table)
Get the total capacity of all tables in the chain.
uintptr_t hash
Hash key for the entry.
Definition: hashtable.h:51
sys_hashtable_entry_t * sys_hashtable_delete_value(sys_hashtable_t *table, uintptr_t value)
Delete an entry from the hash table by value.
sys_hashtable_entry_t * sys_hashtable_put(sys_hashtable_t *table, uintptr_t hash, void *keyptr, bool *samekey)
Return a has table entry in which to put the value, and perhaps the key.
size_t sys_hashtable_count(sys_hashtable_t *table)
Get the number of active entries in the hash table chain.