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
25namespace itk
26{
44class ITKCommon_EXPORT EquivalencyTable : public DataObject
45{
46public:
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
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
166 {
167 return m_HashMap.end();
168 }
169
171 // void PrintHashTable();
172
173protected:
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
Base class for all data objects in ITK.
Hash table to manage integral label equivalencies.
unsigned long RecursiveLookup(const unsigned long a) const
void PrintSelf(std::ostream &os, Indent indent) const override
EquivalencyTable()=default
unsigned long Lookup(const unsigned long a) const
HashTableType::size_type Size() const
bool Add(unsigned long a, unsigned long b)
HashTableType::value_type ValueType
bool AddAndFlatten(unsigned long a, unsigned long b)
HashTableType::iterator Iterator
bool IsEntry(const unsigned long a) const
~EquivalencyTable() override=default
HashTableType::const_iterator ConstIterator
std::unordered_map< unsigned long, unsigned long, std::hash< unsigned long > > HashTableType
void Erase(const unsigned long a)
Control indentation during Print() invocation.
Definition: itkIndent.h:50
Base class for most ITK classes.
Definition: itkObject.h:62
The "itk" namespace contains all Insight Segmentation and Registration Toolkit (ITK) classes....
class ITK_FORWARD_EXPORT DataObject
Definition: itkDataObject.h:42