hashtable.h 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  1. #ifndef TOOLBOX_HASHTABLE_H
  2. #define TOOLBOX_HASHTABLE_H
  3. #include "toolbox/errno.h"
  4. #include <stddef.h>
  5. #include <stdint.h>
  6. #ifndef HASHTABLE_SIZE_BYTES
  7. #define HASHTABLE_SIZE_BYTES (1024*1024)
  8. #endif
  9. #ifdef TOOLBOX_TYPEDEF
  10. typedef struct hashtable hashtable_st;
  11. #endif
  12. struct hashtable;
  13. __attribute__((__pure__))
  14. struct hashtable *
  15. hashtable_create(void);
  16. RET_TYPE
  17. hashtable_destroy(struct hashtable **self);
  18. __attribute__((__pure__))
  19. _Bool
  20. hashtable_contain_item(const struct hashtable *self
  21. , const void* item, const size_t item_size);
  22. __attribute__((__pure__))
  23. _Bool
  24. hashtable_contain_key(const struct hashtable *self
  25. , const char *key);
  26. __attribute__((__pure__))
  27. _Bool
  28. hashtable_contain_key_hash(const struct hashtable *self
  29. , const size_t key_hash);
  30. __attribute__((__pure__))
  31. const void *
  32. hashtable_get(const struct hashtable *self
  33. , const char *key);
  34. __attribute__((__pure__))
  35. const void *
  36. hashtable_get_or_default(const struct hashtable *self
  37. , const char *key
  38. , const void *default_item);
  39. __attribute__((__pure__))
  40. _Bool
  41. hashtable_is_empty(const struct hashtable *self);
  42. RET_TYPE
  43. hashtable_put(struct hashtable *self
  44. , const char *key
  45. , const void *item, const size_t item_size);
  46. const void *
  47. hashtable_remove(struct hashtable *self, const char *key);
  48. _Bool
  49. hashtable_remove_if_equal(struct hashtable *self
  50. , const char *key
  51. , const void *item, const size_t item_size);
  52. const void *
  53. hashtable_replace(struct hashtable *self
  54. , const char *key
  55. , const void *item, const size_t item_size);
  56. _Bool
  57. hashtable_replace_if_equal(struct hashtable *self
  58. , const char *key
  59. , const void *restrict old_item
  60. , const size_t item_old_size
  61. , const void *restrict new_item
  62. , const size_t item_new_size);
  63. size_t
  64. hashtable_used_size(const struct hashtable *self);
  65. RET_TYPE
  66. hashtable_for_each(struct hashtable *self
  67. , void (*for_each)(void *item, size_t *item_size));
  68. #endif