ITK  4.4.0
Insight Segmentation and Registration Toolkit
itkEquivalencyTable.h
Go to the documentation of this file.
1 /*=========================================================================
2  *
3  * Copyright Insight Software Consortium
4  *
5  * Licensed under the Apache License, Version 2.0 (the "License");
6  * you may not use this file except in compliance with the License.
7  * You may obtain a copy of the License at
8  *
9  * http://www.apache.org/licenses/LICENSE-2.0.txt
10  *
11  * Unless required by applicable law or agreed to in writing, software
12  * distributed under the License is distributed on an "AS IS" BASIS,
13  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14  * See the License for the specific language governing permissions and
15  * limitations under the License.
16  *
17  *=========================================================================*/
18 #ifndef __itkEquivalencyTable_h
19 #define __itkEquivalencyTable_h
20 
21 
22 #include "itkProcessObject.h"
23 #include "itksys/hash_map.hxx"
24 
25 namespace itk
26 {
44 class ITKCommon_EXPORT EquivalencyTable:public DataObject
45 {
46 public:
52  itkNewMacro(Self);
53  itkTypeMacro(EquivalencyTable, DataObject);
55 
57  typedef itksys::hash_map< unsigned long, unsigned long,
58  itksys::hash< unsigned long > > HashTableType;
59 
60  typedef HashTableType::iterator Iterator;
61  typedef HashTableType::const_iterator ConstIterator;
62  typedef HashTableType::value_type ValueType;
63 
67  void Flatten();
68 
75  bool Add(unsigned long a, unsigned long b);
76 
84  bool AddAndFlatten(unsigned long a, unsigned long b);
85 
89  unsigned long Lookup(const unsigned long a) const
90  {
91  ConstIterator result = m_HashMap.find(a);
92 
93  if ( result == m_HashMap.end() ) { return a; }
94  else { return ( *result ).second; }
95  }
96 
101  unsigned long RecursiveLookup(const unsigned long a) const;
102 
105  bool IsEntry(const unsigned long a) const
106  {
107  if ( m_HashMap.find(a) == m_HashMap.end() ) { return false; }
108  else { return true; }
109  }
111 
113  void Erase(const unsigned long a)
114  { m_HashMap.erase(a); }
115 
117  void Clear()
118  { m_HashMap.clear(); }
119 
121  bool Empty() const
122  { return m_HashMap.empty(); }
123 
125  HashTableType::size_type Size() const
126  { return m_HashMap.size(); }
127 
130  Iterator Begin() { return m_HashMap.begin(); }
131 
134  Iterator End() { return m_HashMap.end(); }
135 
137  // void PrintHashTable();
138 
139 protected:
141  virtual ~EquivalencyTable() {}
142  EquivalencyTable(const Self &); // purposely not implemented
143  void operator=(const Self &); // purposely not implemented
144 
145  void PrintSelf(std::ostream & os, Indent indent) const;
146 
148 };
149 } // end namespace itk
150 
151 #endif
152