KWStyle - itkOneWayEquivalencyTable.cxx
 
Matrix View
Description

1 /*=========================================================================
2
3   Program:   Insight Segmentation & Registration Toolkit
4   Module:    $RCSfile: itkOneWayEquivalencyTable.cxx.html,v $
5   Language:  C++
6   Date:      $Date: 2006/01/17 19:15:43 $
7   Version:   $Revision: 1.4 $
8
9   Copyright (c) Insight Software Consortium. All rights reserved.
10   See ITKCopyright.txt or http://www.itk.org/HTML/Copyright.htm for details.
11
12      This software is distributed WITHOUT ANY WARRANTY; without even 
13      the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR 
14      PURPOSE.  See the above copyright notices for more information.
15
16 DEF =========================================================================*/
17 #include "itkOneWayEquivalencyTable.h"
18
19 namespace itk
20 {
21   
22 bool OneWayEquivalencyTable::Add(unsigned long a, unsigned long b)
23 {
24   //
25   // Unlike EquivalencyTable, the order of the equivalence is important.
26   //
27   std::pair<Iterator, bool> result;
28   if (a == b) return false;
29   result = m_HashMap.insert( ValueType(a, b) );
30
31   return result.second;
32 }
33   
34 //void OneWayEquivalencyTable::PrintHashTable()
35 //{
36 IND //  ConstIterator it = this->Begin();
37 IND //  while (it != this->End() )
38 IND //    {
39 IND //      std::cout << (*it).first << " = " << (*it).second << std::endl;
40 //      it++;
41 //    }
42 //}
43
44 void OneWayEquivalencyTable::Flatten()
45 {
46   Iterator it = this->Begin();
47   while ( it != this->End() )
48     {
49     (*it).second = this->RecursiveLookup((*it).first);
50     it++;
51     }
52 }
53
54 unsigned long OneWayEquivalencyTable::RecursiveLookup(const unsigned a) const
55 {
56   unsigned long ans = a;
57   unsigned long last_ans=a;
58
59   ConstIterator it;
60   ConstIterator hashEnd = m_HashMap.end();
61   while ( (it = m_HashMap.find(ans)) != hashEnd )
62     {
63     ans = (*it).second;
64     if (ans == a ) return last_ans; // about to cycle again.
65     last_ans = ans;
66     }
67
68   return ans;
69 }
70
71 void 
72 OneWayEquivalencyTable
73 ::PrintSelf(std::ostream& os, Indent indent) const
74 {
75   Superclass::PrintSelf(os,indent);
76 }
77
78 }// end namespace itk
79

Generated by KWStyle 1.0b on Tuesday January,17 at 02:14:37PM
© Kitware Inc.