ITK  6.0.0
Insight Toolkit
itkOneWayEquivalencyTable.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 itkOneWayEquivalencyTable_h
19#define itkOneWayEquivalencyTable_h
20
21
22#include "itkProcessObject.h"
23#include <unordered_map>
24#include "ITKWatershedsExport.h"
25
26namespace itk
27{
47class ITKWatersheds_EXPORT OneWayEquivalencyTable : public DataObject
48{
49public:
50 ITK_DISALLOW_COPY_AND_MOVE(OneWayEquivalencyTable);
51
57 itkNewMacro(Self);
58 itkOverrideGetNameOfClassMacro(OneWayEquivalencyTable);
62 using HashTableType = std::unordered_map<unsigned long, unsigned long>;
63
64 using Iterator = HashTableType::iterator;
65 using ConstIterator = HashTableType::const_iterator;
66 using ValueType = HashTableType::value_type;
67
71 void
73
81 bool
82 Add(unsigned long a, unsigned long b);
83
87 unsigned long
88 Lookup(const unsigned long a) const
89 {
90 auto result = m_HashMap.find(a);
91
92 if (result == m_HashMap.end())
93 {
94 return a;
95 }
96 else
97 {
98 return result->second;
99 }
100 }
101
106 unsigned long
107 RecursiveLookup(const unsigned long a) const;
108
111 bool
112 IsEntry(const unsigned long a) const
113 {
114 if (m_HashMap.find(a) == m_HashMap.end())
115 {
116 return false;
117 }
118 else
119 {
120 return true;
121 }
122 }
126 void
127 Erase(const unsigned long a)
128 {
129 m_HashMap.erase(a);
130 }
131
133 void
135 {
136 m_HashMap.clear();
137 }
138
140 bool
141 Empty() const
142 {
143 return m_HashMap.empty();
144 }
145
148 Iterator
150 {
151 return m_HashMap.begin();
152 }
153
156 Iterator
158 {
159 return m_HashMap.end();
160 }
161
163 // void PrintHashTable();
164
165protected:
167 ~OneWayEquivalencyTable() override = default;
168 void
169 PrintSelf(std::ostream & os, Indent indent) const override;
170
171 HashTableType m_HashMap{};
172};
173} // end namespace itk
174
175#endif
Base class for all data objects in ITK.
Control indentation during Print() invocation.
Definition: itkIndent.h:50
Base class for most ITK classes.
Definition: itkObject.h:62
Hash table to manage integral label equivalencies that are order dependent.
~OneWayEquivalencyTable() override=default
unsigned long Lookup(const unsigned long a) const
bool IsEntry(const unsigned long a) const
std::unordered_map< unsigned long, unsigned long > HashTableType
HashTableType::value_type ValueType
void PrintSelf(std::ostream &os, Indent indent) const override
bool Add(unsigned long a, unsigned long b)
HashTableType::const_iterator ConstIterator
unsigned long RecursiveLookup(const unsigned long a) const
void Erase(const unsigned long a)
The "itk" namespace contains all Insight Segmentation and Registration Toolkit (ITK) classes....
class ITK_FORWARD_EXPORT DataObject
Definition: itkDataObject.h:42