![]() |
Sorting Network Search
Backtracking for Small Sorting Networks
|
Searchable sorting network with nearsort. More...
#include <Nearsort.h>
Public Member Functions | |
CNearsort (CMatching &, const size_t) | |
Constructor. More... | |
![]() | |
CAutocomplete (CMatching &, const size_t) | |
Constructor. More... | |
![]() | |
C2NF (CMatching &, const size_t) | |
Constructor. More... | |
void | Backtrack () |
Backtracking search. More... | |
![]() | |
CSearchable () | |
Constructor. More... | |
virtual void | Backtrack () |
Backtracking search. More... | |
const size_t | GetCount () const |
Get count. More... | |
![]() | |
C1NF () | |
Constructor. More... | |
![]() | |
CSortingNetwork () | |
Constructor. More... | |
~CSortingNetwork () | |
Destructor. More... | |
![]() | |
CComparatorNetwork () | |
Constructor. More... | |
virtual | ~CComparatorNetwork () |
Destructor. More... | |
void | Save (const std::string &) |
Save to file. More... | |
Protected Member Functions | |
bool | StillNearsorts (const size_t) |
Does it still nearsort with this input change? More... | |
bool | EvenNearsorts () |
Does it nearly sort, even number of inputs? More... | |
bool | Nearsorts () |
Does it nearly sort? More... | |
void | Process () |
Process a candidate comparator network. More... | |
void | SetToS () |
Set top of stack. More... | |
![]() | |
void | SetToS () |
Set top of stack. More... | |
bool | StillSorts (const size_t) |
Does it still sort when a bit is changed? More... | |
void | Initialize () |
Initialize the sorting test. More... | |
void | initLastLevel () |
Initialize the last level of the comparator network. More... | |
bool | Sorts () |
Does it sort? More... | |
![]() | |
void | Save () |
Save comparator network. More... | |
![]() | |
void | FirstComparatorNetwork (size_t) |
Set to first comparator network. More... | |
bool | NextComparatorNetwork () |
Change to next comparator network. More... | |
void | SynchMatchingRepresentations (size_t) |
Synchronize the two different matching representations. More... | |
void | InitMatchingRepresentations (size_t) |
Initialize the two different matching representations. More... | |
virtual void | Save () |
Save comparator network. More... | |
virtual void | SetToS () |
Set top of stack. More... | |
virtual void | Process () |
Process a candidate comparator network. More... | |
void | Search () |
Do the actual search. More... | |
![]() | |
void | Initialize () |
Initialize the sorting test. More... | |
bool | Sorts () |
Does it sort all inputs? More... | |
bool | StillSorts (const size_t) |
Does it still sort when a bit is changed? More... | |
bool | EvenSorts () |
Does it sort if there are an odd number of inputs and we fix the value on the last channel? More... | |
![]() | |
virtual void | Initialize () |
Initialize the sorting test. More... | |
virtual bool | Sorts () |
Does it sort? More... | |
virtual bool | StillSorts (const size_t) |
Does it still sort when a bit is changed? More... | |
size_t | FlipInput (size_t, const size_t, const size_t) |
Recompute network values when a bit is changed. More... | |
void | InitValues (const size_t, const size_t) |
Initialize the network values to the all zero input. More... | |
Protected Attributes | |
bool | m_bReachableFrom [MAXINPUTS][MAXINPUTS] = {false} |
Reachable from. More... | |
int | m_nReachCountFrom [MAXINPUTS] = {0} |
Count of channels reachable from. More... | |
bool | m_bReachableTo [MAXINPUTS][MAXINPUTS] = {false} |
Reachable to. More... | |
int | m_nReachCountTo [MAXINPUTS] = {0} |
Count of channels reachable to. More... | |
bool | m_bReachable [MAXINPUTS][MAXINPUTS] = {false} |
Reachable from or to. More... | |
int | m_nReachCount [MAXINPUTS] = {0} |
Count of channels reachable from or to. More... | |
![]() | |
size_t | m_nLevel2Index = 0 |
Index of current level 2 candidate. More... | |
![]() | |
size_t | m_nCount = 0 |
Number of comparator networks found that sort. More... | |
CMatching | m_cMatching [MAXDEPTH] |
Matchings that make up comparator network in a form that makes searching faster. More... | |
int | m_nStack [MAXDEPTH] = {0} |
Stack to remove recursion from search. More... | |
int | m_nToS = 0 |
Top of stack. More... | |
size_t | m_nNumMatchings = 0 |
Number of matchings of this size. More... | |
size_t | m_nTop = 0 |
Topmost level. More... | |
![]() | |
CBinaryGrayCode * | m_pGrayCode = nullptr |
Gray code generator. More... | |
size_t | m_nValue [MAXDEPTH][MAXINPUTS] = {0} |
Values at each level when sorting. More... | |
size_t | m_nZeros = 0 |
Number of zeros in the input. More... | |
![]() | |
size_t | m_nComparator [MAXDEPTH][MAXINPUTS] = {0} |
Comparator array. More... | |
Additional Inherited Members | |
![]() | |
static void | SetWidth (const size_t) |
Set width. More... | |
static void | SetDepth (const size_t) |
Set depth. More... | |
![]() | |
static size_t | m_nWidth = 9 |
Comparator network width. More... | |
static size_t | m_nDepth = 6 |
Comparator network depth. More... | |
CNearsort
is a version of CAutocomplete
that uses the nearsort heuristic, which is based on reachability, to prune the second-last level.
Definition at line 38 of file Nearsort.h.
CNearsort::CNearsort | ( | CMatching & | L2Matching, |
const size_t | index | ||
) |
Constructor.
L2Matching | Level 2 matching. |
index | Lexicographic number of level 2 matching. |
Definition at line 33 of file Nearsort.cpp.
|
protected |
Check whether sorting network nearsorts all inputs.
Definition at line 40 of file Nearsort.cpp.
|
protected |
Check whether sorting network nearsorts all inputs. Works for both odd and even n.
Definition at line 58 of file Nearsort.cpp.
|
protectedvirtual |
Process a comparator network, which is pretty much the same as CSearchable::Process()
except that you stop one level early and prune if the network so far fails to nearsort all inputs. If it fails to nearsort, then it won't sort. Continue with those that nearsort because some of them might actually sort.
Reimplemented from CSearchable.
Reimplemented in CNearsort2.
Definition at line 134 of file Nearsort.cpp.
|
protectedvirtual |
Set top of stack m_nToS
to the third-last level of the sorting network.
Reimplemented from CAutocomplete.
Reimplemented in CNearsort2.
Definition at line 150 of file Nearsort.cpp.
|
protected |
Check whether sorting network nearsorts when the current input has channel flipped.
delta | Index of channel to flip. |
Definition at line 95 of file Nearsort.cpp.
Definition at line 46 of file Nearsort.h.
Definition at line 40 of file Nearsort.h.
Definition at line 43 of file Nearsort.h.
|
protected |
Definition at line 47 of file Nearsort.h.
|
protected |
Definition at line 41 of file Nearsort.h.
|
protected |
Definition at line 44 of file Nearsort.h.