There are many classic data structures in the Linux kernel, such as list, hlist, and rbtree. These data structures are all written in C language and have nothing to do with the platform, it can be taken out from the kernel and put into your own code.
List
========
Transplanted from Linux kernel, available on Windows Platform
Windows does not have typeof, so Win32:
#define list_for_each_entry(pos, head, member, type) for (pos = list_entry((head)->next, type, member); &pos->member != (head); pos = list_entry(pos->member.next, type, member))
Other functions or macros that involve the use of the typeof keyword are not transplanted.
Function
========
1. list_add append a node after the head
2. list_add_tail append a node before the head, that is, append a node at the end.
3. delete a node in list_del and set next and Prev of the node to null.
4. list_del_init: delete a node and initialize the deleted node.
5. Replace list_replace with a node
6. Replace list_replace_init with a node and initialize the replaced node.
7. Move the list_move node to the end of the head
8. Before list_move_tail moves the node to the head
9. list_is_last checks whether the node is the last in the linked list.
10. list_empty: determines whether the linked list is empty (that is, whether there are only head nodes)
11. list_is_singular checks whether there is only one node in the Linked List (except the head)
12. list_cut_position: truncates one linked list into two linked lists.
13. list_splice combines two linked lists into one linked list. After adding all nodes (excluding list) in @ list to the head
14. list_splice_tail combines two linked lists into one linked list. All nodes in @ list (excluding list) are added to the head.
15. list_splice_init is the same as list_splice, and @ list is initialized.
16. list_splice_tail_init is the same as list_splice_tail, and @ list will be initialized.
Macro
========
1. list_entry: Get the struct containing this node
2. list_first_entry: obtain the first struct containing this node.
3. list_for_each starts to loop backward from a node after the head node
4. list_for_each_prev starts a forward loop from a node before the head node.
5. The secure version of list_for_each_safe list_for_each, that is, it can run normally even if other threads Delete nodes during a loop.
6. Security version of list_for_each_prev_safe list_for_each_prev
7. The list_for_each_entry and list_for_each parameters are different.
8. list_for_each_entry_reverse is the same as list_for_each_prev, but the parameters are different.
9. list_for_each_entry_continue is the same as list_for_each_entry, but it does not start from the beginning (head ).
10. list_for_each_entry_continue_reverse is the same as list_for_each_entry_reverse, but it does not start from the beginning (head ).
11. list_for_each_entry_from starts from the specified position and loops backward.
12. Security version of list_for_each_entry_safe list_for_each_entry
13. Security version of list_for_each_entry_safe_continue list_for_each_entry_continue
14. Security version of list_for_each_entry_safe_from list_for_each_entry_from
15. list_for_each_entry_safe_reverse list_for_each
Code download: https://github.com/xieweihua/Data-structure-and-algorithm/tree/master/list
Classic Data Structure: List