-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTeraSortItem.cpp
More file actions
119 lines (105 loc) · 2.79 KB
/
TeraSortItem.cpp
File metadata and controls
119 lines (105 loc) · 2.79 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
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
#include "TeraSortItem.h"
static uint64_t POWERS[11] = {1,
37,
0x0559,
0x0C5DD,
0x1C98F1,
0x04221AD5,
0x98EDE0C9,
0x0161A617D0D,
0x0331D01712E1,
0x076331355BA85,
0x0111561CB63F539};
TeraSortItem::TeraSortItem()
{
key_value= 0;
}
TeraSortItem::TeraSortItem (TeraSortItem & teraSortItem)
{
memcpy(teraitem,teraSortItem.teraitem,sizeof(teraitem_r));
key_value= teraSortItem.key_value;;
}
TeraSortItem::TeraSortItem (teraitem_r * p_teraitem)
{
teraitem = p_teraitem;
key_value= 0;
}
void TeraSortItem::operator = (TeraSortItem * teraSortItem)
{
memcpy(teraitem,teraSortItem->teraitem,sizeof(teraitem_r));
key_value= teraSortItem->key_value;
}
uint128_t TeraSortItem::key()
{
uint8_t * v = teraitem->key;
uint128_t k =0;
uint8_t * c = (uint8_t *) &k;
c[0] = v[9];
c[1] = v[8];
c[2] = v[7];
c[3] = v[6];
c[4] = v[5];
c[5] = v[4];
c[6] = v[3];
c[7] = v[2];
c[8] = v[1];
c[9] = v[0];
return k;
}
void TeraSortItem::swap (TeraSortItem * p_teraSortItem)
{
teraitem_r * s_teraitem = p_teraSortItem->teraitem;
teraitem_r p_teraitem;
memcpy(&p_teraitem,s_teraitem,sizeof(teraitem_r));
memcpy(s_teraitem,teraitem,sizeof(teraitem_r));
memcpy(teraitem,&p_teraitem,sizeof(teraitem_r));
}
bool TeraSortItem::operator > (TeraSortItem * p_teraSortItem)
{
return ( key() > p_teraSortItem->key());
}
bool TeraSortItem::operator < (TeraSortItem * p_teraSortItem)
{
return ( key() < p_teraSortItem->key());
}
bool TeraSortItem::operator >= (TeraSortItem * p_teraSortItem)
{
return ( key() >= p_teraSortItem->key());
}
bool TeraSortItem::operator <= (TeraSortItem * p_teraSortItem)
{
return ( key() <= p_teraSortItem->key());
}
bool TeraSortItem::operator == (TeraSortItem * p_teraSortItem)
{
return ( key() == p_teraSortItem->key());
}
bool TeraSortItem::operator != (TeraSortItem * p_teraSortItem)
{
return ( key() != p_teraSortItem->key());
}
uint16_t TeraSortItem::hash(uint16_t p_reducers)
{
uint64_t h= 0 ;
for ( uint8_t i =10 ; i > 0 ; i --)
h+= teraitem->key[i-1] * POWERS[i-1];
return h%p_reducers;
}
teraitem_r * TeraSortItem::getTeraItem ()
{
return teraitem;
}
void TeraSortItem::addToKeyValue(uint128_t p_key_value)
{
key_value += p_key_value;
}
uint128_t TeraSortItem::getKeyValue()
{
return key_value;
}
void TeraSortItem::keyValueAverage(uint16_t p_divisor)
{
key_value /= p_divisor;
}
TeraSortItem::~TeraSortItem()
{}