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
HashSetManager.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 HASH_SET_MANAGER
19 #define HASH_SET_MANAGER
20 
21 
22 #include "AbstractHashSet.h"
23 
24 namespace pdb {
25 
26 /*
27  * encapsulates a hash set manager to manage hash tables allocated on heap
28  * this functionality will be replaced by Pangea storage manger
29  */
30 
32 
33 private:
34  // all hash tables allocated
35  std::map<std::string, AbstractHashSetPtr> hashSets;
36  size_t totalSize = 0;
37 
38 public:
39  // to get a hash set
40  AbstractHashSetPtr getHashSet(std::string name) {
41  if (hashSets.count(name) == 0) {
42  return nullptr;
43  } else {
44  return hashSets[name];
45  }
46  }
47 
48  // to add a hash set
49  bool addHashSet(std::string name, AbstractHashSetPtr hashSet) {
50  if (hashSets.count(name) != 0) {
51  std::cout << "Error: hash set exists: " << name << std::endl;
52  return false;
53  } else {
54  hashSets[name] = hashSet;
55  if (hashSet != nullptr) {
56  totalSize += hashSet->getSize();
57  }
58  return true;
59  }
60  }
61 
62  // to remove a hash set
63  bool removeHashSet(std::string name) {
64  if (hashSets.count(name) == 0) {
65  std::cout << "Error: hash set doesn't exist: " << name << std::endl;
66  return false;
67  } else {
68  totalSize -= hashSets[name]->getSize();
69  hashSets.erase(name);
70  return true;
71  }
72  }
73 
74  // get total size
75  size_t getTotalSize() {
76  auto a = hashSets.begin();
77  size_t totalSize = 0;
78  while (a != hashSets.end()) {
79  totalSize += a->second->getSize();
80  ++a;
81  }
82  return totalSize;
83  }
84 };
85 }
86 
87 
88 #endif
std::shared_ptr< AbstractHashSet > AbstractHashSetPtr
AbstractHashSetPtr getHashSet(std::string name)
std::map< std::string, AbstractHashSetPtr > hashSets
bool removeHashSet(std::string name)
bool addHashSet(std::string name, AbstractHashSetPtr hashSet)