linux内核数据结构之哈希表

devtools/2025/2/22 19:31:53/

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.ppmy.cn/devtools/160694.html

相关文章

关于uniApp的面试题及其答案解析

我的血液里流淌着战意&#xff01;力量与智慧指引着我&#xff01; 文章目录 1. 什么是uniApp&#xff1f;2. uniApp与原生小程序开发有什么区别&#xff1f;3. 如何使用uniApp实现条件编译&#xff1f;4. uniApp支持哪些平台&#xff0c;各有什么特点&#xff1f;5. 在uniApp中…

【我要成为配环境高手】node卸载与nvm安装

node卸载与nvm安装 1. node卸载 参考了这篇文章&#xff1a; https://blog.csdn.net/weixin_43801036/article/details/141487791 2. nvm安装 参考了这两篇文章&#xff1a; https://www.cnblogs.com/rnny/p/17839190.html#tid-z7A3nR https://blog.csdn.net/weixin_45811…

RAGFLOW使用flask转发的open ai接口

flask转发openai标准接口 背景 搭建RAGFLOW 的过程中&#xff0c;遇到一个比较严重的问题&#xff0c;公司部署的大模型代理需要获取token&#xff0c;且token存在有效期5分钟&#xff0c;在RAGFLOW中不能直接用&#xff0c;所以希望通过flask项目转发请求。 方案 比较好的…

lab4 CSAPP:Cachelab

写在前面 最简单的一集 实验室分为两个部分。在A部分中&#xff0c;实现一个缓存模拟器。在B部分中&#xff0c;编写一个矩阵针对高速缓存性能优化的转置功能。 感觉是比较经典的问题&#xff0c;之前在体系结构的课程中接触过&#xff0c;终于能通过lab实操一下了。 实验目…

# 10分钟了解DeepSeek,保姆级部署DeepSeek到WPS,实现AI赋能

10分钟了解DeepSeek&#xff0c;保姆级部署DeepSeek到WPS&#xff0c;实现AI赋能 原创 DeepSeek 2025年02月12日 08:01 西安 AI技术、 AI知识 、 AI应用 、 人工智能 、 大语言模型 一、什么是deepseek 1、DeepSeek&#xff0c;全称杭州深度求索人工智能基础技术研究有限公司…

python中的深度学习框架TensorFlow 和 PyTorch 有什么区别?

TensorFlow 和 PyTorch 是目前最流行的两个深度学习框架,它们在设计理念、使用方式和社区支持等方面存在一些显著的区别。以下是它们的主要区别: 1. 设计理念 TensorFlow: 静态计算图:TensorFlow 使用静态计算图,即在运行模型之前需要先定义整个计算图。这使得 TensorFlo…

Spring Boot 示例项目:从零开始构建 Web 应用

一、项目概述 本文档将指导您通过一个示例项目,了解如何使用 Spring Boot 框架构建一个简单的 Web 应用程序。该项目涵盖了从数据模型定义到控制器、服务层以及数据访问层的完整开发流程,帮助您快速掌握 Spring Boot 的基本使用方法。 二、项目结构 1. 项目模块 本示例项…

Spring中事务的传播行为有哪些?

在 Spring 框架里&#xff0c;事务传播行为用于定义在嵌套事务场景下&#xff0c;新事务与现有事务之间的交互方式。Spring 定义了 7 种事务传播行为&#xff0c;这些行为由org.springframework.transaction.annotation.Propagation枚举类提供。以下是对这些传播行为的详细介绍…