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 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 }
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
171 {
172 return m_HashMap.end();
173 }
174
176 // void PrintHashTable();
177
178protected:
179 EquivalencyTable() = default;
180 ~EquivalencyTable() override = default;
181 void
182 PrintSelf(std::ostream & os, Indent indent) const override;
183
184 HashTableType m_HashMap{};
185};
186} // end namespace itk
187
188#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