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-2008
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 //
00014 // Version: 4.0.0 (2006/06/28)
00015 
00016 #ifndef WM4TSTRINGHASHTABLE_H
00017 #define WM4TSTRINGHASHTABLE_H
00018 
00019 #include "Wm4FoundationLIB.h"
00020 
00021 // The class TVALUE is either native data or is class data that has the
00022 // following member functions:
00023 //   TVALUE::TVALUE ()
00024 //   TVALUE& TVALUE::operator= (const TVALUE&)
00025 
00026 #include "Wm4System.h"
00027 
00028 namespace Wm4
00029 {
00030 
00031 template <class TVALUE>
00032 class TStringHashTable
00033 {
00034 public:
00035     // construction and destruction
00036     TStringHashTable (int iTableSize);
00037     ~TStringHashTable ();
00038 
00039     // element access
00040     int GetQuantity () const;
00041 
00042     // insert a key-value pair into the hash table
00043     bool Insert (const std::string& rkKey, const TVALUE& rtValue);
00044 
00045     // search for a key and returns it value (null, if key does not exist)
00046     TVALUE* Find (const std::string& rkKey) const;
00047 
00048     // remove key-value pairs from the hash table
00049     bool Remove (const std::string& rkKey);
00050     void RemoveAll ();
00051 
00052     // linear traversal of table
00053     TVALUE* GetFirst (std::string* pkKey) const;
00054     TVALUE* GetNext (std::string* pkKey) const;
00055 
00056 private:
00057     class HashItem
00058     {
00059     public:
00060         HashItem () : m_kKey("") {  }
00061 
00062         std::string m_kKey;
00063         TVALUE m_tValue;
00064         HashItem* m_pkNext;
00065     };
00066 
00067     // key-to-index construction
00068     int HashFunction (const std::string& rkKey) const;
00069 
00070     // hash table
00071     int m_iTableSize;
00072     int m_iQuantity;
00073     HashItem** m_apkTable;
00074 
00075     // iterator for traversal
00076     mutable int m_iIndex;
00077     mutable HashItem* m_pkItem;
00078 };
00079 
00080 #include "Wm4TStringHashTable.inl"
00081 
00082 }
00083 
00084 #endif

Generated on Fri Feb 13 13:58:10 2009 for meshmorph by  doxygen 1.5.1