Skip to content

hget

Category: hash
GitHub: cute_hashtable.h


Fetches the item that k maps to.

#define hget(h, k) cf_hashtable_get(h, k)
Parameters Description
h The hashtable. Can not be NULL. Needs to be a pointer to the type of items in the table.
k The key for lookups. Each {key, item} pair must be unique. Keys are always typecasted to uint64_t e.g. you can use pointers as keys.

Return Value

Returns a pointer to the item set into the table.

Code Example

Set and get a few elements from a hashtable.

htbl int table = NULL;
hadd(table, 0, 5);
hadd(table, 1, 12);
CF_ASSERT(hget(table, 0) == 5);
CF_ASSERT(hget(table, 1) == 12);
hfree(table);

Remarks

Items are returned by value, not pointer. If the item doesn't exist a zero'd out item is instead returned. If you want to get a pointer (so you can see if it's NULL in case the item didn't exist, then use hget_ptr). You can also call hhas for a bool. This function does the same as hfind.

htbl
hset
hadd
hfree
hfind
hget_ptr
hfind_ptr
hhas
hdel
hclear
hkeys
hitems
hswap
hsize
hcount