---
name: "rte_fbk_hash_lookup"
section: "3"
platform: "linux"
package: "dpdk-doc"
version: "24.11.4-0+deb13u1"
release: "Debian 13 (Trixie)"
platforms: ["linux"]
url: "https://new.carta.tech/rte_fbk_hash.h"
---

# rte\_fbk\_hash\_lookup(3)

Part of [rte\_fbk\_hash.h(3)](/rte_fbk_hash.h/3.md).

## NAME

rte\_fbk\_hash.h

## SYNOPSIS

`#include <stdint.h>`\
 `#include <errno.h>`\
 `#include <string.h>`\
 `#include <rte_hash_crc.h>`\
 `#include <rte_jhash.h>`\

### Data Structures

struct **rte\_fbk\_hash\_params**\
 union **rte\_fbk\_hash\_entry**\
 struct **rte\_fbk\_hash\_table**\

### Macros

\#define **RTE\_FBK\_HASH\_INIT\_VAL\_DEFAULT**   0xFFFFFFFF\
 \#define **RTE\_FBK\_HASH\_ENTRIES\_MAX**   (1 \<\< 20)\
 \#define **RTE\_FBK\_HASH\_ENTRIES\_PER\_BUCKET\_MAX**   256\
 \#define **RTE\_FBK\_HASH\_NAMESIZE**   32\

### Typedefs

**typedef** uint32\_t(\* **rte\_fbk\_hash\_fn**) (uint32\_t key, uint32\_t init\_val)\

### Functions

