Main Page | Namespace List | Class Hierarchy | Alphabetical List | Class List | File List | Namespace Members | Class Members | Related Pages

hashtable.h

Go to the documentation of this file.
00001 /***************************************************************************
00002                           hashtable.h  -  Hash table
00003                              -------------------
00004     begin                : Sun Sep 1 2002
00005     copyright            : (C) 2002 by Reality Rift Studios
00006     email                : mattias@realityrift.com
00007  ***************************************************************************
00008 
00009  The contents of this file are subject to the Mozilla Public License Version
00010  1.1 (the "License"); you may not use this file except in compliance with
00011  the License. You may obtain a copy of the License at 
00012  http://www.mozilla.org/MPL/
00013 
00014  Software distributed under the License is distributed on an "AS IS" basis,
00015  WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
00016  for the specific language governing rights and limitations under the
00017  License.
00018 
00019  The Original Code is the NeoEngine, hashtable.h
00020 
00021  The Initial Developer of the Original Code is Mattias Jansson.
00022  Portions created by Mattias Jansson are Copyright (C) 2002
00023  Reality Rift Studios. All Rights Reserved.
00024 
00025  ***************************************************************************/
00026 
00027 #ifndef __NEHASHTABLE_H
00028 #define __NEHASHTABLE_H
00029 
00030 
00031 #include "base.h"
00032 #include "hashstring.h"
00033 
00034 #include <vector>
00035 
00036 #include <assert.h>
00037 
00038 
00045 namespace NeoEngine
00046 {
00047 
00048 
00054 template < class HashTableType > class HashTableNode
00055 {
00056     public:
00057 
00059         HashString                                    m_strKey;
00060 
00062         HashTableType                                *m_pkData;
00063 
00064 
00069         inline                                        HashTableNode( const HashString &rstrKey, HashTableType *pkData );
00070 
00074         inline                                        HashTableNode( const HashTableNode< HashTableType > &rkNode );
00075 };
00076 
00077 
00086 template < class HashTableType > class HashTable
00087 {
00088     public:
00089 
00090         typedef HashTableNode< HashTableType >        HashTableNodeType;
00091         typedef std::vector< HashTableNodeType  >     HashTableNodeVec; 
00092         typedef std::vector< HashTableNodeType* >     HashTableNodePtrVec;  
00093 
00097         enum HASHTABLEDEF
00098         {
00100           DEFAULTSIZE                                 = 256
00101         };
00102 
00103 
00104     protected:
00105 
00107         HashTableNodeVec                             *m_pvkTable;
00108 
00110         int                                           m_iSize;
00111 
00113         unsigned int                                  m_uiElements;
00114 
00115 
00122         inline HashTableNodeType                     *LookupNode( const HashString &rstrKey, int iIndex = 0 );
00123 
00124         
00125     public:
00126 
00131                                                       HashTable( int iSize = DEFAULTSIZE );
00132 
00137         virtual                                      ~HashTable();
00138 
00139 
00148         HashTableType                                *Insert( const HashString &rstrKey, HashTableType *pkData );
00149 
00155         HashTableType                                *Find( const HashString &rstrKey );
00156 
00165         HashTableType                                *Delete( const HashString &rstrKey, HashTableType *pkData = 0 );
00166 
00174         void                                          GetAllNodes( std::vector< HashTableNode< HashTableType >* > *pvpkVector );
00175 
00182         void                                          GetAllNodeData( std::vector< HashTableType* > *pvpkVector );
00183 
00189         void                                          Clear();
00190 };
00191 
00192 
00193 //Macro for easy typing
00194 #if defined( WIN32 ) && defined( _MSC_VER ) && !defined( BUILD_STATIC )
00195 
00196   #define HashTableExport(classname) \
00197   class classname; \
00198   EXPIMP_TEMPLATE template class NEOENGINE_API HashTable< classname >
00199 
00200 #else
00201 
00202   #define HashTableExport(classname)
00203 
00204 #endif
00205 
00206 
00207 #include "hashtable_inl.h"
00208 
00209 
00210 };
00211 
00212 
00213 #endif
00214 

Generated on Wed Jan 21 14:21:06 2004 for NeoEngine by doxygen 1.3.5