VMware GemFire Native C++ Reference  9.2.4
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 
149 typedef HashSetT<CacheableKeyPtr> _HashSetOfCacheableKey;
150 
156  public SharedBase {
157  public:
160 
163 
166 
169  : _HashSetOfCacheableKey(other) {}
170 
171  private:
172  const HashSetOfCacheableKey& operator=(const HashSetOfCacheableKey&);
173 };
174 
175 typedef SharedPtr<HashSetOfCacheableKey> HashSetOfCacheableKeyPtr;
176 } // namespace client
177 } // namespace geode
178 } // namespace apache
179 
180 #endif // GEODE_HASHSETT_H_
apache::geode::client::HashSetOfSharedBase::begin
Iterator begin() const
Get an iterator pointing to the start of hash_set.
CacheableKey.hpp
apache::geode::client::HashSetT::HashSetT
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
apache::geode::client::HashSetT::end
Iterator end() const
Get an iterator pointing to the end of hash_set.
Definition: HashSetT.hpp:124
apache::geode::client::HashSetT::size
int32_t size() const
Returns the size of the hash set.
Definition: HashSetT.hpp:86
apache
Each enum represents a predefined RegionAttributes in a {}.
Definition: Assert.hpp:31
apache::geode::client::HashSetOfSharedBase::insert
bool insert(const SharedBasePtr &k)
Inserts the key k into the hash_set.
apache::geode::client::HashSetOfSharedBase::erase
int32_t erase(const SharedBasePtr &k)
Erases the element whose key is k.
apache::geode::client::HashSetT::Iterator
Interface of an iterator for HashSetT.
Definition: HashSetT.hpp:42
apache::geode::client::HashSetOfSharedBase::clear
void clear()
Erases all of the elements.
apache::geode::client::HashSetT::~HashSetT
~HashSetT()
Destructor: the destructor of m_set would do required stuff.
Definition: HashSetT.hpp:146
apache::geode::client::HashSetOfSharedBase::Iterator
Interface of an iterator for HashSetOfSharedBase.
Definition: HashSetOfSharedBase.hpp:56
apache::geode::client::HashSetT
HashSet of TKEY.
Definition: HashSetT.hpp:36
apache::geode::client::HashSetT::count
int32_t count(const TKEY &k) const
Counts the number of elements whose key is k.
Definition: HashSetT.hpp:118
apache::geode::client::HashSetT::HashSetT
HashSetT(const HashSetT &other)
Copy constructor.
Definition: HashSetT.hpp:143
apache::geode::client::HashSetT::empty
bool empty() const
true if the hash set's size is 0.
Definition: HashSetT.hpp:92
apache::geode::client::HashSetOfSharedBase
Represents a HashSet of SharedBase
Definition: HashSetOfSharedBase.hpp:47
apache::geode::client::HashSetOfCacheableKey::HashSetOfCacheableKey
HashSetOfCacheableKey(int32_t n)
Creates an empty hash set with at least n buckets.
Definition: HashSetT.hpp:165
apache::geode::client::HashSetT::contains
bool contains(const TKEY &k) const
Check if a given key k exists in the hash set.
Definition: HashSetT.hpp:115
apache::geode::client::HashSetOfCacheableKey::HashSetOfCacheableKey
HashSetOfCacheableKey()
Create an empty HashSet.
Definition: HashSetT.hpp:162
apache::geode::client::HashSetOfSharedBase::swap
void swap(HashSetOfSharedBase &other)
Swaps the contents of two hash_sets.
geode
HashSetOfSharedBase.hpp
apache::geode::client::HashSetOfSharedBase::max_size
int32_t max_size() const
Returns the largest possible size of the hash_set.
apache::geode::client::HashSetT::erase
int32_t erase(const TKEY &k)
Erases the element whose key is k.
Definition: HashSetT.hpp:109
CPPCACHE_EXPORT
#define CPPCACHE_EXPORT
Defines a Geode CPPCACHE export.
Definition: geode_base.hpp:58
apache::geode::client::HashSetT::insert
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
apache::geode::client::HashSetOfSharedBase::empty
bool empty() const
true if the hash_set's size is 0.
apache::geode::client::HashSetOfSharedBase::size
int32_t size() const
Returns the size of the hash_set.
apache::geode::client::HashSetT::clear
void clear()
Erases all of the elements.
Definition: HashSetT.hpp:112
apache::geode::client::HashSetOfSharedBase::count
int32_t count(const SharedBasePtr &k) const
Counts the number of elements whose key is k.
apache::geode::client::HashSetT::swap
void swap(HashSetT &other)
Swaps the contents of two hash sets.
Definition: HashSetT.hpp:101
apache::geode::client::HashSetOfSharedBase::end
Iterator end() const
Get an iterator pointing to the end of hash_set.
apache::geode::client::SharedBase
Definition: SharedBase.hpp:40
apache::geode::client::HashSetOfSharedBase::bucket_count
int32_t bucket_count() const
Returns the number of buckets used by the hash_set.
apache::geode::client::HashSetOfCacheableKey
A hash set of CacheableKey objects that also extends SharedBase for smart pointers.
Definition: HashSetT.hpp:155
apache::geode::client::HashSetT::begin
Iterator begin() const
Get an iterator pointing to the start of hash_set.
Definition: HashSetT.hpp:121
apache::geode::client::HashSetT::bucket_count
int32_t bucket_count() const
Returns the number of buckets used by the hash set.
Definition: HashSetT.hpp:95
apache::geode::client::HashSetOfSharedBase::contains
bool contains(const SharedBasePtr &k) const
Check if a given key k exists in the hash_set.
apache::geode::client::HashSetOfCacheableKey::Iterator
_HashSetOfCacheableKey::Iterator Iterator
Iterator class for the hash set.
Definition: HashSetT.hpp:159
apache::geode::client::HashSetOfCacheableKey::HashSetOfCacheableKey
HashSetOfCacheableKey(const HashSetOfCacheableKey &other)
Copy constructor.
Definition: HashSetT.hpp:168
apache::geode::client::HashSetT::operator=
HashSetT & operator=(const HashSetT &other)
Assignment operator.
Definition: HashSetT.hpp:127
apache::geode::client::SharedPtr
Defines a reference counted shared pointer.
Definition: SharedPtr.hpp:52
apache::geode::client::HashSetT::HashSetT
HashSetT()
Creates an empty hash set with hash function hasher<TKEY> and equal to function equal_to<TKEY>.
Definition: HashSetT.hpp:135
apache::geode::client::HashSetT::resize
void resize(int32_t n)
Increases the bucket count to at least n.
Definition: HashSetT.hpp:98
apache::geode::client::HashSetT::max_size
int32_t max_size() const
Returns the largest possible size of the hash set.
Definition: HashSetT.hpp:89
apache::geode::client::HashSetOfSharedBase::resize
void resize(int32_t n)
Increases the bucket count to at least n.

Pivotal GemFire C++ Cache API Documentation