-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPartitioner.cpp
More file actions
80 lines (65 loc) · 2.11 KB
/
Partitioner.cpp
File metadata and controls
80 lines (65 loc) · 2.11 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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
#ifndef PARTITIONER_CPP_
#define PARTITIONER_CPP_
#include "Partitioner.h"
template <class T, typename S>
Partitioner<T,S>::Partitioner (FILE * f,uint16_t p_partitions_count,uint64_t p_partition_expected_size)
{
partitions_count = p_partitions_count;
partitions = (Partition<T,S> **) calloc (partitions_count,sizeof(Partition<T,S> *));
for ( uint16_t i = 0 ; i < partitions_count ; i++)
partitions[i] = new Partition <T,S> (f,p_partition_expected_size,1000);
cutpoints = (T **) calloc (partitions_count-1,sizeof(T *));
for ( uint16_t i = 0 ; i < partitions_count-1 ; i++)
cutpoints[i] = new T();
}
template <class T, typename S>
void Partitioner<T,S>::addCutpoint(uint16_t index,T * t)
{
cutpoints[index]->addToKeyValue(t->key());
}
template <class T, typename S>
void Partitioner<T,S>::calcCutpointsAverage(uint16_t p_mappers_count)
{
for(int i=0; i<partitions_count-1; i++)
{
cutpoints[i]->keyValueAverage(p_mappers_count);
cout<<" cutpoints["<<i<<"] : " <<(unsigned)cutpoints[i]->getKeyValue()<<endl<<endl;
}
}
template <class T, typename S>
void Partitioner<T,S>::addItem(T * t)
{
bool partition_set = false;
for ( uint16_t i = 0 ; i < partitions_count-1 ; i++)
{
if (cutpoints[i]->getKeyValue() > t->key())
{
partition_set = true;
partitions[i]->addItem(t->getTeraItem());
break;
}
}
if ( !partition_set) { partitions[partitions_count-1]->addItem(t->getTeraItem());}
}
template <class T, typename S>
uint16_t Partitioner<T,S>::getPartitionsCount()
{
return partitions_count;
}
template <class T, typename S>
Partition<T,S> * Partitioner<T,S>::getPartition (uint16_t index)
{
if ( index < partitions_count) return partitions[index];
else return NULL;
}
template <class T, typename S>
Partitioner<T,S>::~Partitioner ()
{
for ( uint16_t i = 0 ; i < partitions_count ; i++)
delete(partitions[i]);
for ( uint16_t i = 0 ; i < partitions_count-1 ; i++)
delete(cutpoints[i]);
free(partitions);
free(cutpoints);
}
#endif