hashmap.h 601 B

12345678910111213141516171819202122232425262728
  1. typedef struct Hashentry Hashentry;
  2. typedef struct Hashtable Hashtable;
  3. typedef struct Hashmap Hashmap;
  4. struct Hashentry {
  5. uint64_t key;
  6. uint64_t val;
  7. };
  8. struct Hashtable {
  9. Hashentry *tab;
  10. size_t len;
  11. size_t cap; // always a power of 2.
  12. };
  13. struct Hashmap {
  14. Hashtable *cur;
  15. Hashtable *next;
  16. Hashtable tabs[2];
  17. };
  18. int hmapinit(Hashmap *ht);
  19. int hmapfree(Hashmap *ht);
  20. int hmapdel(Hashmap *ht, uint64_t key, uint64_t *valp);
  21. int hmapget(Hashmap *ht, uint64_t key, uint64_t *valp);
  22. int hmapput(Hashmap *ht, uint64_t key, uint64_t val);
  23. int hmapstats(Hashmap *ht, size_t *lens, size_t nlens);