ITK  6.0.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  * https://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  itkOverrideGetNameOfClassMacro(EquivalencyTable);
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 
103  return result->second;
104  }
105 
110  unsigned long
111  RecursiveLookup(const unsigned long a) const;
112 
115  bool
116  IsEntry(const unsigned long a) const
117  {
118  if (m_HashMap.find(a) == m_HashMap.end())
119  {
120  return false;
121  }
122 
123  return true;
124  }
125 
127  void
128  Erase(const unsigned long a)
129  {
130  m_HashMap.erase(a);
131  }
132 
134  void
136  {
137  m_HashMap.clear();
138  }
139 
141  bool
142  Empty() const
143  {
144  return m_HashMap.empty();
145  }
146 
148  HashTableType::size_type
149  Size() const
150  {
151  return m_HashMap.size();
152  }
153 
156  Iterator
158  {
159  return m_HashMap.begin();
160  }
161 
164  Iterator
165  End()
166  {
167  return m_HashMap.end();
168  }
169 
171  // void PrintHashTable();
172 
173 protected:
174  EquivalencyTable() = default;
175  ~EquivalencyTable() override = default;
176  void
177  PrintSelf(std::ostream & os, Indent indent) const override;
178 
179  HashTableType m_HashMap{};
180 };
181 } // end namespace itk
182 
183 #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:157
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:128
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:142
itk::EquivalencyTable::Clear
void Clear()
Definition: itkEquivalencyTable.h:135
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:116
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: itkAnatomicalOrientation.h:29
itk::EquivalencyTable::End
Iterator End()
Definition: itkEquivalencyTable.h:165
itk::Object
Base class for most ITK classes.
Definition: itkObject.h:61
itk::EquivalencyTable::Size
HashTableType::size_type Size() const
Definition: itkEquivalencyTable.h:149
itk::DataObject
Base class for all data objects in ITK.
Definition: itkDataObject.h:293