static uint32\_t **rte\_fbk\_hash\_get\_bucket** (const struct **rte\_fbk\_hash\_table** \*ht, uint32\_t key)\
 static int **rte\_fbk\_hash\_add\_key\_with\_bucket** (struct **rte\_fbk\_hash\_table** \*ht, uint32\_t key, uint16\_t value, uint32\_t bucket)\
 static int **rte\_fbk\_hash\_add\_key** (struct **rte\_fbk\_hash\_table** \*ht, uint32\_t key, uint16\_t value)\
 static int **rte\_fbk\_hash\_delete\_key\_with\_bucket** (struct **rte\_fbk\_hash\_table** \*ht, uint32\_t key, uint32\_t bucket)\
 static int **rte\_fbk\_hash\_delete\_key** (struct **rte\_fbk\_hash\_table** \*ht, uint32\_t key)\
 static int **rte\_fbk\_hash\_lookup\_with\_bucket** (const struct **rte\_fbk\_hash\_table** \*ht, uint32\_t key, uint32\_t bucket)\
 static int **rte\_fbk\_hash\_lookup** (const struct **rte\_fbk\_hash\_table** \*ht, uint32\_t key)\
 static void **rte\_fbk\_hash\_clear\_all** (struct **rte\_fbk\_hash\_table** \*ht)\
 static double **rte\_fbk\_hash\_get\_load\_factor** (struct **rte\_fbk\_hash\_table** \*ht)\
 struct **rte\_fbk\_hash\_table** \* **rte\_fbk\_hash\_find\_existing** (const char \*name)\
 struct **rte\_fbk\_hash\_table** \* **rte\_fbk\_hash\_create** (const struct **rte\_fbk\_hash\_params** \*params)\
 void **rte\_fbk\_hash\_free** (struct **rte\_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 **rte\_fbk\_hash.h**.

## Macro Definition Documentation

### #define RTE\_FBK\_HASH\_INIT\_VAL\_DEFAULT 0xFFFFFFFF

Initialising value used when calculating hash.

Definition at line **32** of file **rte\_fbk\_hash.h**.

### #define RTE\_FBK\_HASH\_ENTRIES\_MAX (1 \<\< 20)

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

Definition at line **36** of file **rte\_fbk\_hash.h**.

### #define RTE\_FBK\_HASH\_ENTRIES\_PER\_BUCKET\_MAX 256

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

Definition at line **39** of file **rte\_fbk\_hash.h**.

### #define RTE\_FBK\_HASH\_NAMESIZE 32

Maximum size of string for naming the hash.

Definition at line **42** of file **rte\_fbk\_hash.h**.

## Typedef Documentation

### typedef uint32\_t(\* rte\_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 **rte\_fbk\_hash.h**.

## Function Documentation

### static uint32\_t rte\_fbk\_hash\_get\_bucket (const struct rte\_fbk\_hash\_table \* ht, uint32\_t key)` [inline]`, ` [static]`

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

**Parameters**

*ht* Pointer to hash table. \
 *key* Key to calculate bucket for.

**Returns**

Offset into hash table.

Definition at line **94** of file **rte\_fbk\_hash.h**.

### static int rte\_fbk\_hash\_add\_key\_with\_bucket (struct rte\_fbk\_hash\_table \* ht, uint32\_t key, uint16\_t value, uint32\_t bucket)` [inline]`, ` [static]`

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**

*ht* Hash table to add the key to. \
 *key* Key to add to the hash table. \
 *value* Value to associate with key. \
 *bucket* Bucket to associate with key.

**Returns**

0 if ok, or negative value on error.

Definition at line **117** of file **rte\_fbk\_hash.h**.

### static int rte\_fbk\_hash\_add\_key (struct rte\_fbk\_hash\_table \* ht, uint32\_t key, uint16\_t value)` [inline]`, ` [static]`

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

**Parameters**

*ht* Hash table to add the key to. \
 *key* Key to add to the hash table. \
 *value* Value to associate with key.

**Returns**

0 if ok, or negative value on error.

Definition at line **162** of file **rte\_fbk\_hash.h**.

### static int rte\_fbk\_hash\_delete\_key\_with\_bucket (struct rte\_fbk\_hash\_table \* ht, uint32\_t key, uint32\_t bucket)` [inline]`, ` [static]`

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**

*ht* Hash table to remove the key from. \
 *key* Key to remove from the hash table. \
 *bucket* Bucket id associate with key.

**Returns**

0 if ok, or negative value on error.

Definition at line **184** of file **rte\_fbk\_hash.h**.

### static int rte\_fbk\_hash\_delete\_key (struct rte\_fbk\_hash\_table \* ht, uint32\_t key)` [inline]`, ` [static]`

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

**Parameters**

*ht* Hash table to remove the key from. \
 *key* Key to remove from the hash table.

**Returns**

0 if ok, or negative value on error.

Definition at line **227** of file **rte\_fbk\_hash.h**.

### static int rte\_fbk\_hash\_lookup\_with\_bucket (const struct rte\_fbk\_hash\_table \* ht, uint32\_t key, uint32\_t bucket)` [inline]`, ` [static]`

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

**Parameters**

*ht* Hash table to look in. \
 *key* Key to find. \
 *bucket* Bucket associate to the key.

**Returns**

The value that was associated with the key, or negative value on error.

Definition at line **247** of file **rte\_fbk\_hash.h**.

### static int rte\_fbk\_hash\_lookup (const struct rte\_fbk\_hash\_table \* ht, uint32\_t key)` [inline]`, ` [static]`

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

**Parameters**

*ht* Hash table to look in. \
 *key* Key to find.

**Returns**

The value that was associated with the key, or negative value on error.

Definition at line **277** of file **rte\_fbk\_hash.h**.

### static void rte\_fbk\_hash\_clear\_all (struct rte\_fbk\_hash\_table \* ht)` [inline]`, ` [static]`

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

**Parameters**

*ht* Hash table to delete entries in.

Definition at line **291** of file **rte\_fbk\_hash.h**.

### static double rte\_fbk\_hash\_get\_load\_factor (struct rte\_fbk\_hash\_table \* ht)` [inline]`, ` [static]`

Find what fraction of entries are being used.

**Parameters**

*ht* Hash 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 **306** of file **rte\_fbk\_hash.h**.

### struct rte\_fbk\_hash\_table \* rte\_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**

*name* Name of the hash table to find

**Returns**

pointer to hash table structure or NULL on error with rte\_errno set appropriately. Possible rte\_errno values include:

- •

  ENOENT - required entry not available to return.

### struct rte\_fbk\_hash\_table \* rte\_fbk\_hash\_create (const struct rte\_fbk\_hash\_params \* params)

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

**Parameters**

*params* Parameters 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 rte\_errno set appropriately. Possible rte\_errno error values include:

- •

  E\_RTE\_NO\_CONFIG - function could not get pointer to rte\_config structure

- •

  E\_RTE\_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

### void rte\_fbk\_hash\_free (struct rte\_fbk\_hash\_table \* ht)

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

**Parameters**

*ht* Hash table to deallocate.

## Author

Generated automatically by Doxygen for DPDK from the source code.
