qdf_hashtable.h 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144
  1. /*
  2. * Copyright (c) 2018-2019 The Linux Foundation. All rights reserved.
  3. * Copyright (c) 2023 Qualcomm Innovation Center, Inc. All rights reserved.
  4. *
  5. * Permission to use, copy, modify, and/or distribute this software for
  6. * any purpose with or without fee is hereby granted, provided that the
  7. * above copyright notice and this permission notice appear in all
  8. * copies.
  9. *
  10. * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL
  11. * WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED
  12. * WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE
  13. * AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL
  14. * DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR
  15. * PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
  16. * TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
  17. * PERFORMANCE OF THIS SOFTWARE.
  18. */
  19. /**
  20. * DOC: qdf_hashtable.h - Public APIs for a hashtable data structure
  21. */
  22. #ifndef __QDF_HASHTABLE_H
  23. #define __QDF_HASHTABLE_H
  24. #include "i_qdf_hashtable.h"
  25. /*
  26. * qdf_ht - opaque hashtable data type
  27. */
  28. #define qdf_ht __qdf_ht
  29. /*
  30. * qdf_ht_entry - opaque hashtable entry for membership in a qdf_ht
  31. */
  32. #define qdf_ht_entry __qdf_ht_entry
  33. /**
  34. * qdf_ht_declare() - declare a new qdf_ht
  35. * @name: variable name of the hashtable to declare
  36. * @bits: number of hash bits to use; buckets=2^bits; Needs to be a compile
  37. * time constant
  38. *
  39. */
  40. #define qdf_ht_declare(name, bits) __qdf_ht_declare(name, bits)
  41. /**
  42. * qdf_ht_init() - initialize a qdf_ht instance
  43. * @table: a non-pointer qdf_ht instance to initialize
  44. *
  45. * Return: none
  46. */
  47. #define qdf_ht_init(table) __qdf_ht_init(table)
  48. /**
  49. * qdf_ht_deinit() - de-initialize a qdf_ht instance
  50. * @table: a non-pointer qdf_ht instance to de-initialize
  51. *
  52. * Return: none
  53. */
  54. #define qdf_ht_deinit(table) __qdf_ht_deinit(table)
  55. /**
  56. * qdf_ht_empty() - check if a qdf_ht has any entries
  57. * @table: a non-pointer qdf_ht instance to check
  58. *
  59. * Return: true if the hashtable is empty
  60. */
  61. #define qdf_ht_empty(table) __qdf_ht_empty(table)
  62. /**
  63. * qdf_ht_add() - add an entry to a qdf_ht instance
  64. * @table: a non-pointer qdf_ht instance to add an entry to
  65. * @entry: pointer to a qdf_ht_entry instance to add to @table
  66. * @key: the key to use for entry insertion and lookup
  67. *
  68. * Return: none
  69. */
  70. #define qdf_ht_add(table, entry, key) __qdf_ht_add(table, entry, key)
  71. /**
  72. * qdf_ht_remove() - remove and entry from a qdf_ht instance
  73. * @entry: pointer to a qdf_ht_entry instance to remove
  74. *
  75. * Return: none
  76. */
  77. #define qdf_ht_remove(entry) __qdf_ht_remove(entry)
  78. /**
  79. * qdf_ht_for_each() - iterate all entries in @table
  80. * @table: a non-pointer qdf_ht instance to iterate
  81. * @i: int type cursor populated with the bucket index
  82. * @cursor: container struct pointer populated with each iteration
  83. * @entry_field: name of the entry field in the entry container struct
  84. */
  85. #define qdf_ht_for_each(table, i, cursor, entry_field) \
  86. __qdf_ht_for_each(table, i, cursor, entry_field)
  87. /**
  88. * qdf_ht_for_each_safe() - iterate all entries in @table safe against removal
  89. * of hash entry.
  90. * @table: a non-pointer qdf_ht instance to iterate
  91. * @i: int type cursor populated with the bucket index
  92. * @tmp: a &struct used for temporary storage
  93. * @cursor: container struct pointer populated with each iteration
  94. * @entry_field: name of the entry field in the entry container struct
  95. */
  96. #define qdf_ht_for_each_safe(table, i, tmp, cursor, entry_field) \
  97. __qdf_ht_for_each_safe(table, i, tmp, cursor, entry_field)
  98. /**
  99. * qdf_ht_for_each_in_bucket() - iterate entries in the bucket for @key
  100. * @table: a non-pointer qdf_ht instance to iterate
  101. * @cursor: container struct pointer populated with each iteration
  102. * @entry_field: name of the entry field in the entry container struct
  103. * @key: key used to lookup the hashtable bucket
  104. */
  105. #define qdf_ht_for_each_in_bucket(table, cursor, entry_field, key) \
  106. __qdf_ht_for_each_in_bucket(table, cursor, entry_field, key)
  107. /**
  108. * qdf_ht_for_each_match() - iterates through each entry matching @key
  109. * @table: a non-pointer qdf_ht instance to iterate
  110. * @cursor: container struct pointer populated with each iteration
  111. * @entry_field: name of the entry field in the entry container struct
  112. * @key: key used to lookup the entries
  113. * @key_field: name of the key field in the entry container struct
  114. */
  115. #define qdf_ht_for_each_match(table, cursor, entry_field, key, key_field) \
  116. __qdf_ht_for_each_match(table, cursor, entry_field, key, key_field)
  117. /**
  118. * qdf_ht_get() - get the first entry with a key matching @key
  119. * @table: a non-pointer qdf_ht instance to look in
  120. * @cursor: container struct pointer populated with each iteration
  121. * @entry_field: name of the entry field in the entry container struct
  122. * @key: key used to lookup the entry
  123. * @key_field: name of the key field in the entry container struct
  124. */
  125. #define qdf_ht_get(table, cursor, entry_field, key, key_field) \
  126. __qdf_ht_get(table, cursor, entry_field, key, key_field)
  127. #endif /* __QDF_HASHTABLE_H */