Sfoglia il codice sorgente

Variants of Shape::init() that work for general T as well

Ian Goldberg 1 anno fa
parent
commit
a359afae5d
2 ha cambiato i file con 52 aggiunte e 5 eliminazioni
  1. 5 0
      cell.cpp
  2. 47 5
      duoram.hpp

+ 5 - 0
cell.cpp

@@ -22,6 +22,11 @@ void cell(MPCIO &mpcio,
         size_t size = size_t(1)<<depth;
         Duoram<Cell> oram(tio.player(), size);
         auto A = oram.flat(tio, yield);
+        Cell init;
+        init.key.set(0xffffffffffffffff);
+        init.pointers.set(0xeeeeeeeeeeeeeeee);
+        init.value.set(0xdddddddddddddddd);
+        A.init(init);
         Cell c;
         c.key.set(0x0102030405060708);
         c.pointers.set(0x1112131415161718);

+ 47 - 5
duoram.hpp

@@ -246,15 +246,30 @@ public:
     inline size_t size() const { return shape_size; }
 
     // Initialize the contents of the Shape to a constant.  This method
-    // does no communication; all the operations are local.
+    // does no communication; all the operations are local.  This only
+    // works for T=RegXS or RegAS.
     void init(size_t value) {
+        T v;
+        v.set(value);
+        init([v] (size_t i) { return v; });
+    }
+
+    // As above, but for general T
+    void init(const T &value) {
         init([value] (size_t i) { return value; });
     }
 
-    // Pass a function f: size_t -> size_t, and initialize element i of
-    // the Shape to f(i) for each i.  This method does no communication;
-    // all the operations are local.  This function _must_ be
-    // deterministic.
+    // As above, but use the default initializer for T (probably sets
+    // everything to 0).
+    void init() {
+        T deflt;
+        init(deflt);
+    }
+
+    // Pass a function f: size_t -> size_t, and initialize element i of the
+    // Shape to f(i) for each i.  This method does no communication; all
+    // the operations are local.  This function must be deterministic
+    // and public.  Only works for T=RegAS or RegXS.
     void init(std::function<size_t(size_t)> f) {
         int player = tio.player();
         if (player < 2) {
@@ -278,6 +293,33 @@ public:
         }
     }
 
+    // Pass a function f: size_t -> T, and initialize element i of the
+    // Shape to f(i) for each i.  This method does no communication; all
+    // the operations are local.  This function must be deterministic
+    // and public.
+    void init(std::function<T(size_t)> f) {
+        int player = tio.player();
+        if (player < 2) {
+            for (size_t i=0; i<shape_size; ++i) {
+                auto [DB, BL, PBD] = get_comp(i);
+                BL = T();
+                if (player) {
+                    DB = f(i);
+                    PBD = T();
+                } else {
+                    DB = T();
+                    PBD = f(i);
+                }
+            }
+        } else {
+            for (size_t i=0; i<shape_size; ++i) {
+                auto [BL0, BL1] = get_server(i);
+                BL0 = T();
+                BL1 = T();
+            }
+        }
+    }
+
     // Enable or disable explicit-only mode.  Only using [] with
     // explicit (address_t) indices are allowed in this mode.  Using []
     // with RegAS or RegXS indices will automatically turn off this