A platform for high-performance distributed tool and library development written in C++. It can be deployed in two different cluster modes: standalone or distributed. API for v0.5.0, released on June 13, 2018.
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
SharedHashSet.h
Go to the documentation of this file.
1 /*****************************************************************************
2  * *
3  * Copyright 2018 Rice University *
4  * *
5  * Licensed under the Apache License, Version 2.0 (the "License"); *
6  * you may not use this file except in compliance with the License. *
7  * You may obtain a copy of the License at *
8  * *
9  * http://www.apache.org/licenses/LICENSE-2.0 *
10  * *
11  * Unless required by applicable law or agreed to in writing, software *
12  * distributed under the License is distributed on an "AS IS" BASIS, *
13  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. *
14  * See the License for the specific language governing permissions and *
15  * limitations under the License. *
16  * *
17  *****************************************************************************/
18 #ifndef SHARED_HASH_SET
19 #define SHARED_HASH_SET
20 
21 
22 #include "AbstractHashSet.h"
23 
24 namespace pdb {
25 
27 typedef std::shared_ptr<SharedHashSet> SharedHashSetPtr;
28 
29 /*
30  * This class encapsulates a shared hash set, which is one unmanaged block, which contains a PDBMap.
31  * In the end, this class will be removed and replaced by Pangea hash set
32  */
33 
35 
36 private:
37  // the name of this partitioned hash set
38  std::string setName;
39 
40  // the hash map page
41  void* pageData = nullptr;
42 
43  // the size of the page
44  size_t pageSize;
45 
46 
47 public:
48  // constructor
49  SharedHashSet(std::string myName, size_t pageSize) {
50  this->setName = myName;
51  this->pageSize = pageSize;
52  this->pageData = (void*)malloc(sizeof(char) * pageSize);
53  if (pageData == nullptr) {
54  std::cout << "SharedHashSet Error: insufficient heap memory" << std::endl;
55  }
56  }
57 
58  bool isValid() {
59  if (pageData == nullptr) {
60  return false;
61  } else {
62  return true;
63  }
64  }
65 
66  size_t getSize() override {
67  return pageSize;
68  }
69 
70  // destructor
72  this->cleanup();
73  }
74 
75  // get type of this hash set
76  std::string getHashSetType() override {
77  return "SharedHashSet";
78  }
79 
80  // get name of this hash set
81  std::string getHashSetName() {
82  return setName;
83  }
84 
85  // get page size
86  size_t getPageSize() {
87  return pageSize;
88  }
89 
90  // get page for a particular partition
91  void* getPage() {
92  return pageData;
93  }
94 
95  // cleanup
96  void cleanup() override {
97  if (pageData != nullptr) {
98  free(pageData);
99  pageData = nullptr;
100  }
101  }
102 };
103 }
104 
105 
106 #endif
std::string getHashSetName()
Definition: SharedHashSet.h:81
size_t getSize() override
Definition: SharedHashSet.h:66
std::shared_ptr< SharedHashSet > SharedHashSetPtr
Definition: SharedHashSet.h:26
std::string getHashSetType() override
Definition: SharedHashSet.h:76
SharedHashSet(std::string myName, size_t pageSize)
Definition: SharedHashSet.h:49
void cleanup() override
Definition: SharedHashSet.h:96
std::string setName
Definition: SharedHashSet.h:38