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
DepartmentEmployeeAges.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 
19 #ifndef DEPARTMENT_EMPLOYEE_AGES_H
20 #define DEPARTMENT_EMPLOYEE_AGES_H
21 
22 #include "Object.h"
23 #include "PDBString.h"
24 #include "Employee.h"
25 #include "PDBMap.h"
26 #include "PDBVector.h"
27 
28 // PRELOAD %DepartmentEmployeeAges%
29 
30 namespace pdb {
31 
33 
34 public:
36  employees = makeObject<Map<String, Vector<int>>>();
37  }
38 
40 
41  String departmentName; // the name of the department
43  employees; // for each supervisor in this department, the list of employees
45 
46 
48  return departmentName;
49  }
50 
52  return employees;
53  }
54 
55  void print() {
56  std::cout << "Department: " << departmentName << std::endl;
57  auto iter = employees->begin();
58  while (iter != employees->end()) {
59  std::cout << "----Supervisor: " << (*iter).key << std::endl;
60  std::cout << "----NumEmployees: " << (*iter).value.size() << std::endl;
61  for (int i = 0; i < (*iter).value.size(); i++) {
62  std::cout << i << ": " << (((*iter).value)[i]) << ";";
63  }
64  std::cout << std::endl;
65  ++iter;
66  }
67  }
68 };
69 
71  Handle<Map<String, Vector<int>>>& rhs) {
72  auto iter = rhs->begin();
73  while (iter != rhs->end()) {
74  String myKey = (*iter).key;
75  if (lhs->count(myKey) == 0) {
76  try {
77  (*lhs)[myKey] = (*iter).value;
78  } catch (NotEnoughSpace& n) {
79  // std :: cout << "not enough space when inserting new pair" << std :: endl;
80  lhs->setUnused(myKey);
81  throw n;
82  }
83  } else {
84 
85  size_t mySize = (*lhs)[myKey].size();
86  size_t otherSize = (*iter).value.size();
87  // std :: cout << "mySize is " << mySize << " and otherSize is " << otherSize << std ::
88  // endl;
89  for (size_t i = mySize; i < mySize + otherSize; i++) {
90  try {
91 
92  (*lhs)[myKey].push_back((*iter).value[i - mySize]);
93 
94  } catch (NotEnoughSpace& n) {
95 
96  // std :: cout << i << ": not enough space when updating value for pushing back:
97  // " << (*lhs)[myKey].size() << std :: endl;
98  size_t curSize = (*lhs)[myKey].size();
99  for (size_t j = mySize; j < curSize; j++) {
100  (*lhs)[myKey].pop_back();
101  }
102  // std :: cout << "size restored to " << (*lhs)[myKey].size() << std :: endl;
103  for (size_t j = 0; j < (*lhs)[myKey].size(); j++) {
104  std::cout << j << ": " << (*lhs)[myKey][j] << ";";
105  }
106  throw n;
107  }
108  }
109  // std :: cout << "now my size is " << (*lhs)[myKey].size() << std :: endl;
110  }
111  ++iter;
112  }
113  return lhs;
114 }
115 }
116 
117 #endif
#define ENABLE_DEEP_COPY
Definition: DeepCopy.h:52
ENABLE_DEEP_COPY String & getKey()
Handle< Map< String, Vector< int > > > & operator+(Handle< Map< String, Vector< int >>> &lhs, Handle< Map< String, Vector< int >>> &rhs)
Handle< Map< String, Vector< int > > > & getValue()
Handle< Map< String, Vector< int > > > employees