Umair Hussain Malik p10-6016 p106016@nu.edu.pk
As with any large software project, the Linux kernel provides these generic data structures and primitives to encourage code reuse. Kernel developers should use these data structures whenever possible and not “roll your own” solutions. In the following sections, we cover the most useful of these generic data structures, which are the following: * Linked lists * Queues * Maps * Binary trees
Linked Lists
The linked list is the most common data structure in the Linux kernel which, allows the storage and manipulation of a variable number of elements, called the nodes of the list. The elements in a linked list are dynamically created and inserted into the list. This enables the management of a varying number of elements unknown at compile time and each element in the list contains a pointer to the next element. As elements are added to or removed from the list, the pointer to the next node is simply adjusted.
Singly and Doubly Linked Lists
The simplest data structure representing such a linked list might look similar to the following:
/* an element in a linked list */ struct list_element { void *data; struct list_element *next;
};
In some linked lists, each element also contains a pointer to the previous element. These lists are called doubly linked lists because they are linked both forward and backward. Linked lists that do not have a pointer to the previous element are called singly linked lists.
A data structure representing a doubly linked list would look similar to this:
/* an element in a linked list */ struct list_element { void *data; /* struct list_element *next; struct list_element *prev;
};
Circular Linked Lists
Normally, the last element in a linked list has no next element, it is set to point to a special value, such as NULL, to indicate it is the last element in the list. In some linked lists, the last element does not point to a