1*0Sstevel@tonic-gate // Copyright (c) 1994 James Clark 2*0Sstevel@tonic-gate // See the file COPYING for copying permission. 3*0Sstevel@tonic-gate #pragma ident "%Z%%M% %I% %E% SMI" 4*0Sstevel@tonic-gate 5*0Sstevel@tonic-gate #ifndef PointerTable_INCLUDED 6*0Sstevel@tonic-gate #define PointerTable_INCLUDED 1 7*0Sstevel@tonic-gate 8*0Sstevel@tonic-gate #include "Vector.h" 9*0Sstevel@tonic-gate #include "Boolean.h" 10*0Sstevel@tonic-gate #include <stddef.h> 11*0Sstevel@tonic-gate 12*0Sstevel@tonic-gate #ifdef SP_NAMESPACE 13*0Sstevel@tonic-gate namespace SP_NAMESPACE { 14*0Sstevel@tonic-gate #endif 15*0Sstevel@tonic-gate 16*0Sstevel@tonic-gate template<class P, class K, class HF, class KF> class PointerTableIter; 17*0Sstevel@tonic-gate 18*0Sstevel@tonic-gate template<class P, class K, class HF, class KF> 19*0Sstevel@tonic-gate class PointerTable { constraints()20*0Sstevel@tonic-gate void constraints() { 21*0Sstevel@tonic-gate P p(0); 22*0Sstevel@tonic-gate const K &key = KF::key(*p); 23*0Sstevel@tonic-gate unsigned long n = HF::hash(key); 24*0Sstevel@tonic-gate n = 0; // prevent warning 25*0Sstevel@tonic-gate } 26*0Sstevel@tonic-gate public: 27*0Sstevel@tonic-gate PointerTable(); 28*0Sstevel@tonic-gate P insert(P, Boolean replace = 0); 29*0Sstevel@tonic-gate // Return a reference so that it is possible to do 30*0Sstevel@tonic-gate // lookups into a table of smart-pointers from multiple threads. 31*0Sstevel@tonic-gate const P &lookup(const K &) const; 32*0Sstevel@tonic-gate P remove(const K &); count()33*0Sstevel@tonic-gate size_t count() const { return used_; } 34*0Sstevel@tonic-gate void clear(); 35*0Sstevel@tonic-gate void swap(PointerTable<P, K, HF, KF> &); 36*0Sstevel@tonic-gate protected: 37*0Sstevel@tonic-gate size_t used_; 38*0Sstevel@tonic-gate size_t usedLimit_; 39*0Sstevel@tonic-gate Vector<P> vec_; 40*0Sstevel@tonic-gate P null_; 41*0Sstevel@tonic-gate startIndex(const K & k)42*0Sstevel@tonic-gate size_t startIndex(const K &k) const { 43*0Sstevel@tonic-gate return size_t(HF::hash(k) & (vec_.size() - 1)); 44*0Sstevel@tonic-gate } nextIndex(size_t i)45*0Sstevel@tonic-gate size_t nextIndex(size_t i) const { 46*0Sstevel@tonic-gate return i == 0 ? vec_.size() - 1 : i - 1; 47*0Sstevel@tonic-gate } 48*0Sstevel@tonic-gate friend class PointerTableIter<P, K, HF, KF>; 49*0Sstevel@tonic-gate }; 50*0Sstevel@tonic-gate 51*0Sstevel@tonic-gate template<class P, class K, class HF, class KF> 52*0Sstevel@tonic-gate class PointerTableIter { 53*0Sstevel@tonic-gate public: 54*0Sstevel@tonic-gate PointerTableIter(const PointerTable<P, K, HF, KF> &); 55*0Sstevel@tonic-gate const P &next(); 56*0Sstevel@tonic-gate private: 57*0Sstevel@tonic-gate const PointerTable<P, K, HF, KF> *tablePtr_; 58*0Sstevel@tonic-gate size_t i_; 59*0Sstevel@tonic-gate }; 60*0Sstevel@tonic-gate 61*0Sstevel@tonic-gate #ifdef SP_NAMESPACE 62*0Sstevel@tonic-gate } 63*0Sstevel@tonic-gate #endif 64*0Sstevel@tonic-gate 65*0Sstevel@tonic-gate #endif /* not PointerTable_INCLUDED */ 66*0Sstevel@tonic-gate 67*0Sstevel@tonic-gate #ifdef SP_DEFINE_TEMPLATES 68*0Sstevel@tonic-gate #include "PointerTable.cxx" 69*0Sstevel@tonic-gate #endif 70