Browse Source

Remove set_num_items

We don't want code outside of MinHeap to manually set num_items.
Have the 3-arg form of init() take the number of items as the third arg
(instead of the constant 1) and set num_items internally.
Ian Goldberg 7 months ago
parent
commit
e15fbf8991
2 changed files with 13 additions and 16 deletions
  1. 7 5
      heap.cpp
  2. 6 11
      heap.hpp

+ 7 - 5
heap.cpp

@@ -473,13 +473,14 @@ void MinHeap::init(MPCTIO tio, yield_t & yield) {
 
 
 // This function simply inits a heap with values 1,2,...,n
-// We use this function only to setup our heap 
+// We use this function only to set up our heap 
 // to do timing experiments on insert and extractmins
-void MinHeap::init(MPCTIO tio, yield_t & yield, size_t which_init) {
+void MinHeap::init(MPCTIO tio, yield_t & yield, size_t n) {
     auto HeapArray = oram.flat(tio, yield);
 
+    num_items = n;
     HeapArray.explicitonly(true);
-    for (size_t j = 1; j <= num_items; ++j) {
+    for (size_t j = 1; j <= n; ++j) {
         RegAS v;
         v.ashare = j * tio.player();
         HeapArray[j] = v;
@@ -699,8 +700,9 @@ void Heap(MPCIO & mpcio,  const PRACOptions & opts, char ** args, int argc) {
         size_t size = size_t(1) << maxdepth;
         MinHeap tree(tio.player(), size);
         tree.init(tio, yield);
-        tree.set_num_items((size_t(1) << heapdepth) - 1);
-        tree.init(tio, yield, 1);
+        // This form of init with a third parameter of n sets the heap
+        // to contain 1, 2, 3, ..., n.
+        tree.init(tio, yield, (size_t(1) << heapdepth) - 1);
         std::cout << "\n===== Init Stats =====\n";
         tio.sync_lamport();
         mpcio.dump_stats(std::cout);

+ 6 - 11
heap.hpp

@@ -8,18 +8,13 @@
 #include "mpcops.hpp"
 
 class MinHeap {
-    private: 
+private: 
     Duoram < RegAS > oram;
     size_t MAX_SIZE;
     size_t num_items;
 
-    public: 
-    
-    MinHeap(int player_num, size_t size) : oram(player_num, size){
-
-    };
-
-    void set_num_items (size_t n) {num_items = n;}
+public: 
+    MinHeap(int player_num, size_t size) : oram(player_num, size) {};
 
     // The extractmin protocol returns the minimum element (the root), removes it
     // and restores the heap property
@@ -30,9 +25,9 @@ class MinHeap {
     void init(MPCTIO tio, yield_t & yield);
     
     // This function simply inits a heap with values 1,2,...,n
-    // We use this function only to setup our heap 
+    // We use this function only to set up our heap 
     // to do timing experiments on insert and extractmins
-    void init(MPCTIO tio, yield_t & yield, size_t which_init);
+    void init(MPCTIO tio, yield_t & yield, size_t n);
     
     // The Basic Insert Protocol
     // Takes in the additive share of the value to be inserted
@@ -63,4 +58,4 @@ class MinHeap {
 
 void Heap(MPCIO &mpcio,
    const PRACOptions &opts, char **args, int argc);
-#endif
+#endif