/[projects]/queensgui/src/containerhash.cpp
ViewVC logotype

Diff of /queensgui/src/containerhash.cpp

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

queensgui/src/solutionhash.cpp revision 1 by torben, Thu Jul 19 21:34:15 2007 UTC queensgui/src/containerhash.cpp revision 6 by torben, Fri Jul 20 09:54:09 2007 UTC
# Line 17  Line 17 
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)  
23    ContainerHash::ContainerHash(GUIUpdate* update)
24    : SolutionContainer(update)    : SolutionContainer(update)
25  {  {
26      total = -1;      total = -1;
# Line 31  SolutionHash::SolutionHash(GUIUpdate* up Line 32  SolutionHash::SolutionHash(GUIUpdate* up
32  }  }
33    
34    
35  SolutionHash::~SolutionHash()  ContainerHash::~ContainerHash()
36  {  {
37            for (int i=0; i<max_size; i++)
38            {
39                    delete solutions[i];
40            }
41  }  }
42    
43  int SolutionHash::numSolutions()  int ContainerHash::numSolutions()
44  {  {
45          int size = 0;          int size = 0;
46          for (int i=0; i<m_hashroof; i++) {          for (int i=0; i<m_hashroof; i++) {
# Line 44  int SolutionHash::numSolutions() Line 49  int SolutionHash::numSolutions()
49          return size;          return size;
50  }  }
51    
52  int SolutionHash::totalSolutions()  int ContainerHash::totalSolutions()
53  {  {
54          return total;          return total;
55  }  }
56    
57    
58  void SolutionHash::uniqueSolutions()  void ContainerHash::uniqueSolutions()
59  {  {
60          while (m_hashroof >1 ) {          while (m_hashroof >1 ) {
61                  for (int bucket=0; bucket < m_hashroof; bucket++) {                  for (int bucket=0; bucket < m_hashroof; bucket++) {
# Line 62  void SolutionHash::uniqueSolutions() Line 67  void SolutionHash::uniqueSolutions()
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;
# Line 88  void SolutionHash::uniqueSolutions() Line 85  void SolutionHash::uniqueSolutions()
85    
86    
87    
88  void SolutionHash::uniqueSolutionsWorker(int bucket, int rot,bool mirror)  void ContainerHash::uniqueSolutionsWorker(int bucket, int rot,bool mirror)
89  {  {
90          int match_count;          int match_count;
91    
# Line 101  void SolutionHash::uniqueSolutionsWorker Line 98  void SolutionHash::uniqueSolutionsWorker
98                  if (m_halt)                  if (m_halt)
99                          return;                          return;
100                  match_count = 0;                  match_count = 0;
101                  Solution tmp(*i);                  
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++)
107                          tmp.rotate90();                          tmp->rotate90();
108    
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                          }                          }
# Line 119  void SolutionHash::uniqueSolutionsWorker Line 120  void SolutionHash::uniqueSolutionsWorker
120          }          }
121  }  }
122    
123    void ContainerHash::addSolution(Solution* sol)
 /* 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;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;  
                         }  
                 }  
         }  
 }  
 */  
   
 void SolutionHash::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    
129  }  }
130    
131  Solution SolutionHash::solution(int index)  Solution* ContainerHash::solution(int index)
132  {  {
133      int count=0;      int count=0;
134      Solution returndata;          ListIt it;
135      for (ListIt it = solutions[0]->begin(); it != solutions[0]->end(); it++, count++) {      for (it = solutions[0]->begin(); it != solutions[0]->end(); it++, count++) {
136          if (count == index) {          if (count == index) {
137              returndata =  *it ;                  break;
138              break;                  }
         }  
139      }      }
140      return returndata;      return (*it).get();
141  }  }
142    

Legend:
Removed from v.1  
changed lines
  Added in v.6

  ViewVC Help
Powered by ViewVC 1.1.20