COMBINATORIAL_BLAS  1.6
tommyhashdyn.h
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2010, Andrea Mazzoleni. All rights reserved.
3  *
4  * Redistribution and use in source and binary forms, with or without
5  * modification, are permitted provided that the following conditions
6  * are met:
7  *
8  * 1. Redistributions of source code must retain the above copyright
9  * notice, this list of conditions and the following disclaimer.
10  *
11  * 2. Redistributions in binary form must reproduce the above copyright
12  * notice, this list of conditions and the following disclaimer in the
13  * documentation and/or other materials provided with the distribution.
14  *
15  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
16  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
17  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
18  * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
19  * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
20  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
21  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
22  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
23  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
24  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
25  * POSSIBILITY OF SUCH DAMAGE.
26  */
27 
137 #ifndef __TOMMYHASHDYN_H
138 #define __TOMMYHASHDYN_H
139 
140 #include "tommyhash.h"
141 
142 /******************************************************************************/
143 /* hashdyn */
144 
149 #define TOMMY_HASHDYN_BIT 4
150 
156 
161 typedef struct tommy_hashdyn_struct {
167 } tommy_hashdyn;
168 
172 void tommy_hashdyn_init(tommy_hashdyn* hashdyn);
173 
180 void tommy_hashdyn_done(tommy_hashdyn* hashdyn);
181 
185 void tommy_hashdyn_insert(tommy_hashdyn* hashdyn, tommy_hashdyn_node* node, void* data, tommy_hash_t hash);
186 
198 void* tommy_hashdyn_remove(tommy_hashdyn* hashdyn, tommy_search_func* cmp, const void* cmp_arg, tommy_hash_t hash);
199 
209 {
210  return hashdyn->bucket[hash & hashdyn->bucket_mask];
211 }
212 
224 {
225  tommy_hashdyn_node* i = tommy_hashdyn_bucket(hashdyn, hash);
226 
227  while (i) {
228  /* we first check if the hash matches, as in the same bucket we may have multiples hash values */
229  if (i->key == hash && cmp(cmp_arg, i->data) == 0)
230  return i->data;
231  i = i->next;
232  }
233  return 0;
234 }
235 
242 
274 
278 void tommy_hashdyn_foreach_arg(tommy_hashdyn* hashdyn, tommy_foreach_arg_func* func, void* arg);
279 
284 {
285  return hashdyn->count;
286 }
287 
293 
294 #endif
295 
void tommy_hashdyn_insert(tommy_hashdyn *hashdyn, tommy_hashdyn_node *node, void *data, tommy_hash_t hash)
void * tommy_hashdyn_remove(tommy_hashdyn *hashdyn, tommy_search_func *cmp, const void *cmp_arg, tommy_hash_t hash)
tommy_uint_t bucket_bit
Definition: tommyhashdyn.h:163
tommy_count_t bucket_mask
Definition: tommyhashdyn.h:165
void tommy_hashdyn_done(tommy_hashdyn *hashdyn)
struct tommy_hashdyn_struct tommy_hashdyn
tommy_uint32_t tommy_count_t
Definition: tommytypes.h:67
tommy_inline tommy_hashdyn_node * tommy_hashdyn_bucket(tommy_hashdyn *hashdyn, tommy_hash_t hash)
Definition: tommyhashdyn.h:208
struct tommy_node_struct * next
Definition: tommytypes.h:188
tommy_key_t tommy_hash_t
Definition: tommyhash.h:43
tommy_node tommy_hashdyn_node
Definition: tommyhashdyn.h:155
void tommy_hashdyn_foreach(tommy_hashdyn *hashdyn, tommy_foreach_func *func)
int tommy_search_func(const void *arg, const void *obj)
Definition: tommytypes.h:273
tommy_inline void * tommy_hashdyn_search(tommy_hashdyn *hashdyn, tommy_search_func *cmp, const void *cmp_arg, tommy_hash_t hash)
Definition: tommyhashdyn.h:223
#define tommy_inline
Definition: tommytypes.h:115
tommy_uint32_t tommy_uint_t
Definition: tommytypes.h:60
tommy_hashdyn_node ** bucket
Definition: tommyhashdyn.h:162
tommy_size_t tommy_hashdyn_memory_usage(tommy_hashdyn *hashdyn)
void tommy_foreach_func(void *obj)
Definition: tommytypes.h:284
void * tommy_hashdyn_remove_existing(tommy_hashdyn *hashdyn, tommy_hashdyn_node *node)
tommy_inline tommy_count_t tommy_hashdyn_count(tommy_hashdyn *hashdyn)
Definition: tommyhashdyn.h:283
tommy_count_t count
Definition: tommyhashdyn.h:166
size_t tommy_size_t
Definition: tommytypes.h:50
void tommy_hashdyn_foreach_arg(tommy_hashdyn *hashdyn, tommy_foreach_arg_func *func, void *arg)
unsigned int hash(unsigned int a)
Definition: utils.h:79
tommy_key_t key
Definition: tommytypes.h:207
void tommy_hashdyn_init(tommy_hashdyn *hashdyn)
tommy_count_t bucket_max
Definition: tommyhashdyn.h:164
void tommy_foreach_arg_func(void *arg, void *obj)
Definition: tommytypes.h:291