Linux的内核实现了一些经典的数据结构,看内核代码学习数据结构,避免自己造轮子。
内核实现的主要数据结构如下:
链表
队列
映射
二叉树
1. 链表
链表声明在内核的头文件<linux/list.h>中,结构如下:
struct list_head{ struct list_head *next; struct list_head *prev; }
struct fox{ unsigned long tail_length; unsigned long weight; bool is_fantastic; struct list_head list; }
内核中链表的实现和平时不太一样,内核中是根据链表直针来寻找父结构的。
网友评论