Sorting Network Search
Backtracking for Small Sorting Networks
Public Member Functions | Private Member Functions | Private Attributes | List of all members
CMatching Class Reference

Perfect matching. More...

#include <Matching.h>

Inheritance diagram for CMatching:
CSettings

Public Member Functions

 CMatching ()
 Void constructor. More...
 
 CMatching (const CMatching &)
 Copy constructor. More...
 
void Initialize ()
 Initialize. More...
 
bool Next ()
 Advance to next matching. More...
 
void Swap (const size_t, const size_t)
 Swap. More...
 
void Normalize ()
 Normalize. More...
 
size_t & operator[] (const size_t)
 Overloaded index operator. More...
 
const size_t operator[] (const size_t) const
 Overloaded index operator. More...
 
 operator std::string () const
 Cast to a string. More...
 

Private Member Functions

void SwapPair (int[], size_t, size_t)
 Swap pair. More...
 

Private Attributes

size_t m_nMatching [MAXINPUTS+1] = {0}
 Matching. More...
 
size_t m_nMap [MAXINPUTS+1] = {0}
 Matching index map. More...
 
int m_nStack [MAXINPUTS+1] = {0}
 Stack to remove recursion from permutation. More...
 

Additional Inherited Members

- Static Public Member Functions inherited from CSettings
static void SetWidth (const size_t)
 Set width. More...
 
static void SetDepth (const size_t)
 Set depth. More...
 
- Static Protected Attributes inherited from CSettings
static size_t m_nWidth = 9
 Comparator network width. More...
 
static size_t m_nDepth = 6
 Comparator network depth. More...
 

Detailed Description

CMatching represents a perfect matching... well, as perfect as it can be if its size is odd.

Definition at line 39 of file Matching.h.

Constructor & Destructor Documentation

◆ CMatching() [1/2]

CMatching::CMatching ( )

Initialize the matching to the identity matching.

Definition at line 32 of file Matching.cpp.

◆ CMatching() [2/2]

CMatching::CMatching ( const CMatching m)

The copy constructor.

Parameters
mMatching to copy.

Definition at line 39 of file Matching.cpp.

Member Function Documentation

◆ Initialize()

void CMatching::Initialize ( )

Initialize to the identity matching.

Definition at line 50 of file Matching.cpp.

◆ Next()

bool CMatching::Next ( )

Get the next matching. Uses the stack to avoid recursing.

Returns
true if there was a next matching

Definition at line 62 of file Matching.cpp.

◆ Normalize()

void CMatching::Normalize ( )

Normalize the matching.

< Integer copy of matching.

Definition at line 117 of file Matching.cpp.

◆ operator std::string()

CMatching::operator std::string ( ) const

Type cast to a string consisting of space-separated values from m_nMatching.

Returns
String describing this matching.

Definition at line 172 of file Matching.cpp.

◆ operator[]() [1/2]

size_t & CMatching::operator[] ( const size_t  i)

Index operator, used to access members of m_nMatching as an L-value.

Parameters
iIndex.
Returns
Reference to the indexed element of the matching.

Definition at line 185 of file Matching.cpp.

◆ operator[]() [2/2]

const size_t CMatching::operator[] ( const size_t  i) const

Index operator, used to access members of m_nMatching as an R-value.

Parameters
iIndex.
Returns
The indexed element of the matching.

Definition at line 193 of file Matching.cpp.

◆ Swap()

void CMatching::Swap ( const size_t  i,
const size_t  j 
)

Swap two pairs of entries in the m_nMatching and m_nMap arrays.

Parameters
iIndex of first pair.
jIndex of second pair.

Definition at line 148 of file Matching.cpp.

◆ SwapPair()

void CMatching::SwapPair ( int  m[],
size_t  i,
size_t  j 
)
private

Swap a pair of entries in an array.

Parameters
mAn array.
iThe first index.
jThe second index.

Definition at line 99 of file Matching.cpp.

Member Data Documentation

◆ m_nMap

size_t CMatching::m_nMap[MAXINPUTS+1] = {0}
private

Definition at line 42 of file Matching.h.

◆ m_nMatching

size_t CMatching::m_nMatching[MAXINPUTS+1] = {0}
private

Definition at line 41 of file Matching.h.

◆ m_nStack

int CMatching::m_nStack[MAXINPUTS+1] = {0}
private

Definition at line 43 of file Matching.h.