VMware GemFire Native C++ Reference  9.1
HashSetT.hpp
Go to the documentation of this file.
1 #pragma once
2 
3 #ifndef GEODE_HASHSETT_H_
4 #define GEODE_HASHSETT_H_
5 
6 /*
7  * Licensed to the Apache Software Foundation (ASF) under one or more
8  * contributor license agreements. See the NOTICE file distributed with
9  * this work for additional information regarding copyright ownership.
10  * The ASF licenses this file to You under the Apache License, Version 2.0
11  * (the "License"); you may not use this file except in compliance with
12  * the License. You may obtain a copy of the License at
13  *
14  * http://www.apache.org/licenses/LICENSE-2.0
15  *
16  * Unless required by applicable law or agreed to in writing, software
17  * distributed under the License is distributed on an "AS IS" BASIS,
18  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
19  * See the License for the specific language governing permissions and
20  * limitations under the License.
21  */
22 
23 #include "geode_globals.hpp"
24 #include "HashSetOfSharedBase.hpp"
25 #include "CacheableKey.hpp"
26 
30 namespace apache {
31 namespace geode {
32 namespace client {
33 
35 template <typename TKEY>
36 class HashSetT {
37  private:
38  HashSetOfSharedBase m_set;
39 
40  public:
42  class Iterator {
43  private:
45 
46  inline Iterator(const HashSetOfSharedBase::Iterator& iter) : m_iter(iter) {}
47 
48  // Never defined.
49  Iterator();
50 
51  public:
52  inline const TKEY operator*() const { return staticCast<TKEY>(*m_iter); }
53 
54  inline bool isEnd() const { return m_iter.isEnd(); }
55 
56  inline Iterator& operator++() {
57  ++m_iter;
58  return *this;
59  }
60 
61  inline void operator++(int) { m_iter++; }
62 
63  inline bool operator==(const Iterator& other) const {
64  return (m_iter == other.m_iter);
65  }
66 
67  inline bool operator!=(const Iterator& other) const {
68  return (m_iter != other.m_iter);
69  }
70 
71  inline void reset() { m_iter.reset(); }
72 
73  friend class HashSetT;
74  };
75 
76  inline static int32_t hasher(const SharedBasePtr& p) {
77  return apache::geode::client::hashFunction<TKEY>(staticCast<TKEY>(p));
78  }
79 
80  inline static bool equal_to(const SharedBasePtr& x, const SharedBasePtr& y) {
81  return apache::geode::client::equalToFunction<TKEY>(staticCast<TKEY>(x),
82  staticCast<TKEY>(y));
83  }
84 
86  inline int32_t size() const { return m_set.size(); }
87 
89  inline int32_t max_size() const { return m_set.max_size(); }
90 
92  inline bool empty() const { return m_set.empty(); }
93 
95  inline int32_t bucket_count() const { return m_set.bucket_count(); }
96 
98  inline void resize(int32_t n) { m_set.resize(n); }
99 
101  inline void swap(HashSetT& other) { m_set.swap(other.m_set); }
102 
106  inline bool insert(const TKEY& k) { return m_set.insert(k); }
107 
109  inline int32_t erase(const TKEY& k) { return m_set.erase(k); }
110 
112  inline void clear() { m_set.clear(); }
113 
115  inline bool contains(const TKEY& k) const { return m_set.contains(k); }
116 
118  int32_t count(const TKEY& k) const { return m_set.count(k); }
119 
121  inline Iterator begin() const { return Iterator(m_set.begin()); }
122 
124  inline Iterator end() const { return Iterator(m_set.end()); }
125 
127  inline HashSetT& operator=(const HashSetT& other) {
128  m_set = other.m_set;
129  return *this;
130  }
131 
135  inline HashSetT() : m_set(hasher, equal_to) {}
136 
140  inline HashSetT(int32_t n) : m_set(n, hasher, equal_to) {}
141 
143  inline HashSetT(const HashSetT& other) : m_set(other.m_set) {}
144 
146  inline ~HashSetT() {}
147 };
148 
150 
155 class CPPCACHE_EXPORT HashSetOfCacheableKey : public _HashSetOfCacheableKey,
156  public SharedBase {
157  public:
160 
162  inline HashSetOfCacheableKey() : _HashSetOfCacheableKey() {}
163 
165  inline HashSetOfCacheableKey(int32_t n) : _HashSetOfCacheableKey(n) {}
166 
169  : _HashSetOfCacheableKey(other) {}
170 
171  private:
173 };
174 
176 } // namespace client
177 } // namespace geode
178 } // namespace apache
179 
180 #endif // GEODE_HASHSETT_H_
HashSetT()
Creates an empty hash set with hash function hasher<TKEY> and equal to function equal_to<TKEY>.
Definition: HashSetT.hpp:135
void resize(int32_t n)
Increases the bucket count to at least n.
Definition: HashSetT.hpp:98
void clear()
Erases all of the elements.
Definition: HashSetT.hpp:112
bool contains(const SharedBasePtr &k) const
Check if a given key k exists in the hash_set.
HashSetT(const HashSetT &other)
Copy constructor.
Definition: HashSetT.hpp:143
Each enum represents a predefined RegionAttributes in a Cache.
Definition: Assert.hpp:31
bool empty() const
true if the hash_set&#39;s size is 0.
int32_t count(const SharedBasePtr &k) const
Counts the number of elements whose key is k.
A hash set of CacheableKey objects that also extends SharedBase for smart pointers.
Definition: HashSetT.hpp:155
#define CPPCACHE_EXPORT
Defines a Geode CPPCACHE export.
Definition: geode_base.hpp:58
int32_t bucket_count() const
Returns the number of buckets used by the hash_set.
Interface of an iterator for HashSetT.
Definition: HashSetT.hpp:42
int32_t count(const TKEY &k) const
Counts the number of elements whose key is k.
Definition: HashSetT.hpp:118
int32_t erase(const SharedBasePtr &k)
Erases the element whose key is k.
void resize(int32_t n)
Increases the bucket count to at least n.
_HashSetOfCacheableKey::Iterator Iterator
Iterator class for the hash set.
Definition: HashSetT.hpp:159
HashSetOfCacheableKey(const HashSetOfCacheableKey &other)
Copy constructor.
Definition: HashSetT.hpp:168
int32_t max_size() const
Returns the largest possible size of the hash_set.
bool empty() const
true if the hash set&#39;s size is 0.
Definition: HashSetT.hpp:92
Iterator begin() const
Get an iterator pointing to the start of hash_set.
Definition: HashSetT.hpp:121
Defines a reference counted shared pointer.
Definition: SharedPtr.hpp:52
int32_t size() const
Returns the size of the hash set.
Definition: HashSetT.hpp:86
bool contains(const TKEY &k) const
Check if a given key k exists in the hash set.
Definition: HashSetT.hpp:115
int32_t erase(const TKEY &k)
Erases the element whose key is k.
Definition: HashSetT.hpp:109
bool insert(const SharedBasePtr &k)
Inserts the key k into the hash_set.
HashSetOfCacheableKey()
Create an empty HashSet.
Definition: HashSetT.hpp:162
HashSetOfCacheableKey(int32_t n)
Creates an empty hash set with at least n buckets.
Definition: HashSetT.hpp:165
~HashSetT()
Destructor: the destructor of m_set would do required stuff.
Definition: HashSetT.hpp:146
Iterator end() const
Get an iterator pointing to the end of hash_set.
HashSetT & operator=(const HashSetT &other)
Assignment operator.
Definition: HashSetT.hpp:127
HashSet of TKEY.
Definition: HashSetT.hpp:36
int32_t max_size() const
Returns the largest possible size of the hash set.
Definition: HashSetT.hpp:89
This abstract base class is the base class of all user objects that have the shared capability of ref...
Definition: SharedBase.hpp:40
void swap(HashSetT &other)
Swaps the contents of two hash sets.
Definition: HashSetT.hpp:101
Iterator begin() const
Get an iterator pointing to the start of hash_set.
void swap(HashSetOfSharedBase &other)
Swaps the contents of two hash_sets.
Represents a HashSet of SharedBase
Definition: HashSetOfSharedBase.hpp:47
int32_t size() const
Returns the size of the hash_set.
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:140
Iterator end() const
Get an iterator pointing to the end of hash_set.
Definition: HashSetT.hpp:124
Interface of an iterator for HashSetOfSharedBase.
Definition: HashSetOfSharedBase.hpp:56
int32_t bucket_count() const
Returns the number of buckets used by the hash set.
Definition: HashSetT.hpp:95
This namespace contains all the Geode C++ API classes, enumerations and globals.
void clear()
Erases all of the elements.
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:106

Pivotal GemFire C++ Cache API Documentation