A clone of btpd with my configuration changes.
Vous ne pouvez pas sélectionner plus de 25 sujets Les noms de sujets doivent commencer par une lettre ou un nombre, peuvent contenir des tirets ('-') et peuvent comporter jusqu'à 35 caractères.

81 lignes
2.3 KiB

  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. void *obj;
  8. };
  9. struct _htbl *_htbl_create(int (*equal)(const void *, const void *),
  10. uint32_t (*hash)(const void *), size_t keyoff, size_t chainoff);
  11. void _htbl_free(struct _htbl *tbl);
  12. void _htbl_insert(struct _htbl *tbl, void *o);
  13. void *_htbl_remove(struct _htbl *tbl, const void *key);
  14. void *_htbl_find(struct _htbl *tbl, const void *key);
  15. void _htbl_tov(struct _htbl *tb, void **v);
  16. size_t _htbl_size(struct _htbl *tbl);
  17. void _htbl_iter_init(struct _htbl *tbl, struct htbl_iter *it);
  18. void *_htbl_iter_next(struct htbl_iter *it);
  19. #define HTBLTYPE(name, type, ktype, kname, cname) \
  20. __attribute__((always_inline)) static inline struct name * \
  21. name##_create(int (*equal)(const ktype *, const ktype *), \
  22. uint32_t (*hash)(const ktype *)) \
  23. { \
  24. return (struct name *) \
  25. _htbl_create((int (*)(const void *, const void *))equal, \
  26. (uint32_t (*)(const void *))hash, offsetof(struct type, kname), \
  27. offsetof(struct type, cname)); \
  28. } \
  29. \
  30. __attribute__((always_inline)) static inline struct type * \
  31. name##_find(struct name *tbl, const ktype *key) \
  32. { \
  33. return (struct type *)_htbl_find((struct _htbl *)tbl, key); \
  34. } \
  35. \
  36. __attribute__((always_inline)) static inline struct type * \
  37. name##_remove(struct name *tbl, const ktype *key) \
  38. { \
  39. return (struct type *)_htbl_remove((struct _htbl *)tbl, key); \
  40. } \
  41. \
  42. __attribute__((always_inline)) static inline void \
  43. name##_free(struct name *tbl) \
  44. { \
  45. _htbl_free((struct _htbl *)tbl); \
  46. } \
  47. \
  48. __attribute__((always_inline)) static inline void \
  49. name##_insert(struct name *tbl, struct type *o) \
  50. { \
  51. _htbl_insert((struct _htbl *)tbl, o); \
  52. } \
  53. __attribute__((always_inline)) static inline void \
  54. name##_tov(struct name *tbl, struct type **v) \
  55. { \
  56. _htbl_tov((struct _htbl *)tbl, (void **)v); \
  57. } \
  58. \
  59. __attribute__((always_inline)) static inline size_t \
  60. name##_size(struct name *tbl) \
  61. { \
  62. return _htbl_size((struct _htbl *)tbl); \
  63. } \
  64. \
  65. __attribute__((always_inline)) static inline void \
  66. name##_iter_init(struct name *tbl, struct htbl_iter *it) \
  67. { \
  68. _htbl_iter_init((struct _htbl *)tbl, it); \
  69. } \
  70. \
  71. __attribute__((always_inline)) static inline struct type * \
  72. name##_iter_next(struct htbl_iter *it) \
  73. { \
  74. return (struct type *)_htbl_iter_next(it); \
  75. }
  76. #endif