• Home
  • History
  • Annotate
  • Raw
  • Download
  • only in /netgear-R7000-V1.0.7.12_1.2.5/components/opensource/linux/linux-2.6.36/drivers/staging/batman-adv/

Lines Matching refs:hash

23 #include "hash.h"
25 /* clears the hash */
26 static void hash_init(struct hashtable_t *hash)
30 hash->elements = 0;
32 for (i = 0 ; i < hash->size; i++)
33 hash->table[i] = NULL;
36 /* remove the hash structure. if hashdata_free_cb != NULL, this function will be
37 * called to remove the elements inside of the hash. if you don't remove the
39 void hash_delete(struct hashtable_t *hash, hashdata_free_cb free_cb)
44 for (i = 0; i < hash->size; i++) {
45 bucket = hash->table[i];
57 hash_destroy(hash);
60 /* free only the hashtable and the hash itself. */
61 void hash_destroy(struct hashtable_t *hash)
63 kfree(hash->table);
64 kfree(hash);
67 /* iterate though the hash. First element is selected if an iterator
72 struct hash_it_t *hash_iterate(struct hashtable_t *hash,
75 if (!hash)
92 &hash->table[iter->index];
123 /* go through the entries of the hash table */
124 while (iter->index < hash->size) {
125 if ((hash->table[iter->index]) != NULL) {
127 iter->bucket = hash->table[iter->index];
128 iter->first_bucket = &hash->table[iter->index];
139 /* allocates and clears the hash */
143 struct hashtable_t *hash;
145 hash = kmalloc(sizeof(struct hashtable_t) , GFP_ATOMIC);
147 if (hash == NULL)
150 hash->size = size;
151 hash->table = kmalloc(sizeof(struct element_t *) * size, GFP_ATOMIC);
153 if (hash->table == NULL) {
154 kfree(hash);
158 hash_init(hash);
160 hash->compare = compare;
161 hash->choose = choose;
163 return hash;
167 int hash_add(struct hashtable_t *hash, void *data)
172 if (!hash)
175 index = hash->choose(data, hash->size);
176 bucket = hash->table[index];
179 if (hash->compare(bucket->data, data))
197 hash->table[index] = bucket;
201 hash->elements++;
207 void *hash_find(struct hashtable_t *hash, void *keydata)
212 if (!hash)
215 index = hash->choose(keydata , hash->size);
216 bucket = hash->table[index];
219 if (hash->compare(bucket->data, keydata))
231 * fiddles with hash-internals. */
232 void *hash_remove_bucket(struct hashtable_t *hash, struct hash_it_t *hash_it_t)
244 hash->elements--;
249 /* removes data from hash, if found. returns pointer do data on success, so you
253 void *hash_remove(struct hashtable_t *hash, void *data)
257 hash_it_t.index = hash->choose(data, hash->size);
258 hash_it_t.bucket = hash->table[hash_it_t.index];
262 if (hash->compare(hash_it_t.bucket->data, data)) {
265 hash->table[hash_it_t.index] ?
266 &hash->table[hash_it_t.index] : NULL);
267 return hash_remove_bucket(hash, &hash_it_t);
277 /* resize the hash, returns the pointer to the new hash or NULL on
278 * error. removes the old hash on success. */
279 struct hashtable_t *hash_resize(struct hashtable_t *hash, int size)
285 /* initialize a new hash with the new size */
286 new_hash = hash_new(size, hash->compare, hash->choose);
292 for (i = 0; i < hash->size; i++) {
293 bucket = hash->table[i];
301 /* remove hash and eventual overflow buckets but not the content
303 hash_delete(hash, NULL);