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
PDBMap.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 MAP_H
20 #define MAP_H
21 
22 // PRELOAD %Map <Nothing>%
23 
24 #include "Object.h"
25 #include "Handle.h"
26 #include "PairArray.h"
27 
28 namespace pdb {
29 
30 // This is the basic Map type that works correcrly with Objects and Handles.
31 
32 template <class KeyType, class ValueType = Nothing>
33 class Map : public Object {
34 
35 protected:
36  // this is where the data are actually stored
38 
39 public:
41 
42  // this constructor pre-allocates initSize slots... initSize must be a power of two
43  Map(uint32_t initSize);
44 
45  // this constructor creates a map with a single slot
46  Map();
47 
48  // destructor
49  ~Map();
50 
51  // access the value at "which"; if this is undefined, define it and return a reference
52  ValueType& operator[](const KeyType& which);
53 
54  // clears the particular key from the map, destructing both the key and the value. NOTE THAT
55  // THIS IS ONLY SAFE TO USE IF CLEARME WAS THE VERY LAST ITEM ADDED TO THE MAP. If it is not,
56  // the hash table may be in an inconsistent state. This is typically used when an out-of-memory
57  // exception is thrown when we try to add to the hash table, and we want to immediately clear
58  // the last item added.
59  void setUnused(const KeyType& clearMe);
60 
61  // returns the number of elements in the map
62  size_t size() const;
63 
64  // returns 0 if this entry is undefined; 1 if it is defined
65  int count(const KeyType& which);
66 
67  // these are used for iteration
70 
72 };
73 }
74 
75 #include "PDBMap.cc"
76 
77 #endif
#define ENABLE_DEEP_COPY
Definition: DeepCopy.h:52
~Map()
Definition: PDBMap.cc:102
ValueType & operator[](const KeyType &which)
Definition: PDBMap.cc:112
Handle< PairArray< KeyType, ValueType > > & getArray()
Definition: PDBMap.cc:152
int count(const KeyType &which)
Definition: PDBMap.cc:129
Handle< PairArray< KeyType, ValueType > > myArray
Definition: PDBMap.h:37
size_t size() const
Definition: PDBMap.cc:134
void setUnused(const KeyType &clearMe)
Definition: PDBMap.cc:106
PDBMapIterator< KeyType, ValueType > begin()
Definition: PDBMap.cc:139
Map()
Definition: PDBMap.cc:94
PDBMapIterator< KeyType, ValueType > end()
Definition: PDBMap.cc:145