/*************************************************************************** * Copyright (C) 2005 by Torben Nielsen * * torben@t-hoerup.dk * * * * This program is free software; you can redistribute it and/or modify * * it under the terms of the GNU General Public License as published by * * the Free Software Foundation; either version 2 of the License, or * * (at your option) any later version. * * * * This program is distributed in the hope that it will be useful, * * but WITHOUT ANY WARRANTY; without even the implied warranty of * * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * * GNU General Public License for more details. * * * * You should have received a copy of the GNU General Public License * * along with this program; if not, write to the * * Free Software Foundation, Inc., * * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * ***************************************************************************/ #include "solutionhash.h" SolutionHash::SolutionHash(GUIUpdate* update) : SolutionContainer(update) { total = -1; m_size = 0; m_hashroof = max_size; for (int i=0; i< max_size; i++) solutions[i] = new SolList(); } SolutionHash::~SolutionHash() { } int SolutionHash::numSolutions() { int size = 0; for (int i=0; isize(); } return size; } int SolutionHash::totalSolutions() { return total; } void SolutionHash::uniqueSolutions() { while (m_hashroof >1 ) { for (int bucket=0; bucket < m_hashroof; bucket++) { for (int i=1;i<=4;i++) { if (m_halt) return; uniqueSolutionsWorker(bucket, i,false); uniqueSolutionsWorker(bucket, i,true); } } 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; } for (int i=1;i<=4;i++) { uniqueSolutionsWorker(0, i, false); uniqueSolutionsWorker(0, i, true); } } void SolutionHash::uniqueSolutionsWorker(int bucket, int rot,bool mirror) { int match_count; if (solutions[bucket]->size() == 0) return; if (total == -1) total = solutions[bucket]->size(); for (ListIt i=solutions[bucket]->begin(); i != solutions[bucket]->end(); i++) { if (m_halt) return; match_count = 0; Solution tmp(*i); if (mirror) tmp.mirror(); for (int k=0;kend();j++) { if ( tmp == (*j) ) { solutions[bucket]->erase(j); break; } } } } /* 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); m_size++; } Solution SolutionHash::solution(int index) { int count=0; Solution returndata; for (ListIt it = solutions[0]->begin(); it != solutions[0]->end(); it++, count++) { if (count == index) { returndata = *it ; break; } } return returndata; }