ITK  5.2.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  * http://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 
26 namespace itk
27 {
47 class ITKWatersheds_EXPORT OneWayEquivalencyTable : public DataObject
48 {
49 public:
50  ITK_DISALLOW_COPY_AND_MOVE(OneWayEquivalencyTable);
51 
57  itkNewMacro(Self);
58  itkTypeMacro(OneWayEquivalencyTable, DataObject);
60 
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
72  Flatten();
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  }
124 
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
157  End()
158  {
159  return m_HashMap.end();
160  }
161 
163  // void PrintHashTable();
164 
165 protected:
166  OneWayEquivalencyTable() = default;
167  ~OneWayEquivalencyTable() override = default;
168  void
169  PrintSelf(std::ostream & os, Indent indent) const override;
170 
172 };
173 } // end namespace itk
174 
175 #endif
itk::OneWayEquivalencyTable
Hash table to manage integral label equivalencies that are order dependent.
Definition: itkOneWayEquivalencyTable.h:47
itk::OneWayEquivalencyTable::HashTableType
std::unordered_map< unsigned long, unsigned long > HashTableType
Definition: itkOneWayEquivalencyTable.h:62
itk::OneWayEquivalencyTable::ValueType
HashTableType::value_type ValueType
Definition: itkOneWayEquivalencyTable.h:66
itk::SmartPointer< Self >
itk::Indent
Control indentation during Print() invocation.
Definition: itkIndent.h:49
itk::OneWayEquivalencyTable::IsEntry
bool IsEntry(const unsigned long a) const
Definition: itkOneWayEquivalencyTable.h:112
itk::OneWayEquivalencyTable::Begin
Iterator Begin()
Definition: itkOneWayEquivalencyTable.h:149
itk::OneWayEquivalencyTable::Clear
void Clear()
Definition: itkOneWayEquivalencyTable.h:134
itk::OneWayEquivalencyTable::ConstIterator
HashTableType::const_iterator ConstIterator
Definition: itkOneWayEquivalencyTable.h:65
itk::OneWayEquivalencyTable::Empty
bool Empty() const
Definition: itkOneWayEquivalencyTable.h:141
itk::OneWayEquivalencyTable::Lookup
unsigned long Lookup(const unsigned long a) const
Definition: itkOneWayEquivalencyTable.h:88
itkProcessObject.h
itk::OneWayEquivalencyTable::Erase
void Erase(const unsigned long a)
Definition: itkOneWayEquivalencyTable.h:127
itk::DataObject
class ITK_FORWARD_EXPORT DataObject
Definition: itkDataObject.h:42
itk::OneWayEquivalencyTable::m_HashMap
HashTableType m_HashMap
Definition: itkOneWayEquivalencyTable.h:171
itk
The "itk" namespace contains all Insight Segmentation and Registration Toolkit (ITK) classes....
Definition: itkAnnulusOperator.h:24
itk::OneWayEquivalencyTable::End
Iterator End()
Definition: itkOneWayEquivalencyTable.h:157
itk::Object
Base class for most ITK classes.
Definition: itkObject.h:62
itk::OneWayEquivalencyTable::Iterator
HashTableType::iterator Iterator
Definition: itkOneWayEquivalencyTable.h:64
itk::DataObject
Base class for all data objects in ITK.
Definition: itkDataObject.h:293