VMware GemFire Native C++ Reference  9.1
HashFunction.hpp
Go to the documentation of this file.
1 #pragma once
2 
3 #ifndef GEODE_HASHFUNCTION_H_
4 #define GEODE_HASHFUNCTION_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 "SharedPtr.hpp"
25 #include "CacheableKey.hpp"
26 
30 namespace apache {
31 namespace geode {
32 namespace client {
33 
35 typedef int32_t (*Hasher)(const SharedBasePtr&);
36 
38 typedef bool (*EqualTo)(const SharedBasePtr&, const SharedBasePtr&);
39 
40 class HashSB {
41  private:
42  Hasher m_hashFn;
43 
44  // Never defined.
45  HashSB();
46 
47  public:
48  HashSB(const Hasher hashFn) : m_hashFn(hashFn) {}
49 
50  int32_t operator()(const SharedBasePtr& p) const { return m_hashFn(p); }
51 };
52 
53 class EqualToSB {
54  private:
55  EqualTo m_equalFn;
56 
57  // Never defined.
58  EqualToSB();
59 
60  public:
61  EqualToSB(const EqualTo equalFn) : m_equalFn(equalFn) {}
62 
63  bool operator()(const SharedBasePtr& x, const SharedBasePtr& y) const {
64  return m_equalFn(x, y);
65  }
66 };
67 
68 template <typename TKEY>
69 inline int32_t hashFunction(const TKEY& k) {
70  return k->hashcode();
71 }
72 
73 template <typename TKEY>
74 inline bool equalToFunction(const TKEY& x, const TKEY& y) {
75  return (*x.ptr() == *y.ptr());
76 }
77 } // namespace client
78 } // namespace geode
79 } // namespace apache
80 
81 #endif // GEODE_HASHFUNCTION_H_
Each enum represents a predefined RegionAttributes in a Cache.
Definition: Assert.hpp:31
bool(* EqualTo)(const SharedBasePtr &, const SharedBasePtr &)
typedef for the hashing key equality function.
Definition: HashFunction.hpp:38
Defines a reference counted shared pointer.
Definition: SharedPtr.hpp:52
int32_t(* Hasher)(const SharedBasePtr &)
typedef for the hash function used by the hashing schemes.
Definition: HashFunction.hpp:35
This namespace contains all the Geode C++ API classes, enumerations and globals.

Pivotal GemFire C++ Cache API Documentation