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

Diff of /queensgui/src/containerhash.cpp

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

revision 5 by torben, Thu Jul 19 23:44:01 2007 UTC revision 6 by torben, Fri Jul 20 09:54:09 2007 UTC
# Line 19  Line 19 
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  {  {
# Line 33  ContainerHash::ContainerHash(GUIUpdate* Line 34  ContainerHash::ContainerHash(GUIUpdate*
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()
# Line 62  void ContainerHash::uniqueSolutions() Line 67  void ContainerHash::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 101  void ContainerHash::uniqueSolutionsWorke Line 98  void ContainerHash::uniqueSolutionsWorke
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++)
# Line 110  void ContainerHash::uniqueSolutionsWorke Line 109  void ContainerHash::uniqueSolutionsWorke
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 ContainerHash::uniqueSolutionsWorke Line 120  void ContainerHash::uniqueSolutionsWorke
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    
129  }  }
130    
131  Solution* ContainerHash::solution(int index)  Solution* ContainerHash::solution(int index)
# Line 166  Solution* ContainerHash::solution(int in Line 137  Solution* ContainerHash::solution(int in
137                  break;                  break;
138                  }                  }
139      }      }
140      return *it;      return (*it).get();
141  }  }
142    

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

  ViewVC Help
Powered by ViewVC 1.1.20