当前位置: 首页 > article >正文

linux内核数据结构之哈希表

1数据结构

struct hlist_head {
	struct hlist_node *first;
};

struct hlist_node {
    struct hlist_node *next;
    struct hlist_node **pprev;
};

2 操作函数

初始化

struct hlist_head *hash_table;
//初始化
for (i = 0; i < 1024; i++) {
	INIT_HLIST_NODE(&hash_table[i]);
}

赋值

struct vsd_node {
struct hlist_node hash_node;
u16 vsd_id;
u8 local_id;
u8  act_id;
} ;
u32 hash_index;
struct vsd_node *new_node;
new_node->vsd_id = 10;
new_node->local_id = 11;
new_node->act_id =15;

hash_index = (vsd_id + local_id )%(1024);

hlist_add_head(&new_node->hash_node,&hash_table[hash_index]);

3底层实现

static inline void INIT_HLIST_NODE(struct hlist_node *h)
{
 h->next = NULL;
 h->pprev = NULL;
}

/**
 * hlist_add_head - add a new entry at the beginning of the hlist
 * @n: new entry to be added
 * @h: hlist head to add it after
 *
 * Insert a new entry after the specified head.
 * This is good for implementing stacks.
 */
static inline void hlist_add_head(struct hlist_node *n, struct hlist_head *h)
{
 struct hlist_node *first = h->first;
 WRITE_ONCE(n->next, first);
 if (first)
  WRITE_ONCE(first->pprev, &n->next);
 WRITE_ONCE(h->first, n);
 WRITE_ONCE(n->pprev, &h->first);
}

http://www.kler.cn/a/553619.html

相关文章:

  • 【Cesium学习(十二)】Cesium常见问题整理总结
  • dockerfile2-15
  • Vue 3最新组件解析与实践指南:提升开发效率的利器
  • Excel如何给单元格填色,以及如何用Python 3实现单元格填色
  • deepseek帮我设计物理量采集单片机口保护电路方案
  • 市场波动中的数据分析与策略优化
  • Spring源码分析のBean创建流程(下)
  • 科普:Docker run的相关事项
  • Vue前端开发-Vant之Image组件
  • 【基于SprintBoot+Mybatis+Mysql】电脑商城项目之设置默认收货地址及删除收货地址
  • React 渲染 Flash 接口数据
  • AI技术生成【参考】
  • K8s学习总结
  • 智慧园区安全调度的重要性
  • Oppo手机投屏到Windows的两个方法,Windows系统自带投屏的替补!
  • 代码随想录算法【Day50】
  • 并发和多线程
  • 提升信息检索准确性和效率的搜索技巧
  • Windows桌面系统管理7:国产操作系统与Linux操作系统
  • 深度学习-119-Text2SQL之实现的三种技术途径