19 |
***************************************************************************/ |
***************************************************************************/ |
20 |
#include "containerhash.h" |
#include "containerhash.h" |
21 |
|
|
22 |
|
|
23 |
ContainerHash::ContainerHash(GUIUpdate* update) |
ContainerHash::ContainerHash(GUIUpdate* update) |
24 |
: SolutionContainer(update) |
: SolutionContainer(update) |
25 |
{ |
{ |
26 |
total = -1; |
total = 0; |
27 |
m_size = 0; |
m_size = 0; |
28 |
m_hashroof = max_size; |
m_hashroof = max_size; |
29 |
for (int i=0; i< max_size; i++) |
for (int i=0; i< max_size; i++) |
34 |
|
|
35 |
ContainerHash::~ContainerHash() |
ContainerHash::~ContainerHash() |
36 |
{ |
{ |
37 |
|
for (int i=0; i<max_size; i++) |
38 |
|
{ |
39 |
|
delete solutions[i]; |
40 |
|
} |
41 |
} |
} |
42 |
|
|
43 |
int ContainerHash::numSolutions() |
int ContainerHash::numSolutions() |
67 |
} |
} |
68 |
} |
} |
69 |
for (int i=0; i< (m_hashroof/2); i++) { |
for (int i=0; i< (m_hashroof/2); i++) { |
|
//int base = i*2; |
|
70 |
int base2 = (m_hashroof/2)+i; |
int base2 = (m_hashroof/2)+i; |
71 |
|
|
|
/*if (i!=0) { |
|
|
solutions[i] = solutions[base]; |
|
|
} |
|
72 |
|
|
73 |
ListIt p = solutions[i]->end(); |
ListIt p = solutions[i]->end(); |
|
solutions[i]->splice(p, *solutions[base+1] ); |
|
|
*/ |
|
|
|
|
|
ListIt p = solutions[i]->end(); |
|
74 |
solutions[i]->splice(p, *solutions[base2]); |
solutions[i]->splice(p, *solutions[base2]); |
75 |
} |
} |
76 |
m_hashroof /= 2; |
m_hashroof /= 2; |
98 |
if (m_halt) |
if (m_halt) |
99 |
return; |
return; |
100 |
match_count = 0; |
match_count = 0; |
101 |
Solution* tmp = (*i)->copy(); |
|
102 |
|
std::auto_ptr<Solution> tmp( (*i).get()->copy() ); |
103 |
|
|
104 |
if (mirror) |
if (mirror) |
105 |
tmp->mirror(); |
tmp->mirror(); |
106 |
for (int k=0;k<rot;k++) |
for (int k=0;k<rot;k++) |
109 |
//unders�g kun resten af m�ngden, start ved i+1 |
//unders�g kun resten af m�ngden, start ved i+1 |
110 |
ListIt j =i; |
ListIt j =i; |
111 |
j++; |
j++; |
112 |
for ( ; j!=solutions[bucket]->end();j++) { |
for ( ; j!=solutions[bucket]->end();j++) |
113 |
if ( *tmp == *(*j) ) { |
{ |
114 |
|
if ( *tmp == *(*j) ) |
115 |
|
{ |
116 |
solutions[bucket]->erase(j); |
solutions[bucket]->erase(j); |
117 |
break; |
break; |
118 |
} |
} |
120 |
} |
} |
121 |
} |
} |
122 |
|
|
|
|
|
|
/* BACKUP |
|
|
void ContainerHash::uniqueSolutionsWorker(int rot,bool mirror) |
|
|
{ |
|
|
int match_count; |
|
|
|
|
|
unique = true; |
|
|
if (total == -1) |
|
|
total = solutions.size(); |
|
|
|
|
|
for (ListIt i=solutions.begin(); i != solutions.end(); i++) { |
|
|
match_count = 0; |
|
|
Solution tmp(*i); |
|
|
if (mirror) |
|
|
tmp.mirror(); |
|
|
for (int k=0;k<rot;k++) |
|
|
tmp.rotate90(); |
|
|
|
|
|
//unders�g kun resten af m�ngden, start ved i+1 |
|
|
ListIt j =i; |
|
|
j++; |
|
|
for ( ; j!=solutions.end();j++) { |
|
|
if ( tmp == (*j) ) { |
|
|
solutions.erase(j); |
|
|
break; |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
*/ |
|
|
|
|
123 |
void ContainerHash::addSolution(Solution* sol) |
void ContainerHash::addSolution(Solution* sol) |
124 |
{ |
{ |
125 |
int hash = m_size % max_size; |
int hash = m_size % max_size; |
126 |
solutions[hash]->push_back(sol); |
solutions[hash]->push_back( boost::shared_ptr<Solution>(sol) ); |
127 |
m_size++; |
m_size++; |
128 |
|
total++; |
129 |
|
|
130 |
} |
} |
131 |
|
|
132 |
Solution* ContainerHash::solution(int index) |
Solution* ContainerHash::solution(int index) |
138 |
break; |
break; |
139 |
} |
} |
140 |
} |
} |
141 |
return *it; |
return (*it).get(); |
142 |
} |
} |
143 |
|
|