forked from data61/MP-SPDZ
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathRectangle.hpp
124 lines (106 loc) · 2.51 KB
/
Rectangle.hpp
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
120
121
122
123
124
/*
* Rectangle.cpp
*
*/
#ifndef OT_RECTANGLE_HPP_
#define OT_RECTANGLE_HPP_
#include "Rectangle.h"
#include "Math/Z2k.h"
#include "OT/BitMatrix.h"
#include <assert.h>
template<class U, class V>
const int Rectangle<U, V>::N_ROWS;
template<class U, class V>
const int Rectangle<U, V>::N_ROWS_ALLOCATED;
template<class U, class V>
bool Rectangle<U, V>::operator ==(const Rectangle<U, V>& other) const
{
for (int i = 0; i < N_ROWS; i++)
if (rows[i] != other.rows[i])
return false;
return true;
}
template<class U, class V>
Rectangle<U, V>& Rectangle<U, V>::operator +=(const Rectangle<U, V>& other)
{
for (int i = 0; i < N_ROWS; i++)
rows[i] += other.rows[i];
return *this;
}
template<class U, class V>
Rectangle<U, V> Rectangle<U, V>::operator -(const Rectangle<U, V>& other)
{
Rectangle<U, V> res = other;
res.rsub_(*this);
return res;
}
template<class U, class V>
Rectangle<U, V>& Rectangle<U, V>::rsub_(Rectangle<U, V>& other)
{
for (int i = 0; i < N_ROWS; i++)
rows[i] = other.rows[i] - rows[i];
return *this;
}
template<class U, class V>
Rectangle<U, V>& Rectangle<U, V>::sub_(const void* other)
{
for (int i = 0; i < N_ROWS; i++)
rows[i] = rows[i] - V(other);
return *this;
}
template<class U, class V>
void Rectangle<U, V>::bit_sub(const BitVector& bits, int start)
{
for (int i = 0; i < N_ROWS; i++)
rows[i] = rows[i] - bits.get_bit(start + i);
}
template<class U, class V>
void Rectangle<U, V>::mul(const BitVector& a, const V& b)
{
assert(a.size() == N_ROWS);
for (int i = 0; i < N_ROWS; i++)
rows[i] = b * a.get_bit(i);
}
template<class U, class V>
void Rectangle<U, V>::randomize(PRNG& G)
{
for (int i = 0; i < N_ROWS; i++)
rows[i].randomize(G);
}
template<class U, class V>
void Rectangle<U, V>::conditional_add_(BitVector& conditions,
Rectangle<U, V>& other, int offset)
{
for (int i = 0; i < N_ROWS; i++)
if (conditions.get_bit(N_ROWS_ALLOCATED * offset + i))
rows[i] += other.rows[i];
}
template<class U, class V>
template<class T>
void Rectangle<U, V>::to(T& result)
{
result = bigint(0);
for (int i = 0; i < min(N_ROWS, result.N_BITS); i++)
{
result += T(rows[i]) << i;
}
}
template<class U, class V>
void Rectangle<U, V>::pack(octetStream& o) const
{
for (int i = 0; i < N_ROWS; i++)
rows[i].pack(o);
}
template<class U, class V>
void Rectangle<U, V>::unpack(octetStream& o)
{
for (int i = 0; i < N_ROWS; i++)
rows[i].unpack(o);
}
template<class U, class V>
void Rectangle<U, V>::print(int i, int j)
{
(void) j;
cout << dec << i << ": " << hex << rows[i] << endl;
}
#endif