00001 #ifndef _GEMFIRE_HASHSETT_HPP_ 00002 #define _GEMFIRE_HASHSETT_HPP_ 00003 00004 /*========================================================================= 00005 * (c) Copyright 2002-2007, GemStone Systems, Inc. All Rights Reserved. 00006 * 1260 NW Waterhouse Ave., Suite 200, Beaverton, OR 97006 00007 *======================================================================== 00008 */ 00009 00010 #include "gfcpp_globals.hpp" 00011 #include "HashSetOfSharedBase.hpp" 00012 #include "CacheableKey.hpp" 00013 00014 00018 namespace gemfire 00019 { 00020 00022 template< typename TKEY > class HashSetT 00023 { 00024 private: 00025 00026 HashSetOfSharedBase m_set; 00027 00028 00029 public: 00030 00032 class Iterator 00033 { 00034 private: 00035 00036 HashSetOfSharedBase::Iterator m_iter; 00037 00038 00039 inline Iterator( const HashSetOfSharedBase::Iterator& iter ) 00040 : m_iter( iter ) { } 00041 00042 // Never defined. 00043 Iterator( ); 00044 00045 00046 public: 00047 00048 inline const TKEY operator * ( ) const 00049 { 00050 return staticCast<TKEY>( *m_iter ); 00051 } 00052 00053 inline bool isEnd( ) const 00054 { 00055 return m_iter.isEnd( ); 00056 } 00057 00058 inline Iterator& operator ++ ( ) 00059 { 00060 ++m_iter; 00061 return *this; 00062 } 00063 00064 inline void operator ++ ( int ) 00065 { 00066 m_iter++; 00067 } 00068 00069 inline bool operator == ( const Iterator& other ) const 00070 { 00071 return ( m_iter == other.m_iter ); 00072 } 00073 00074 inline bool operator != ( const Iterator& other ) const 00075 { 00076 return ( m_iter != other.m_iter ); 00077 } 00078 00079 inline void reset( ) 00080 { 00081 m_iter.reset( ); 00082 } 00083 00084 00085 friend class HashSetT; 00086 }; 00087 00088 00089 inline static size_t hasher( const SharedBasePtr& p ) 00090 { 00091 return gemfire::hashFunction< TKEY >( staticCast<TKEY>( p ) ); 00092 } 00093 00094 inline static bool equal_to( const SharedBasePtr& x, const SharedBasePtr& y ) 00095 { 00096 return gemfire::equalToFunction< TKEY >( staticCast<TKEY>( x ), 00097 staticCast<TKEY>( y ) ); 00098 } 00099 00101 inline size_t size() const 00102 { 00103 return m_set.size(); 00104 } 00105 00107 inline size_t max_size() const 00108 { 00109 return m_set.max_size(); 00110 } 00111 00113 inline bool empty( ) const 00114 { 00115 return m_set.empty( ); 00116 } 00117 00119 inline size_t bucket_count( ) const 00120 { 00121 return m_set.bucket_count( ); 00122 } 00123 00125 inline void resize( size_t n ) 00126 { 00127 m_set.resize( n ); 00128 } 00129 00131 inline void swap( HashSetT& other ) 00132 { 00133 m_set.swap( other.m_set ); 00134 } 00135 00139 inline bool insert( const TKEY& k ) 00140 { 00141 return m_set.insert( k ); 00142 } 00143 00145 inline size_t erase( const TKEY& k ) 00146 { 00147 return m_set.erase( k ); 00148 } 00149 00151 inline void clear( ) 00152 { 00153 m_set.clear( ); 00154 } 00155 00157 inline bool contains( const TKEY& k ) const 00158 { 00159 return m_set.contains( k ); 00160 } 00161 00163 size_t count( const TKEY& k ) const 00164 { 00165 return m_set.count( k ); 00166 } 00167 00169 inline Iterator begin( ) const 00170 { 00171 return Iterator( m_set.begin( ) ); 00172 } 00173 00175 inline Iterator end( ) const 00176 { 00177 return Iterator( m_set.end( ) ); 00178 } 00179 00181 inline HashSetT& operator = ( const HashSetT& other ) 00182 { 00183 m_set = other.m_set; 00184 return *this; 00185 } 00186 00190 inline HashSetT( ) 00191 : m_set( hasher, equal_to ) 00192 { 00193 } 00194 00198 inline HashSetT( size_t n ) 00199 : m_set( n, hasher, equal_to ) 00200 { 00201 } 00202 00204 inline HashSetT( const HashSetT& other ) 00205 : m_set( other.m_set ) 00206 { 00207 } 00208 00210 inline ~HashSetT( ) 00211 { 00212 } 00213 }; 00214 00215 00216 typedef HashSetT<CacheableKeyPtr> _HashSetOfCacheableKey; 00217 00222 class CPPCACHE_EXPORT HashSetOfCacheableKey : 00223 public _HashSetOfCacheableKey, public SharedBase 00224 { 00225 public: 00227 typedef _HashSetOfCacheableKey::Iterator Iterator; 00228 00230 inline HashSetOfCacheableKey() : 00231 _HashSetOfCacheableKey() { } 00232 00234 inline HashSetOfCacheableKey(size_t n) : 00235 _HashSetOfCacheableKey(n) { } 00236 00238 inline HashSetOfCacheableKey(const HashSetOfCacheableKey& other) : 00239 _HashSetOfCacheableKey(other) { } 00240 }; 00241 00242 typedef SharedPtr<HashSetOfCacheableKey> HashSetOfCacheableKeyPtr; 00243 00244 } 00245 00246 00247 #endif