/* * Rectangle.cpp * */ #ifndef OT_RECTANGLE_HPP_ #define OT_RECTANGLE_HPP_ #include "Rectangle.h" #include "Math/Z2k.h" #include "OT/BitMatrix.h" #include template const int Rectangle::N_ROWS; template const int Rectangle::N_ROWS_ALLOCATED; template bool Rectangle::operator ==(const Rectangle& other) const { for (int i = 0; i < N_ROWS; i++) if (rows[i] != other.rows[i]) return false; return true; } template Rectangle& Rectangle::operator +=(const Rectangle& other) { for (int i = 0; i < N_ROWS; i++) rows[i] += other.rows[i]; return *this; } template Rectangle Rectangle::operator -(const Rectangle& other) { Rectangle res = other; res.rsub_(*this); return res; } template Rectangle& Rectangle::rsub_(Rectangle& other) { for (int i = 0; i < N_ROWS; i++) rows[i] = other.rows[i] - rows[i]; return *this; } template Rectangle& Rectangle::sub_(const void* other) { for (int i = 0; i < N_ROWS; i++) rows[i] = rows[i] - V(other); return *this; } template void Rectangle::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 void Rectangle::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 void Rectangle::randomize(PRNG& G) { for (int i = 0; i < N_ROWS; i++) rows[i].randomize(G); } template void Rectangle::conditional_add_(BitVector& conditions, Rectangle& 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 template void Rectangle::to(T& result) { result = bigint(0); for (int i = 0; i < min(N_ROWS, result.N_BITS); i++) { result += T(rows[i]) << i; } } template void Rectangle::pack(octetStream& o) const { for (int i = 0; i < N_ROWS; i++) rows[i].pack(o); } template void Rectangle::unpack(octetStream& o) { for (int i = 0; i < N_ROWS; i++) rows[i].unpack(o); } template void Rectangle::print(int i, int j) { (void) j; cout << dec << i << ": " << hex << rows[i] << endl; } #endif