diff options
Diffstat (limited to 'src/libmdsserver')
-rw-r--r-- | src/libmdsserver/hash-table.c | 24 | ||||
-rw-r--r-- | src/libmdsserver/hash-table.h | 9 |
2 files changed, 33 insertions, 0 deletions
diff --git a/src/libmdsserver/hash-table.c b/src/libmdsserver/hash-table.c index ab78f0a..dac9303 100644 --- a/src/libmdsserver/hash-table.c +++ b/src/libmdsserver/hash-table.c @@ -247,6 +247,30 @@ size_t hash_table_get(const hash_table_t* restrict this, size_t key) /** + * Look up an entry in the table + * + * @param this The hash table + * @param key The key associated with the value + * @return The entry associated with the key, `NULL` if the key was not used + */ +hash_entry_t* hash_table_get_entry(const hash_table_t* restrict this, size_t key) +{ + size_t key_hash = hash(this, key); + size_t index = truncate_hash(this, key_hash); + hash_entry_t* restrict bucket = this->buckets[index]; + + while (bucket) + { + if (TEST_KEY(this, bucket, key, key_hash)) + return bucket; + bucket = bucket->next; + } + + return NULL; +} + + +/** * Add an entry to the table * * @param this The hash table diff --git a/src/libmdsserver/hash-table.h b/src/libmdsserver/hash-table.h index 9a84db2..edf8d3a 100644 --- a/src/libmdsserver/hash-table.h +++ b/src/libmdsserver/hash-table.h @@ -184,6 +184,15 @@ int hash_table_contains_key(const hash_table_t* restrict this, size_t key) __att size_t hash_table_get(const hash_table_t* restrict this, size_t key); /** + * Look up an entry in the table + * + * @param this The hash table + * @param key The key associated with the value + * @return The entry associated with the key, `NULL` if the key was not used + */ +hash_entry_t* hash_table_get_entry(const hash_table_t* restrict this, size_t key); + +/** * Add an entry to the table * * @param this The hash table |