--- queensgui/src/solutionhash.cpp 2007/07/19 22:26:42 2 +++ queensgui/src/containerhash.cpp 2007/07/25 19:39:37 15 @@ -17,12 +17,13 @@ * Free Software Foundation, Inc., * * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * ***************************************************************************/ -#include "solutionhash.h" +#include "containerhash.h" -SolutionHash::SolutionHash(GUIUpdate* update) + +ContainerHash::ContainerHash(GUIUpdate* update) : SolutionContainer(update) { - total = -1; + total = 0; m_size = 0; m_hashroof = max_size; for (int i=0; i< max_size; i++) @@ -31,11 +32,15 @@ } -SolutionHash::~SolutionHash() +ContainerHash::~ContainerHash() { + for (int i=0; i1 ) { for (int bucket=0; bucket < m_hashroof; bucket++) { @@ -62,18 +67,10 @@ } } for (int i=0; i< (m_hashroof/2); i++) { - //int base = i*2; int base2 = (m_hashroof/2)+i; - /*if (i!=0) { - solutions[i] = solutions[base]; - } ListIt p = solutions[i]->end(); - solutions[i]->splice(p, *solutions[base+1] ); - */ - - ListIt p = solutions[i]->end(); solutions[i]->splice(p, *solutions[base2]); } m_hashroof /= 2; @@ -88,7 +85,7 @@ -void SolutionHash::uniqueSolutionsWorker(int bucket, int rot,bool mirror) +void ContainerHash::uniqueSolutionsWorker(int bucket, int rot,bool mirror) { int match_count; @@ -101,7 +98,9 @@ if (m_halt) return; match_count = 0; - Solution* tmp = (*i)->copy(); + + std::auto_ptr tmp( (*i).get()->copy() ); + if (mirror) tmp->mirror(); for (int k=0;kend();j++) { - if ( *tmp == *(*j) ) { + for ( ; j!=solutions[bucket]->end();j++) + { + if ( *tmp == *(*j) ) + { solutions[bucket]->erase(j); break; } @@ -119,45 +120,16 @@ } } - -/* BACKUP -void SolutionHash::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;kpush_back(sol); + solutions[hash]->push_back( boost::shared_ptr(sol) ); m_size++; + total++; + } -Solution* SolutionHash::solution(int index) +Solution* ContainerHash::solution(int index) { int count=0; ListIt it; @@ -166,6 +138,6 @@ break; } } - return *it; + return (*it).get(); }