-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathHistogram.h
62 lines (51 loc) · 1.97 KB
/
Histogram.h
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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
// TODO: Switch histogram calculation from mask/shift to union
#pragma once
template< unsigned PowerOfTwoRadix, unsigned Log2ofPowerOfTwoRadix >
inline size_t* HistogramByteComponents_1(unsigned inArray[], size_t l, size_t r)
{
const unsigned numberOfDigits = Log2ofPowerOfTwoRadix;
const unsigned NumberOfBins = PowerOfTwoRadix;
size_t* count = new size_t[numberOfDigits * NumberOfBins];
for (unsigned i = 0; i < numberOfDigits * NumberOfBins; i++)
count[i] = 0;
size_t* count0 = count + (0 * NumberOfBins);
size_t* count1 = count + (1 * NumberOfBins);
size_t* count2 = count + (2 * NumberOfBins);
size_t* count3 = count + (3 * NumberOfBins);
for (size_t current = l; current <= r; current++) // Scan the array and count the number of times each digit value appears - i.e. size of each bin
{
unsigned value = inArray[current];
count0[ value & 0xff]++;
count1[(value >> 8) & 0xff]++;
count2[(value >> 16) & 0xff]++;
count3[(value >> 24) & 0xff]++;
}
return count;
}
template< unsigned PowerOfTwoRadix, unsigned Log2ofPowerOfTwoRadix >
inline size_t** HistogramByteComponents(unsigned long long inArray[], int l, int r)
{
const unsigned numberOfDigits = Log2ofPowerOfTwoRadix;
const unsigned NumberOfBins = PowerOfTwoRadix;
size_t** count = new size_t * [numberOfDigits];
for (unsigned i = 0; i < numberOfDigits; i++)
{
count[i] = new size_t[NumberOfBins];
for (unsigned j = 0; j < NumberOfBins; j++)
count[i][j] = 0;
}
// Faster version, since it doesn't use a 2-D array, reducing one level of indirection
size_t* count0 = count[0];
size_t* count1 = count[1];
size_t* count2 = count[2];
size_t* count3 = count[3];
for (int current = l; current <= r; current++) // Scan the array and count the number of times each digit value appears - i.e. size of each bin
{
unsigned long value = inArray[current];
count0[value & 0xff]++;
count1[(value >> 8) & 0xff]++;
count2[(value >> 16) & 0xff]++;
count3[(value >> 24) & 0xff]++;
}
return count;
}