CNDP  22.08.0
cne_fbk_hash.h File Reference
#include <stdint.h>
#include <errno.h>
#include <sys/queue.h>
#include <string.h>
#include <cne_hash_crc.h>
#include <cne_jhash.h>

Go to the source code of this file.

Data Structures

struct  cne_fbk_hash_params
 
union  cne_fbk_hash_entry
 
struct  cne_fbk_hash_table
 

Macros

#define CNE_FBK_HASH_INIT_VAL_DEFAULT   0xFFFFFFFF
 
#define CNE_FBK_HASH_ENTRIES_MAX   (1 << 20)
 
#define CNE_FBK_HASH_ENTRIES_PER_BUCKET_MAX   256
 
#define CNE_FBK_HASH_NAMESIZE   32
 

Typedefs

typedef uint32_t(* cne_fbk_hash_fn) (uint32_t key, uint32_t init_val)
 

Functions

static uint32_t cne_fbk_hash_get_bucket (const struct cne_fbk_hash_table *ht, uint32_t key)
 
static int cne_fbk_hash_add_key_with_bucket (struct cne_fbk_hash_table *ht, uint32_t key, uint16_t value, uint32_t bucket)
 
static int cne_fbk_hash_add_key (struct cne_fbk_hash_table *ht, uint32_t key, uint16_t value)
 
static int cne_fbk_hash_delete_key_with_bucket (struct cne_fbk_hash_table *ht, uint32_t key, uint32_t bucket)
 
static int cne_fbk_hash_delete_key (struct cne_fbk_hash_table *ht, uint32_t key)
 
static int cne_fbk_hash_lookup_with_bucket (const struct cne_fbk_hash_table *ht, uint32_t key, uint32_t bucket)
 
static int cne_fbk_hash_lookup (const struct cne_fbk_hash_table *ht, uint32_t key)
 
static void cne_fbk_hash_clear_all (struct cne_fbk_hash_table *ht)
 
static double cne_fbk_hash_get_load_factor (struct cne_fbk_hash_table *ht)
 
struct cne_fbk_hash_tablecne_fbk_hash_find_existing (const char *name)
 
struct cne_fbk_hash_tablecne_fbk_hash_create (const struct cne_fbk_hash_params *params)
 
void cne_fbk_hash_free (struct cne_fbk_hash_table *ht)
 

Detailed Description

This is a hash table implementation for four byte keys (fbk).

Note that the return value of the add function should always be checked as, if a bucket is full, the key is not added even if there is space in other buckets. This keeps the lookup function very simple and therefore fast.

Definition in file cne_fbk_hash.h.

Macro Definition Documentation

◆ CNE_FBK_HASH_INIT_VAL_DEFAULT

#define CNE_FBK_HASH_INIT_VAL_DEFAULT   0xFFFFFFFF

Initialising value used when calculating hash.

Definition at line 32 of file cne_fbk_hash.h.

◆ CNE_FBK_HASH_ENTRIES_MAX

#define CNE_FBK_HASH_ENTRIES_MAX   (1 << 20)

The maximum number of entries in the hash table that is supported.

Definition at line 36 of file cne_fbk_hash.h.

◆ CNE_FBK_HASH_ENTRIES_PER_BUCKET_MAX

#define CNE_FBK_HASH_ENTRIES_PER_BUCKET_MAX   256

The maximum number of entries in each bucket that is supported.

Definition at line 39 of file cne_fbk_hash.h.

◆ CNE_FBK_HASH_NAMESIZE

#define CNE_FBK_HASH_NAMESIZE   32

Maximum size of string for naming the hash.

Definition at line 42 of file cne_fbk_hash.h.

Typedef Documentation

◆ cne_fbk_hash_fn

typedef uint32_t(* cne_fbk_hash_fn) (uint32_t key, uint32_t init_val)

Type of function that can be used for calculating the hash value.

Definition at line 45 of file cne_fbk_hash.h.

Function Documentation

◆ cne_fbk_hash_get_bucket()

static uint32_t cne_fbk_hash_get_bucket ( const struct cne_fbk_hash_table ht,
uint32_t  key 
)
inlinestatic

Find the offset into hash table of the bucket containing a particular key.

Parameters
htPointer to hash table.
keyKey to calculate bucket for.
Returns
Offset into hash table.

Definition at line 93 of file cne_fbk_hash.h.

◆ cne_fbk_hash_add_key_with_bucket()

static int cne_fbk_hash_add_key_with_bucket ( struct cne_fbk_hash_table ht,
uint32_t  key,
uint16_t  value,
uint32_t  bucket 
)
inlinestatic

Add a key to an existing hash table with bucket id. This operation is not multi-thread safe and should only be called from one thread.

