Method and device for managing universal double linked list with type and node security
By defining the general node class NODE and linked list class LIST, the head and tail node design and template class NODELIST are adopted to solve the problem of mixed use of node data types in the bidirectional linked list, and type-safe and node-safe linked list management is realized, and memory management efficiency and data access speed are improved.
Patent Information
- Application Number
- CN202510631389.8
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2025-05-16
- Publication Date
- 2025-09-02
AI Technical Summary
In the prior art, bidirectional linked lists are easily mixed when the node data types are inconsistent, resulting in program exceptions, and the node memory management efficiency is low, code coupling is serious, and it is impossible to efficiently judge the existence status of the node in the linked list.
Define the general node class NODE and linked list class LIST, realize type and node security through template class NODELIST, adopt head node and tail node tail design, limit the uniqueness of nodes in the linked list, and use POSITION type and data type offset node_offset to perform address conversion, providing type-safe and node-safe linked list management methods.
It realizes the isolation of linked lists of different types of data, avoids node mixing, reduces memory management time consumption, reduces code coupling, and improves data access efficiency and type security.
Smart Images

Figure CN120578660A_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the technical field of linked lists, and in particular to a general bidirectional linked list management method and device with type and node security. Background Art
[0002] In computer technology, linked lists are a basic data structure. Linked lists are divided into one-way linked lists and two-way linked lists. The node structure of a two-way linked list is generally like this:
[0003] struct Node{Node*next;Node*prev;};
[0004] Linked lists are used for data management. Each node in a linked list is associated with a piece of data. The data on a linked list node is referred to as node data or node data in this application, and the nodes associated with data are referred to as data nodes or data nodes in this application. There are two ways to organize nodes and node data: one is to store node data in the node, and the other is to store the node in the node data.
[0005] For the first type of node data stored in the node, the node structure of the linked list is generally as follows:
[0006]
[0007]
[0008] In the example above, the NodeInt node data type is int, the NodeA node data type is A, and the NodeAPointer node data type is a pointer to type A. Node data types vary, and each type requires a matching node structure. Each node structure requires a set of linked list management methods or operation functions. The code for these functions is similar, differing only in their node structures.
[0009] std::list in the C++ standard library solves the node data type problem. By using the node data type as a template parameter and programming based on the template parameter, std::list provides a general set of linked list management methods with a wide range of applications.
[0010] When the node data type is an object pointer, such as std::list<A*> , the node data type is A*, A is a class or struct type, the chain means Figure 13 Using std::list<A*> A similar linked list, for example:
[0011]
[0012]
[0013]
[0014] The above code constructs two temporary linked lists, listUnSelected and listNewSelected. listUnSelected contains the node data that are in the listPrevSelected linked list but not in the listSelected linked list, and listNewSelected contains the node data that are in the listSelected linked list but not in the listPrevSelected linked list. Whether the data is in the linked list can be determined by searching the linked list. In the above code, std::find traverses the linked list to search for the target node that matches the data. Assume that there are m data in listPrevSelected and n data in listSelected. The time complexity of generating listUnSelected is O(n*m), and the time complexity of generating listNewSelected is O(m*n).
[0015] For std::list<CFODrawShape*> , the type of its node data is CFODrawShape*, and the value is the address of a data object. The memory (data object) pointed to by the address and the node memory are two unrelated pieces of memory. When the CFODrawShape* value is known, you can only traverse the linked list to obtain the nodes related to it, so as to determine whether the CFODrawShape* value is in the linked list. In particular, when the object pointed to by the CFODrawShape* value is deleted, if its CFODrawShape* value cannot be removed from the linked list, it will cause access to an illegal address. To remove the CFODrawShape* value from the linked list, you can only traverse the linked list to search for the data node and then remove the node from the linked list.
[0016] Similar to std::list<A*> The linked list (here A is for example CFODrawShape) has the following deficiencies:
[0017] The node's memory is stored in std::list<A*> Separate allocation and release may result in frequent memory operations.
[0018] The memory of the node is unrelated to the memory of the type A object. The node stores the address of the type A object. When the type A object is destroyed, it needs to be in the linked list std::list<A*> Find the node corresponding to the data (A* value) in td::list<A*> ::iterator), and then explicitly remove the node from the std::list<A*> Remove from the linked list. The above must be displayed to access std::list<A*> Linked lists increase code coupling; when data is moved out of the linked list, the linked list must be traversed, which increases time consumption.
[0019] All operations on linked lists are performed on std::list<A*> Object access and calling, expanding std::list<A*> The scope of object access increases code coupling.
[0020] When only A type objects are accessible, it is impossible to determine whether the object address is in std::list<A*> In a linked list, you can only traverse the linked list to compare node data.
[0021] When only type A objects are accessible, the object address of the next or previous node of the node where the object address is located cannot be directly obtained.
[0022] After searching, Chinese invention patent application publication number CN115794838A discloses a method, apparatus, terminal device, and storage medium for storing a doubly linked list. By storing different types of nodes in corresponding target files, this method facilitates the storage of doubly linked lists without the need for a database. This existing patent application addresses the problem of storing the node data of a doubly linked list in memory in an external memory device, specifically how to store the data of any node in a doubly linked list in a sequentially stored file in an external memory device.
[0023] Using a general linked list of nodes of the general NODE type to store data can avoid std::list<A*> However, data nodes may be mixed and cause program exceptions. How to ensure that data nodes are not mixed and implement a general bidirectional linked list with type safety and node safety has become a technical problem that needs to be solved. Summary of the Invention
[0024] The purpose of the present invention is to overcome the defects of the above-mentioned prior art and provide a general bidirectional linked list management method and device with type and node security.
[0025] The purpose of the present invention can be achieved by the following technical solutions:
[0026] According to one aspect of the present invention, a general bidirectional linked list management method with type and node security is provided, the method comprising:
[0027] The method includes:
[0028] Define the general node class NODE and the general linked list class LIST, where LIST includes the head node head and the tail node tail of the linked list;
[0029] Define a general template class template<class data_t,int node_offset> class NODELIST, where NODELIST inherits from the LIST class, data_t is the type of node data, and node_offset is the memory offset of the node in the data_t type;
[0030] With NODE type as parameter, define linked list operation function and linked list traversal function in LIST class;
[0031] Define the linked list operation function in the NODELIST class with data_t type as parameter;
[0032] Define the POSITION type in the NODELIST class to indicate the traversal position. Using the POSITION type as a parameter, define the linked list traversal function in the NODELIST class to obtain the data pointer of the node corresponding to the POSITION position and adjust the POSITION position.
[0033] With data_t type as parameter, define the linked list traversal function in the NODELIST class to obtain the data pointer of the next node or previous node corresponding to the input data pointer.
[0034] Preferably, the node is a variable of general NODE type, and the same node can only appear once in a linked list;
[0035] When data_t type data is destructed, the node is automatically removed from the linked list, and the data_t type data containing the node is automatically removed from the linked list.
[0036] Preferably, the head node head and the tail node tail are both non-data nodes, and the node with a memory offset of node_offset in the data_t type is a data node;
[0037] The next field of the head node head points to the first data node of the linked list, and the prev field of the head node head is empty;
[0038] The prev field of the tail node tail points to the last data node of the linked list, and the next field of the tail node tail is empty; wherein prev and next respectively store the pointers of the previous and next nodes of the bidirectional linked list;
[0039] The nodes between the head node head and the tail node tail are data nodes. When there is no data node in the linked list, the next field of the head node head points to the tail node tail, and the prev field of the tail node points to the head node;
[0040] The head node head and the tail node tail cannot be removed from the linked list.
[0041] Preferably, with the NODE type as a parameter, a linked list operation function and a linked list traversal function are defined in the LIST class, and both the linked list operation function and the linked list traversal function are declared as protected restrictions and can only be called by subclasses.
[0042] More preferably, the linked list traversal function includes a GetNext() function for traversing the next node in the linked list; the GetNext() function is declared as a static member function of the class, and can obtain the address of the next node based on the node alone, and returns NULL when the next node is identified as the tail node of the linked list based on the next field value of the next node being empty; the GetNext() function can only return the address of the data node or return NULL.
[0043] More preferably, the linked list traversal function includes a GetPrev() function for prev traversal in the linked list; the GetPrev() is declared as a static member function of the class, and can obtain the address of the previous node only based on the node, and returns NULL when the previous node is identified as the head node of the linked list based on the prev field value of the previous node being empty; the GetPrev() function can only return the address of the data node or return NULL.
[0044] Preferably, the method comprises: defining a mutual conversion function between non-public NODE* and data_t* in the NODELIST class;
[0045] The mutual conversion function between NODE* and data_t* includes:
[0046] Use the node address and node_offset value to calculate the data address to which the node belongs, and then convert the calculation result according to data_t to obtain the pointer of the data_t object;
[0047] The node address is calculated using the data address and node_offset value of the node, and then the calculation result is converted into a type according to NODE to obtain the node address.
[0048] More preferably, a linked list operation function is defined in the NODELIST class with the data_t type as a parameter, and the linked list operation function includes functions for adding, removing, and clearing nodes. The input parameters of the linked list operation function are of data_t type. If there are output parameters and return values, the output parameters and return values are also of data_t type. The linked list operation function calls the mutual conversion function between data_t* and NODE*, and then calls the general implementation of the LIST class with the NODE type as a parameter.
[0049] Preferably, with data_t type as a parameter, a linked list traversal function is defined in the NODELIST class, and the linked list traversal function includes GetHeadData() and GetNext() functions for next traversal in the linked list, and GetTailData() and GetPrev() functions for prev traversal in the linked list.
[0050] More preferably, the GetHeadData() function returns the data address of the first data node in the linked list, and the type of the data address is data_t*; when there is no data node in the linked list, the GetHeadData() function returns NULL;
[0051] The GetNext() function is declared as a static member function of the class. The input parameter is a data_t type pointer, i.e., data_t*. The GetNext() function converts the input parameter into a NODE type pointer, i.e., NODE*, and then calls the general implementation of the LIST class to return the NODE type address of the next node. Finally, the returned NODE type address of the next node is converted into a data type address data_t* and returned to the caller.
[0052] More preferably, the GetTailData() function returns the data address of the last data node in the linked list, the type of the data address is data_t*, and when there is no data node in the linked list, the GetTailData() function returns NULL;
[0053] The GetPrev() function is declared as a static member function of the class, and its input parameter is a data_t type pointer, i.e., data_t*. The GetPrev() function converts the input parameter into a NODE type pointer, i.e., NODE*, and then calls the general implementation of the LIST class to return the NODE type address of the previous node. Finally, the returned NODE type address of the previous node is converted into a data type address data_t* and returned to the caller.
[0054] Preferably, a linked list traversal function is defined in the NODELIST class with the POSITION type as a parameter, and the linked list traversal function includes GetHeadPosition() and GetNext() functions for next traversal in the linked list, and GetTailPosition() and GetPrev() functions for prev traversal in the linked list.
[0055] More preferably, the GetHeadPosition() function returns the POSITION position of the first data node in the linked list; when there is no data node in the linked list, the GetHeadPosition() function returns NULL;
[0056] The GetNext() function is declared as a static member function of the class. The input parameter is a POSITION reference type, and the return value is a data_t type pointer, i.e., data_t*. The GetNext() function converts the input POSITION type parameter into a NODE type pointer, calls the general implementation of the base class to return the NODE type address of the next node, and then converts the NODE type address of the input parameter into a data type address and returns it to the caller, and adjusts the input parameter to the POSITION position of the next data node.
[0057] More preferably, the GetTailPosition() function returns the POSITION position of the last data node in the linked list; when there is no data node in the linked list, the GetTailPosition() function returns NULL;
[0058] The GetPrev() function is declared as a static member function of the class. The input parameter is a POSITION reference type, and the return value is a data_t type pointer, i.e., data_t*. The GetPrev() function converts the input POSITION type parameter into a NODE type pointer, calls the general implementation of the base class to return the NODE type address of the previous node, and then converts the NODE type address of the input parameter into a data type address and returns it to the caller, and adjusts the input parameter to the POSITION position of the previous data node.
[0059] Preferably, the method further comprises defining a K_LIST_NODE macro, wherein the K_LIST_NODE macro is used in a data_t type declaration to declare a node, which is a variable of a general NODE type.
[0060] More preferably, the method further comprises defining a K_LIST macro, wherein the K_LIST macro is used for a simplified definition of the template class NODELIST and implicitly includes the calculation of the node_offset value.
[0061] More preferably, the K_LIST macro is used in pair with the K_LIST_NODE macro, and each node defined by the K_LIST_NODE macro has an exclusive linked list NODELIST type defined by the K_LIST macro. The K_LIST_NODE macro and the K_LIST macro can be used multiple times in the data_t type to define multiple exclusive linked lists NODELIST types. A data_t type data can be added to each exclusive NODELIST type linked list of the data_t type at the same time.
[0062] Preferably, the POSITION type is only used for traversal of this type of linked list.
[0063] According to another aspect of the present invention, an electronic device is provided, comprising a memory and a processor, wherein a computer program is stored in the memory, and the method described above is implemented when the processor executes the program.
[0064] According to a third aspect of the present invention, a computer-readable storage medium is provided, on which a computer program is stored, and when the program is executed by a processor, the method described above is implemented.
[0065] Compared with the prior art, the present invention has the following beneficial effects:
[0066] 1) The present invention defines a general node class, a LIST class, and a general template class template<class data_t,intnode_offset> class NODELIST, where LIST includes the head node and tail node of non-data nodes. NODELIST inherits from the LIST class and defines the POSITION type in the NODELIST class; and defines various types of linked list operation functions or linked list traversal functions; data can only be added to the linked list related to it, and different types of data cannot be added to the same linked list, avoiding mixing of data types and having high type safety; when there are multiple node variables in the data, the same node variable can only be added to one linked list type, and different node variables cannot be added to the same type of linked list, which has high node safety.
[0067] 2) In the present invention, data will be automatically removed from the linked list when it is deconstructed, and there is no need to explicitly call the removal function of the linked list object, thereby reducing the code coupling between the data and the linked list object.
[0068] 3) In the present invention, the linked list nodes are included in the data, and the node memory is not allocated separately, which reduces the time consumption of memory allocation and release.
[0069] 4) In the present invention, NODE and LIST restrict access to data and functions with protected, have good encapsulation, avoid explicit calls to general NODE types, and avoid misuse of NODE type nodes.
[0070] 5) In this method, the node variable name is represented by the template parameter node_offset, eliminating the need for explicit node variable name calls. This effectively avoids incorrect node variable name usage and eliminates the need to identify node variable names. Nodes of different data_t types, and different nodes within the same data_t type, are all data nodes, sharing the same NODE type. These nodes with different uses cannot be mixed.
[0071] 6) The NODELIST template class in the present invention provides GetNext() and GetPrev() static member functions with data_t data type as parameters. When only a data pointer is available, the data of the next node or the previous node can be obtained, avoiding dependence on the linked list, reducing code coupling, and accelerating data access efficiency.
[0072] 7) In the present invention, the K_LIST and K_LIST_NODE macros are used together in the declaration of data types, which simplifies the definition of the NODELIST list type related to the data type. BRIEF DESCRIPTION OF THE DRAWINGS
[0073] Figure 1 Schematic diagram of the linked list pointer structure after NODE destruction in the present invention;
[0074] Figure 2 This is a schematic diagram of the structure of inserting LIST::head before the head node of the linked list in the present invention;
[0075] Figure 3 This is a schematic diagram of the structure of inserting LIST:tail before the tail node of the linked list in the present invention;
[0076] Figure 4 Schematic diagram of the bidirectional linked list structure in the present invention;
[0077] Figure 5 Schematic diagram of the linked list structure after the linked list is cleared and initialized in the present invention;
[0078] Figure 6 This is a schematic diagram of the flow of the class static member function LIST::GetNext in the present invention;
[0079] Figure 7 This is a flow chart of the class static member function LIST::GetPrev in the present invention;
[0080] Figure 8Schematic diagram of memory offset of nodes and data types in the present invention;
[0081] Figure 9 Schematic diagram of the NODELIST::GetNext function flow chart with POSITION as parameter in the present invention;
[0082] Figure 10 Schematic diagram of the NODELIST::GetPrev function flow with POSITION as parameter in the present invention;
[0083] Figure 11 This is a flow chart of the NODELIST::GetNext function with data types as parameters in the present invention;
[0084] Figure 12 This is a flow chart of the NODELIST::GetPrev function with data types as parameters in the present invention;
[0085] Figure 13 for std::list<A*> Schematic diagram of the linked list structure described. DETAILED DESCRIPTION
[0086] The following will clearly and completely describe the technical solutions in the embodiments of the present invention in conjunction with the accompanying drawings. Obviously, the described embodiments are part of the embodiments of the present invention, not all of them. Based on the embodiments of the present invention, all other embodiments obtained by ordinary technicians in this field without making creative efforts should fall within the scope of protection of the present invention.
[0087] This embodiment relates to a general bidirectional linked list management method with type and node safety. This method has the versatility of linked lists and the type safety of the C++ language. It not only strengthens the data type of the linked list, but also avoids the semantic confusion caused by general nodes. Note: All linked lists mentioned in this application refer to bidirectional linked lists.
[0088] In order to reduce time consumption and reduce code coupling, a bidirectional linked list NODELIST is redesigned to solve similar problems as std::list<A*> The NODELIST linked list is a two-way linked list based on a template class designed in C++. It adopts the second linked list structure in the background technology and has the following features:
[0089] Nodes are stored in the data, and no memory is allocated for nodes separately;
[0090] There is a mutual conversion relationship between node memory and data memory. When the node address is known, the data address can be obtained, and when the data address is known, the node address can be obtained.
[0091] When data (object) is destructed, the data is automatically removed from the linked list, and there is no need to traverse and access the linked list object;
[0092] When there is only a data (object) pointer, you can get the next node data or the previous node data;
[0093] When there is only a data (object) pointer, it can be determined whether the data (object) is in the linked list;
[0094] It has type safety, and different types of data (objects) cannot be added to the same linked list;
[0095] With node security, different nodes in the same data (object) cannot be added to the same linked list;
[0096] The design of a doubly linked list includes the following steps:
[0097] 1) Define a general node class (class NODE):
[0098] When a data object is destructed, the nodes in the data object are automatically removed from the linked list; the same node NODE can only appear once in a linked list.
[0099] 2) Define a general linked list class (class LIST), which includes a head node and a tail node. The head and tail nodes are non-data nodes, while all other nodes are data nodes. In the destructor of the LIST class, remove all data nodes from the linked list.
[0100] When the NODELIST linked list object is destroyed, all data nodes are automatically removed from the linked list.
[0101] 3) Taking the NODE type as a parameter, define the linked list operation functions in the LIST class: push_back, push_front, insert, unlink, unlinkall, IsLinked, etc., to provide a general implementation for the NODELIST linked list operation functions.
[0102] 4) With the NODE type as a parameter, define the list traversal functions GetHeadPosition, GetNext, GetTailPosition, and GetPrev in the LIST class to provide a general implementation for the traversal functions of the NODELIST list.
[0103] 5) Define the template class template<class data_t,int node_offset> class NODELIST.
[0104] NODELIST inherits from the LIST class. data_t is the data type of the node. node_offset is the memory offset of the node in the data_t type. The node defined in the data_t type is a data node.
[0105] Template classes are type-safe, and different data types data_t cannot be added to the same type linked list.
[0106] The template class has node security. Different nodes of the same data have different node_offset values and cannot be added to the same type of linked list, avoiding the misuse of common nodes.
[0107] 6) Define the mutual conversion function between non-public NODE* and data_t* in the NODELIST class, that is, the internal auxiliary function of address conversion.
[0108] 7) Using the data_t data type as a parameter, define linked list operation functions in the NODELIST class, including push_back, push_front, insert, unlink, and IsLinked, which are data type-based operation functions.
[0109] 8) Define the POSITION type in the NODELIST class.
[0110] The class-limited POSITION variable can only be used to traverse the linked list of this class and cannot be used for different linked list types, reducing coding errors.
[0111] 9) Using the POSITION type as a parameter, define the linked list traversal functions in the NODELIST class, including GetHeadPosition, GetNext, GetTailPosition, and GetPrev, which are traversal functions based on the POSITION type.
[0112] 10) Using the data_t data type as a parameter, define the linked list traversal functions GetHeadData, GetNext, GetTailData, and GetPrev in the NODELIST class, which are traversal functions based on the data_t type.
[0113] 11) Define K_LIST_NODE macro and K_LIST macro.
[0114] K_LIST_NODE is used in data_t type declarations to declare nodes, which are variables of the general NODE type. K_LIST is used to define the linked list type associated with a data_t node.
[0115] K_LIST is used in pairs with K_LIST_NODE, and each node has a dedicated linked list type.
[0116] Here are a few examples to illustrate how to use the NODELIST list.
[0117] One example of NODELIST list application: the use of K_LIST_NODE and K_LIST macros.
[0118] For example, class CFODrawShape is the basic class in the software. Now two linked list types are provided for CFODrawShape. The sample code is as follows:
[0119]
[0120] The above defines the linked list types LISTA and LISTB, which are embedded classes of CFODrawShape and are generally used in the form of CFODrawShape::LISTA and CFODrawShape::LISTB.
[0121] The same CFODrawShape object can be in both LISTA and LISTB type linked lists, but can only be in one LISTA type linked list or one LISTB type linked list.
[0122] Example 2 of NODELIST linked list application: adding data objects to the linked list.
[0123] CFODrawShape*pa,*pb;
[0124] pa=…;pb=…; / / Assume pa and pb are two data object pointers
[0125] / / pa is inserted into the end of the linked list
[0126] listUnSelected.push_back(*pa);
[0127] / / pa is removed from listUnSelected and inserted into the head of listNewSelected
[0128] listNewSelected.push_front(*pa);
[0129] / / pa is removed from listNewSelected and inserted into the end of listNewSelected
[0130] listNewSelected.push_back(*pa);
[0131] / / pa is inserted at the end of listAllSelected, and pa is also at the end of listNewSelected
[0132] listAllSelected.push_back(*pa);
[0133] It can be seen that: each node matches a linked list type; data can appear in each linked list type; data can only appear once in a linked list type; for multiple linked lists of the same type, data can only appear in one of the linked lists.
[0134] Example 3 of NODELIST linked list application: traversal based on POSITION type.
[0135] Forward traversal examples are as follows:
[0136]
[0137] An example of backward traversal is:
[0138]
[0139] It can be seen that NODELIST traversal implies NODE node information.
[0140] Example 4 of NODELIST linked list application: traversal based on data type data_t.
[0141] When the pointer of a data object is known, find the next or previous data of the node related to the data.
[0142] Forward traversal examples are as follows:
[0143]
[0144] An example of backward traversal is:
[0145]
[0146] It can be seen that NODELIST traversal only focuses on data types and linked list types, and does not focus on NODE node information, so NODE node-related mixing errors are impossible.
[0147] NODELIST linked list application example 5: data objects are removed from the linked list.
[0148] Unlike std::list, NODELIST does not need to search for nodes, but directly removes nodes in the data from the linked list.
[0149] Sample code such as:
[0150] CFODrawShape*pShape=...; / / A data object
[0151] / / When data is removed from the LISTA type linked list, there is no need to traverse the search node
[0152] CFODrawShape::LISTA::unlink(*pShape);
[0153] It can be seen that the time complexity of moving data out of a linked list is O(1). On the other hand, when moving data out of a std::list, it is necessary to first traverse the linked list to find the node to which the data belongs, i.e., the std::list::iterator, and then move the node out. The time complexity of moving data out is O(n), where n is the number of nodes in the linked list.
[0154] Example 6 of NODELIST linked list application: removing the data object from the linked list when it is destroyed.
[0155] Sample code such as:
[0156] CFODrawShape*pShape=...; / / A data object
[0157] / / Release the data object
[0158] delete pShape;
[0159] / / NODE destructor is called, each NODE node is removed from the linked list to which it belongs, the time complexity is O(1), the time complexity of std::list is O(n), where n is the number of linked list nodes.
[0160] Example 7 of NODELIST linked list application: The previous CheckSelectionChange function is based on the NODELIST modification example:
[0161]
[0162]
[0163]
[0164] Sections 1) to 10) above describe a general type-safe linked list implementation method, and section 11) describes how to simply define a type-safe linked list for a data type.
[0165] This embodiment also relates to a general bidirectional linked list management method with type and node security, which provides a simple data type-related exclusive linked list type definition method through type-safe linked list definition.
[0166] Define a general linked list node class NODE, whose structure is defined as follows:
[0167]
[0168] Next and prev store the pointers to the previous and next nodes of the doubly linked list. The constructor NODE() initializes next = prev = NULL. Restricting next and prev to non-public strengthens data encapsulation. LIST, as a friend class of NODE, can access all members of NODE.
[0169] In the NODE destructor, remove the node from the linked list. The sample code is as follows:
[0170]
[0171] When a NODE is in a linked list, its next and prev are non-empty.
[0172] The node NODE is stored in the data type data_t. When the data object is destructed, C++ will automatically call the destructor of NODE, so that the node is automatically removed from the linked list. Figure 1 It is the linked list pointer after NODE is destroyed. Delete identifies the data object after destruction. Since the object has been released, its next and prev (thick arrows) are no longer accessed.
[0173] Define a general class LIST, which includes the head node and tail node of the linked list. The sample code is as follows:
[0174]
[0175]
[0176] There is a problem with the NODE::~NODE() destructor. When the node being destructed is the first node of a linked list, the head pointer of the linked list needs to be modified, and access to the head pointer is required. Similarly, when the node being destructed is the last node of a linked list, the tail pointer of the linked list needs to be modified, and access to the tail pointer is required. Add a head node head and a tail node tail, and insert the head node in front of the first data node of the linked list. This way, the head node becomes the head node of the linked list, but the head is not a member of the data type. It is different from other nodes in the linked list, that is, the head node of the linked list will not be removed from the linked list, so that the node pointed to by head.next is the first data node of the linked list, and head.next becomes the de facto head pointer of the linked list. Because both the head node head and the data node are of NODE type, when the first data node is destructed, head.next is modified, and there is no need to access the head pointer of the linked list.
[0177] from Figure 2 As shown, although both head and data_t nodes are of type NODE, their field values differ. head.prev is always null, while the prev field of all other data_t nodes is always non-null. Therefore, for any NODE type node, the node with an empty prev field is the head node in the list. Since head is a non-data node in the list, data addresses cannot be obtained from non-data nodes like head until they are inserted into the data nodes of the linked list.
[0178] Similarly, in LIST, tail is inserted as a non-data node after the last data node of the linked list, making it the tail node of the linked list. However, tail is not a member of the data type, unlike other nodes in the linked list. That is, the tail node of the linked list will not be removed from the linked list, so the node pointed to by tail.prev is the last data node of the linked list, and tail.prev becomes the de facto tail pointer of the linked list. Because the tail node and the data nodes are both of NODE type, when the last data node is destroyed, tail.prev is modified, without the need to access the tail pointer of the linked list.
[0179] from Figure 3 As shown, although tail and data_t nodes are both NODE types, their field values differ. tail.next is always null, while the next field of all other data_t nodes is always non-null. Therefore, the node with a null next field is the tail node in the list. After the tail node in the list is inserted as a non-data node into the data node of the linked list, the data address cannot be obtained from the non-data node.
[0180] head.next is the head pointer of the linked list data node, and tail.prev is the tail pointer of the linked list data node. Although the space of head.prev and tail.next is wasted, it can be simply concluded that the node with an empty prev field is the head of the list, and the node with an empty next field is the tail of the list. The node after the head is the first data node of the linked list, and the node before the tail is the last data node of the linked list, such as Figure 4 shown.
[0181] The head, tail and data nodes in LIST are of the same type NODE, so the process of deleting the first and last data nodes of the linked list is the same as the process of deleting other nodes in the linked list.
[0182]
[0183] The unlink function is used to remove the linked list node pos, where pos can be the first data node, the last data node, or other data nodes in the linked list, but cannot be the head and tail nodes in LIST.
[0184] Remove all nodes in the destructor of LIST. The sample code is as follows:
[0185]
[0186]
[0187] In the destructor ~LIST(), the unlinkall() function is called to remove all nodes from the linked list. The unlink() function removes a node from the linked list. The tail node in LIST is not a data node and cannot be removed from the linked list. Therefore, the while statement above needs to check if pnode&&pnode->next is true. Only nodes with a true value are data nodes.
[0188] Figure 5 It shows the link relationship after LIST is initialized and cleared. The node with an empty next field is tail, and the node with an empty prev field is head.
[0189] The link relationship when the linked list is cleared is the same as the link relationship when the linked list is initialized. The LIST constructor code is as follows:
[0190]
[0191] The constructor of the NODE node initializes head.prev and tail.next to empty.
[0192] The constructor and destructor of LIST are declared as protected, which makes LIST usable only as a base class. However, the unlinkall function has no parameters and can be used as a public function.
[0193] With the NODE type as a parameter, the linked list operation functions push_back, push_front, insert, unlink, unlinkall, and IsLinked are defined in LIST. The LIST class declares the functions as follows:
[0194]
[0195]
[0196] The above functions are declared as protected and can only be called by subclasses to prevent incorrect use of NODE nodes. The functions in the LIST class are a general purpose doubly linked list manager. The LIST class addresses the shortcomings of std::list, but it also presents a new problem: the functions defined in the class take a general NODE type as a parameter, which can easily lead to mixed node usage. Mixed nodes must be specially controlled, otherwise program exceptions will occur. The design of the LIST class itself includes examples of mixed nodes, where the head node and tail node are not data nodes but are linked to the same linked list as data nodes. The LIST class provides special handling for this mixing. The LIST class provides functions for inserting, removing, and traversing data nodes. These data nodes may also be mixed, such as nodes of different data types or different nodes of the same data type. These nodes are all of the general NODE type. Once these nodes are mixed in a linked list, it is difficult to identify the data corresponding to different nodes. In this application, protected restrictions are imposed on the LIST class to avoid function calls with NODE type as parameters. List users cannot directly use the general NODE type, thereby avoiding node mixing due to misuse of general NODE type variables.
[0197] unlink() is used to remove a NODE node, as described above. insert() is used to insert a new node before the specified node, push_back() is used to insert a node at the end of the linked list, push_front() is used to insert a node at the head of the linked list, and IsLinked() is used to determine whether the NODE node has been added to the linked list. The sample code is as follows:
[0198]
[0199]
[0200] With the NODE type as a parameter, define the linked list traversal functions GetHeadPosition, GetNext, GetTailPosition, and GetPrev in LIST. The LIST declaration is as follows:
[0201]
[0202] The traversal functions are restricted to protected to prevent misuse of the NODE pointer. GetHeadPosition() and GetNext() are used for next traversal of the linked list, while GetTailPosition() and GetPrev() are used for prev traversal of the linked list. The sample code is as follows:
[0203]
[0204] The GetHeadPosition() function returns the next field value of the head node head. When head.next->next is empty, it indicates that head.next points to the tail node tail, and NULL is returned.
[0205] GetNext() returns the address of the next node of the current node pos. If the next field value of the next node is empty, it indicates that the next node is a tail node rather than a data node. In this case, NULL is returned, indicating that the linked list has been traversed to the end. Figure 6 .
[0206] Here, GetNext() is declared as a static member function of the class. The tail node of the linked list can be identified based solely on the empty values of the input parameters pos and next fields, thereby identifying the last data node.
[0207] GetNext() is declared as a static member function of the class. It retrieves the next node address based solely on the node. Static member functions can be called by the class name, reducing the access scope of the class object and reducing code coupling.
[0208]
[0209] The GetTailPosition() function returns the prev field value of the head node tail. When tail.prev->prev is empty, it indicates that tail.prev points to the head node head, and NULL is returned.
[0210] GetPrev() returns the address of the previous node of the current node pos. If the prev field value of the previous node is empty, it indicates that the previous node is the head node rather than the data node. In this case, NULL is returned, indicating that the linked list has been traversed to the end. Figure 7 .
[0211] Here, GetPrev() is declared as a static member function of the class. The head node of the linked list can be identified based solely on the empty values of the input parameters pos and prev fields, thereby identifying the first data node.
[0212] GetPrev() is declared as a static member function of the class. It retrieves the previous node address based solely on the node. Static member functions can be called using the class name, reducing the access scope of class objects and reducing code coupling.
[0213] Define the template class template<class data_t,int node_offset> class NODELIST, the sample code is as follows:
[0214]
[0215] NODELIST inherits from the LIST class. data_t is the data type added to the linked list. node_offset is the memory offset of the linked list node variable in the data_t type. For example Figure 8 .
[0216] The mutual conversion function between the non-public NODE* and data_t* is defined in the NODELIST class, which means using the node address and node_offset value to calculate the data address to which the node belongs, and then performing type conversion based on data_t to obtain the pointer of the data_t object.
[0217]
[0218] For the head and tail nodes in the LIST, the NODE* cannot be converted to data_t*. The GetData() function needs to exclude the head and tail nodes in the LIST by ensuring that the next and prev fields are not empty. Similarly, NODELIST uses the data_t address and the node_offset value to calculate the node address.
[0219]
[0220]
[0221] GetData() and GetNode() are defined as static functions, which do not involve access to the this pointer.
[0222] The linked list operation functions defined in the template class NODELIST take the data_t type as a parameter. Their purpose is to provide data type-based linked list operation functions, avoiding calls to generic node types. In the implementation of these functions, the actual NODE node address is calculated based on the data_t type parameter and the node_offset value, and then the generic implementation of the base class LIST is called with the NODE type as the parameter. The code example of the NODELIST linked list operation function is as follows:
[0223]
[0224]
[0225] The function of the template class NODELIST takes a data_t type pointer as a parameter and uses the node_offset value to calculate the address of the node related to the data, thereby realizing the addition and removal of the node.
[0226] data_t ensures that data of other types cannot be added to NODELIST, and node_offset ensures that only node variables with the same memory offset can be added to NODELIST. The NODELIST template class is type-safe; different data types cannot be added to the same linked list, preventing data type misuse. The NODELIST template class is node-safe; different node variables cannot be added to the same linked list, preventing misuse of generic linked list nodes.
[0227] The NODELIST template class hides the node variable name, making it impossible to misuse the node variable name. It also improves the readability of the code. Therefore, NODELIST is a linked list type based on the type safety of the C++ language. It is impossible to misuse the data type and node variable name, so it has type safety and node safety.
[0228] The POSITION type is defined in the NODELIST class to indicate position traversal semantics. Using the POSITION type as a parameter, the linked list traversal functions GetHeadPosition, GetNext, GetTailPosition, and GetPrev are defined in the NODELIST template class, providing traversal functions based on POSITION semantics. In the implementation of these functions, the data_t address is calculated based on the NODE address, thereby obtaining the returned data pointer. The sample code is as follows:
[0229]
[0230]
[0231] GetHeadPosition() returns the position of the first data node, GetNext() returns the data pointer of the current position pos and adjusts the current position pos to the next node, see Figure 9 NODELIST::GetNext() calls the base class function of the same name to traverse, and NODELIST completes the conversion between data addresses and node addresses.
[0232] The code example of reverse traversal of GetTailPosition() and GetPrev() functions is as follows:
[0233]
[0234] GetTailPosition() returns the position of the last data node, GetPrev() returns the data of the current position pos and adjusts the current position pos to the previous node, see Figure 10 NODELIST::GetPrev() calls the base class function of the same name to traverse, and NODELIST completes the conversion between data addresses and node addresses.
[0235] The GetNext() and GetPrev() functions are declared as static functions. When position pos is the last data node in the linked list, GetNext() identifies the tail of the list based on the null value of the next field and adjusts position pos to NULL. When position pos is the first data node in the linked list, GetPrev() identifies the head of the list based on the null value of the prev field and adjusts position pos to NULL.
[0236] With data_t type as parameter, define the linked list traversal functions GetHeadData, GetNext, GetTailData, and GetPrev in the template class NODELIST. Calculate the NODE address based on the data_t address, call the general implementation of LIST with the NODE address, and then reversely calculate the data_t address based on the returned NODE address. The sample code is as follows:
[0237]
[0238] GetHeadData() returns the data address of the first data node, that is, it returns a data_t* type value. GetNext() returns the data address of the next node of the current data. The process of GetNext() is as follows Figure 11 As shown, NODELIST::GetNext() calls the base class function of the same name to traverse, and NODELIST completes the conversion between data addresses and node addresses.
[0239] The code example of reverse traversal of GetTailData and GetPrev functions is as follows:
[0240]
[0241]
[0242] GetTailData() returns the data address of the last data node, that is, it returns a data_t* type value. GetPrev() returns the data of the previous node of the current data. The process of GetPrev() is as follows Figure 12 , NODELIST::GetPrev() calls the base class function of the same name to traverse, and NODELIST completes the mutual conversion between data address and node address.
[0243] The GetNext() and GetPrev() functions are declared as static functions. When only a data pointer is available, GetNext() and GetPrev() can be used to obtain the data addresses of the next and previous nodes. When the data is the last data node in the linked list, GetNext() identifies the tail of the list based on the null value of the next field and returns NULL. When the data is the first data node in the linked list, GetPrev() identifies the head of the list based on the null value of the prev field and returns NULL.
[0244] The K_LIST_NODE and K_LIST macros are paired macros. K_LIST_NODE is used to define nodes within a data type, while K_LIST simplifies the definition of the template class NODELIST. When the inventive method is applied, to prevent namespace contamination, NODE, LIST, and NODELIST must be defined within a specific domain name space. The K_LIST_NODE and K_LIST macros also simplify the limited reference to domain names. The sample code of the present invention does not use domain name qualifiers.
[0245]
[0246] As can be seen from the definition of K_LIST_NODE, an embedded linked list type, list_type, is declared when defining a node in the data. Linked list types are related to data types and serve them. Defining a linked list type as an embedded class within a data type makes it easier to identify in the code.
[0247] The sole reason for the node variable to exist is to provide storage for the nodes. The only use of the node variable name is to obtain the memory offset of the node relative to the data type. list_type##_name simply gives the variable a different name; the node variable is never explicitly called in the code. Therefore, declaring the node variable as non-public is appropriate, but this requires declaring the linked list type as a nested class of the data type. In C++, nested classes can access non-public members of the data type.
[0248] The NODE and LIST defined by the method of the present invention are general classes, and NODELIST is a general template class. K_LIST and K_LIST_NODE simplify the definition of linked lists related to data types. When applying the method of the present invention, you only need to pay attention to the use of K_LIST_NODE, K_LIST and linked list functions.
[0249] The K_LIST_NODE macro stores nodes in the data, eliminating the need for memory allocation, release, and management of nodes. When the data is destroyed, C++ will automatically destroy the node variables in the data, thereby automatically removing the data from the linked list, avoiding access to the linked list object name and reducing code coupling. When the data and nodes are destroyed, the time complexity of removing the node from the linked list is O(1). When using the C++ standard library std::list to remove data, the data must first be searched in the linked list, and the search time complexity is O(n). The K_LIST_NODE macro restricts the nodes stored in the data to non-public access, avoiding the misuse of the general NODE variable. The K_LIST macro defines the linked list type as an embedded class of the data type. This requires the use of the linked list type within the data type, making the linked list type and the data type more conceptually integrated and improving the readability of the code.
[0250] The electronic device of the present invention includes a central processing unit (CPU), which can perform various appropriate actions and processes according to computer program instructions stored in a read-only memory (ROM) or loaded from a storage unit into a random access memory (RAM). In the RAM, various programs and data required for device operation can also be stored. The CPU, ROM, and RAM are connected to each other via a bus. An input / output (I / O) interface is also connected to the bus.
[0251] Many components in a device are connected to the I / O interface, including: input units, such as a keyboard and mouse; output units, such as various types of displays and speakers; storage units, such as magnetic disks and optical disks; and communication units, such as network cards, modems, and wireless communication transceivers. The communication unit allows the device to exchange information / data with other devices via computer networks such as the Internet and / or various telecommunication networks.
[0252] The processing unit performs the various methods and processes described above. For example, in some embodiments, the method can be implemented as a computer software program, which is tangibly contained in a machine-readable medium, such as a storage unit. In some embodiments, part or all of the computer program can be loaded and / or installed on the device via a ROM and / or a communication unit. When the computer program is loaded into RAM and executed by the CPU, one or more steps of the method described above can be performed. Alternatively, in other embodiments, the CPU can be configured to execute the method in any other appropriate manner (e.g., by means of firmware).
[0253] The functions described above herein may be performed, at least in part, by one or more hardware logic components. For example, and without limitation, exemplary types of hardware logic components that may be used include: field programmable gate arrays (FPGAs), application specific integrated circuits (ASICs), application specific standard products (ASSPs), systems on chip (SOCs), complex programmable logic devices (CPLDs), and the like.
[0254] The program code for implementing the method of the present invention can be written in any combination of one or more programming languages. Such program code can be provided to a processor or controller of a general-purpose computer, a special-purpose computer, or other programmable data processing device so that when the program code is executed by the processor or controller, the functions / operations specified in the flow chart and / or block diagram are implemented. The program code can be executed entirely on the machine, partially on the machine, as a stand-alone software package, partially on the machine and partially on a remote machine, or entirely on a remote machine or server.
[0255] In the context of the present invention, machine-readable medium can be a tangible medium that can contain or store a program for use with an instruction execution system, device or equipment or used in combination with an instruction execution system, device or equipment. Machine-readable medium can be a machine-readable signal medium or a machine-readable storage medium. Machine-readable medium can include, but is not limited to, electronic, magnetic, optical, electromagnetic, infrared or semiconductor systems, devices or equipment, or any suitable combination of the foregoing. More specific examples of machine-readable storage media can include electrical connections based on one or more lines, portable computer disks, hard disks, random access memories (RAM), read-only memories (ROM), erasable programmable read-only memories (EPROM or flash memory), optical fibers, portable compact disk read-only memories (CD-ROM), optical storage devices, magnetic storage devices, or any suitable combination of the foregoing.
[0256] The above description is merely a specific embodiment of the present invention, but the scope of protection of the present invention is not limited thereto. Any person skilled in the art can easily conceive of various equivalent modifications or substitutions within the technical scope disclosed in the present invention, and such modifications or substitutions are intended to be within the scope of protection of the present invention. Therefore, the scope of protection of the present invention shall be subject to the scope of protection of the claims.
Claims
1. A general bidirectional linked list management method with type and node security, characterized in that: The method includes: Define the general node class NODE and the general linked list class LIST, where LIST includes the head node head and the tail node tail of the linked list; Define a general template class template<class data_t,int node_offset> class NODELIST, where NODELIST inherits from the LIST class, data_t is the type of node data, and node_offset is the memory offset of the node in the data_t type; With NODE type as parameter, define linked list operation function and linked list traversal function in LIST class; Define the linked list operation function in the NODELIST class with data_t type as parameter; Define the POSITION type in the NODELIST class to indicate the traversal position. Using the POSITION type as a parameter, define the linked list traversal function in the NODELIST class to obtain the data pointer of the node corresponding to the POSITION position and adjust the POSITION position. With data_t type as parameter, define the linked list traversal function in the NODELIST class to obtain the data pointer of the next node or previous node corresponding to the input data pointer.
2. A general bidirectional linked list management method with type and node security according to claim 1, characterized in that: The node is a variable of the general NODE type, and the same node can only appear once in a linked list; When data_t type data is destructed, the node is automatically removed from the linked list, and the data_t type data containing the node is automatically removed from the linked list.
3. A general bidirectional linked list management method with type and node security according to claim 1, characterized in that: The head node head and the tail node tail are both non-data nodes, and the node with memory offset node_offset in type data_t is a data node; The next field of the head node head points to the first data node of the linked list, and the prev field of the head node head is empty; The prev field of the tail node tail points to the last data node of the linked list, and the next field of the tail node tail is empty; wherein prev and next respectively store the pointers of the previous and next nodes of the bidirectional linked list; The nodes between the head node head and the tail node tail are data nodes. When there is no data node in the linked list, the next field of the head node head points to the tail node tail, and the prev field of the tail node points to the head node; The head node head and the tail node tail cannot be removed from the linked list.
4. A general bidirectional linked list management method with type and node security according to claim 1, characterized in that: With NODE type as a parameter, the linked list operation function and the linked list traversal function are defined in the LIST class. The linked list operation function and the linked list traversal function are both declared as protected restrictions and can only be called by subclasses.
5. A general bidirectional linked list management method with type and node security according to claim 4, characterized in that: The linked list traversal function includes a GetNext() function for traversing the next node in the linked list; the GetNext() function is declared as a static member function of the class, and can obtain the address of the next node based only on the node. When the next node is identified as the tail node of the linked list based on the next field value of the next node being empty, NULL is returned; the GetNext() function can only return the address of the data node or return NULL.
6. A general bidirectional linked list management method with type and node security according to claim 4, characterized in that: The linked list traversal function includes a GetPrev() function for prev traversal in a linked list; the GetPrev() function is declared as a static member function of a class, and can obtain the address of the previous node based solely on the node. When the previous node is identified as the head node of the linked list based on the prev field value of the previous node being empty, NULL is returned; the GetPrev() function can only return the address of a data node or NULL.
7. A general bidirectional linked list management method with type and node security according to claim 1, characterized in that: The method comprises: defining a mutual conversion function between non-public NODE* and data_t* in the NODELIST class; The mutual conversion function between NODE* and data_t* includes: Use the node address and node_offset value to calculate the data address to which the node belongs, and then convert the calculation result according to data_t to obtain the pointer of the data_t object; The node address is calculated using the data address and node_offset value of the node, and then the calculation result is converted into a type according to NODE to obtain the node address.
8. A general bidirectional linked list management method with type and node security according to claim 7, characterized in that: A linked list operation function is defined in the NODELIST class with the data_t type as a parameter. The linked list operation function includes functions for adding, removing, and clearing nodes. The input parameters of the linked list operation function are of data_t type. If there are output parameters and return values, the output parameters and return values are also of data_t type. The linked list operation function calls the mutual conversion function between data_t* and NODE*, and then calls the general implementation of the LIST class with the NODE type as a parameter.
9. A general bidirectional linked list management method with type and node security according to claim 1, characterized in that: With data_t type as parameter, a linked list traversal function is defined in the NODELIST class. The linked list traversal function includes GetHeadData() and GetNext() functions for next traversal in the linked list, and GetTailData() and GetPrev() functions for prev traversal in the linked list.
10. A general bidirectional linked list management method with type and node security according to claim 9, characterized in that: The GetHeadData() function returns the data address of the first data node in the linked list, and the type of the data address is data_t*; when there is no data node in the linked list, the GetHeadData() function returns NULL; The GetNext() function is declared as a static member function of the class. The input parameter is a data_t type pointer, i.e., data_t*. The GetNext() function converts the input parameter into a NODE type pointer, i.e., NODE*, and then calls the general implementation of the LIST class to return the NODE type address of the next node. Finally, the returned NODE type address of the next node is converted into a data type address data_t* and returned to the caller.
11. A general bidirectional linked list management method with type and node security according to claim 9, characterized in that: The GetTailData() function returns the data address of the last data node in the linked list. The data address type is data_t*. When there is no data node in the linked list, the GetTailData() function returns NULL. The GetPrev() function is declared as a static member function of the class, and its input parameter is a data_t type pointer, i.e., data_t*. The GetPrev() function converts the input parameter into a NODE type pointer, i.e., NODE*, and then calls the general implementation of the LIST class to return the NODE type address of the previous node. Finally, the returned NODE type address of the previous node is converted into a data type address data_t* and returned to the caller.
12. A general bidirectional linked list management method with type and node security according to claim 1, characterized in that: The linked list traversal function is defined in the NODELIST class with the POSITION type as a parameter. The linked list traversal function includes the GetHeadPosition() and GetNext() functions for the next traversal in the linked list, and the GetTailPosition() and GetPrev() functions for the prev traversal in the linked list.
13. A general bidirectional linked list management method with type and node security according to claim 12, characterized in that: The GetHeadPosition() function returns the POSITION position of the first data node in the linked list; when there is no data node in the linked list, the GetHeadPosition() function returns NULL; The GetNext() function is declared as a static member function of the class. The input parameter is a POSITION reference type, and the return value is a data_t type pointer, i.e., data_t*. The GetNext() function converts the input POSITION type parameter into a NODE type pointer, calls the general implementation of the base class to return the NODE type address of the next node, and then converts the NODE type address of the input parameter into a data type address and returns it to the caller, and adjusts the input parameter to the POSITION position of the next data node.
14. A general bidirectional linked list management method with type and node security according to claim 12, characterized in that: The GetTailPosition() function returns the POSITION position of the last data node in the linked list; when there is no data node in the linked list, the GetTailPosition() function returns NULL; The GetPrev() function is declared as a static member function of the class. The input parameter is a POSITION reference type, and the return value is a data_t type pointer, i.e., data_t*. The GetPrev() function converts the input POSITION type parameter into a NODE type pointer, calls the general implementation of the base class to return the NODE type address of the previous node, and then converts the NODE type address of the input parameter into a data type address and returns it to the caller, and adjusts the input parameter to the POSITION position of the previous data node.
15. A general bidirectional linked list management method with type and node security according to claim 1, characterized in that: The method further includes defining a K_LIST_NODE macro, which is used in a data_t type declaration to declare a node, where the node is a variable of a general NODE type.
16. A general bidirectional linked list management method with type and node security according to claim 15, characterized in that: The method further includes defining a K_LIST macro, wherein the K_LIST macro is used for a simplified definition of the template class NODELIST and implicitly includes the calculation of the node_offset value.
17. A general bidirectional linked list management method with type and node security according to claim 16, characterized in that: The K_LIST macro is used in pairs with the K_LIST_NODE macro. Each node defined by the K_LIST_NODE macro has an exclusive linked list NODELIST type defined by the K_LIST macro. The K_LIST_NODE macro and the K_LIST macro can be used multiple times in the data_t type to define multiple exclusive linked lists NODELIST types. A data_t type data can be added to each exclusive NODELIST type linked list of the data_t type at the same time.
18. A general bidirectional linked list management method with type and node security according to claim 1, characterized in that: The POSITION type is only used for traversal of this type of linked list.
19. An electronic device comprising a memory and a processor, wherein a computer program is stored in the memory, wherein: When the processor executes the program, the method according to any one of claims 1 to 18 is implemented.
20. A computer-readable storage medium having a computer program stored thereon, characterized in that: When the program is executed by a processor, the method according to any one of claims 1 to 18 is implemented.
Citation Information
Patent Citations
Link table management method and device, equipment and medium
CN116401415A