A clone of btpd with my configuration changes.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

пре 18 година
пре 18 година
пре 18 година
пре 18 година
пре 18 година
пре 18 година
пре 18 година
пре 18 година
пре 18 година
пре 18 година
пре 18 година
пре 18 година
пре 18 година
пре 18 година
пре 18 година
1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  1. #ifndef BTPD_HASHTABLE_H
  2. #define BTPD_HASHTABLE_H
  3. struct htbl_iter {
  4. struct _htbl *tbl;
  5. size_t bi;
  6. size_t cnt;
  7. struct _any **ptr;
  8. struct _any *obj;
  9. };
  10. struct _htbl *_htbl_create(float ratio,
  11. int (*equal)(const void *, const void *),
  12. uint32_t (*hash)(const void *), size_t keyoff, size_t chainoff);
  13. void _htbl_free(struct _htbl *tbl);
  14. void _htbl_insert(struct _htbl *tbl, struct _any *o);
  15. struct _any *_htbl_remove(struct _htbl *tbl, const void *key);
  16. struct _any *_htbl_find(struct _htbl *tbl, const void *key);
  17. void _htbl_fillv(struct _htbl *tbl, struct _any **v);
  18. struct _any **_htbl_tov(struct _htbl *tbl);
  19. size_t _htbl_size(struct _htbl *tbl);
  20. struct _any *_htbl_iter_first(struct _htbl *tbl, struct htbl_iter *it);
  21. struct _any *_htbl_iter_next(struct htbl_iter *it);
  22. struct _any *_htbl_iter_del(struct htbl_iter *it);
  23. #define HTBL_ENTRY(name) struct _any *name
  24. #define HTBL_TYPE(name, type, ktype, kname, cname) \
  25. __attribute__((always_inline)) static inline struct name * \
  26. name##_create(float ratio, int (*equal)(const void *, const void *), \
  27. uint32_t (*hash)(const void *)) \
  28. { \
  29. return (struct name *) \
  30. _htbl_create(ratio, equal, hash, offsetof(struct type, kname), \
  31. offsetof(struct type, cname)); \
  32. } \
  33. \
  34. __attribute__((always_inline)) static inline struct type * \
  35. name##_find(struct name *tbl, const ktype *key) \
  36. { \
  37. return (struct type *)_htbl_find((struct _htbl *)tbl, key); \
  38. } \
  39. \
  40. __attribute__((always_inline)) static inline struct type * \
  41. name##_remove(struct name *tbl, const ktype *key) \
  42. { \
  43. return (struct type *)_htbl_remove((struct _htbl *)tbl, key); \
  44. } \
  45. \
  46. __attribute__((always_inline)) static inline void \
  47. name##_free(struct name *tbl) \
  48. { \
  49. _htbl_free((struct _htbl *)tbl); \
  50. } \
  51. \
  52. __attribute__((always_inline)) static inline void \
  53. name##_insert(struct name *tbl, struct type *o) \
  54. { \
  55. _htbl_insert((struct _htbl *)tbl, (struct _any *)o); \
  56. } \
  57. __attribute__((always_inline)) static inline struct type ** \
  58. name##_tov(struct name *tbl) \
  59. { \
  60. return (struct type **) _htbl_tov((struct _htbl *)tbl); \
  61. } \
  62. __attribute__((always_inline)) static inline void \
  63. name##_fillv(struct name *tbl, struct type **v) \
  64. { \
  65. _htbl_fillv((struct _htbl *)tbl, (struct _any **)v); \
  66. } \
  67. \
  68. __attribute__((always_inline)) static inline size_t \
  69. name##_size(struct name *tbl) \
  70. { \
  71. return _htbl_size((struct _htbl *)tbl); \
  72. } \
  73. \
  74. __attribute__((always_inline)) static inline struct type * \
  75. name##_iter_first(struct name *tbl, struct htbl_iter *it) \
  76. { \
  77. return (struct type *)_htbl_iter_first((struct _htbl *)tbl, it); \
  78. } \
  79. \
  80. __attribute__((always_inline)) static inline struct type * \
  81. name##_iter_del(struct htbl_iter *it) \
  82. { \
  83. return (struct type *)_htbl_iter_del(it); \
  84. } \
  85. __attribute__((always_inline)) static inline struct type * \
  86. name##_iter_next(struct htbl_iter *it) \
  87. { \
  88. return (struct type *)_htbl_iter_next(it); \
  89. }
  90. #endif