Wm4TStringHashTable.h

Go to the documentation of this file.
00001 // Wild Magic Source Code
00002 // David Eberly
00003 // http://www.geometrictools.com
00004 // Copyright (c) 1998-2007
00005 //
00006 // This library is free software; you can redistribute it and/or modify it
00007 // under the terms of the GNU Lesser General Public License as published by
00008 // the Free Software Foundation; either version 2.1 of the License, or (at
00009 // your option) any later version.  The license is available for reading at
00010 // either of the locations:
00011 //     http://www.gnu.org/copyleft/lgpl.html
00012 //     http://www.geometrictools.com/License/WildMagicLicense.pdf
00013 // The license applies to versions 0 through 4 of Wild Magic.
00014 //
00015 // Version: 4.0.0 (2006/06/28)
00016 
00017 #ifndef WM4TSTRINGHASHTABLE_H
00018 #define WM4TSTRINGHASHTABLE_H
00019 
00020 #include "Wm4FoundationLIB.h"
00021 
00022 // The class TVALUE is either native data or is class data that has the
00023 // following member functions:
00024 //   TVALUE::TVALUE ()
00025 //   TVALUE& TVALUE::operator= (const TVALUE&)
00026 
00027 #include "Wm4System.h"
00028 
00029 namespace Wm4
00030 {
00031 
00032 template <class TVALUE>
00033 class TStringHashTable
00034 {
00035 public:
00036     // construction and destruction
00037     TStringHashTable (int iTableSize);
00038     ~TStringHashTable ();
00039 
00040     // element access
00041     int GetQuantity () const;
00042 
00043     // insert a key-value pair into the hash table
00044     bool Insert (const std::string& rkKey, const TVALUE& rtValue);
00045 
00046     // search for a key and returns it value (null, if key does not exist)
00047     TVALUE* Find (const std::string& rkKey) const;
00048 
00049     // remove key-value pairs from the hash table
00050     bool Remove (const std::string& rkKey);
00051     void RemoveAll ();
00052 
00053     // linear traversal of table
00054     TVALUE* GetFirst (std::string* pkKey) const;
00055     TVALUE* GetNext (std::string* pkKey) const;
00056 
00057 private:
00058     class HashItem
00059     {
00060     public:
00061         HashItem () : m_kKey("") {  }
00062 
00063         std::string m_kKey;
00064         TVALUE m_tValue;
00065         HashItem* m_pkNext;
00066     };
00067 
00068     // key-to-index construction
00069     int HashFunction (const std::string& rkKey) const;
00070 
00071     // hash table
00072     int m_iTableSize;
00073     int m_iQuantity;
00074     HashItem** m_apkTable;
00075 
00076     // iterator for traversal
00077     mutable int m_iIndex;
00078     mutable HashItem* m_pkItem;
00079 };
00080 
00081 }
00082 
00083 #include "Wm4TStringHashTable.inl"
00084 
00085 #endif

Generated on Wed Nov 23 19:01:10 2011 for FreeCAD by  doxygen 1.6.1