DPDK rte_hash 简述

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);    
                 
posted @ 2017-08-10 13:58  raintwice  阅读(4855)  评论(0编辑  收藏  举报