00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
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
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