Sorting Network Search
Backtracking for Small Sorting Networks
Searchable.h
Go to the documentation of this file.
1
3
4// MIT License
5//
6// Copyright (c) 2023 Ian Parberry
7//
8// Permission is hereby granted, free of charge, to any person obtaining a copy
9// of this software and associated documentation files (the "Software"), to
10// deal in the Software without restriction, including without limitation the
11// rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
12// sell copies of the Software, and to permit persons to whom the Software is
13// furnished to do so, subject to the following conditions:
14//
15// The above copyright notice and this permission notice shall be included in
16// all copies or substantial portions of the Software.
17//
18// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
19// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
20// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
21// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
22// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
23// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
24// IN THE SOFTWARE.
25
26#ifndef __Searchable_h__
27#define __Searchable_h__
28
29#include "1NF.h"
30
31#include "Defines.h"
32#include "Matching.h"
33
38
39class CSearchable: public C1NF{
40 protected:
41 size_t m_nCount = 0;
42
44
45 int m_nStack[MAXDEPTH] = {0};
46 int m_nToS = 0;
47
48 size_t m_nNumMatchings = 0;
49 size_t m_nTop = 0;
50
51 void FirstComparatorNetwork(size_t);
53 void SynchMatchingRepresentations(size_t);
54 void InitMatchingRepresentations(size_t);
55
56 virtual void Save();
57 virtual void SetToS();
58 virtual void Process();
59
60 void Search();
61
62 public:
63 CSearchable();
64
65 virtual void Backtrack();
66
67 const size_t GetCount() const;
68}; //CSearchable
69
70#endif //__Searchable_h__
Interface for the first normal form sorting network C1NF.
Useful definitions.
#define MAXDEPTH
Maximum depth.
Definition: Defines.h:30
Interface for the matching CMatching.
Sorting network in first normal form.
Definition: 1NF.h:62
Perfect matching.
Definition: Matching.h:39
Searchable sorting network.
Definition: Searchable.h:39
size_t m_nTop
Topmost level.
Definition: Searchable.h:49
size_t m_nCount
Number of comparator networks found that sort.
Definition: Searchable.h:41
size_t m_nNumMatchings
Number of matchings of this size.
Definition: Searchable.h:48
virtual void Backtrack()
Backtracking search.
Definition: Searchable.cpp:82
void InitMatchingRepresentations(size_t)
Initialize the two different matching representations.
Definition: Searchable.cpp:120
CSearchable()
Constructor.
Definition: Searchable.cpp:30
virtual void Save()
Save comparator network.
Definition: Searchable.cpp:42
virtual void SetToS()
Set top of stack.
Definition: Searchable.cpp:53
int m_nStack[MAXDEPTH]
Stack to remove recursion from search.
Definition: Searchable.h:45
CMatching m_cMatching[MAXDEPTH]
Matchings that make up comparator network in a form that makes searching faster.
Definition: Searchable.h:43
virtual void Process()
Process a candidate comparator network.
Definition: Searchable.cpp:60
bool NextComparatorNetwork()
Change to next comparator network.
Definition: Searchable.cpp:135
void SynchMatchingRepresentations(size_t)
Synchronize the two different matching representations.
Definition: Searchable.cpp:102
int m_nToS
Top of stack.
Definition: Searchable.h:46
void FirstComparatorNetwork(size_t)
Set to first comparator network.
Definition: Searchable.cpp:91
void Search()
Do the actual search.
Definition: Searchable.cpp:70
const size_t GetCount() const
Get count.
Definition: Searchable.cpp:160