Structure of an exclusive or linked list
This is a data structure. The bitwise OR operation of a computer is used to reduce the storage needs of two-way linked lists.
... A B C D E ... –> next –> next –> next –> <– prev <– prev <– prev <–
As shown in the preceding figure, each node has two pointers pointing to the frontend and successor of the node respectively.
The XOR linked list is shown below:
... A B C D E ... <–> A⊕C <-> B⊕D <-> C⊕E <->
The exclusive or exclusive address in a pointer. For example, B stores the value of a branch C.
In this way, we need to know how to start from the beginning.Two nodes(Unlike normal linked lists, only one is needed ).
For example, if we know node A and Node B, we can use the address of node A and A between C in Node B to get a C from a between C. This isForward Traversal
Reverse TraversalFor example, if you know nodes E and D, you can use the address of E and the C branch e operation in D to obtain c Branch E
However, this structure is used for research and usage.We do not recommend this function for the following reasons::
- Common debug tools do not support XOR linked lists.
- Reduces memory overhead by increasing Code complexity and increases maintenance costs.
- The normal garbage collection mechanism does not work properly.
- Although most languages Support XOR, some languages do not support XOR operations.
- The pointer is meaningless when it is not in a traversal table. For example, another data structure also contains pointers in the linked list.
- In order to calculate the address of the next pointer, you must remember the address of the previous node.
- XOR linked lists cannot provide functions provided by two-way linked lists. For example, if only one node is known, the node is removed from the linked list or inserted to the end of the node when only one node is known.
As resources become cheaper and memory grows, memory is no longer an important factor except for some embedded systems.
Deformation of the structure
Addition linked list: the sum of the put addresses
... A B C D E ... <–> A+C <-> B+D <-> C+E <->
Subtraction linked list: the difference of the placed address
... A B C D E ... <–> C-A <-> D-B <-> E-C <->
The difference is that the forward and reverse operations need to be performed differently.
Http://en.wikipedia.org/wiki/XOR_linked_list