hatab.h 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. #ifndef hatab_H_INCLUDED
  2. #define hatab_H_INCLUDED
  3. #include "mem.h"
  4. typedef struct HatabPair_ HatabPair;
  5. /* Hatab stores key/value pairs. */
  6. struct HatabPair_ {
  7. void * key;
  8. void * value;
  9. };
  10. // Hash function for the hash table.
  11. typedef int (HatabHash)(const void * key);
  12. // Comparison function for the hash table
  13. typedef int (HatabCompare)(const void * one, const void * two);
  14. // Free function for the hash table's pairs.
  15. typedef int (HatabPairFree)(HatabPair * pair);
  16. struct HatabActs_;
  17. typedef struct HatabActs_ HatabActs;
  18. // function pointers that determine the hash table's functioning,
  19. // especially how it compares and hashes keys
  20. struct HatabActs_ {
  21. HatabCompare * compare;
  22. HatabHash * hash;
  23. HatabPairFree * free_pair;
  24. };
  25. typedef struct Hatab_ Hatab;
  26. #include <stdint.h>
  27. // need stdint for uint32_t
  28. uint32_t hatab_jenkins (char *key , size_t len );
  29. uint32_t hatab_hash_cstr (void * key );
  30. uint32_t hatab_hash_uint32 (void * key );
  31. int hatab_cellarfull_p (Hatab * self );
  32. int hatab_pailsfull_p (Hatab * self );
  33. Hatab * hatab_done (Hatab * self );
  34. Hatab * hatab_free (Hatab * self );
  35. Hatab * hatab_clear (Hatab * self );
  36. Hatab * hatab_initroom (Hatab * self , HatabActs * acts , int pails , int cellars );
  37. Hatab * hatab_alloc (void);
  38. Hatab * hatab_init (Hatab * self , HatabActs * acts );
  39. Hatab * hatab_newroom (HatabActs * acts , int pails , int cellars );
  40. Hatab * hatab_new (HatabActs * acts);
  41. uint32_t hatab_hash (Hatab * self , void * ptr );
  42. int hatab_compare (Hatab * self , void * pa , void * pb );
  43. void * hatab_get (Hatab * self , void * key );
  44. void * hatab_drop (Hatab * self , void * key );
  45. Hatab * hatab_grow (Hatab * self );
  46. void * hatab_put (Hatab * self , void * key , void * value );
  47. #endif