ADS
Algorithms and Data Structures
Loading...
Searching...
No Matches

The XOR list of the discussion of chapter 3 of Morin's book, beyond the book. More...

Files

file  ADS/sequence/XorList.h
 The XOR list of the discussion of chapter 3 of Morin's book, beyond the book: a doubly linked list whose cells keep one word of links instead of two, the exclusive or \( \mathit{prev} \oplus \mathit{next} \) of the addresses of their two neighbors (nil at the ends being 0), so that a walk that knows the cell it comes from finds the next one by an exclusive or, \( \mathit{next} = \mathit{link} \oplus \mathit{prev} \), in either direction.

Classes

class  ADS::XorList< T >
 a doubly linked list with one word of links per cell, the exclusive or of the two neighbors More...

Functions

template<std::unsigned_integral U>
constexpr void ADS::xorSwap (U &a, U &b)
 \( a \) and \( b \) swapped by three exclusive ors and no third variable (exercise 3.19 of Morin's book)

Detailed description

The XOR list of the discussion of chapter 3 of Morin's book, beyond the book.

The definitions, the invariants and the costs of the area are in Theory of sequences and lists.

Function documentation

◆ xorSwap()

template<std::unsigned_integral U>
void ADS::xorSwap ( U & a,
U & b )
constexpr

\( a \) and \( b \) swapped by three exclusive ors and no third variable (exercise 3.19 of Morin's book)

In pseudocode (Morin, exercise 3.19):

\[\class{pseudocode}{\begin{array}{r@{\quad}l} 1 & \textbf{procedure}\ \mathrm{xorSwap}( a , b ) \cr 2 & \quad a \gets a \oplus b;\ b \gets a \oplus b;\ a \gets a \oplus b \end{array}} \]

Precondition
\( a \) and \( b \) are not the same object