hset¶
Category: hash
GitHub: cute_hashtable.h
Add's a {key, item} pair.
Parameters | Description |
---|---|
h | The hashtable. Can 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. |
... | An item to place in the table. |
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;
hset(table, 0, 5);
hset(table, 1, 12);
CF_ASSERT(hget(table, 0) == 5);
CF_ASSERT(hget(table, 1) == 12);
hfree(table);
Remarks¶
If the item does not exist in the table it is added. The pointer returned is not stable. Internally the table can be resized, invalidating all pointers to any elements within the table. Therefor, no items may store pointers to themselves or other items. Indices however, are totally fine.
Related Pages¶
htbl
hfree
hadd
hget
hfind
hget_ptr
hfind_ptr
hhas
hdel
hclear
hkeys
hitems
hswap
hsize
hcount