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
PairArray.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 
23 #ifndef PAIR_ARRAY_H
24 #define PAIR_ARRAY_H
25 
26 #include <cstddef>
27 #include <iostream>
28 #include <iterator>
29 #include <cstring>
30 
31 // PRELOAD %PairArray <Nothing>%
32 
33 namespace pdb {
34 
35 template <class KeyType, class ValueType>
36 class PairArray;
37 template <class KeyType, class ValueType>
38 struct MapRecordClass;
39 
40 // this little class is used to support iteration over pdb :: Maps
41 template <class KeyType, class ValueType>
43 
44 public:
46  done = true;
47  iterateMe = nullptr;
48  };
49  bool operator!=(const PDBMapIterator& me) const;
51  void operator++();
54 
55 private:
56  uint32_t slot;
58  bool done;
59 };
60 
61 // The Array type is the one type that we allow to be variable length. This is accomplished
62 // the the data[] array at the end of the class. When an Array object is alllocated, it is
63 // always allocated with some extra space at the end of the class to allow this array to
64 // be used.
65 //
66 // Since the array class can be variable length, it is used as the key building block for
67 // both the Vector and String classes.
68 
69 template <class KeyType, class ValueType = Nothing>
70 class PairArray : public Object {
71 
72 public:
73  // constructor/sdestructor
74  PairArray();
75  PairArray(uint32_t numSlots);
76  PairArray(const PairArray& copyFromMe);
77  ~PairArray();
78 
79  // normally these would be defined by the ENABLE_DEEP_COPY macro, but because
80  // PairArray is quite special, we need to manually override these methods
81  void setUpAndCopyFrom(void* target, void* source) const;
82  void deleteObject(void* deleteMe);
83  size_t getSize(void* forMe);
84 
85 private:
86  // and this gives us our info about TypeContained
89 
90  // the size of the records we need to store
91  uint32_t objSize;
92 
93  // the offset to where the value is in the records that we store
94  uint32_t valueOffset;
95 
96  // the number of slots actually used
97  uint32_t usedSlots;
98 
99  // the number of slots
100  uint32_t numSlots;
101 
102  // the max number of slots before doubling
103  uint32_t maxSlots;
104 
105  // the array of data
107 
108 
109  // delete flag to avoid to run destructor if the flag is set to true
111 
112 public:
113  // create a new PairArray via doubling
115 
116  // access the value at which; if this is undefined, define it and return a reference
117  // to a newly-creaated value
118  ValueType& operator[](const KeyType& which);
119 
120  // returns true if this has hit its max fill factor
121  bool isOverFull();
122 
123  // returns the number of items in this PairArray
124  uint32_t numUsedSlots();
125 
126  // returns 0 if this entry is undefined; 1 if it is defined
127  int count(const KeyType& which);
128 
129  // so this guy can look inside
130  template <class KeyTwo, class ValueTwo>
131  friend class PDBMapIterator;
132 
133  // clear an item
134  void setUnused(const KeyType& clearMe);
135 
136  // set disable destructor
137  void setDisableDestructor(bool disableOrNot);
138 
139  // get disable destructor
140  bool isDestructorDisabled();
141 };
142 }
143 
144 #include "PairArray.cc"
145 
146 #endif
PDBTemplateBase keyTypeInfo
Definition: PairArray.h:87
size_t getSize(void *forMe)
Definition: PairArray.cc:531
void deleteObject(void *deleteMe)
Definition: PairArray.cc:526
uint32_t maxSlots
Definition: PairArray.h:103
int count(const KeyType &which)
Definition: PairArray.cc:235
uint32_t usedSlots
Definition: PairArray.h:97
Nothing data[0]
Definition: PairArray.h:106
PDBTemplateBase valueTypeInfo
Definition: PairArray.h:88
bool operator!=(const PDBMapIterator &me) const
Definition: PairArray.cc:578
Handle< PairArray< KeyType, ValueType > > doubleArray()
Definition: PairArray.cc:490
uint32_t numSlots
Definition: PairArray.h:100
void setUpAndCopyFrom(void *target, void *source) const
Definition: PairArray.cc:131
uint32_t valueOffset
Definition: PairArray.h:94
uint32_t objSize
Definition: PairArray.h:91
Handle< PairArray< KeyType, ValueType > > iterateMe
Definition: PairArray.h:57
ValueType & operator[](const KeyType &which)
Definition: PairArray.cc:325
bool isDestructorDisabled()
Definition: PairArray.cc:124
MapRecordClass< KeyType, ValueType > & operator*()
Definition: PairArray.cc:571
bool isOverFull()
Definition: PairArray.cc:430
uint32_t numUsedSlots()
Definition: PairArray.cc:521
void setDisableDestructor(bool disableOrNot)
Definition: PairArray.cc:118
bool disableDestructor
Definition: PairArray.h:110
void setUnused(const KeyType &clearMe)
Definition: PairArray.cc:276