19 #ifndef DL_HASHTABLE2_HPP
20 #define DL_HASHTABLE2_HPP
22 #include <ndb_global.h>
23 #include "ArrayPool.hpp"
32 template <
class T,
class U>
43 bool setSize(Uint32 noOfElements);
78 T *
getPtr(Uint32 i)
const;
84 void remove(
Ptr<T> &,
const T & key);
90 void remove(Uint32
i);
123 inline bool isNull()
const {
return curr.isNull();}
124 inline void setNull() { curr.setNull(); }
152 inline bool isEmpty()
const {
Iterator iter;
return !
first(iter); }
160 template<
class T,
class U>
169 template<
class T,
class U>
173 delete [] hashValues;
176 template<
class T,
class U>
181 while(i < size) i *= 2;
198 hashValues =
new Uint32[
i];
199 for(Uint32 j = 0; j<
i; j++)
200 hashValues[j] = RNIL;
205 template<
class T,
class U>
209 const Uint32 hv = obj.p->hashValue() & mask;
210 const Uint32
i = hashValues[hv];
213 hashValues[hv] = obj.i;
214 obj.p->nextHash = RNIL;
215 obj.p->prevHash = RNIL;
218 T * tmp = (T*)thePool.
getPtr(i);
219 tmp->prevHash = obj.i;
221 obj.p->prevHash = RNIL;
223 hashValues[hv] = obj.i;
230 template<
class T,
class U>
235 while(i <= mask && hashValues[i] == RNIL) i++;
238 iter.curr.i = hashValues[
i];
239 iter.curr.p = (T*)thePool.
getPtr(iter.curr.i);
247 template<
class T,
class U>
251 if(iter.curr.p->nextHash == RNIL){
252 Uint32
i = iter.bucket + 1;
253 while(i <= mask && hashValues[i] == RNIL) i++;
256 iter.curr.i = hashValues[
i];
257 iter.curr.p = (T*)thePool.
getPtr(iter.curr.i);
265 iter.curr.i = iter.curr.p->nextHash;
266 iter.curr.p = (T*)thePool.
getPtr(iter.curr.i);
270 template<
class T,
class U>
274 const Uint32 hv = key.hashValue() & mask;
283 p = (T*)thePool.
getPtr(i);
285 const Uint32
next = p->nextHash;
287 hashValues[hv] =
next;
289 prev.p->nextHash =
next;
293 T * nextP = (T*)thePool.
getPtr(next);
294 nextP->prevHash = prev.i;
308 template<
class T,
class U>
312 const Uint32 hv = key.hashValue() & mask;
321 p = (T*)thePool.
getPtr(i);
323 const Uint32
next = p->nextHash;
325 hashValues[hv] =
next;
327 prev.p->nextHash =
next;
331 T * nextP = (T*)thePool.
getPtr(next);
332 nextP->prevHash = prev.i;
348 template<
class T,
class U>
354 tmp.p = (T*)thePool.
getPtr(i);
358 template<
class T,
class U>
364 tmp.p = (T*)thePool.
getPtr(i);
368 template<
class T,
class U>
372 const Uint32
next = ptr.p->nextHash;
373 const Uint32 prev = ptr.p->prevHash;
376 T * prevP = (T*)thePool.
getPtr(prev);
377 prevP->nextHash =
next;
379 const Uint32 hv = ptr.p->hashValue() & mask;
380 if (hashValues[hv] == ptr.i)
382 hashValues[hv] =
next;
391 T * nextP = (T*)thePool.
getPtr(next);
392 nextP->prevHash = prev;
396 template<
class T,
class U>
400 const Uint32
next = ptr.p->nextHash;
401 const Uint32 prev = ptr.p->prevHash;
404 T * prevP = (T*)thePool.
getPtr(prev);
405 prevP->nextHash =
next;
407 const Uint32 hv = ptr.p->hashValue() & mask;
408 if (hashValues[hv] == ptr.i)
410 hashValues[hv] =
next;
419 T * nextP = (T*)thePool.
getPtr(next);
420 nextP->prevHash = prev;
426 template<
class T,
class U>
430 for(Uint32
i = 0;
i<=mask;
i++)
431 hashValues[
i] = RNIL;
434 template<
class T,
class U>
438 while (bucket <= mask && hashValues[bucket] == RNIL)
442 iter.bucket = bucket;
447 iter.bucket = bucket;
448 iter.curr.i = hashValues[bucket];
449 iter.curr.p = (T*)thePool.
getPtr(iter.curr.i);
453 template<
class T,
class U>
462 ptr.p->nextHash = RNIL;
463 ptr.p->prevHash = RNIL;
466 return !ptr.isNull();
469 template<
class T,
class U>
474 ptr.p = (T*)thePool.
getPtr(i);
477 template<
class T,
class U>
487 template<
class T,
class U>
491 return (T*)thePool.
getPtr(i);
494 template<
class T,
class U>
498 const Uint32 hv = key.hashValue() & mask;
505 p = (T*)thePool.
getPtr(i);