Parameters
htHash table to add the key to.
keyKey to add to the hash table.
valueValue to associate with key.
bucketBucket to associate with key.
Returns
0 if ok, or negative value on error.

Definition at line 115 of file cne_fbk_hash.h.

◆ cne_fbk_hash_add_key()

static int cne_fbk_hash_add_key ( struct cne_fbk_hash_table ht,
uint32_t  key,
uint16_t  value 
)
inlinestatic

Add a key to an existing hash table. This operation is not multi-thread safe and should only be called from one thread.

Parameters
htHash table to add the key to.
keyKey to add to the hash table.
valueValue to associate with key.
Returns
0 if ok, or negative value on error.

Definition at line 159 of file cne_fbk_hash.h.

◆ cne_fbk_hash_delete_key_with_bucket()

static int cne_fbk_hash_delete_key_with_bucket ( struct cne_fbk_hash_table ht,
uint32_t  key,
uint32_t  bucket 
)
inlinestatic

Remove a key with a given bucket id from an existing hash table. This operation is not multi-thread safe and should only be called from one thread.

Parameters
htHash table to remove the key from.
keyKey to remove from the hash table.
bucketBucket id associate with key.
Returns
0 if ok, or negative value on error.

Definition at line 179 of file cne_fbk_hash.h.

◆ cne_fbk_hash_delete_key()

static int cne_fbk_hash_delete_key ( struct cne_fbk_hash_table ht,
uint32_t  key 
)
inlinestatic

Remove a key from an existing hash table. This operation is not multi-thread safe and should only be called from one thread.

Parameters
htHash table to remove the key from.
keyKey to remove from the hash table.
Returns
0 if ok, or negative value on error.

Definition at line 220 of file cne_fbk_hash.h.

◆ cne_fbk_hash_lookup_with_bucket()

static int cne_fbk_hash_lookup_with_bucket ( const struct cne_fbk_hash_table ht,
uint32_t  key,
uint32_t  bucket 
)
inlinestatic

Find a key in the hash table with a given bucketid. This operation is multi-thread safe.

Parameters
htHash table to look in.
keyKey to find.
bucketBucket associate to the key.
Returns
The value that was associated with the key, or negative value on error.

Definition at line 239 of file cne_fbk_hash.h.

◆ cne_fbk_hash_lookup()

static int cne_fbk_hash_lookup ( const struct cne_fbk_hash_table ht,
uint32_t  key 
)
inlinestatic

Find a key in the hash table. This operation is multi-thread safe.

Parameters
htHash table to look in.
keyKey to find.
Returns
The value that was associated with the key, or negative value on error.

Definition at line 268 of file cne_fbk_hash.h.

◆ cne_fbk_hash_clear_all()

static void cne_fbk_hash_clear_all ( struct cne_fbk_hash_table ht)
inlinestatic

Delete all entries in a hash table. This operation is not multi-thread safe and should only be called from one thread.

Parameters
htHash table to delete entries in.

Definition at line 281 of file cne_fbk_hash.h.

◆ cne_fbk_hash_get_load_factor()

static double cne_fbk_hash_get_load_factor ( struct cne_fbk_hash_table ht)
inlinestatic

Find what fraction of entries are being used.

Parameters
htHash table to find how many entries are being used in.
Returns
Load factor of the hash table, or negative value on error.

Definition at line 296 of file cne_fbk_hash.h.

◆ cne_fbk_hash_find_existing()

struct cne_fbk_hash_table* cne_fbk_hash_find_existing ( const char *  name)

Performs a lookup for an existing hash table, and returns a pointer to the table if found.

Parameters
nameName of the hash table to find
Returns
pointer to hash table structure or NULL on error with errno set appropriately. Possible errno values include:
  • ENOENT - required entry not available to return.

◆ cne_fbk_hash_create()

struct cne_fbk_hash_table* cne_fbk_hash_create ( const struct cne_fbk_hash_params params)

Create a new hash table for use with four byte keys.

Parameters
paramsParameters used in creation of hash table.
Returns
Pointer to hash table structure that is used in future hash table operations, or NULL on error with errno set appropriately. Possible errno error values include:
  • E_CNE_NO_CONFIG - function could not get pointer to cne_config structure
  • E_CNE_SECONDARY - function was called from a secondary process instance
  • EINVAL - invalid parameter value passed to function
  • ENOSPC - the maximum number of memzones has already been allocated
  • EEXIST - a memzone with the same name already exists
  • ENOMEM - no appropriate memory area found in which to create memzone

◆ cne_fbk_hash_free()

void cne_fbk_hash_free ( struct cne_fbk_hash_table ht)

Free all memory used by a hash table. Has no effect on hash tables allocated in memory zones

Parameters
htHash table to deallocate.