-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathhistogram.cpp
More file actions
executable file
·39 lines (28 loc) · 1.01 KB
/
histogram.cpp
File metadata and controls
executable file
·39 lines (28 loc) · 1.01 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
#include "partitioner.h"
void calcHist(relation& r, size_t start, size_t end, Histogram*& res,
int64_t bits) {
Histogram* _res = new Histogram{1 << bits};
// histogram with as many partitions as threads
for (size_t t = start; t < end; t++) {
tuple record = r[t];
int64_t index = Partitioner::hash1(record.getKey(), bits);
(*_res)[index]++;
}
res = _res;
}
// create histogram with 2^n entries -- zero initialize all}
Histogram::Histogram(int64_t size)
: entries{new int64_t[size]{}}, psum{new int64_t[size]{}}, size{size} {}
// increase value for a hashvalue
int64_t& Histogram::operator[](int64_t index) { return entries[index]; }
const int64_t* Histogram::generatePsum() {
psum[0] = 0;
for (int64_t p = 1; p < size; p++) psum[p] = psum[p - 1] + entries[p - 1];
return psum;
}
int64_t Histogram::getPartitionPsum(int64_t index) const { return psum[index]; }
int64_t Histogram::getSize() const { return size; }
Histogram::~Histogram() {
delete[] entries;
delete[] psum;
}