hfind¶
Category: hash
GitHub: cute_hashtable.h
Fetches the item that k
maps to.
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(hfind(table, 0) == 5);
CF_ASSERT(hfind(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 hfind_ptr). You can also call hhas for a bool. This function does
the same as hget.
Related Pages¶
htbl
hset
hadd
hget
hfree
hget_ptr
hfind_ptr
hhas
hdel
hclear
hkeys
hitems
hswap
hsize
hcount