Random iteration?
DirectorX opened this issue · comments
Is random iteration over entries possible?
Anything is possible. The struct hashmap
is currently in the public header, so this could be done externally, or you could fork the library and add the feature. The strategy would be as follows:
- Perform a pseudo-random iteration of all numbers between 0 and hashmap.table_size -1.
- Index into the array of
struct hashmap_entry
with the number calculated above. - If you're doing this externally, the struct hashmap_entry is opaque, but it happens to be the same as a
struct hashmap_iter
(implementation detail). Ifhashmap_iter_get_key()
returns NULL, skip the entry, and move on to the next one. Otherwise, the entry is valid.