Linux内核笔记9
来源:互联网 发布:自己建一个淘宝秒杀群 编辑:程序博客网 时间:2024/06/01 22:47
Linux散列链表
散列链表从形式上看,就像是由多个链表的头部所构成的一个数组,每个链表都对应该数组中的某个元素,用以解决键值冲突的问题。
末节点的next指向NULL;node1的pprev指向first
这个图不知道理解的对不对,请各位指教!
1、散列链表的定义
struct hlist_head {
struct hlist_node *first;
};
struct hlist_node {
struct hlist_node *next, **pprev;//pprev是指向上一个节点的pprev所指向的下一个单元
};
2、散列链表的初始化
#define INIT_HLIST_HEAD(ptr) ((ptr)->first = NULL)
#define INIT_HLIST_NODE(ptr) ((ptr)->next = NULL, (ptr)->pprev = NULL)
3、散列链表操作
static inline int hlist_unhashed(const struct hlist_node *h)
{
return !h->pprev;//若返回非空,说明该节点没有假如链表中
}
static inline int hlist_empty(const struct hlist_head *h)
{
return !h->first;//若返回是非空,说明该链表是空链表
}
static inline void hlist_del(struct hlist_node *n)
{
__hlist_del(n);
n->next = LIST_POISON1;
n->pprev = LIST_POISON2;
}
static inline void __hlist_del(struct hlist_node *n)
{
struct hlist_node *next = n->next;
struct hlist_node **pprev = n->pprev;
*pprev = next;//*pprev是它所在节点的next指针,这个指针指向n的下一个节点
if (next)
next->pprev = pprev;//同上
}
static inline void hlist_add_head(struct hlist_node *n, struct hlist_head *h)//在head和node1之间插入节点
{
struct hlist_node *first = h->first;
n->next = first;
if (first)
first->pprev = &n->next;
h->first = n;
n->pprev = &h->first;
}
static inline void hlist_add_before(struct hlist_node *n,
struct hlist_node *next)//在中间插入节点
{
n->pprev = next->pprev;
n->next = next;
next->pprev = &n->next;
*(n->pprev) = n;
}
static inline void hlist_add_after(struct hlist_node *n,
struct hlist_node *next)//在后面插入节点
- Linux内核笔记9
- linux内核笔记-内核同步
- linux内核裁减笔记
- LINUX内核阅读笔记
- Linux 0.11 内核笔记
- linux 内核 笔记
- linux内核编译笔记
- linux内核编译笔记
- Linux 内核开发-笔记
- linux内核笔记之一
- linux 内核学习笔记
- Linux内核编译笔记
- Linux内核定时器笔记
- linux内核分析笔记
- 【笔记】linux 内核
- linux内核模块笔记
- linux内核分析笔记
- Linux 内核学习笔记
- 在windows和linux文件共享
- 图片
- 分治法 大数乘法
- 链表的循环链接
- linux平台上通过jfreechart生成的PNG图像中显示的汉字为方框的问题的解决
- Linux内核笔记9
- C#中简单调用c/c++模块
- 深度优先、广度优先java实现
- php引用传值
- 虚拟化网络演进模拟对话
- java中将double转型为int。java中的幕运算方法Math.pow()。
- eclipse无法检测加载插件可以偿试的方法
- JDBC连接sql server数据库的详细步骤和代码
- WCF服务配置总结