btree-128.h 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109
  1. extern struct btree_geo btree_geo128;
  2. struct btree_head128 { struct btree_head h; };
  3. static inline void btree_init_mempool128(struct btree_head128 *head,
  4. mempool_t *mempool)
  5. {
  6. btree_init_mempool(&head->h, mempool);
  7. }
  8. static inline int btree_init128(struct btree_head128 *head)
  9. {
  10. return btree_init(&head->h);
  11. }
  12. static inline void btree_destroy128(struct btree_head128 *head)
  13. {
  14. btree_destroy(&head->h);
  15. }
  16. static inline void *btree_lookup128(struct btree_head128 *head, u64 k1, u64 k2)
  17. {
  18. u64 key[2] = {k1, k2};
  19. return btree_lookup(&head->h, &btree_geo128, (unsigned long *)&key);
  20. }
  21. static inline void *btree_get_prev128(struct btree_head128 *head,
  22. u64 *k1, u64 *k2)
  23. {
  24. u64 key[2] = {*k1, *k2};
  25. void *val;
  26. val = btree_get_prev(&head->h, &btree_geo128,
  27. (unsigned long *)&key);
  28. *k1 = key[0];
  29. *k2 = key[1];
  30. return val;
  31. }
  32. static inline int btree_insert128(struct btree_head128 *head, u64 k1, u64 k2,
  33. void *val, gfp_t gfp)
  34. {
  35. u64 key[2] = {k1, k2};
  36. return btree_insert(&head->h, &btree_geo128,
  37. (unsigned long *)&key, val, gfp);
  38. }
  39. static inline int btree_update128(struct btree_head128 *head, u64 k1, u64 k2,
  40. void *val)
  41. {
  42. u64 key[2] = {k1, k2};
  43. return btree_update(&head->h, &btree_geo128,
  44. (unsigned long *)&key, val);
  45. }
  46. static inline void *btree_remove128(struct btree_head128 *head, u64 k1, u64 k2)
  47. {
  48. u64 key[2] = {k1, k2};
  49. return btree_remove(&head->h, &btree_geo128, (unsigned long *)&key);
  50. }
  51. static inline void *btree_last128(struct btree_head128 *head, u64 *k1, u64 *k2)
  52. {
  53. u64 key[2];
  54. void *val;
  55. val = btree_last(&head->h, &btree_geo128, (unsigned long *)&key[0]);
  56. if (val) {
  57. *k1 = key[0];
  58. *k2 = key[1];
  59. }
  60. return val;
  61. }
  62. static inline int btree_merge128(struct btree_head128 *target,
  63. struct btree_head128 *victim,
  64. gfp_t gfp)
  65. {
  66. return btree_merge(&target->h, &victim->h, &btree_geo128, gfp);
  67. }
  68. void visitor128(void *elem, unsigned long opaque, unsigned long *__key,
  69. size_t index, void *__func);
  70. typedef void (*visitor128_t)(void *elem, unsigned long opaque,
  71. u64 key1, u64 key2, size_t index);
  72. static inline size_t btree_visitor128(struct btree_head128 *head,
  73. unsigned long opaque,
  74. visitor128_t func2)
  75. {
  76. return btree_visitor(&head->h, &btree_geo128, opaque,
  77. visitor128, func2);
  78. }
  79. static inline size_t btree_grim_visitor128(struct btree_head128 *head,
  80. unsigned long opaque,
  81. visitor128_t func2)
  82. {
  83. return btree_grim_visitor(&head->h, &btree_geo128, opaque,
  84. visitor128, func2);
  85. }
  86. #define btree_for_each_safe128(head, k1, k2, val) \
  87. for (val = btree_last128(head, &k1, &k2); \
  88. val; \
  89. val = btree_get_prev128(head, &k1, &k2))