ITK  5.2.0
Insight Toolkit
itkEquivalencyTable.h
Go to the documentation of this file.
1 /*=========================================================================
2  *
3  * Copyright NumFOCUS
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 <unordered_map>
24 
25 namespace itk
26 {
44 class ITKCommon_EXPORT EquivalencyTable : public DataObject
45 {
46 public:
47  ITK_DISALLOW_COPY_AND_MOVE(EquivalencyTable);
48 
54  itkNewMacro(Self);
55  itkTypeMacro(EquivalencyTable, DataObject);
57 
59  using HashTableType = std::unordered_map<unsigned long, unsigned long, std::hash<unsigned long>>;
60 
61  using Iterator = HashTableType::iterator;
62  using ConstIterator = HashTableType::const_iterator;
63  using ValueType = HashTableType::value_type;
64 
68  void
69  Flatten();
70 
77  bool
78  Add(unsigned long a, unsigned long b);
79 
87  bool
88  AddAndFlatten(unsigned long a, unsigned long b);
89 
93  unsigned long
94  Lookup(const unsigned long a) const
95  {
96  auto result = m_HashMap.find(a);
97 
98  if (result == m_HashMap.end())
99  {
100  return a;
101  }
102  else
103  {
104  return (*result).second;
105  }
106  }
107 
112  unsigned long
113  RecursiveLookup(const unsigned long a) const;
114 
117  bool
118  IsEntry(const unsigned long a) const
119  {
120  if (m_HashMap.find(a) == m_HashMap.end())
121  {
122  return false;
123  }
124  else
125  {
126  return true;
127  }
128  }
130 
132  void
133  Erase(const unsigned long a)
134  {
135  m_HashMap.erase(a);
136  }
137 
139  void
141  {
142  m_HashMap.clear();
143  }
144 
146  bool
147  Empty() const
148  {
149  return m_HashMap.empty();
150  }
151 
153  HashTableType::size_type
154  Size() const
155  {
156  return m_HashMap.size();
157  }
158 
161  Iterator
163  {
164  return m_HashMap.begin();
165  }
166 
169  Iterator
170  End()
171  {
172  return m_HashMap.end();
173  }
174 
176  // void PrintHashTable();
177 
178 protected:
179  EquivalencyTable() = default;
180  ~EquivalencyTable() override = default;
181  void
182  PrintSelf(std::ostream & os, Indent indent) const override;
183 
185 };
186 } // end namespace itk
187 
188 #endif
itk::EquivalencyTable
Hash table to manage integral label equivalencies.
Definition: itkEquivalencyTable.h:44
itk::EquivalencyTable::ConstIterator
HashTableType::const_iterator ConstIterator
Definition: itkEquivalencyTable.h:62
itk::EquivalencyTable::Begin
Iterator Begin()
Definition: itkEquivalencyTable.h:162
itk::SmartPointer< Self >
itk::Indent
Control indentation during Print() invocation.
Definition: itkIndent.h:49
itk::EquivalencyTable::Erase
void Erase(const unsigned long a)
Definition: itkEquivalencyTable.h:133
itk::EquivalencyTable::HashTableType
std::unordered_map< unsigned long, unsigned long, std::hash< unsigned long > > HashTableType
Definition: itkEquivalencyTable.h:59
itk::EquivalencyTable::Empty
bool Empty() const
Definition: itkEquivalencyTable.h:147
itk::EquivalencyTable::Clear
void Clear()
Definition: itkEquivalencyTable.h:140
itk::EquivalencyTable::Iterator
HashTableType::iterator Iterator
Definition: itkEquivalencyTable.h:61
itkProcessObject.h
itk::EquivalencyTable::Lookup
unsigned long Lookup(const unsigned long a) const
Definition: itkEquivalencyTable.h:94
itk::DataObject
class ITK_FORWARD_EXPORT DataObject
Definition: itkDataObject.h:42
itk::EquivalencyTable::IsEntry
bool IsEntry(const unsigned long a) const
Definition: itkEquivalencyTable.h:118
itk::EquivalencyTable::ValueType
HashTableType::value_type ValueType
Definition: itkEquivalencyTable.h:63
itk
The "itk" namespace contains all Insight Segmentation and Registration Toolkit (ITK) classes....
Definition: itkAnnulusOperator.h:24
itk::EquivalencyTable::End
Iterator End()
Definition: itkEquivalencyTable.h:170
itk::Object
Base class for most ITK classes.
Definition: itkObject.h:62
itk::EquivalencyTable::m_HashMap
HashTableType m_HashMap
Definition: itkEquivalencyTable.h:184
itk::EquivalencyTable::Size
HashTableType::size_type Size() const
Definition: itkEquivalencyTable.h:154
itk::DataObject
Base class for all data objects in ITK.
Definition: itkDataObject.h:293