jmalkin commented on code in PR #48:
URL: 
https://github.com/apache/datasketches-bigquery/pull/48#discussion_r1772424809


##########
theta/theta_sketch.cpp:
##########
@@ -150,96 +99,35 @@ EMSCRIPTEN_BINDINGS(theta_sketch) {
       auto bytes = self.get_result().serialize_compressed();
       return Uint8Array.new_(emscripten::typed_memory_view(bytes.size(), 
bytes.data()));
     }))
-    .function("getResultB64", emscripten::optional_override([](theta_union& 
self) {
-      auto bytes = self.get_result().serialize();
-      std::vector<char> b64(b64_enc_len(bytes.size()));
-      b64_encode((const char*) bytes.data(), bytes.size(), b64.data());
-      return std::string(b64.data(), b64.size());
-    }))
-    .function("getResultB64Compressed", 
emscripten::optional_override([](theta_union& self) {
-      auto bytes = self.get_result().serialize_compressed();
-      std::vector<char> b64(b64_enc_len(bytes.size()));
-      b64_encode((const char*) bytes.data(), bytes.size(), b64.data());
-      return std::string(b64.data(), b64.size());
+    .class_function("computeWithBytesReturnCompressed", 
emscripten::optional_override([](const std::string& bytes1, const std::string& 
bytes2, uint8_t lg_k, uint64_t seed) {
+      auto u = theta_union::builder().set_lg_k(lg_k).set_seed(seed).build();
+      u.update(wrapped_compact_theta_sketch::wrap(bytes1.data(), 
bytes1.size(), seed));
+      u.update(wrapped_compact_theta_sketch::wrap(bytes2.data(), 
bytes2.size(), seed));
+      const auto bytes = u.get_result().serialize_compressed();
+      return Uint8Array.new_(emscripten::typed_memory_view(bytes.size(), 
bytes.data()));
     }))
     ;
 
-  emscripten::class_<theta_intersection>("theta_intersection")
-    .constructor(emscripten::optional_override([](uint64_t seed) {
-      return new theta_intersection(seed);
-    }))
-    .function("updateWithCompactSketch", 
emscripten::optional_override([](theta_intersection& self, const 
compact_theta_sketch& sketch) {
-      self.update(sketch);
-    }))
-    .function("updateWithWrappedSketch", 
emscripten::optional_override([](theta_intersection& self, const 
wrapped_compact_theta_sketch& sketch) {
-      self.update(sketch);
-    }))
-    .function("updateWithB64", 
emscripten::optional_override([](theta_intersection& self, const std::string& 
b64, uint64_t seed) {
-      std::vector<char> bytes(b64_dec_len(b64.data(), b64.size()));
-      b64_decode(b64.data(), b64.size(), bytes.data());
-      self.update(wrapped_compact_theta_sketch::wrap(bytes.data(), 
bytes.size(), seed));
-    }), emscripten::allow_raw_pointers())
-    .function("getResultB64", 
emscripten::optional_override([](theta_intersection& self) {
-      auto bytes = self.get_result().serialize();
-      std::vector<char> b64(b64_enc_len(bytes.size()));
-      b64_encode((const char*) bytes.data(), bytes.size(), b64.data());
-      return std::string(b64.data(), b64.size());
-    }))
-    .function("getResultB64Compressed", 
emscripten::optional_override([](theta_intersection& self) {
-      auto bytes = self.get_result().serialize_compressed();
-      std::vector<char> b64(b64_enc_len(bytes.size()));
-      b64_encode((const char*) bytes.data(), bytes.size(), b64.data());
-      return std::string(b64.data(), b64.size());
+  emscripten::function("thetaIntersectionCompressed", 
emscripten::optional_override([](const std::string& bytes1, const std::string& 
bytes2, uint64_t seed) {
+      auto intersection = theta_intersection(seed);
+      intersection.update(wrapped_compact_theta_sketch::wrap(bytes1.data(), 
bytes1.size(), seed));
+      intersection.update(wrapped_compact_theta_sketch::wrap(bytes2.data(), 
bytes2.size(), seed));
+      const auto bytes = intersection.get_result().serialize_compressed();
+      return Uint8Array.new_(emscripten::typed_memory_view(bytes.size(), 
bytes.data()));
     }))
     ;
 
-  emscripten::class_<theta_a_not_b>("theta_a_not_b")
-    .constructor(emscripten::optional_override([](uint64_t seed) {
-      return new theta_a_not_b(seed);
-    }))
-    .function("computeWithCompactSketch", 
emscripten::optional_override([](theta_a_not_b& self,
-      const compact_theta_sketch& sketch1, const compact_theta_sketch& 
sketch2) {
-      return self.compute(sketch1, sketch2);
-    }))
-    .function("computeWithWrappedSketch", 
emscripten::optional_override([](theta_a_not_b& self,
-      const wrapped_compact_theta_sketch& sketch1, const 
wrapped_compact_theta_sketch& sketch2) {
-      return self.compute(sketch1, sketch2);
-    }))
-    .function("computeWithB64ReturnB64", 
emscripten::optional_override([](theta_a_not_b& self,
-      const std::string& b64_1, const std::string& b64_2, uint64_t seed) {
-      std::vector<char> bytes1(b64_dec_len(b64_1.data(), b64_1.size()));
-      b64_decode(b64_1.data(), b64_1.size(), bytes1.data());
-      std::vector<char> bytes2(b64_dec_len(b64_2.data(), b64_2.size()));
-      b64_decode(b64_2.data(), b64_2.size(), bytes2.data());
-      auto bytes = self.compute(
-        wrapped_compact_theta_sketch::wrap(bytes1.data(), bytes1.size(), seed),
-        wrapped_compact_theta_sketch::wrap(bytes2.data(), bytes2.size(), seed)
-      ).serialize();
-      std::vector<char> b64(b64_enc_len(bytes.size()));
-      b64_encode((const char*) bytes.data(), bytes.size(), b64.data());
-      return std::string(b64.data(), b64.size());
-    }))
-    .function("computeWithB64ReturnB64Compressed", 
emscripten::optional_override([](theta_a_not_b& self,
-      const std::string& b64_1, const std::string& b64_2, uint64_t seed) {
-      std::vector<char> bytes1(b64_dec_len(b64_1.data(), b64_1.size()));
-      b64_decode(b64_1.data(), b64_1.size(), bytes1.data());
-      std::vector<char> bytes2(b64_dec_len(b64_2.data(), b64_2.size()));
-      b64_decode(b64_2.data(), b64_2.size(), bytes2.data());
-      auto bytes = self.compute(
+  emscripten::function("thetaAnotBCompressed", 
emscripten::optional_override([](const std::string& bytes1, const std::string& 
bytes2, uint64_t seed) {
+      auto a_not_b = theta_a_not_b(seed);
+      const auto bytes = a_not_b.compute(
         wrapped_compact_theta_sketch::wrap(bytes1.data(), bytes1.size(), seed),
         wrapped_compact_theta_sketch::wrap(bytes2.data(), bytes2.size(), seed)
       ).serialize_compressed();
-      std::vector<char> b64(b64_enc_len(bytes.size()));
-      b64_encode((const char*) bytes.data(), bytes.size(), b64.data());
-      return std::string(b64.data(), b64.size());
+      return Uint8Array.new_(emscripten::typed_memory_view(bytes.size(), 
bytes.data()));

Review Comment:
   should we specify a return_value_policy on things like this? (it's an actual 
question, not saying we need to)



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to