Learning BSD.sys/queue.h
Posted 三叁
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Learning BSD.sys/queue.h相关的知识,希望对你有一定的参考价值。
This file includes 4 data-structures..
Insteresting because they are written in 1994.. to make it easier using the structures..
LIST:
the common usage of the structures is to create a structure containing the list-entry as manage-tools of its pointers, this structure might contain prev|next pointers.
Then to create a header of the specific data-structure.. this header contains only 1 pointer pointing to the first struct of the data-structure..
then the pointed struct\'s next pointer is pointing to the next struct of the list, or null, the prev pointer is pointing to the previous pointer\'s address.
so this kind of design has its problem: cannot know if it\'s the first struct of this structure, even do not know if it has a prev pointer.. and actually cannot traverse backward..
As i forseen, this kind of design can back-traverse, but in other way like using methods like container_of(le_prev,type). though no macros in queue.h can do this. As the document says, it\'s a list may only be traversed in forward direction. and that is the difference between List & TailQueue.
this doubly linked list has its fast insertion in the middle of the list, if buildt a hash table for all the **prev address and their entries. O(1).
the usages:
List is used in places need to insert and delete everywhere frequently, but without quick addition/removement at tail ( because no pointer in the head struct pointing to the tail, and that\'s why it cannot be backward-traversed).
S(inglyLinked)list is used in places need to insert and delete from head frequently, it maynot be inserted/deleted from middle/tail.
S(inglyLinked)tailqueue is used in places need to insert after any element, delete head or any named element(O(n)), get the last element, insert after the last item quickly, this datastruct accelerates things to be done at the tail.
S(imple)queue is ued in places which is identically as S(inglyLinked)tailqueue..
Tailqueue is used to insert at head/tail quickly, before/after any element, delete any given item(O(1)). Traverse in either direction.
CircleQueue is used to insert/delete anywhere, insert/delete head/tail items are quicklier, tail & head are linked as previous/post element one another.
My own slist realization:
以上是关于Learning BSD.sys/queue.h的主要内容,如果未能解决你的问题,请参考以下文章
Predictive learning vs. representation learning
Reinforcement Learning Q-learning 算法学习-4