00001 #ifndef _GEMFIRE_HASHSETT_HPP_ 00002 #define _GEMFIRE_HASHSETT_HPP_ 00003 00004 /*========================================================================= 00005 * Copyright (c) 2002-2014 Pivotal Software, Inc. All Rights Reserved. 00006 * This product is protected by U.S. and international copyright 00007 * and intellectual property laws. Pivotal products are covered by 00008 * more patents listed at http://www.pivotal.io/patents. 00009 *======================================================================== 00010 */ 00011 00012 #include "gfcpp_globals.hpp" 00013 #include "HashSetOfSharedBase.hpp" 00014 #include "CacheableKey.hpp" 00015 00016 00020 namespace gemfire 00021 { 00022 00024 template< typename TKEY > class HashSetT 00025 { 00026 private: 00027 00028 HashSetOfSharedBase m_set; 00029 00030 00031 public: 00032 00034 class Iterator 00035 { 00036 private: 00037 00038 HashSetOfSharedBase::Iterator m_iter; 00039 00040 00041 inline Iterator( const HashSetOfSharedBase::Iterator& iter ) 00042 : m_iter( iter ) { } 00043 00044 // Never defined. 00045 Iterator( ); 00046 00047 00048 public: 00049 00050 inline const TKEY operator * ( ) const 00051 { 00052 return staticCast<TKEY>( *m_iter ); 00053 } 00054 00055 inline bool isEnd( ) const 00056 { 00057 return m_iter.isEnd( ); 00058 } 00059 00060 inline Iterator& operator ++ ( ) 00061 { 00062 ++m_iter; 00063 return *this; 00064 } 00065 00066 inline void operator ++ ( int ) 00067 { 00068 m_iter++; 00069 } 00070 00071 inline bool operator == ( const Iterator& other ) const 00072 { 00073 return ( m_iter == other.m_iter ); 00074 } 00075 00076 inline bool operator != ( const Iterator& other ) const 00077 { 00078 return ( m_iter != other.m_iter ); 00079 } 00080 00081 inline void reset( ) 00082 { 00083 m_iter.reset( ); 00084 } 00085 00086 00087 friend class HashSetT; 00088 }; 00089 00090 00091 inline static int32_t hasher( const SharedBasePtr& p ) 00092 { 00093 return gemfire::hashFunction< TKEY >( staticCast<TKEY>( p ) ); 00094 } 00095 00096 inline static bool equal_to( const SharedBasePtr& x, const SharedBasePtr& y ) 00097 { 00098 return gemfire::equalToFunction< TKEY >( staticCast<TKEY>( x ), 00099 staticCast<TKEY>( y ) ); 00100 } 00101 00103 inline int32_t size() const 00104 { 00105 return m_set.size(); 00106 } 00107 00109 inline int32_t max_size() const 00110 { 00111 return m_set.max_size(); 00112 } 00113 00115 inline bool empty( ) const 00116 { 00117 return m_set.empty( ); 00118 } 00119 00121 inline int32_t bucket_count( ) const 00122 { 00123 return m_set.bucket_count( ); 00124 } 00125 00127 inline void resize( int32_t n ) 00128 { 00129 m_set.resize( n ); 00130 } 00131 00133 inline void swap( HashSetT& other ) 00134 { 00135 m_set.swap( other.m_set ); 00136 } 00137 00141 inline bool insert( const TKEY& k ) 00142 { 00143 return m_set.insert( k ); 00144 } 00145 00147 inline int32_t erase( const TKEY& k ) 00148 { 00149 return m_set.erase( k ); 00150 } 00151 00153 inline void clear( ) 00154 { 00155 m_set.clear( ); 00156 } 00157 00159 inline bool contains( const TKEY& k ) const 00160 { 00161 return m_set.contains( k ); 00162 } 00163 00165 int32_t count( const TKEY& k ) const 00166 { 00167 return m_set.count( k ); 00168 } 00169 00171 inline Iterator begin( ) const 00172 { 00173 return Iterator( m_set.begin( ) ); 00174 } 00175 00177 inline Iterator end( ) const 00178 { 00179 return Iterator( m_set.end( ) ); 00180 } 00181 00183 inline HashSetT& operator = ( const HashSetT& other ) 00184 { 00185 m_set = other.m_set; 00186 return *this; 00187 } 00188 00192 inline HashSetT( ) 00193 : m_set( hasher, equal_to ) 00194 { 00195 } 00196 00200 inline HashSetT( int32_t n ) 00201 : m_set( n, hasher, equal_to ) 00202 { 00203 } 00204 00206 inline HashSetT( const HashSetT& other ) 00207 : m_set( other.m_set ) 00208 { 00209 } 00210 00212 inline ~HashSetT( ) 00213 { 00214 } 00215 }; 00216 00217 00218 typedef HashSetT<CacheableKeyPtr> _HashSetOfCacheableKey; 00219 00224 class CPPCACHE_EXPORT HashSetOfCacheableKey : 00225 public _HashSetOfCacheableKey, public SharedBase 00226 { 00227 public: 00229 typedef _HashSetOfCacheableKey::Iterator Iterator; 00230 00232 inline HashSetOfCacheableKey() : 00233 _HashSetOfCacheableKey() { } 00234 00236 inline HashSetOfCacheableKey(int32_t n) : 00237 _HashSetOfCacheableKey(n) { } 00238 00240 inline HashSetOfCacheableKey(const HashSetOfCacheableKey& other) : 00241 _HashSetOfCacheableKey(other) { } 00242 00243 private: 00244 const HashSetOfCacheableKey& operator=( const HashSetOfCacheableKey& ); 00245 00246 }; 00247 00248 typedef SharedPtr<HashSetOfCacheableKey> HashSetOfCacheableKeyPtr; 00249 00250 } 00251 00252 00253 #endif