You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
structlist_head*p;
list_for_each(p, fox_list) {
/* p points to an entry in the list */
}
// 上面可以简化为list_for_each_entry(pos, head, member)
// 如果在遍历过程中需要删除元素list_for_each_entry_safe(pos, next, head, member)
// 反向遍历list_for_each_entry_reverse(pos, head, member)
使用示例
structlist_head*p;
structfox*f;
list_for_each(p, &fox_list) {
/* f points to the structure in which the list is embedded */f=list_entry(p, structfox, list);
}
队列
kfifo
Maps
Maps,也称为关联数组,是唯一键的集合,其中每个键都与特定值相关联。
Maps支持至少3种操作
Add (key, value)
Remove (key)
value = Lookup (key)
The path from a node to one of its leaves contains the same number of black nodes as the shortest path to any of its other leaves. rb_link_node()在指定地方插入新节点,rb_insert_color()实现复杂的reblancing
如何选择数据结构
If your primary access method is iterating over all your data, use a linked list.
If your code follows the producer/consumer pattern, use a queue, particularly if you want (or can cope with) a fixed-size buffer
If you need to map a UID to an object, use a map.
If you need to store a large amount of data and look it up efficiently, consider a redblack tree.
算法复杂度
时间复杂度
The text was updated successfully, but these errors were encountered:
链表
初始化
LIST_HEAD_INIT
链表头
设置链表头并初始化。
链表操作
从尾部添加
示例:
删除并重新初始化
检查链表是否为空
将两个不相连的链表连接
使用示例
队列
kfifo
Maps
Maps,也称为关联数组,是唯一键的集合,其中每个键都与特定值相关联。
Maps支持至少3种操作
Linux中的Mpas设计有特殊用途:将指针映射为唯一值(UID),称为
idr
初始化idr
分配新UID
注意,
idr_pre_get
成功返回1错误返回0,这与内核中绝大多数函数不一样。2. 获取新ID
成功返回0.
示例:
查找UID
成功idp保存了返回的idr.
示例:
移除UID
销毁idr
成功调用 idr_destroy() 只会释放与 idp 指向的 idr 关联的未使用内存,它不会释放分配的 UID 当前正在使用的任何内存。
二叉树
红黑树
rb_link_node()
在指定地方插入新节点,rb_insert_color()
实现复杂的reblancing
如何选择数据结构
算法复杂度
时间复杂度
The text was updated successfully, but these errors were encountered: