20
20
namespace peloton {
21
21
namespace codegen {
22
22
23
+ /* *
24
+ * The main hash table access class for util::HashTable.
25
+ */
23
26
class HashTable {
24
27
public:
25
28
/* *
@@ -44,20 +47,29 @@ class HashTable {
44
47
};
45
48
46
49
/* *
47
- * A callback used when inserting insert a new entry into the hash table. The
48
- * caller implements the StoreValue() method to perform the insertion. The
49
- * argument provided to StoreValue() is the address where the contents can be
50
- * stored. The size of this space is equal to the value returned by
51
- * GetValueSize().
50
+ * A callback used when inserting a new entry into the hash table. The caller
51
+ * implements StoreValue() to perform the insertion, and GetValueSize() to
52
+ * indicate the number of bytes needed to store the value associated with the
53
+ * inserted key.
52
54
*/
53
55
struct InsertCallback {
54
56
/* * Virtual destructor */
55
57
virtual ~InsertCallback () = default ;
56
58
57
- // Called to store the value associated with the key used for insertion.
59
+ /* *
60
+ * Serialize the value into a provided memory space in the hash table.
61
+ *
62
+ * @param codegen The codegen instance
63
+ * @param space The memory space for the value
64
+ */
58
65
virtual void StoreValue (CodeGen &codegen, llvm::Value *space) const = 0;
59
66
60
- // Called to determine the size of the payload the caller wants to store
67
+ /* *
68
+ * Return the number of bytes for the value
69
+ *
70
+ * @param codegen The codegen instance
71
+ * @return The number of bytes needed to store the value
72
+ */
61
73
virtual llvm::Value *GetValueSize (CodeGen &codegen) const = 0;
62
74
};
63
75
@@ -71,60 +83,87 @@ class HashTable {
71
83
}
72
84
};
73
85
74
- // ===--------------------------------------------------------------------===//
75
- // This callback is used to iterate over all (or a subset) of the entries in
76
- // the hash table that match a provided key. The ProcessEntry() method is
77
- // called for every match and we provide a pointer to the actual HashEntry,
78
- // and a vector of codegen::Value for every value stored in the HashEntry.
79
- // ===--------------------------------------------------------------------===//
86
+ /* *
87
+ * A callback used when iterating over the entries in the hash table.
88
+ * ProcessEntry() is invoked for each entry in the table, or only those
89
+ * entries that match a provided key if a search key is provided.
90
+ */
80
91
struct IterateCallback {
81
92
/* * Virtual destructor */
82
93
virtual ~IterateCallback () = default ;
83
94
84
- // Callback to process an entry in the hash table. The key and opaque set of
85
- // bytes (representing the value space) are provided as arguments.
95
+ /* *
96
+ * The primary callback function for each entry in the table, or for each
97
+ * matching key-value pair when provided a search key.
98
+ *
99
+ * @param codegen The codegen instance
100
+ * @param keys The key stored in the hash table
101
+ * @param values A pointer to a set of bytes where the value is stored
102
+ */
86
103
virtual void ProcessEntry (CodeGen &codegen,
87
104
const std::vector<codegen::Value> &keys,
88
105
llvm::Value *values) const = 0;
89
106
};
90
107
91
108
class HashTableAccess ;
92
109
93
- // ===--------------------------------------------------------------------===//
94
- // This callback is used when performing a vectorized iteration over all
95
- // entries in the hash table that match a provided key. For each vector of
96
- // entries, ProcessEntries() is called indicating the range of entries in the
97
- // hash-table to cover, and a selection vector indicating which entries in
98
- // this range are occupied.
99
- // ===--------------------------------------------------------------------===//
110
+ /* *
111
+ * A callback used when performing a batched/vectorized iteration over the
112
+ * entries in the hash table. Iteration may be over the entire table, or a
113
+ * subset of the table if a matching probing key was provided.
114
+ */
100
115
struct VectorizedIterateCallback {
101
116
/* * Virtual destructor */
102
117
virtual ~VectorizedIterateCallback () = default ;
103
118
104
- // Process a vector of entries in this hash-table
119
+ /* *
120
+ * Process a vector of entries in the hash table.
121
+ *
122
+ * @param codegen The codegen instance
123
+ * @param start
124
+ * @param end
125
+ * @param selection_vector A vector containing indexes of valid entries
126
+ * @param access A hash-table random-access helper
127
+ */
105
128
virtual void ProcessEntries (CodeGen &codegen, llvm::Value *start,
106
129
llvm::Value *end, Vector &selection_vector,
107
130
HashTableAccess &access) const = 0;
108
131
};
109
132
110
- // ===--------------------------------------------------------------------===//
111
- // Convenience class proving a random access interface over the hash-table
112
- // ===--------------------------------------------------------------------===/ /
133
+ /* *
134
+ * Convenience class proving a random access interface over the hash-table
135
+ * /
113
136
class HashTableAccess {
114
137
public:
115
138
/* * Virtual destructor */
116
139
virtual ~HashTableAccess () = default ;
117
140
141
+ /* *
142
+ * Extracts the key of an entry at a given index into the hash table storing
143
+ * results into the output 'keys' vector.
144
+ *
145
+ * @param codegen The codegen instance
146
+ * @param index The index in the directory
147
+ * @param[out] keys Where each column of the key is stored
148
+ */
118
149
// Extract the keys for the bucket at the given index
119
150
virtual void ExtractBucketKeys (CodeGen &codegen, llvm::Value *index,
120
151
std::vector<codegen::Value> &keys) const = 0;
152
+
153
+ /* *
154
+ * Returns a pointer to a value stored at the entry at the given index.
155
+ *
156
+ * @param codegen The codegen instance
157
+ * @param index An index in the directory
158
+ * @return A pointer to where the value is serialized
159
+ */
121
160
virtual llvm::Value *BucketValue (CodeGen &codegen,
122
161
llvm::Value *index) const = 0;
123
162
};
124
163
125
- // ===--------------------------------------------------------------------===//
126
- // Return type for ProbeOrInsert
127
- // ===--------------------------------------------------------------------===/ /
164
+ /* *
165
+ * A struct storing the result of a probe into the hash table
166
+ * /
128
167
struct ProbeResult {
129
168
// Actual probe result (bool), if the key already exists in the hast table
130
169
llvm::Value *key_exists;
@@ -142,26 +181,20 @@ class HashTable {
142
181
// Destructor
143
182
virtual ~HashTable () = default ;
144
183
145
- // Initialize the hash-table instance
146
184
virtual void Init (CodeGen &codegen, llvm::Value *ht_ptr) const ;
147
185
virtual void Init (CodeGen &codegen, llvm::Value *exec_ctx,
148
186
llvm::Value *ht_ptr) const ;
149
187
150
- // Generate code to handle the insertion of a new tuple
151
188
virtual void ProbeOrInsert (CodeGen &codegen, llvm::Value *ht_ptr,
152
189
llvm::Value *hash,
153
190
const std::vector<codegen::Value> &key,
154
191
ProbeCallback &probe_callback,
155
192
InsertCallback &insert_callback) const ;
156
193
157
- // Probe the hash table and insert a new slot if needed, returning both the
158
- // result and the data pointer
159
194
virtual ProbeResult ProbeOrInsert (
160
195
CodeGen &codegen, llvm::Value *ht_ptr, llvm::Value *hash,
161
196
const std::vector<codegen::Value> &key) const ;
162
197
163
- // Insert a new entry into the hash table with the given keys, but don't
164
- // perform any key matching or merging
165
198
virtual void Insert (CodeGen &codegen, llvm::Value *ht_ptr, llvm::Value *hash,
166
199
const std::vector<codegen::Value> &keys,
167
200
InsertCallback &callback) const ;
@@ -178,21 +211,17 @@ class HashTable {
178
211
void MergeLazyUnfinished (CodeGen &codegen, llvm::Value *global_ht,
179
212
llvm::Value *local_ht) const ;
180
213
181
- // Generate code to iterate over the entire hash table
182
214
virtual void Iterate (CodeGen &codegen, llvm::Value *ht_ptr,
183
215
IterateCallback &callback) const ;
184
216
185
- // Generate code to iterate over the entire hash table in vectorized fashion
186
217
virtual void VectorizedIterate (CodeGen &codegen, llvm::Value *ht_ptr,
187
218
Vector &selection_vector,
188
219
VectorizedIterateCallback &callback) const ;
189
220
190
- // Generate code that iterates all the matches
191
221
virtual void FindAll (CodeGen &codegen, llvm::Value *ht_ptr,
192
222
const std::vector<codegen::Value> &key,
193
223
IterateCallback &callback) const ;
194
224
195
- // Destroy/cleanup the hash table
196
225
virtual void Destroy (CodeGen &codegen, llvm::Value *ht_ptr) const ;
197
226
198
227
private:
0 commit comments