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