Pivotal GemFire Native Client Cache Reference  9.0.6
HashSetT.hpp
Go to the documentation of this file.
1 #ifndef _GEMFIRE_HASHSETT_HPP_
2 #define _GEMFIRE_HASHSETT_HPP_
3 
4 /*=========================================================================
5  * Copyright (c) 2002-2014 Pivotal Software, Inc. All Rights Reserved.
6  * This product is protected by U.S. and international copyright
7  * and intellectual property laws. Pivotal products are covered by
8  * more patents listed at http://www.pivotal.io/patents.
9  *========================================================================
10  */
11 
12 #include "gfcpp_globals.hpp"
13 #include "HashSetOfSharedBase.hpp"
14 #include "CacheableKey.hpp"
15 
16 
20 namespace gemfire
21 {
22 
24  template< typename TKEY > class HashSetT
25  {
26  private:
27 
28  HashSetOfSharedBase m_set;
29 
30 
31  public:
32 
34  class Iterator
35  {
36  private:
37 
39 
40 
41  inline Iterator( const HashSetOfSharedBase::Iterator& iter )
42  : m_iter( iter ) { }
43 
44  // Never defined.
45  Iterator( );
46 
47 
48  public:
49 
50  inline const TKEY operator * ( ) const
51  {
52  return staticCast<TKEY>( *m_iter );
53  }
54 
55  inline bool isEnd( ) const
56  {
57  return m_iter.isEnd( );
58  }
59 
60  inline Iterator& operator ++ ( )
61  {
62  ++m_iter;
63  return *this;
64  }
65 
66  inline void operator ++ ( int )
67  {
68  m_iter++;
69  }
70 
71  inline bool operator == ( const Iterator& other ) const
72  {
73  return ( m_iter == other.m_iter );
74  }
75 
76  inline bool operator != ( const Iterator& other ) const
77  {
78  return ( m_iter != other.m_iter );
79  }
80 
81  inline void reset( )
82  {
83  m_iter.reset( );
84  }
85 
86 
87  friend class HashSetT;
88  };
89 
90 
91  inline static int32_t hasher( const SharedBasePtr& p )
92  {
93  return gemfire::hashFunction< TKEY >( staticCast<TKEY>( p ) );
94  }
95 
96  inline static bool equal_to( const SharedBasePtr& x, const SharedBasePtr& y )
97  {
98  return gemfire::equalToFunction< TKEY >( staticCast<TKEY>( x ),
99  staticCast<TKEY>( y ) );
100  }
101 
103  inline int32_t size() const
104  {
105  return m_set.size();
106  }
107 
109  inline int32_t max_size() const
110  {
111  return m_set.max_size();
112  }
113 
115  inline bool empty( ) const
116  {
117  return m_set.empty( );
118  }
119 
121  inline int32_t bucket_count( ) const
122  {
123  return m_set.bucket_count( );
124  }
125 
127  inline void resize( int32_t n )
128  {
129  m_set.resize( n );
130  }
131 
133  inline void swap( HashSetT& other )
134  {
135  m_set.swap( other.m_set );
136  }
137 
141  inline bool insert( const TKEY& k )
142  {
143  return m_set.insert( k );
144  }
145 
147  inline int32_t erase( const TKEY& k )
148  {
149  return m_set.erase( k );
150  }
151 
153  inline void clear( )
154  {
155  m_set.clear( );
156  }
157 
159  inline bool contains( const TKEY& k ) const
160  {
161  return m_set.contains( k );
162  }
163 
165  int32_t count( const TKEY& k ) const
166  {
167  return m_set.count( k );
168  }
169 
171  inline Iterator begin( ) const
172  {
173  return Iterator( m_set.begin( ) );
174  }
175 
177  inline Iterator end( ) const
178  {
179  return Iterator( m_set.end( ) );
180  }
181 
183  inline HashSetT& operator = ( const HashSetT& other )
184  {
185  m_set = other.m_set;
186  return *this;
187  }
188 
192  inline HashSetT( )
193  : m_set( hasher, equal_to )
194  {
195  }
196 
200  inline HashSetT( int32_t n )
201  : m_set( n, hasher, equal_to )
202  {
203  }
204 
206  inline HashSetT( const HashSetT& other )
207  : m_set( other.m_set )
208  {
209  }
210 
212  inline ~HashSetT( )
213  {
214  }
215  };
216 
217 
219 
225  public _HashSetOfCacheableKey, public SharedBase
226  {
227  public:
230 
233  _HashSetOfCacheableKey() { }
234 
236  inline HashSetOfCacheableKey(int32_t n) :
237  _HashSetOfCacheableKey(n) { }
238 
241  _HashSetOfCacheableKey(other) { }
242 
243  private:
245 
246  };
247 
249 
250 }
251 
252 
253 #endif
Iterator end() const
Get an iterator pointing to the end of hash_set.
bool contains(const TKEY &k) const
Check if a given key k exists in the hash set.
Definition: HashSetT.hpp:159
void clear()
Erases all of the elements.
void resize(int32_t n)
Increases the bucket count to at least n.
int32_t size() const
Returns the size of the hash_set.
int32_t erase(const TKEY &k)
Erases the element whose key is k.
Definition: HashSetT.hpp:147
int32_t count(const TKEY &k) const
Counts the number of elements whose key is k.
Definition: HashSetT.hpp:165
void clear()
Erases all of the elements.
Definition: HashSetT.hpp:153
HashSetOfCacheableKey(const HashSetOfCacheableKey &other)
Copy constructor.
Definition: HashSetT.hpp:240
void swap(HashSetT &other)
Swaps the contents of two hash sets.
Definition: HashSetT.hpp:133
void resize(int32_t n)
Increases the bucket count to at least n.
Definition: HashSetT.hpp:127
bool insert(const TKEY &k)
Inserts the key k into the hash set, when k does not exist in the hash set.
Definition: HashSetT.hpp:141
bool empty() const
true if the hash_set&#39;s size is 0.
bool contains(const SharedBasePtr &k) const
Check if a given key k exists in the hash_set.
int32_t size() const
Returns the size of the hash set.
Definition: HashSetT.hpp:103
int32_t max_size() const
Returns the largest possible size of the hash set.
Definition: HashSetT.hpp:109
int32_t bucket_count() const
Returns the number of buckets used by the hash_set.
This namespace contains all the GemFire C++ API classes, enumerations and globals.
Definition: Assert.hpp:19
int32_t count(const SharedBasePtr &k) const
Counts the number of elements whose key is k.
Iterator begin() const
Get an iterator pointing to the start of hash_set.
HashSetT & operator=(const HashSetT &other)
Assignment operator.
Definition: HashSetT.hpp:183
~HashSetT()
Destructor: the destructor of m_set would do required stuff.
Definition: HashSetT.hpp:212
A hash set of CacheableKey objects that also extends SharedBase for smart pointers.
Definition: HashSetT.hpp:224
HashSetOfCacheableKey()
Create an empty HashSet.
Definition: HashSetT.hpp:232
Iterator end() const
Get an iterator pointing to the end of hash_set.
Definition: HashSetT.hpp:177
Iterator begin() const
Get an iterator pointing to the start of hash_set.
Definition: HashSetT.hpp:171
HashSetT(int32_t n)
Creates an empty hash set with at least n buckets and hash function hasher<TKEY> and equal to functio...
Definition: HashSetT.hpp:200
void swap(HashSetOfSharedBase &other)
Swaps the contents of two hash_sets.
int32_t max_size() const
Returns the largest possible size of the hash_set.
Interface of an iterator for HashSetT.
Definition: HashSetT.hpp:34
bool insert(const SharedBasePtr &k)
Inserts the key k into the hash_set.
HashSetT(const HashSetT &other)
Copy constructor.
Definition: HashSetT.hpp:206
Interface of an iterator for HashSetOfSharedBase.
Definition: HashSetOfSharedBase.hpp:51
#define CPPCACHE_EXPORT
Defines a GemFire CPPCACHE export.
Definition: gf_base.hpp:51
This abstract base class is the base class of all user objects that have the shared capability of ref...
Definition: SharedBase.hpp:31
HashSetT()
Creates an empty hash set with hash function hasher<TKEY> and equal to function equal_to<TKEY>.
Definition: HashSetT.hpp:192
bool empty() const
true if the hash set&#39;s size is 0.
Definition: HashSetT.hpp:115
int32_t erase(const SharedBasePtr &k)
Erases the element whose key is k.
Represents a HashSet of SharedBase
Definition: HashSetOfSharedBase.hpp:38
_HashSetOfCacheableKey::Iterator Iterator
Iterator class for the hash set.
Definition: HashSetT.hpp:229
Defines a reference counted shared pointer.
Definition: SharedPtr.hpp:35
int32_t bucket_count() const
Returns the number of buckets used by the hash set.
Definition: HashSetT.hpp:121
HashSetOfCacheableKey(int32_t n)
Creates an empty hash set with at least n buckets.
Definition: HashSetT.hpp:236
HashSet of TKEY.
Definition: HashSetT.hpp:24

GemFire C++ Cache API Documentation