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_in_bucket() - iterate entries in the bucket for @key 101 * @table: a non-pointer qdf_ht instance to iterate 102 * @cursor: container struct pointer populated with each iteration 103 * @entry_field: name of the entry field in the entry container struct 104 * @key: key used to lookup the hashtable bucket 105 */ 106 #define qdf_ht_for_each_in_bucket(table, cursor, entry_field, key) \ 107 __qdf_ht_for_each_in_bucket(table, cursor, entry_field, key) 108 109 /** 110 * qdf_ht_for_each_match() - iterates through each entry matching @key 111 * @table: a non-pointer qdf_ht instance to iterate 112 * @cursor: container struct pointer populated with each iteration 113 * @entry_field: name of the entry field in the entry container struct 114 * @key: key used to lookup the entries 115 * @key_field: name of the key field in the entry container struct 116 */ 117 #define qdf_ht_for_each_match(table, cursor, entry_field, key, key_field) \ 118 __qdf_ht_for_each_match(table, cursor, entry_field, key, key_field) 119 120 /** 121 * qdf_ht_get() - get the first entry with a key matching @key 122 * @table: a non-pointer qdf_ht instance to look in 123 * @cursor: container struct pointer populated with each iteration 124 * @entry_field: name of the entry field in the entry container struct 125 * @key: key used to lookup the entry 126 * @key_field: name of the key field in the entry container struct 127 */ 128 #define qdf_ht_get(table, cursor, entry_field, key, key_field) \ 129 __qdf_ht_get(table, cursor, entry_field, key, key_field) 130 131 #endif /* __QDF_HASHTABLE_H */ 132