ITK  5.0.0
Insight Segmentation and Registration Toolkit
itkOneWayEquivalencyTable.h
Go to the documentation of this file.
1 /*=========================================================================
2  *
3  * Copyright Insight Software Consortium
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 "itksys/hash_map.hxx"
24 #include "ITKWatershedsExport.h"
25 
26 namespace itk
27 {
46 class ITKWatersheds_EXPORT OneWayEquivalencyTable:public DataObject
47 {
48 public:
49  ITK_DISALLOW_COPY_AND_ASSIGN(OneWayEquivalencyTable);
50 
56  itkNewMacro(Self);
57  itkTypeMacro(OneWayEquivalencyTable, DataObject);
59 
61  using HashTableType = itksys::hash_map< unsigned long, unsigned long,
62  itksys::hash< unsigned long > >;
63 
64  using Iterator = HashTableType::iterator;
65  using ConstIterator = HashTableType::const_iterator;
66  using ValueType = HashTableType::value_type;
67 
71  void Flatten();
72 
80  bool Add(unsigned long a, unsigned long b);
81 
85  unsigned long Lookup(const unsigned long a) const
86  {
87  ConstIterator result = m_HashMap.find(a);
88 
89  if ( result == m_HashMap.end() ) { return a; }
90  else { return ( *result ).second; }
91  }
92 
97  unsigned long RecursiveLookup(const unsigned long a) const;
98 
101  bool IsEntry(const unsigned long a) const
102  {
103  if ( m_HashMap.find(a) == m_HashMap.end() ) { return false; }
104  else { return true; }
105  }
107 
109  void Erase(const unsigned long a)
110  { m_HashMap.erase(a); }
111 
113  void Clear()
114  { m_HashMap.clear(); }
115 
117  bool Empty() const
118  { return m_HashMap.empty(); }
119 
122  Iterator Begin() { return m_HashMap.begin(); }
123 
126  Iterator End() { return m_HashMap.end(); }
127 
129  // void PrintHashTable();
130 
131 protected:
132  OneWayEquivalencyTable() = default;
133  ~OneWayEquivalencyTable() override = default;
134  void PrintSelf(std::ostream & os, Indent indent) const override;
135 
137 };
138 } // end namespace itk
139 
140 #endif
unsigned long Lookup(const unsigned long a) const
class ITK_FORWARD_EXPORT DataObject
Definition: itkDataObject.h:41
bool IsEntry(const unsigned long a) const
Hash table to manage integral label equivalencies that are order dependent.
HashTableType::const_iterator ConstIterator
HashTableType::value_type ValueType
void Erase(const unsigned long a)
Control indentation during Print() invocation.
Definition: itkIndent.h:49
Base class for most ITK classes.
Definition: itkObject.h:60
Base class for all data objects in ITK.
itksys::hash_map< unsigned long, unsigned long, itksys::hash< unsigned long > > HashTableType