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
JoinPairArray.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 #include "Object.h"
20 #include "PDBTemplateBase.h"
21 #include "Handle.h"
22 #include "PDBVector.h"
23 
24 #ifndef JOIN_PAIR_ARRAY_H
25 #define JOIN_PAIR_ARRAY_H
26 
27 #include <cstddef>
28 #include <iostream>
29 #include <iterator>
30 #include <cstring>
31 
32 // PRELOAD %JoinPairArray <Nothing>%
33 
34 namespace pdb {
35 
36 template <class ValueType>
38 
39 // this little class is used to ask the compiler to build the layout of the records used to
40 // store (hash, next, ValueType) triples
41 template <class ValueType>
43  size_t hash;
44  uint32_t next;
45  ValueType value;
46 
47  size_t getObjSize() {
48  return sizeof(JoinMapRecordClass<ValueType>);
49  }
50 };
51 
52 // this allows us to access all of the records with the same key as
53 // we iterate through the map
54 template <class ValueType>
56 
57 private:
58  // the slot in the pair array
59  uint32_t whichOne;
60 
61  // the pair array
63 
64 public:
65  // constructor
67 
68  // returns the hash value that all of these guys share
69  size_t getHash();
70 
71  // returns the number of items that have this particular key
72  size_t size();
73 
74  // accesses the i^th item in the list
75  ValueType& operator[](const size_t i);
76 };
77 
78 // this little class is used to support iteration over pdb :: Maps
79 template <class ValueType>
81 
82 public:
83  bool operator!=(const JoinMapIterator& me) const;
85  void operator++();
89 
90 private:
91  uint32_t slot;
92  // JiaNote: I change reference to pointer because I need initialize JoinMapIterator using
93  // default constructor for hash partitioned join
95  bool done;
96 };
97 
98 template <class ValueType>
99 class JoinPairArray : public Object {
100 
101 public:
102  // constructor/sdestructor
103  JoinPairArray();
104  JoinPairArray(uint32_t numSlots);
105  JoinPairArray(const JoinPairArray& copyFromMe);
106  ~JoinPairArray();
107 
108  // normally these would be defined by the ENABLE_DEEP_COPY macro, but because
109  // JoinPairArray is quite special, we need to manually override these methods
110  void setUpAndCopyFrom(void* target, void* source) const;
111  void deleteObject(void* deleteMe);
112  size_t getSize(void* forMe);
113 
114 private:
116 
117  // the number of slots actually used
118  uint32_t usedSlots;
119 
120  // the number of slots
121  uint32_t numSlots;
122 
123  // the max number of slots before doubling
124  uint32_t maxSlots;
125 
126  // the size of the data
127  uint32_t objSize;
128 
129  // this stores all of the repeated values (those with the same key)
131 
132  // the array of data
134 
135 public:
136  // create a new PairArray via doubling
138 
139  // adds a new value at position which
140  ValueType& push(const size_t& which);
141 
142  // allows us to access all of the records with a particular hash value
143  JoinRecordList<ValueType> lookup(const size_t& which);
144 
145  // returns true if this has hit its max fill factor
146  bool isOverFull();
147 
148  // returns the number of items in this PairArray
149  uint32_t numUsedSlots();
150 
151  // returns 0 if this entry is undefined; 1 if it is defined
152  int count(const size_t& which);
153 
154  // so this guy can look inside
155  template <class ValueTwo>
156  friend class JoinMapIterator;
157  template <class ValueTwo>
158  friend class JoinRecordList;
159 
160  // clear an item
161  void setUnused(const size_t& clearMe);
162 };
163 }
164 
165 #include "JoinPairArray.cc"
166 
167 #endif
JoinRecordList(uint32_t whichOne, JoinPairArray< ValueType > &parent)
JoinRecordList< ValueType > lookup(const size_t &which)
bool operator!=(const JoinMapIterator &me) const
Handle< JoinPairArray< ValueType > > doubleArray()
Vector< Vector< ValueType > > overflows
void setUnused(const size_t &clearMe)
uint32_t numUsedSlots()
size_t getSize(void *forMe)
PDBTemplateBase valueTypeInfo
void deleteObject(void *deleteMe)
ValueType & push(const size_t &which)
ValueType & operator[](const size_t i)
void setUpAndCopyFrom(void *target, void *source) const
int count(const size_t &which)
JoinPairArray< ValueType > * iterateMe
Definition: JoinPairArray.h:94
JoinRecordList< ValueType > * operator*()
JoinPairArray< ValueType > & parent
Definition: JoinPairArray.h:62
JoinMapRecordClass< Nothing > data[0]