DPDK  16.11.11
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 #define RTE_HASH_EXTRA_FLAGS_MULTI_WRITER_ADD 0x02
65 
67 typedef uint32_t hash_sig_t;
68 
70 typedef uint32_t (*rte_hash_function)(const void *key, uint32_t key_len,
71  uint32_t init_val);
72 
74 typedef int (*rte_hash_cmp_eq_t)(const void *key1, const void *key2, size_t key_len);
75 
80  const char *name;
81  uint32_t entries;
82  uint32_t reserved;
83  uint32_t key_len;
85  uint32_t hash_func_init_val;
86  int socket_id;
87  uint8_t extra_flag;
88 };
89 
91 struct rte_hash;
92 
110 struct rte_hash *
111 rte_hash_create(const struct rte_hash_parameters *params);
112 
124 void rte_hash_set_cmp_func(struct rte_hash *h, rte_hash_cmp_eq_t func);
125 
136 struct rte_hash *
137 rte_hash_find_existing(const char *name);
138 
144 void
145 rte_hash_free(struct rte_hash *h);
146 
152 void
153 rte_hash_reset(struct rte_hash *h);
154 
171 int
172 rte_hash_add_key_data(const struct rte_hash *h, const void *key, void *data);
173 
193 int32_t
194 rte_hash_add_key_with_hash_data(const struct rte_hash *h, const void *key,
195  hash_sig_t sig, void *data);
196 
211 int32_t
212 rte_hash_add_key(const struct rte_hash *h, const void *key);
213 
231 int32_t
232 rte_hash_add_key_with_hash(const struct rte_hash *h, const void *key, hash_sig_t sig);
233 
250 int32_t
251 rte_hash_del_key(const struct rte_hash *h, const void *key);
252 
271 int32_t
272 rte_hash_del_key_with_hash(const struct rte_hash *h, const void *key, hash_sig_t sig);
273 
289 int
290 rte_hash_get_key_with_position(const struct rte_hash *h, const int32_t position,
291  void **key);
292 
310 int
311 rte_hash_lookup_data(const struct rte_hash *h, const void *key, void **data);
312 
333 int
334 rte_hash_lookup_with_hash_data(const struct rte_hash *h, const void *key,
335  hash_sig_t sig, void **data);
336 
352 int32_t
353 rte_hash_lookup(const struct rte_hash *h, const void *key);
354 
372 int32_t
373 rte_hash_lookup_with_hash(const struct rte_hash *h,
374  const void *key, hash_sig_t sig);
375 
387 hash_sig_t
388 rte_hash_hash(const struct rte_hash *h, const void *key);
389 
407 int
408 rte_hash_lookup_bulk_data(const struct rte_hash *h, const void **keys,
409  uint32_t num_keys, uint64_t *hit_mask, void *data[]);
410 
430 int
431 rte_hash_lookup_bulk(const struct rte_hash *h, const void **keys,
432  uint32_t num_keys, int32_t *positions);
433 
453 int32_t
454 rte_hash_iterate(const struct rte_hash *h, const void **key, void **data, uint32_t *next);
455 #ifdef __cplusplus
456 }
457 #endif
458 
459 #endif /* _RTE_HASH_H_ */
uint32_t(* rte_hash_function)(const void *key, uint32_t key_len, uint32_t init_val)
Definition: rte_hash.h:70
int rte_hash_lookup_bulk(const struct rte_hash *h, const void **keys, uint32_t num_keys, int32_t *positions)
uint32_t key_len
Definition: rte_hash.h:83
int rte_hash_get_key_with_position(const struct rte_hash *h, const int32_t position, void **key)
int32_t rte_hash_lookup_with_hash(const struct rte_hash *h, const void *key, hash_sig_t sig)
int rte_hash_lookup_data(const struct rte_hash *h, const void *key, void **data)
struct rte_hash * rte_hash_create(const struct rte_hash_parameters *params)
int rte_hash_lookup_bulk_data(const struct rte_hash *h, const void **keys, uint32_t num_keys, uint64_t *hit_mask, void *data[])
hash_sig_t rte_hash_hash(const struct rte_hash *h, const void *key)
int32_t rte_hash_add_key_with_hash(const struct rte_hash *h, const void *key, hash_sig_t sig)
char name[RTE_HASH_NAMESIZE]
const char * name
Definition: rte_hash.h:80
uint32_t reserved
Definition: rte_hash.h:82
void rte_hash_reset(struct rte_hash *h)
int rte_hash_add_key_data(const struct rte_hash *h, const void *key, void *data)
void rte_hash_free(struct rte_hash *h)
int rte_hash_lookup_with_hash_data(const struct rte_hash *h, const void *key, hash_sig_t sig, void **data)
int32_t rte_hash_lookup(const struct rte_hash *h, const void *key)
int32_t rte_hash_add_key_with_hash_data(const struct rte_hash *h, const void *key, hash_sig_t sig, void *data)
int(* rte_hash_cmp_eq_t)(const void *key1, const void *key2, size_t key_len)
Definition: rte_hash.h:74
rte_hash_function hash_func
Definition: rte_hash.h:84
int32_t rte_hash_del_key_with_hash(const struct rte_hash *h, const void *key, hash_sig_t sig)
uint32_t entries
Definition: rte_hash.h:81
uint32_t hash_func_init_val
Definition: rte_hash.h:85
struct rte_hash * rte_hash_find_existing(const char *name)
int32_t rte_hash_add_key(const struct rte_hash *h, const void *key)
uint32_t hash_sig_t
Definition: rte_hash.h:67
int32_t rte_hash_del_key(const struct rte_hash *h, const void *key)
uint8_t extra_flag
Definition: rte_hash.h:87
void rte_hash_set_cmp_func(struct rte_hash *h, rte_hash_cmp_eq_t func)
int32_t rte_hash_iterate(const struct rte_hash *h, const void **key, void **data, uint32_t *next)