DPDK  16.04.0
rte_hash.h
Go to the documentation of this file.
1 /*-
2  * BSD LICENSE
3  *
4  * Copyright(c) 2010-2015 Intel Corporation. All rights reserved.
5  * All rights reserved.
6  *
7  * Redistribution and use in source and binary forms, with or without
8  * modification, are permitted provided that the following conditions
9  * are met:
10  *
11  * * Redistributions of source code must retain the above copyright
12  * notice, this list of conditions and the following disclaimer.
13  * * Redistributions in binary form must reproduce the above copyright
14  * notice, this list of conditions and the following disclaimer in
15  * the documentation and/or other materials provided with the
16  * distribution.
17  * * Neither the name of Intel Corporation nor the names of its
18  * contributors may be used to endorse or promote products derived
19  * from this software without specific prior written permission.
20  *
21  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
22  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
23  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
24  * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
25  * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
26  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
27  * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
28  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
29  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
30  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
31  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
32  */
33 
34 #ifndef _RTE_HASH_H_
35 #define _RTE_HASH_H_
36 
43 #include <stdint.h>
44 #include <stddef.h>
45 
46 #ifdef __cplusplus
47 extern "C" {
48 #endif
49 
51 #define RTE_HASH_ENTRIES_MAX (1 << 30)
52 
54 #define RTE_HASH_NAMESIZE 32
55 
57 #define RTE_HASH_LOOKUP_BULK_MAX 64
58 #define RTE_HASH_LOOKUP_MULTI_MAX RTE_HASH_LOOKUP_BULK_MAX
59 
61 #define RTE_HASH_EXTRA_FLAGS_TRANS_MEM_SUPPORT 0x01
62 
64 typedef uint32_t hash_sig_t;
65 
67 typedef uint32_t (*rte_hash_function)(const void *key, uint32_t key_len,
68  uint32_t init_val);
69 
71 typedef int (*rte_hash_cmp_eq_t)(const void *key1, const void *key2, size_t key_len);
72 
77  const char *name;
78  uint32_t entries;
79  uint32_t reserved;
80  uint32_t key_len;
82  uint32_t hash_func_init_val;
83  int socket_id;
84  uint8_t extra_flag;
85 };
86 
88 struct rte_hash;
89 
107 struct rte_hash *
108 rte_hash_create(const struct rte_hash_parameters *params);
109 
121 void rte_hash_set_cmp_func(struct rte_hash *h, rte_hash_cmp_eq_t func);
122 
133 struct rte_hash *
134 rte_hash_find_existing(const char *name);
135 
141 void
142 rte_hash_free(struct rte_hash *h);
143 
149 void
150 rte_hash_reset(struct rte_hash *h);
151 
168 int
169 rte_hash_add_key_data(const struct rte_hash *h, const void *key, void *data);
170 
190 int32_t
191 rte_hash_add_key_with_hash_data(const struct rte_hash *h, const void *key,
192  hash_sig_t sig, void *data);
193 
208 int32_t
209 rte_hash_add_key(const struct rte_hash *h, const void *key);
210 
228 int32_t
229 rte_hash_add_key_with_hash(const struct rte_hash *h, const void *key, hash_sig_t sig);
230 
247 int32_t
248 rte_hash_del_key(const struct rte_hash *h, const void *key);
249 
268 int32_t
269 rte_hash_del_key_with_hash(const struct rte_hash *h, const void *key, hash_sig_t sig);
270 
271 
287 int
288 rte_hash_lookup_data(const struct rte_hash *h, const void *key, void **data);
289 
308 int
309 rte_hash_lookup_with_hash_data(const struct rte_hash *h, const void *key,
310  hash_sig_t sig, void **data);
311 
327 int32_t
328 rte_hash_lookup(const struct rte_hash *h, const void *key);
329 
347 int32_t
348 rte_hash_lookup_with_hash(const struct rte_hash *h,
349  const void *key, hash_sig_t sig);
350 
362 hash_sig_t
363 rte_hash_hash(const struct rte_hash *h, const void *key);
364 
365 #define rte_hash_lookup_multi rte_hash_lookup_bulk
366 #define rte_hash_lookup_multi_data rte_hash_lookup_bulk_data
367 
384 int
385 rte_hash_lookup_bulk_data(const struct rte_hash *h, const void **keys,
386  uint32_t num_keys, uint64_t *hit_mask, void *data[]);
387 
407 int
408 rte_hash_lookup_bulk(const struct rte_hash *h, const void **keys,
409  uint32_t num_keys, int32_t *positions);
410 
430 int32_t
431 rte_hash_iterate(const struct rte_hash *h, const void **key, void **data, uint32_t *next);
432 #ifdef __cplusplus
433 }
434 #endif
435 
436 #endif /* _RTE_HASH_H_ */