CNDP  22.08.0
cne_hash.h
Go to the documentation of this file.
1 /* SPDX-License-Identifier: BSD-3-Clause
2  * Copyright (c) 2010-2022 Intel Corporation
3  */
4 
5 #ifndef _CNE_HASH_H_
6 #define _CNE_HASH_H_
7 
13 #include <stdint.h>
14 #include <stddef.h>
15 
16 #ifdef __cplusplus
17 extern "C" {
18 #endif
19 
21 #define CNE_HASH_ENTRIES_MAX (1 << 30)
22 
24 #define CNE_HASH_NAMESIZE 32
25 
27 #define CNE_HASH_LOOKUP_BULK_MAX 64
28 #define CNE_HASH_LOOKUP_MULTI_MAX CNE_HASH_LOOKUP_BULK_MAX
29 
31 #define CNE_HASH_EXTRA_FLAGS_TRANS_MEM_SUPPORT 0x01
32 
34 #define CNE_HASH_EXTRA_FLAGS_MULTI_WRITER_ADD 0x02
35 
37 #define CNE_HASH_EXTRA_FLAGS_RW_CONCURRENCY 0x04
38 
40 #define CNE_HASH_EXTRA_FLAGS_EXT_TABLE 0x08
41 
47 #define CNE_HASH_EXTRA_FLAGS_NO_FREE_ON_DEL 0x10
48 
52 #define CNE_HASH_EXTRA_FLAGS_RW_CONCURRENCY_LF 0x20
53 
58 typedef uint32_t hash_sig_t;
59 
61 typedef uint32_t (*cne_hash_function)(const void *key, uint32_t key_len, uint32_t init_val);
62 
64 typedef int (*cne_hash_cmp_eq_t)(const void *key1, const void *key2, size_t key_len);
65 
70  const char *name;
71  uint32_t entries;
72  uint32_t reserved;
73  uint32_t key_len;
75  uint32_t hash_func_init_val;
76  int socket_id;
77  uint8_t extra_flag;
78 };
79 
81 struct cne_hash;
82 
100 struct cne_hash *cne_hash_create(const struct cne_hash_parameters *params);
101 
114 
125 struct cne_hash *cne_hash_find_existing(const char *name);
126 
132 void cne_hash_free(struct cne_hash *h);
133 
144 void cne_hash_reset(struct cne_hash *h);
145 
154 int32_t cne_hash_count(const struct cne_hash *h);
155 
166 int32_t cne_hash_max_key_id(const struct cne_hash *h);
167 
191 int cne_hash_add_key_data(const struct cne_hash *h, const void *key, void *data);
192 
219 int32_t cne_hash_add_key_with_hash_data(const struct cne_hash *h, const void *key, hash_sig_t sig,
220  void *data);
221 
240 int32_t cne_hash_add_key(const struct cne_hash *h, const void *key);
241 
263 int32_t cne_hash_add_key_with_hash(const struct cne_hash *h, const void *key, hash_sig_t sig);
264 
291 int32_t cne_hash_del_key(const struct cne_hash *h, const void *key);
292 
321 int32_t cne_hash_del_key_with_hash(const struct cne_hash *h, const void *key, hash_sig_t sig);
322 
340 int cne_hash_get_key_with_position(const struct cne_hash *h, const int32_t position, void **key);
341 
363 int cne_hash_free_key_with_position(const struct cne_hash *h, const int32_t position);
364 
384 int cne_hash_lookup_data(const struct cne_hash *h, const void *key, void **data);
385 
408 int cne_hash_lookup_with_hash_data(const struct cne_hash *h, const void *key, hash_sig_t sig,
409  void **data);
410 
428 int32_t cne_hash_lookup(const struct cne_hash *h, const void *key);
429 
449 int32_t cne_hash_lookup_with_hash(const struct cne_hash *h, const void *key, hash_sig_t sig);
450 
462 hash_sig_t cne_hash_hash(const struct cne_hash *h, const void *key);
463 
483 int cne_hash_lookup_bulk_data(const struct cne_hash *h, const void **keys, uint32_t num_keys,
484  uint64_t *hit_mask, void *data[]);
485 
509 int cne_hash_lookup_with_hash_bulk(const struct cne_hash *h, const void **keys, hash_sig_t *sig,
510  uint32_t num_keys, int32_t *positions);
511 
533 int cne_hash_lookup_with_hash_bulk_data(const struct cne_hash *h, const void **keys,
534  hash_sig_t *sig, uint32_t num_keys, uint64_t *hit_mask,
535  void *data[]);
536 
558 int cne_hash_lookup_bulk(const struct cne_hash *h, const void **keys, uint32_t num_keys,
559  int32_t *positions);
560 
580 int32_t cne_hash_iterate(const struct cne_hash *h, const void **key, void **data, uint32_t *next);
581 
582 #ifdef __cplusplus
583 }
584 #endif
585 
586 #endif /* _CNE_HASH_H_ */
int32_t cne_hash_iterate(const struct cne_hash *h, const void **key, void **data, uint32_t *next)
int cne_hash_lookup_with_hash_data(const struct cne_hash *h, const void *key, hash_sig_t sig, void **data)
int(* cne_hash_cmp_eq_t)(const void *key1, const void *key2, size_t key_len)
Definition: cne_hash.h:64
int cne_hash_free_key_with_position(const struct cne_hash *h, const int32_t position)
int cne_hash_lookup_data(const struct cne_hash *h, const void *key, void **data)
void cne_hash_free(struct cne_hash *h)
struct cne_hash * cne_hash_create(const struct cne_hash_parameters *params)
int32_t cne_hash_count(const struct cne_hash *h)
int32_t cne_hash_add_key_with_hash(const struct cne_hash *h, const void *key, hash_sig_t sig)
int cne_hash_lookup_bulk(const struct cne_hash *h, const void **keys, uint32_t num_keys, int32_t *positions)
struct cne_hash * cne_hash_find_existing(const char *name)
int32_t cne_hash_max_key_id(const struct cne_hash *h)
uint32_t(* cne_hash_function)(const void *key, uint32_t key_len, uint32_t init_val)
Definition: cne_hash.h:61
int32_t cne_hash_del_key(const struct cne_hash *h, const void *key)
void cne_hash_set_cmp_func(struct cne_hash *h, cne_hash_cmp_eq_t func)
int cne_hash_lookup_with_hash_bulk_data(const struct cne_hash *h, const void **keys, hash_sig_t *sig, uint32_t num_keys, uint64_t *hit_mask, void *data[])
void cne_hash_reset(struct cne_hash *h)
int cne_hash_add_key_data(const struct cne_hash *h, const void *key, void *data)
int32_t cne_hash_lookup(const struct cne_hash *h, const void *key)
int cne_hash_lookup_with_hash_bulk(const struct cne_hash *h, const void **keys, hash_sig_t *sig, uint32_t num_keys, int32_t *positions)
int cne_hash_get_key_with_position(const struct cne_hash *h, const int32_t position, void **key)
hash_sig_t cne_hash_hash(const struct cne_hash *h, const void *key)
uint32_t hash_sig_t
Definition: cne_hash.h:58
int32_t cne_hash_del_key_with_hash(const struct cne_hash *h, const void *key, hash_sig_t sig)
int cne_hash_lookup_bulk_data(const struct cne_hash *h, const void **keys, uint32_t num_keys, uint64_t *hit_mask, void *data[])
int32_t cne_hash_add_key(const struct cne_hash *h, const void *key)
int32_t cne_hash_add_key_with_hash_data(const struct cne_hash *h, const void *key, hash_sig_t sig, void *data)
int32_t cne_hash_lookup_with_hash(const struct cne_hash *h, const void *key, hash_sig_t sig)
uint32_t hash_func_init_val
Definition: cne_hash.h:75
uint8_t extra_flag
Definition: cne_hash.h:77
cne_hash_function hash_func
Definition: cne_hash.h:74
uint32_t entries
Definition: cne_hash.h:71
uint32_t key_len
Definition: cne_hash.h:73
const char * name
Definition: cne_hash.h:70
uint32_t reserved
Definition: cne_hash.h:72
char name[CNE_HASH_NAMESIZE]