ITK  4.0.0
Insight Segmentation and Registration Toolkit
itkEquivalencyTable.h
Go to the documentation of this file.
00001 /*=========================================================================
00002  *
00003  *  Copyright Insight Software Consortium
00004  *
00005  *  Licensed under the Apache License, Version 2.0 (the "License");
00006  *  you may not use this file except in compliance with the License.
00007  *  You may obtain a copy of the License at
00008  *
00009  *         http://www.apache.org/licenses/LICENSE-2.0.txt
00010  *
00011  *  Unless required by applicable law or agreed to in writing, software
00012  *  distributed under the License is distributed on an "AS IS" BASIS,
00013  *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
00014  *  See the License for the specific language governing permissions and
00015  *  limitations under the License.
00016  *
00017  *=========================================================================*/
00018 #ifndef __itkEquivalencyTable_h
00019 #define __itkEquivalencyTable_h
00020 
00021 
00022 #include "itkProcessObject.h"
00023 #include "itksys/hash_map.hxx"
00024 
00025 namespace itk
00026 {
00044 class ITKCommon_EXPORT EquivalencyTable:public DataObject
00045 {
00046 public:
00048   typedef EquivalencyTable           Self;
00049   typedef DataObject                 Superclass;
00050   typedef SmartPointer< Self >       Pointer;
00051   typedef SmartPointer< const Self > ConstPointer;
00052   itkNewMacro(Self);
00053   itkTypeMacro(EquivalencyTable, DataObject);
00055 
00057   typedef itksys::hash_map< unsigned long, unsigned long,
00058     itksys::hash< unsigned long > > HashTableType;
00059 
00060   typedef HashTableType::iterator       Iterator;
00061   typedef HashTableType::const_iterator ConstIterator;
00062   typedef HashTableType::value_type     ValueType;
00063 
00067   void Flatten();
00068 
00075   bool Add(unsigned long a, unsigned long b);
00076 
00084   bool AddAndFlatten(unsigned long a, unsigned long b);
00085 
00089   unsigned long Lookup(const unsigned long a) const
00090   {
00091     ConstIterator result = m_HashMap.find(a);
00092 
00093     if ( result == m_HashMap.end() ) { return a; }
00094     else { return ( *result ).second; }
00095   }
00096 
00101   unsigned long RecursiveLookup(const unsigned long a) const;
00102 
00105   bool IsEntry(const unsigned long a) const
00106   {
00107     if ( m_HashMap.find(a) == m_HashMap.end() ) { return false; }
00108     else { return true; }
00109   }
00111 
00113   void Erase(const unsigned long a)
00114   {  m_HashMap.erase(a); }
00115 
00117   void Clear()
00118   {  m_HashMap.clear();    }
00119 
00121   bool Empty() const
00122   { return m_HashMap.empty();    }
00123 
00125   HashTableType::size_type Size() const
00126   { return m_HashMap.size(); }
00127 
00130   Iterator Begin() { return m_HashMap.begin(); }
00131 
00134   Iterator End()   { return m_HashMap.end();   }
00135 
00137   //  void PrintHashTable();
00138 protected:
00139   EquivalencyTable()  {}
00140   virtual ~EquivalencyTable() {}
00141   EquivalencyTable(const Self &); // purposely not implemented
00142   void operator=(const Self &);   // purposely not implemented
00144 
00145   void PrintSelf(std::ostream & os, Indent indent) const;
00146 
00147   HashTableType m_HashMap;
00148 };
00149 } // end namespace itk
00150 
00151 #endif
00152