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 #ifndef __SGL_HASH_LIST_HPP
00026 #define __SGL_HASH_LIST_HPP
00027
00028 #include <sgldb.h>
00029 #include <vector>
00030
00031
00033
00034 class SGLDB_DLL_API sglHashTable
00035 {
00036 typedef typename vector<T*>::iterator hash_iterator;
00037 public:
00038 sglHashTable(unsigned int hashsize) :
00039 m_hashsize(hashsize)
00040 {
00041 m_hash_list = new vector<T*>[hashsize];
00042 }
00043
00045 virtual ~sglHashTable() { delete[] m_hash_list; }
00046
00048 T* search(T* t)
00049 {
00050 unsigned int pos = t->hash(m_hashsize);
00051 for (hash_iterator i = m_hash_list[pos].begin();
00052 i != m_hash_list[pos].end(); ++i)
00053 {
00054 if (t->isEqual(*i))
00055 return *i;
00056 }
00057
00058 return NULL;
00059 }
00060
00063 T* searchagain(T* t, T* u)
00064 {
00065 unsigned int pos = t->hash(m_hashsize);
00066 bool foundu = false;
00067 for (hash_iterator i = m_hash_list[pos].begin();
00068 i != m_hash_list[pos].end(); ++i)
00069 {
00070 if (u == *i)
00071 foundu = true;
00072 else if (foundu && t->isEqual(*i))
00073 return *i;
00074 }
00075
00076 return NULL;
00077 }
00078
00080 void add(T* t)
00081 {
00082 unsigned int pos = t->hash(m_hashsize);
00083 m_hash_list[pos].push_back(t);
00084 }
00085
00086 private:
00088 sglHashTable();
00089
00091 sglHashTable(const sglHashTable &);
00092
00094 sglHashTable &operator=(const sglHashTable &);
00095
00096 private:
00098 unsigned int m_hashsize;
00099
00103 vector<T*> *m_hash_list;
00104 };
00105
00106 #endif