DPDK  2.1.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 
45 #ifdef __cplusplus
46 extern "C" {
47 #endif
48 
50 #define RTE_HASH_ENTRIES_MAX (1 << 30)
51 
53 #define RTE_HASH_BUCKET_ENTRIES_MAX 4
54 
56 #define RTE_HASH_KEY_LENGTH_MAX 64
57 
59 #define RTE_HASH_NAMESIZE 32
60 
62 #define RTE_HASH_LOOKUP_BULK_MAX 64
63 #define RTE_HASH_LOOKUP_MULTI_MAX RTE_HASH_LOOKUP_BULK_MAX
64 
66 typedef uint32_t hash_sig_t;
67 
69 typedef uint32_t (*rte_hash_function)(const void *key, uint32_t key_len,
70  uint32_t init_val);
71 
76  const char *name;
77  uint32_t entries;
78  uint32_t reserved;
79  uint32_t key_len;
81  uint32_t hash_func_init_val;
82  int socket_id;
83  uint8_t extra_flag;
84 };
85 
87 struct rte_hash;
88 
106 struct rte_hash *
107 rte_hash_create(const struct rte_hash_parameters *params);
108 
119 struct rte_hash *
120 rte_hash_find_existing(const char *name);
121 
127 void
128 rte_hash_free(struct rte_hash *h);
129 
135 void
136 rte_hash_reset(struct rte_hash *h);
137 
154 int
155 rte_hash_add_key_data(const struct rte_hash *h, const void *key, void *data);
156 
176 int32_t
177 rte_hash_add_key_with_hash_data(const struct rte_hash *h, const void *key,
178  hash_sig_t sig, void *data);
179 
194 int32_t
195 rte_hash_add_key(const struct rte_hash *h, const void *key);
196 
214 int32_t
215 rte_hash_add_key_with_hash(const struct rte_hash *h, const void *key, hash_sig_t sig);
216 
233 int32_t
234 rte_hash_del_key(const struct rte_hash *h, const void *key);
235 
254 int32_t
255 rte_hash_del_key_with_hash(const struct rte_hash *h, const void *key, hash_sig_t sig);
256 
257 
273 int
274 rte_hash_lookup_data(const struct rte_hash *h, const void *key, void **data);
275 
294 int
295 rte_hash_lookup_with_hash_data(const struct rte_hash *h, const void *key,
296  hash_sig_t sig, void **data);
297 
313 int32_t
314 rte_hash_lookup(const struct rte_hash *h, const void *key);
315 
333 int32_t
334 rte_hash_lookup_with_hash(const struct rte_hash *h,
335  const void *key, hash_sig_t sig);
336 
348 hash_sig_t
349 rte_hash_hash(const struct rte_hash *h, const void *key);
350 
351 #define rte_hash_lookup_multi rte_hash_lookup_bulk
352 #define rte_hash_lookup_multi_data rte_hash_lookup_bulk_data
353 
370 int
371 rte_hash_lookup_bulk_data(const struct rte_hash *h, const void **keys,
372  uint32_t num_keys, uint64_t *hit_mask, void *data[]);
373 
393 int
394 rte_hash_lookup_bulk(const struct rte_hash *h, const void **keys,
395  uint32_t num_keys, int32_t *positions);
396 
416 int32_t
417 rte_hash_iterate(const struct rte_hash *h, const void **key, void **data, uint32_t *next);
418 #ifdef __cplusplus
419 }
420 #endif
421 
422 #endif /* _RTE_HASH_H_ */