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
97 return result->second;
98 }
99
104 unsigned long
105 RecursiveLookup(const unsigned long a) const;
106
109 bool
110 IsEntry(const unsigned long a) const
111 {
112 if (m_HashMap.find(a) == m_HashMap.end())
113 {
114 return false;
115 }
116
117 return true;
118 }
119
121 void
122 Erase(const unsigned long a)
123 {
124 m_HashMap.erase(a);
125 }
126
128 void
130 {
131 m_HashMap.clear();
132 }
133
135 bool
136 Empty() const
137 {
138 return m_HashMap.empty();
139 }
140
143 Iterator
145 {
146 return m_HashMap.begin();
147 }
148
151 Iterator
153 {
154 return m_HashMap.end();
155 }
156
158 // void PrintHashTable();
159
160protected:
162 ~OneWayEquivalencyTable() override = default;
163 void
164 PrintSelf(std::ostream & os, Indent indent) const override;
165
166 HashTableType m_HashMap{};
167};
168} // end namespace itk
169
170#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