DPDK rte_hash 简述

本文介绍rte_hash哈希表的操作方法,包括创建、添加、查找、删除等关键函数,并提供了rte_hash_parameters结构体的具体定义及如何选择合适的哈希函数。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

rte_hash

创建表

  • rte_hash_parameters 结构体
struct rte_hash_parameters {
    const char *name;       /**< Name of the hash. */
    uint32_t entries;       /**< Total hash table entries. */
    uint32_t reserved;      /**< Unused field. Should be set to 0 */
    uint32_t key_len;       /**< Length of hash key. */
    rte_hash_function hash_func;    /**< Primary Hash function used to calculate hash. */
    uint32_t hash_func_init_val;    /**< Init value used by hash_func. */
    int socket_id;          /**< NUMA Socket ID for memory. */
    uint8_t extra_flag;     /**< Indicate if additional parameters are present. */
};

填写哈希表的名字,表最大数目,key长度,哈希函数,哈希函数初始值,NUMA套接字, 额外参数标志

重要的是选择 hash 函数

  • 哈希函数
typedef uint32_t (*rte_hash_function)(const void *key, uint32_t key_len,
                      uint32_t init_val);

rte_jhash.h 提供了一些函数如 rte_jhash, rte_jhash_1words, rte_jash_2words

其余相关函数有
设置比较函数

void rte_hash_set_cmp_func(struct rte_hash *h, rte_hash_cmp_eq_t func);

查看是否已经有同名的表

struct rte_hash *
rte_hash_find_existing(const char *name);

删除表

void
rte_hash_free(struct rte_hash *h);
  • 创建函数
struct rte_hash *
rte_hash_create(const struct rte_hash_parameters *params);

添加key、data

int32_t
rte_hash_add_key(const struct rte_hash *h, const void *key);

int
rte_hash_add_key_data(const struct rte_hash *h, const void *key, void *data);

int32_t
rte_hash_add_key_with_hash_data(const struct rte_hash *h, const void *key,
                        hash_sig_t sig, void *data);

int32_t
rte_hash_add_key_with_hash_data(const struct rte_hash *h, const void *key,
                        hash_sig_t sig, void *data);
int32_t
rte_hash_del_key(const struct rte_hash *h, const void *key);

删除key、data

int32_t
rte_hash_del_key(const struct rte_hash h, const void key);

int32_t
rte_hash_del_key_with_hash(const struct rte_hash h, const void key, hash_sig_t sig);

查找

int
rte_hash_get_key_with_position(const struct rte_hash *h, const int32_t position,
                   void **key);

int
rte_hash_lookup_data(const struct rte_hash *h, const void *key, void **data);

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_lookup_with_hash(const struct rte_hash *h,
                const void *key, hash_sig_t sig);

hash_sig_t
rte_hash_hash(const struct rte_hash *h, const void *key);

int
rte_hash_lookup_bulk_data(const struct rte_hash *h, const void **keys,
              uint32_t num_keys, uint64_t *hit_mask, void *data[]);

int
rte_hash_lookup_bulk(const struct rte_hash *h, const void **keys,
              uint32_t num_keys, int32_t *positions);    

int32_t
rte_hash_iterate(const struct rte_hash *h, const void **key, void **data, uint32_t *next);    
                 

转载于:https://www.cnblogs.com/raintwice/p/7338910.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值