|
@@ -1,238 +1,237 @@
|
|
#include <functional>
|
|
#include <functional>
|
|
|
|
|
|
#include "types.hpp"
|
|
#include "types.hpp"
|
|
|
|
+
|
|
#include "duoram.hpp"
|
|
#include "duoram.hpp"
|
|
|
|
+
|
|
#include "cell.hpp"
|
|
#include "cell.hpp"
|
|
|
|
+
|
|
#include "heap.hpp"
|
|
#include "heap.hpp"
|
|
|
|
|
|
|
|
|
|
-
|
|
+void MinHeap::initialize(int num_players, size_t size) {
|
|
-void HEAP::initialize(int num_players, size_t size) {
|
|
+ this -> MAX_SIZE = size;
|
|
- this->MAX_SIZE = size;
|
|
+ this -> num_items = 0;
|
|
- this->num_items = 0;
|
|
+ oram = new Duoram < RegAS > (num_players, size);
|
|
- oram = new Duoram<RegAS>(num_players, size);
|
|
|
|
}
|
|
}
|
|
|
|
|
|
-RegAS reconstruct_AS(MPCTIO &tio, yield_t &yield, RegAS AS) {
|
|
+RegAS reconstruct_AS(MPCTIO & tio, yield_t & yield, RegAS AS) {
|
|
RegAS peer_AS;
|
|
RegAS peer_AS;
|
|
RegAS reconstructed_AS = AS;
|
|
RegAS reconstructed_AS = AS;
|
|
if (tio.player() == 1) {
|
|
if (tio.player() == 1) {
|
|
- tio.queue_peer(&AS, sizeof(AS));
|
|
+ tio.queue_peer( & AS, sizeof(AS));
|
|
} else {
|
|
} else {
|
|
RegAS peer_AS;
|
|
RegAS peer_AS;
|
|
- tio.recv_peer(&peer_AS, sizeof(peer_AS));
|
|
+ tio.recv_peer( & peer_AS, sizeof(peer_AS));
|
|
- reconstructed_AS += peer_AS;
|
|
+ reconstructed_AS += peer_AS;
|
|
}
|
|
}
|
|
|
|
|
|
yield();
|
|
yield();
|
|
|
|
|
|
if (tio.player() == 0) {
|
|
if (tio.player() == 0) {
|
|
- tio.queue_peer(&AS, sizeof(AS));
|
|
+ tio.queue_peer( & AS, sizeof(AS));
|
|
} else {
|
|
} else {
|
|
RegAS peer_flag;
|
|
RegAS peer_flag;
|
|
- tio.recv_peer(&peer_AS, sizeof(peer_AS));
|
|
+ tio.recv_peer( & peer_AS, sizeof(peer_AS));
|
|
reconstructed_AS += peer_AS;
|
|
reconstructed_AS += peer_AS;
|
|
}
|
|
}
|
|
-
|
|
+
|
|
-
|
|
+ return reconstructed_AS;
|
|
- return reconstructed_AS;
|
|
|
|
}
|
|
}
|
|
|
|
|
|
-RegXS reconstruct_XS(MPCTIO &tio, yield_t &yield, RegXS XS) {
|
|
+RegXS reconstruct_XS(MPCTIO & tio, yield_t & yield, RegXS XS) {
|
|
RegXS peer_XS;
|
|
RegXS peer_XS;
|
|
RegXS reconstructed_XS = XS;
|
|
RegXS reconstructed_XS = XS;
|
|
if (tio.player() == 1) {
|
|
if (tio.player() == 1) {
|
|
- tio.queue_peer(&XS, sizeof(XS));
|
|
+ tio.queue_peer( & XS, sizeof(XS));
|
|
} else {
|
|
} else {
|
|
RegXS peer_XS;
|
|
RegXS peer_XS;
|
|
- tio.recv_peer(&peer_XS, sizeof(peer_XS));
|
|
+ tio.recv_peer( & peer_XS, sizeof(peer_XS));
|
|
- reconstructed_XS ^= peer_XS;
|
|
+ reconstructed_XS ^= peer_XS;
|
|
}
|
|
}
|
|
|
|
|
|
yield();
|
|
yield();
|
|
|
|
|
|
if (tio.player() == 0) {
|
|
if (tio.player() == 0) {
|
|
- tio.queue_peer(&XS, sizeof(XS));
|
|
+ tio.queue_peer( & XS, sizeof(XS));
|
|
} else {
|
|
} else {
|
|
RegXS peer_flag;
|
|
RegXS peer_flag;
|
|
- tio.recv_peer(&peer_XS, sizeof(peer_XS));
|
|
+ tio.recv_peer( & peer_XS, sizeof(peer_XS));
|
|
reconstructed_XS ^= peer_XS;
|
|
reconstructed_XS ^= peer_XS;
|
|
}
|
|
}
|
|
-
|
|
+
|
|
-
|
|
+ return reconstructed_XS;
|
|
- return reconstructed_XS;
|
|
|
|
}
|
|
}
|
|
-bool reconstruct_flag(MPCTIO &tio, yield_t &yield, RegBS flag) {
|
|
+bool reconstruct_flag(MPCTIO & tio, yield_t & yield, RegBS flag) {
|
|
RegBS peer_flag;
|
|
RegBS peer_flag;
|
|
RegBS reconstructed_flag = flag;
|
|
RegBS reconstructed_flag = flag;
|
|
if (tio.player() == 1) {
|
|
if (tio.player() == 1) {
|
|
- tio.queue_peer(&flag, sizeof(flag));
|
|
+ tio.queue_peer( & flag, sizeof(flag));
|
|
} else {
|
|
} else {
|
|
RegBS peer_flag;
|
|
RegBS peer_flag;
|
|
- tio.recv_peer(&peer_flag, sizeof(peer_flag));
|
|
+ tio.recv_peer( & peer_flag, sizeof(peer_flag));
|
|
reconstructed_flag ^= peer_flag;
|
|
reconstructed_flag ^= peer_flag;
|
|
}
|
|
}
|
|
|
|
|
|
yield();
|
|
yield();
|
|
|
|
|
|
if (tio.player() == 0) {
|
|
if (tio.player() == 0) {
|
|
- tio.queue_peer(&flag, sizeof(flag));
|
|
+ tio.queue_peer( & flag, sizeof(flag));
|
|
} else {
|
|
} else {
|
|
RegBS peer_flag;
|
|
RegBS peer_flag;
|
|
- tio.recv_peer(&peer_flag, sizeof(peer_flag));
|
|
+ tio.recv_peer( & peer_flag, sizeof(peer_flag));
|
|
reconstructed_flag ^= peer_flag;
|
|
reconstructed_flag ^= peer_flag;
|
|
}
|
|
}
|
|
-
|
|
+
|
|
return reconstructed_flag.bshare;
|
|
return reconstructed_flag.bshare;
|
|
}
|
|
}
|
|
|
|
|
|
-int HEAP::insert(MPCTIO tio, yield_t &yield, RegAS val) {
|
|
+int MinHeap::insert(MPCTIO tio, yield_t & yield, RegAS val) {
|
|
- auto HeapArray = oram->flat(tio, yield);
|
|
+ auto HeapArray = oram -> flat(tio, yield);
|
|
- num_items++;
|
|
+ num_items++;
|
|
- std::cout << "num_items = " << num_items << std::endl;
|
|
+ std::cout << "num_items = " << num_items << std::endl;
|
|
-
|
|
+
|
|
- std::cout << "we are adding in: " << std::endl;
|
|
+ std::cout << "we are adding in: " << std::endl;
|
|
- reconstruct_AS(tio, yield, val);
|
|
+ reconstruct_AS(tio, yield, val);
|
|
- val.dump();
|
|
+ val.dump();
|
|
- yield();
|
|
+ yield();
|
|
- size_t child = num_items;
|
|
+ size_t childindex = num_items;
|
|
- size_t parent = child/2;
|
|
+ size_t parent = childindex / 2;
|
|
- std::cout << "child = " << child << std::endl;
|
|
+ std::cout << "childindex = " << childindex << std::endl;
|
|
- std::cout << "parent = " << parent << std::endl;
|
|
+ std::cout << "parent = " << parent << std::endl;
|
|
- HeapArray[num_items] = val;
|
|
+ HeapArray[num_items] = val;
|
|
- RegAS tmp = HeapArray[num_items];
|
|
+ RegAS tmp = HeapArray[num_items];
|
|
- reconstruct_AS(tio, yield, tmp);
|
|
+ reconstruct_AS(tio, yield, tmp);
|
|
- yield();
|
|
+ yield();
|
|
- while(parent != 0) {
|
|
+ while (parent > 0) {
|
|
-
|
|
+
|
|
- RegAS sharechild = HeapArray[child];
|
|
+ RegAS sharechild = HeapArray[childindex];
|
|
- RegAS shareparent = HeapArray[parent];
|
|
+ RegAS shareparent = HeapArray[parent];
|
|
-
|
|
+
|
|
-
|
|
+
|
|
-
|
|
+
|
|
-
|
|
+
|
|
-
|
|
+
|
|
-
|
|
+
|
|
-
|
|
+
|
|
-
|
|
+
|
|
-
|
|
+
|
|
- CDPF cdpf = tio.cdpf(yield);
|
|
+ CDPF cdpf = tio.cdpf(yield);
|
|
- RegAS diff = sharechild-shareparent;
|
|
+ RegAS diff = sharechild - shareparent;
|
|
-
|
|
+
|
|
-
|
|
+
|
|
-
|
|
+
|
|
-
|
|
+
|
|
- auto [lt, eq, gt] = cdpf.compare(tio, yield, diff, tio.aes_ops());
|
|
+ auto[lt, eq, gt] = cdpf.compare(tio, yield, diff, tio.aes_ops());
|
|
-
|
|
+
|
|
-
|
|
+
|
|
-
|
|
+
|
|
-
|
|
+
|
|
-
|
|
+
|
|
-
|
|
+
|
|
-
|
|
+
|
|
-
|
|
+
|
|
-
|
|
+
|
|
-
|
|
+
|
|
-
|
|
+
|
|
-
|
|
+
|
|
-
|
|
+
|
|
-
|
|
+
|
|
-
|
|
+
|
|
-
|
|
+
|
|
-
|
|
+
|
|
-
|
|
+
|
|
-
|
|
+
|
|
-
|
|
+
|
|
-
|
|
+
|
|
-
|
|
+
|
|
-
|
|
+
|
|
-
|
|
+
|
|
-
|
|
+
|
|
-
|
|
+
|
|
-
|
|
+
|
|
-
|
|
+
|
|
-
|
|
+
|
|
-
|
|
+
|
|
-
|
|
+
|
|
-
|
|
+
|
|
-
|
|
+
|
|
-
|
|
+
|
|
-
|
|
+
|
|
-
|
|
+
|
|
-
|
|
+
|
|
-
|
|
+
|
|
-
|
|
+
|
|
-
|
|
+
|
|
-
|
|
+
|
|
-
|
|
+
|
|
-
|
|
+
|
|
-
|
|
+
|
|
-
|
|
+
|
|
-
|
|
+
|
|
-
|
|
+
|
|
- mpc_oswap(tio, yield, sharechild, shareparent, lt, 64);
|
|
+ mpc_oswap(tio, yield, sharechild, shareparent, lt, 64);
|
|
-
|
|
+
|
|
- HeapArray[child] = sharechild;
|
|
+ HeapArray[childindex] = sharechild;
|
|
- HeapArray[parent] = shareparent;
|
|
+ HeapArray[parent] = shareparent;
|
|
-
|
|
+
|
|
-
|
|
+
|
|
-
|
|
+
|
|
-
|
|
+
|
|
-
|
|
+
|
|
-
|
|
+
|
|
-
|
|
+
|
|
-
|
|
+
|
|
-
|
|
+
|
|
-
|
|
+
|
|
-
|
|
+
|
|
-
|
|
+
|
|
-
|
|
+
|
|
-
|
|
+
|
|
-
|
|
+
|
|
-
|
|
+
|
|
-
|
|
+
|
|
-
|
|
+
|
|
- child = parent;
|
|
+ childindex = parent;
|
|
- parent = child/2;
|
|
+ parent = childindex / 2;
|
|
}
|
|
}
|
|
|
|
|
|
return 1;
|
|
return 1;
|
|
}
|
|
}
|
|
|
|
|
|
-int HEAP::verify_heap_property(MPCTIO tio, yield_t &yield) {
|
|
+int MinHeap::verify_heap_property(MPCTIO tio, yield_t & yield) {
|
|
- std::cout << std::endl << std::endl << "verify_heap_property is being called " << std::endl;
|
|
+ std::cout << std::endl << std::endl << "verify_heap_property is being called " << std::endl;
|
|
- auto HeapArray = oram->flat(tio, yield);
|
|
+ auto HeapArray = oram -> flat(tio, yield);
|
|
-
|
|
+
|
|
- RegAS heapreconstruction[num_items];
|
|
+ RegAS heapreconstruction[num_items];
|
|
- for(size_t j = 0; j <= num_items; ++j)
|
|
+ for (size_t j = 0; j <= num_items; ++j) {
|
|
- {
|
|
+ RegAS tmp = HeapArray[j];
|
|
- RegAS tmp = HeapArray[j];
|
|
+ heapreconstruction[j] = reconstruct_AS(tio, yield, tmp);
|
|
- heapreconstruction[j] = reconstruct_AS(tio, yield, tmp);
|
|
+ yield();
|
|
- yield();
|
|
+
|
|
- }
|
|
+
|
|
-
|
|
+ }
|
|
- for(size_t j = 1; j < num_items/2; ++j)
|
|
+
|
|
- {
|
|
+ for (size_t j = 1; j < num_items / 2; ++j) {
|
|
- if(heapreconstruction[j].ashare > heapreconstruction[2*j].ashare)
|
|
+ if (heapreconstruction[j].ashare > heapreconstruction[2 * j].ashare) {
|
|
- {
|
|
+ std::cout << "heap property failure\n\n";
|
|
- std::cout << "heap property failure\n\n";
|
|
+ std::cout << "j = " << j << std::endl;
|
|
- std::cout << "j = " << j << std::endl;
|
|
+ heapreconstruction[j].dump();
|
|
- heapreconstruction[j].dump();
|
|
+ std::cout << std::endl;
|
|
- std::cout << std::endl;
|
|
+ std::cout << "2*j = " << 2 * j << std::endl;
|
|
- std::cout << "2*j = " << 2*j << std::endl;
|
|
+ heapreconstruction[2 * j].dump();
|
|
- heapreconstruction[2*j].dump();
|
|
+ std::cout << std::endl;
|
|
- std::cout << std::endl;
|
|
+
|
|
-
|
|
+ }
|
|
- }
|
|
+ assert(heapreconstruction[j].ashare <= heapreconstruction[2 * j].ashare);
|
|
- assert(heapreconstruction[j].ashare <= heapreconstruction[2*j].ashare);
|
|
+ assert(heapreconstruction[j].ashare <= heapreconstruction[2 * j + 1].ashare);
|
|
- }
|
|
|
|
-
|
|
|
|
- return 1;
|
|
|
|
-}
|
|
|
|
|
|
|
|
|
|
+ }
|
|
|
|
|
|
-void verify_parent_children_heaps(MPCTIO tio, yield_t &yield, RegAS parent, RegAS leftchild, RegAS rightchild)
|
|
+ return 1;
|
|
-{
|
|
+}
|
|
|
|
+
|
|
|
|
+void verify_parent_children_heaps(MPCTIO tio, yield_t & yield, RegAS parent, RegAS leftchild, RegAS rightchild) {
|
|
RegAS parent_reconstruction = reconstruct_AS(tio, yield, parent);
|
|
RegAS parent_reconstruction = reconstruct_AS(tio, yield, parent);
|
|
yield();
|
|
yield();
|
|
RegAS leftchild_reconstruction = reconstruct_AS(tio, yield, leftchild);
|
|
RegAS leftchild_reconstruction = reconstruct_AS(tio, yield, leftchild);
|
|
@@ -244,83 +243,80 @@ void verify_parent_children_heaps(MPCTIO tio, yield_t &yield, RegAS parent, RegA
|
|
assert(parent_reconstruction.ashare <= rightchild_reconstruction.ashare);
|
|
assert(parent_reconstruction.ashare <= rightchild_reconstruction.ashare);
|
|
}
|
|
}
|
|
|
|
|
|
-
|
|
|
|
-
|
|
|
|
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
-
|
|
+
|
|
|
|
|
|
-
|
|
+
|
|
-
|
|
+
|
|
|
|
|
|
|
|
|
|
-
|
|
+
|
|
-RegXS HEAP::restore_heap_property(MPCTIO tio, yield_t &yield, RegXS index)
|
|
+RegXS MinHeap::restore_heap_property(MPCTIO tio, yield_t & yield, RegXS index) {
|
|
-{
|
|
+ RegAS smallest;
|
|
- RegAS smallest;
|
|
+ auto HeapArray = oram -> flat(tio, yield);
|
|
- auto HeapArray = oram->flat(tio, yield);
|
|
+ RegAS parent = HeapArray[index];
|
|
- RegAS parent = HeapArray[index];
|
|
+ RegXS leftchildindex = index;
|
|
- RegXS leftchildindex = index;
|
|
+ leftchildindex = index << 1;
|
|
- leftchildindex = index << 1;
|
|
|
|
-
|
|
|
|
- RegXS rightchildindex;
|
|
|
|
- rightchildindex.xshare = leftchildindex.xshare ^ (tio.player());
|
|
|
|
-
|
|
|
|
- RegAS leftchild = HeapArray[leftchildindex];
|
|
|
|
- RegAS rightchild = HeapArray[rightchildindex];
|
|
|
|
|
|
|
|
- CDPF cdpf = tio.cdpf(yield);
|
|
+ RegXS rightchildindex;
|
|
- auto [lt, eq, gt] = cdpf.compare(tio, yield, leftchild - rightchild, tio.aes_ops());
|
|
+ rightchildindex.xshare = leftchildindex.xshare ^ (tio.player());
|
|
|
|
|
|
- RegXS smallerindex;
|
|
+ RegAS leftchild = HeapArray[leftchildindex];
|
|
- mpc_select(tio, yield, smallerindex, lt, rightchildindex, leftchildindex, 64);
|
|
+ RegAS rightchild = HeapArray[rightchildindex];
|
|
-
|
|
+ RegAS sum = parent + leftchild + rightchild;
|
|
|
|
+ CDPF cdpf = tio.cdpf(yield);
|
|
|
|
+ auto[lt, eq, gt] = cdpf.compare(tio, yield, leftchild - rightchild, tio.aes_ops());
|
|
|
|
|
|
- RegAS smallerchild;
|
|
+ RegXS smallerindex;
|
|
- mpc_select(tio, yield, smallerchild, lt, rightchild, leftchild, 64);
|
|
+
|
|
-
|
|
|
|
|
|
|
|
- CDPF cdpf0 = tio.cdpf(yield);
|
|
+ smallerindex = leftchildindex ^ lt;
|
|
- auto [lt0, eq0, gt0] = cdpf0.compare(tio, yield, smallerchild - parent, tio.aes_ops());
|
|
+
|
|
-
|
|
|
|
|
|
|
|
- mpc_select(tio, yield, smallest, lt0, parent, smallerchild, 64);
|
|
+ RegAS smallerchild;
|
|
-
|
|
+ mpc_select(tio, yield, smallerchild, lt, rightchild, leftchild, 64);
|
|
|
|
+
|
|
|
|
+ RegAS largerchild = sum - parent - smallerchild;
|
|
|
|
+ CDPF cdpf0 = tio.cdpf(yield);
|
|
|
|
+ auto[lt0, eq0, gt0] = cdpf0.compare(tio, yield, smallerchild - parent, tio.aes_ops());
|
|
|
|
+
|
|
|
|
|
|
|
|
+ mpc_select(tio, yield, smallest, lt0, parent, smallerchild, 64);
|
|
|
|
+
|
|
|
|
|
|
- RegAS otherchild;
|
|
+ RegAS otherchild;
|
|
- mpc_select(tio, yield, otherchild, gt0, parent, smallerchild, 64);
|
|
+
|
|
-
|
|
+ otherchild = sum - smallest - largerchild;
|
|
|
|
+
|
|
|
|
|
|
- HeapArray[index] = smallest;
|
|
+ HeapArray[index] = smallest;
|
|
- HeapArray[smallerindex] = otherchild;
|
|
+ HeapArray[smallerindex] = otherchild;
|
|
|
|
|
|
-
|
|
+
|
|
|
|
|
|
- return smallerindex;
|
|
+ return smallerindex;
|
|
}
|
|
}
|
|
|
|
|
|
-
|
|
|
|
|
|
|
|
|
|
|
|
*/
|
|
*/
|
|
-RegXS HEAP::restore_heap_property_at_root(MPCTIO tio, yield_t &yield, size_t index)
|
|
+RegXS MinHeap::restore_heap_property_at_root(MPCTIO tio, yield_t & yield) {
|
|
-{
|
|
+ size_t index = 1;
|
|
- auto HeapArray = oram->flat(tio, yield);
|
|
+ auto HeapArray = oram -> flat(tio, yield);
|
|
RegAS parent = HeapArray[index];
|
|
RegAS parent = HeapArray[index];
|
|
RegAS leftchild = HeapArray[2 * index];
|
|
RegAS leftchild = HeapArray[2 * index];
|
|
RegAS rightchild = HeapArray[2 * index + 1];
|
|
RegAS rightchild = HeapArray[2 * index + 1];
|
|
CDPF cdpf = tio.cdpf(yield);
|
|
CDPF cdpf = tio.cdpf(yield);
|
|
- auto [lt, eq, gt] = cdpf.compare(tio, yield, leftchild - rightchild, tio.aes_ops());
|
|
+ auto[lt, eq, gt] = cdpf.compare(tio, yield, leftchild - rightchild, tio.aes_ops());
|
|
RegAS smallerchild;
|
|
RegAS smallerchild;
|
|
mpc_select(tio, yield, smallerchild, lt, rightchild, leftchild, 64);
|
|
mpc_select(tio, yield, smallerchild, lt, rightchild, leftchild, 64);
|
|
CDPF cdpf0 = tio.cdpf(yield);
|
|
CDPF cdpf0 = tio.cdpf(yield);
|
|
- auto [lt0, eq0, gt0] = cdpf0.compare(tio, yield, smallerchild - parent, tio.aes_ops());
|
|
+ auto[lt0, eq0, gt0] = cdpf0.compare(tio, yield, smallerchild - parent, tio.aes_ops());
|
|
RegAS smallest;
|
|
RegAS smallest;
|
|
mpc_select(tio, yield, smallest, lt0, parent, smallerchild, 64);
|
|
mpc_select(tio, yield, smallest, lt0, parent, smallerchild, 64);
|
|
RegAS larger_p;
|
|
RegAS larger_p;
|
|
@@ -345,33 +341,39 @@ RegXS HEAP::restore_heap_property_at_root(MPCTIO tio, yield_t &yield, size_t ind
|
|
return smallerindex;
|
|
return smallerindex;
|
|
}
|
|
}
|
|
|
|
|
|
-RegAS HEAP::extract_min(MPCTIO tio, yield_t &yield) {
|
|
+RegAS MinHeap::extract_min(MPCTIO tio, yield_t & yield) {
|
|
-
|
|
+
|
|
- RegAS minval;
|
|
+ RegAS minval;
|
|
- auto HeapArray = oram->flat(tio, yield);
|
|
+ auto HeapArray = oram -> flat(tio, yield);
|
|
- minval = HeapArray[1];
|
|
+ minval = HeapArray[1];
|
|
- HeapArray[1] = RegAS(HeapArray[num_items]);
|
|
+ HeapArray[1] = RegAS(HeapArray[num_items]);
|
|
-
|
|
+
|
|
-
|
|
+ num_items--;
|
|
- return minval;
|
|
+ RegXS smaller = restore_heap_property_at_root(tio, yield);
|
|
- }
|
|
+ std::cout << "num_items = " << num_items << std::endl;
|
|
-
|
|
+ size_t height = std::log2(num_items);
|
|
-
|
|
+ std::cout << "height = " << height << std::endl;
|
|
-void Heap(MPCIO &mpcio, const PRACOptions &opts, char **args)
|
|
+ for (size_t i = 0; i < height; ++i) {
|
|
-{
|
|
+ smaller = restore_heap_property(tio, yield, smaller);
|
|
- nbits_t depth=atoi(args[0]);
|
|
+ }
|
|
|
|
+ return minval;
|
|
|
|
+}
|
|
|
|
+
|
|
|
|
+void Heap(MPCIO & mpcio,
|
|
|
|
+ const PRACOptions & opts, char ** args) {
|
|
|
|
+ nbits_t depth = atoi(args[0]);
|
|
std::cout << "print arguements " << std::endl;
|
|
std::cout << "print arguements " << std::endl;
|
|
std::cout << args[0] << std::endl;
|
|
std::cout << args[0] << std::endl;
|
|
|
|
|
|
- if (*args) {
|
|
+ if ( * args) {
|
|
- depth = atoi(*args);
|
|
+ depth = atoi( * args);
|
|
++args;
|
|
++args;
|
|
}
|
|
}
|
|
|
|
|
|
- size_t items = (size_t(1)<<depth)-1;
|
|
+ size_t items = (size_t(1) << depth) - 1;
|
|
|
|
|
|
- if (*args) {
|
|
+ if ( * args) {
|
|
- items = atoi(*args);
|
|
+ items = atoi( * args);
|
|
++args;
|
|
++args;
|
|
}
|
|
}
|
|
|
|
|
|
@@ -379,37 +381,33 @@ void Heap(MPCIO &mpcio, const PRACOptions &opts, char **args)
|
|
|
|
|
|
MPCTIO tio(mpcio, 0, opts.num_threads);
|
|
MPCTIO tio(mpcio, 0, opts.num_threads);
|
|
|
|
|
|
- run_coroutines(tio, [&tio, depth, items](yield_t &yield) {
|
|
+ run_coroutines(tio, [ & tio, depth, items](yield_t & yield) {
|
|
- size_t size = size_t(1)<<depth;
|
|
+ size_t size = size_t(1) << depth;
|
|
std::cout << "size = " << size << std::endl;
|
|
std::cout << "size = " << size << std::endl;
|
|
-
|
|
|
|
- HEAP tree(tio.player(), size);
|
|
|
|
|
|
|
|
- for(size_t j = 0; j < 3; ++j)
|
|
+ MinHeap tree(tio.player(), size);
|
|
- {
|
|
+
|
|
|
|
+ for (size_t j = 0; j < 60; ++j) {
|
|
RegAS inserted_val;
|
|
RegAS inserted_val;
|
|
- inserted_val.randomize();
|
|
+ inserted_val.randomize(62);
|
|
- inserted_val.ashare = inserted_val.ashare/1000;
|
|
+ inserted_val.ashare = inserted_val.ashare;
|
|
tree.insert(tio, yield, inserted_val);
|
|
tree.insert(tio, yield, inserted_val);
|
|
}
|
|
}
|
|
|
|
|
|
std::cout << std::endl << "=============[Insert Done]================" << std::endl << std::endl;
|
|
std::cout << std::endl << "=============[Insert Done]================" << std::endl << std::endl;
|
|
tree.verify_heap_property(tio, yield);
|
|
tree.verify_heap_property(tio, yield);
|
|
|
|
|
|
- for(size_t j = 0; j < 2; ++j)
|
|
+ for (size_t j = 0; j < 10; ++j) {
|
|
- {
|
|
+ RegAS minval = tree.extract_min(tio, yield);
|
|
- tree.extract_min(tio, yield);
|
|
+ tree.verify_heap_property(tio, yield);
|
|
- RegXS smaller = tree.restore_heap_property_at_root(tio, yield, 1);
|
|
+ RegAS minval_reconstruction = reconstruct_AS(tio, yield, minval);
|
|
- size_t height = std::log(tree.num_items);
|
|
+ yield();
|
|
- for(size_t i = 0; i < height ; ++i)
|
|
+ std::cout << "minval_reconstruction = ";
|
|
- {
|
|
+ minval_reconstruction.dump();
|
|
- smaller = tree.restore_heap_property(tio, yield, smaller);
|
|
+ std::cout << std::endl;
|
|
- }
|
|
|
|
-
|
|
|
|
}
|
|
}
|
|
|
|
|
|
- std::cout << std::endl << "=============[Extract Min Done]================" << std::endl << std::endl;
|
|
+ std::cout << std::endl << "=============[Extract Min Done]================" << std::endl << std::endl;
|
|
tree.verify_heap_property(tio, yield);
|
|
tree.verify_heap_property(tio, yield);
|
|
});
|
|
});
|
|
-}
|
|
+}
|
|
-
|
|
|