1
0

hashmap.h 557 B

12345678910111213141516171819202122232425262728
  1. typedef struct Hashentry Hashentry;
  2. typedef struct Hashtable Hashtable;
  3. typedef struct Hashmap Hashmap;
  4. struct Hashentry {
  5. u64 key;
  6. u64 val;
  7. };
  8. struct Hashtable {
  9. Hashentry *tab;
  10. usize len;
  11. usize 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, u64 key, u64 *valp);
  21. int hmapget(Hashmap *ht, u64 key, u64 *valp);
  22. int hmapput(Hashmap *ht, u64 key, u64 val);
  23. int hmapstats(Hashmap *ht, usize *lens, usize nlens);