17 |
* Free Software Foundation, Inc., * |
* Free Software Foundation, Inc., * |
18 |
* 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * |
* 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * |
19 |
***************************************************************************/ |
***************************************************************************/ |
20 |
#include "solutionhash.h" |
#include "containerhash.h" |
21 |
|
|
22 |
SolutionHash::SolutionHash(GUIUpdate* update) |
ContainerHash::ContainerHash(GUIUpdate* update) |
23 |
: SolutionContainer(update) |
: SolutionContainer(update) |
24 |
{ |
{ |
25 |
total = -1; |
total = -1; |
31 |
} |
} |
32 |
|
|
33 |
|
|
34 |
SolutionHash::~SolutionHash() |
ContainerHash::~ContainerHash() |
35 |
{ |
{ |
36 |
} |
} |
37 |
|
|
38 |
int SolutionHash::numSolutions() |
int ContainerHash::numSolutions() |
39 |
{ |
{ |
40 |
int size = 0; |
int size = 0; |
41 |
for (int i=0; i<m_hashroof; i++) { |
for (int i=0; i<m_hashroof; i++) { |
44 |
return size; |
return size; |
45 |
} |
} |
46 |
|
|
47 |
int SolutionHash::totalSolutions() |
int ContainerHash::totalSolutions() |
48 |
{ |
{ |
49 |
return total; |
return total; |
50 |
} |
} |
51 |
|
|
52 |
|
|
53 |
void SolutionHash::uniqueSolutions() |
void ContainerHash::uniqueSolutions() |
54 |
{ |
{ |
55 |
while (m_hashroof >1 ) { |
while (m_hashroof >1 ) { |
56 |
for (int bucket=0; bucket < m_hashroof; bucket++) { |
for (int bucket=0; bucket < m_hashroof; bucket++) { |
88 |
|
|
89 |
|
|
90 |
|
|
91 |
void SolutionHash::uniqueSolutionsWorker(int bucket, int rot,bool mirror) |
void ContainerHash::uniqueSolutionsWorker(int bucket, int rot,bool mirror) |
92 |
{ |
{ |
93 |
int match_count; |
int match_count; |
94 |
|
|
101 |
if (m_halt) |
if (m_halt) |
102 |
return; |
return; |
103 |
match_count = 0; |
match_count = 0; |
104 |
Solution tmp(*i); |
Solution* tmp = (*i)->copy(); |
105 |
if (mirror) |
if (mirror) |
106 |
tmp.mirror(); |
tmp->mirror(); |
107 |
for (int k=0;k<rot;k++) |
for (int k=0;k<rot;k++) |
108 |
tmp.rotate90(); |
tmp->rotate90(); |
109 |
|
|
110 |
//unders�g kun resten af m�ngden, start ved i+1 |
//unders�g kun resten af m�ngden, start ved i+1 |
111 |
ListIt j =i; |
ListIt j =i; |
112 |
j++; |
j++; |
113 |
for ( ; j!=solutions[bucket]->end();j++) { |
for ( ; j!=solutions[bucket]->end();j++) { |
114 |
if ( tmp == (*j) ) { |
if ( *tmp == *(*j) ) { |
115 |
solutions[bucket]->erase(j); |
solutions[bucket]->erase(j); |
116 |
break; |
break; |
117 |
} |
} |
121 |
|
|
122 |
|
|
123 |
/* BACKUP |
/* BACKUP |
124 |
void SolutionHash::uniqueSolutionsWorker(int rot,bool mirror) |
void ContainerHash::uniqueSolutionsWorker(int rot,bool mirror) |
125 |
{ |
{ |
126 |
int match_count; |
int match_count; |
127 |
|
|
150 |
} |
} |
151 |
*/ |
*/ |
152 |
|
|
153 |
void SolutionHash::addSolution(Solution sol) |
void ContainerHash::addSolution(Solution* sol) |
154 |
{ |
{ |
155 |
int hash = m_size % max_size; |
int hash = m_size % max_size; |
156 |
solutions[hash]->push_back(sol); |
solutions[hash]->push_back(sol); |
157 |
m_size++; |
m_size++; |
158 |
} |
} |
159 |
|
|
160 |
Solution SolutionHash::solution(int index) |
Solution* ContainerHash::solution(int index) |
161 |
{ |
{ |
162 |
int count=0; |
int count=0; |
163 |
Solution returndata; |
ListIt it; |
164 |
for (ListIt it = solutions[0]->begin(); it != solutions[0]->end(); it++, count++) { |
for (it = solutions[0]->begin(); it != solutions[0]->end(); it++, count++) { |
165 |
if (count == index) { |
if (count == index) { |
166 |
returndata = *it ; |
break; |
167 |
break; |
} |
|
} |
|
168 |
} |
} |
169 |
return returndata; |
return *it; |
170 |
} |
} |
171 |
|
|