hashtable.h 2.0 KB

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