DavidLeeds / hashmap

Templated type-safe hashmap implementation in C using open addressing and linear probing for collision resolution.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

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:

  1. Perform a pseudo-random iteration of all numbers between 0 and hashmap.table_size -1.
  2. Index into the array of struct hashmap_entry with the number calculated above.
  3. 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). If hashmap_iter_get_key() returns NULL, skip the entry, and move on to the next one. Otherwise, the entry is valid.