You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@datasketches.apache.org by al...@apache.org on 2024/09/23 23:50:03 UTC
(datasketches-bigquery) branch no_base64 created (now ecdc11b)
This is an automated email from the ASF dual-hosted git repository.
alsay pushed a change to branch no_base64
in repository https://gitbox.apache.org/repos/asf/datasketches-bigquery.git
at ecdc11b no base64 encoding-decoding
This branch includes the following new commits:
new ecdc11b no base64 encoding-decoding
The 1 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails. The revisions
listed as "add" were already present in the repository and have only
been added to this reference.
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@datasketches.apache.org
For additional commands, e-mail: commits-help@datasketches.apache.org
(datasketches-bigquery) 01/01: no base64 encoding-decoding
Posted by al...@apache.org.
This is an automated email from the ASF dual-hosted git repository.
alsay pushed a commit to branch no_base64
in repository https://gitbox.apache.org/repos/asf/datasketches-bigquery.git
commit ecdc11bae530f278a0dc1ae02a62839ca27e29b4
Author: AlexanderSaydakov <Al...@users.noreply.github.com>
AuthorDate: Mon Sep 23 16:49:38 2024 -0700
no base64 encoding-decoding
---
theta/sqlx/theta_sketch_a_not_b_seed.sqlx | 10 +-
.../theta_sketch_get_estimate_and_bounds_seed.sqlx | 19 +--
theta/sqlx/theta_sketch_get_estimate_seed.sqlx | 10 +-
theta/sqlx/theta_sketch_intersection_seed.sqlx | 11 +-
.../sqlx/theta_sketch_jaccard_similarity_seed.sqlx | 2 +
theta/sqlx/theta_sketch_to_string_seed.sqlx | 10 +-
theta/sqlx/theta_sketch_union_lgk_seed.sqlx | 16 +-
theta/theta_sketch.cpp | 162 ++++-----------------
8 files changed, 55 insertions(+), 185 deletions(-)
diff --git a/theta/sqlx/theta_sketch_a_not_b_seed.sqlx b/theta/sqlx/theta_sketch_a_not_b_seed.sqlx
index 9b36bcf..e2ad14c 100644
--- a/theta/sqlx/theta_sketch_a_not_b_seed.sqlx
+++ b/theta/sqlx/theta_sketch_a_not_b_seed.sqlx
@@ -24,6 +24,7 @@ RETURNS BYTES
LANGUAGE js
OPTIONS (
library=["gs://$GCS_BUCKET/theta_sketch.js"],
+ js_parameter_encoding_mode='STANDARD',
description = '''Computes a sketch that represents the scalar set difference: sketchA and not sketchB.
Param sketchA: the first sketch "A" as bytes.
@@ -43,14 +44,9 @@ For more information:
) AS R"""
const default_seed = BigInt(Module.DEFAULT_SEED);
try {
- var a_not_b = null;
- try {
- a_not_b = new Module.theta_a_not_b(seed ? BigInt(seed) : default_seed);
- return a_not_b.computeWithB64ReturnB64Compressed(sketchA, sketchB, seed ? BigInt(seed) : default_seed);
- } finally {
- if (a_not_b != null) a_not_b.delete();
- }
+ return Module.thetaAnotBCompressed(sketchA, sketchB, seed ? BigInt(seed) : default_seed);
} catch (e) {
+ if (e.message != null) throw e;
throw new Error(Module.getExceptionMessage(e));
}
""";
diff --git a/theta/sqlx/theta_sketch_get_estimate_and_bounds_seed.sqlx b/theta/sqlx/theta_sketch_get_estimate_and_bounds_seed.sqlx
index c0d9ec6..1ca5db0 100644
--- a/theta/sqlx/theta_sketch_get_estimate_and_bounds_seed.sqlx
+++ b/theta/sqlx/theta_sketch_get_estimate_and_bounds_seed.sqlx
@@ -24,6 +24,7 @@ RETURNS STRUCT<estimate FLOAT64, lower_bound FLOAT64, upper_bound FLOAT64>
LANGUAGE js
OPTIONS (
library=["gs://$GCS_BUCKET/theta_sketch.js"],
+ js_parameter_encoding_mode='STANDARD',
description = '''Gets cardinality estimate and bounds from given sketch.
Param sketch: The given sketch to query as BYTES.
@@ -45,18 +46,14 @@ For more information:
) AS R"""
const default_seed = BigInt(Module.DEFAULT_SEED);
try {
- var sketchObject = null;
- try {
- sketchObject = Module.compact_theta_sketch.deserializeFromB64(sketch, seed ? BigInt(seed) : default_seed);
- return {
- estimate: sketchObject.getEstimate(),
- lower_bound: sketchObject.getLowerBound(num_std_devs),
- upper_bound: sketchObject.getUpperBound(num_std_devs)
- };
- } finally {
- if (sketchObject != null) sketchObject.delete();
- }
+ const result = Module.compact_theta_sketch.getEstimateAndBoundsFromBytes(sketch, Number(num_std_devs), seed ? BigInt(seed) : default_seed);
+ return {
+ estimate: result.get(0),
+ lower_bound: result.get(1),
+ upper_bound: result.get(2)
+ };
} catch (e) {
+ if (e.message != null) throw e;
throw new Error(Module.getExceptionMessage(e));
}
""";
diff --git a/theta/sqlx/theta_sketch_get_estimate_seed.sqlx b/theta/sqlx/theta_sketch_get_estimate_seed.sqlx
index f51c50f..78ef183 100644
--- a/theta/sqlx/theta_sketch_get_estimate_seed.sqlx
+++ b/theta/sqlx/theta_sketch_get_estimate_seed.sqlx
@@ -24,6 +24,7 @@ RETURNS FLOAT64
LANGUAGE js
OPTIONS (
library=["gs://$GCS_BUCKET/theta_sketch.js"],
+ js_parameter_encoding_mode='STANDARD',
description = '''Gets cardinality estimate and bounds from given sketch.
Param sketch: The given sketch to query as BYTES.
@@ -39,14 +40,9 @@ For more information:
) AS R"""
const default_seed = BigInt(Module.DEFAULT_SEED);
try {
- var sketchObject = null;
- try {
- sketchObject = Module.compact_theta_sketch.deserializeFromB64(sketch, seed ? BigInt(seed) : default_seed);
- return sketchObject.getEstimate();
- } finally {
- if (sketchObject != null) sketchObject.delete();
- }
+ return Module.compact_theta_sketch.getEstimateFromBytes(sketch, seed ? BigInt(seed) : default_seed);
} catch (e) {
+ if (e.message != null) throw e;
throw new Error(Module.getExceptionMessage(e));
}
""";
diff --git a/theta/sqlx/theta_sketch_intersection_seed.sqlx b/theta/sqlx/theta_sketch_intersection_seed.sqlx
index 24a5621..010a280 100644
--- a/theta/sqlx/theta_sketch_intersection_seed.sqlx
+++ b/theta/sqlx/theta_sketch_intersection_seed.sqlx
@@ -24,6 +24,7 @@ RETURNS BYTES
LANGUAGE js
OPTIONS (
library=["gs://$GCS_BUCKET/theta_sketch.js"],
+ js_parameter_encoding_mode='STANDARD',
description = '''Computes a sketch that represents the scalar intersection of the two given sketches.
Param sketchA: the first sketch as BYTES.
@@ -43,15 +44,9 @@ For more information:
) AS R"""
const default_seed = BigInt(Module.DEFAULT_SEED);
try {
- var intersection = new Module.theta_intersection(seed ? BigInt(seed) : default_seed);
- try {
- intersection.updateWithB64(sketchA, seed ? BigInt(seed) : default_seed);
- intersection.updateWithB64(sketchB, seed ? BigInt(seed) : default_seed);
- return intersection.getResultB64Compressed();
- } finally {
- intersection.delete();
- }
+ return Module.thetaIntersectionCompressed(sketchA, sketchB, seed ? BigInt(seed) : default_seed);
} catch (e) {
+ if (e.message != null) throw e;
throw new Error(Module.getExceptionMessage(e));
}
""";
diff --git a/theta/sqlx/theta_sketch_jaccard_similarity_seed.sqlx b/theta/sqlx/theta_sketch_jaccard_similarity_seed.sqlx
index a48fbcc..12058c5 100644
--- a/theta/sqlx/theta_sketch_jaccard_similarity_seed.sqlx
+++ b/theta/sqlx/theta_sketch_jaccard_similarity_seed.sqlx
@@ -24,6 +24,7 @@ RETURNS STRUCT<lower_bound FLOAT64, estimate FLOAT64, upper_bound FLOAT64>
LANGUAGE js
OPTIONS (
library=["gs://$GCS_BUCKET/theta_sketch.js"],
+ js_parameter_encoding_mode='STANDARD',
description = '''Computes the Jaccard similarity index with upper and lower bounds.
The Jaccard similarity index J(A,B) = (A ^ B)/(A U B) is used to measure how similar the two sketches are to each other.
If J = 1.0, the sketches are considered equal. If J = 0, the two sketches are disjoint.
@@ -47,6 +48,7 @@ try {
upper_bound: jaccard.get(2)
};
} catch (e) {
+ if (e.message != null) throw e;
throw new Error(Module.getExceptionMessage(e));
}
""";
diff --git a/theta/sqlx/theta_sketch_to_string_seed.sqlx b/theta/sqlx/theta_sketch_to_string_seed.sqlx
index d59b301..296e4b4 100644
--- a/theta/sqlx/theta_sketch_to_string_seed.sqlx
+++ b/theta/sqlx/theta_sketch_to_string_seed.sqlx
@@ -24,6 +24,7 @@ RETURNS STRING
LANGUAGE js
OPTIONS (
library=["gs://$GCS_BUCKET/theta_sketch.js"],
+ js_parameter_encoding_mode='STANDARD',
description = '''Returns a summary string that represents the state of the given sketch.
Param sketch: the given sketch as BYTES.
@@ -36,14 +37,9 @@ For more information:
) AS R"""
const default_seed = BigInt(Module.DEFAULT_SEED);
try {
- var sketchObject = null;
- try {
- sketchObject = Module.compact_theta_sketch.deserializeFromB64(sketch, seed ? BigInt(seed) : default_seed);
- return sketchObject.toString();
- } finally {
- if (sketchObject != null) sketchObject.delete();
- }
+ return Module.compact_theta_sketch.toStringFromBytes(sketch, seed ? BigInt(seed) : default_seed);
} catch (e) {
+ if (e.message != null) throw e;
throw new Error(Module.getExceptionMessage(e));
}
""";
diff --git a/theta/sqlx/theta_sketch_union_lgk_seed.sqlx b/theta/sqlx/theta_sketch_union_lgk_seed.sqlx
index d3fd346..e501eec 100644
--- a/theta/sqlx/theta_sketch_union_lgk_seed.sqlx
+++ b/theta/sqlx/theta_sketch_union_lgk_seed.sqlx
@@ -24,6 +24,7 @@ RETURNS BYTES
LANGUAGE js
OPTIONS (
library=["gs://$GCS_BUCKET/theta_sketch.js"],
+ js_parameter_encoding_mode='STANDARD',
description = '''Computes a sketch that represents the scalar union of the two given sketches.
Param sketchA: the first sketch as BYTES.
@@ -43,15 +44,14 @@ For more information:
const default_lg_k = Number(Module.DEFAULT_LG_K);
const default_seed = BigInt(Module.DEFAULT_SEED);
try {
- var union = new Module.theta_union(lg_k ? lg_k : default_lg_k, seed ? BigInt(seed) : default_seed);
- try {
- union.updateWithB64(sketchA, seed ? BigInt(seed) : default_seed)
- union.updateWithB64(sketchB, seed ? BigInt(seed) : default_seed)
- return union.getResultB64Compressed();
- } finally {
- union.delete();
- }
+ return Module.theta_union.computeWithBytesReturnCompressed(
+ sketchA,
+ sketchB,
+ lg_k ? Number(lg_k) : default_lg_k,
+ seed ? BigInt(seed) : default_seed
+ );
} catch (e) {
+ if (e.message != null) throw e;
throw new Error(Module.getExceptionMessage(e));
}
""";
diff --git a/theta/theta_sketch.cpp b/theta/theta_sketch.cpp
index f91da30..5ec9664 100644
--- a/theta/theta_sketch.cpp
+++ b/theta/theta_sketch.cpp
@@ -26,8 +26,6 @@
#include <theta_a_not_b.hpp>
#include <theta_jaccard_similarity.hpp>
-#include "../base64.hpp"
-
using datasketches::update_theta_sketch;
using datasketches::compact_theta_sketch;
using datasketches::wrapped_compact_theta_sketch;
@@ -52,22 +50,6 @@ EMSCRIPTEN_BINDINGS(theta_sketch) {
return new update_theta_sketch(update_theta_sketch::builder().set_lg_k(lg_k).set_seed(seed).set_p(p).build());
}))
.function("updateString", emscripten::select_overload<void(const std::string&)>(&update_theta_sketch::update))
- .function("serializeB64", emscripten::optional_override([](const update_theta_sketch& self) {
- auto bytes = self.compact().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("serializeB64Compressed", emscripten::optional_override([](const update_theta_sketch& self) {
- auto bytes = self.compact().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());
- }))
- .function("serializeAsUint8Array", emscripten::optional_override([](const update_theta_sketch& self) {
- auto bytes = self.compact().serialize();
- return Uint8Array.new_(emscripten::typed_memory_view(bytes.size(), bytes.data()));
- }))
.function("serializeAsUint8ArrayCompressed", emscripten::optional_override([](const update_theta_sketch& self) {
auto bytes = self.compact().serialize_compressed();
return Uint8Array.new_(emscripten::typed_memory_view(bytes.size(), bytes.data()));
@@ -75,44 +57,19 @@ EMSCRIPTEN_BINDINGS(theta_sketch) {
;
emscripten::class_<compact_theta_sketch>("compact_theta_sketch")
- .constructor(emscripten::optional_override([](intptr_t bytes, size_t size, uint64_t seed) {
- return new compact_theta_sketch(compact_theta_sketch::deserialize(reinterpret_cast<void*>(bytes), size, seed));
- }))
- .class_function("deserializeFromB64", emscripten::optional_override([](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());
- return new compact_theta_sketch(compact_theta_sketch::deserialize(bytes.data(), bytes.size(), seed));
+ .class_function("getEstimateFromBytes", emscripten::optional_override([](const std::string& bytes, uint64_t seed) {
+ return wrapped_compact_theta_sketch::wrap(bytes.data(), bytes.size(), seed).get_estimate();
}), emscripten::allow_raw_pointers())
- .class_function("deserializeFromBinary", emscripten::optional_override([](const std::string& bytes, uint64_t seed) {
- return new compact_theta_sketch(compact_theta_sketch::deserialize(bytes.data(), bytes.size(), seed));
+ .class_function("getEstimateAndBoundsFromBytes", emscripten::optional_override([](const std::string& bytes, uint8_t num_std_devs, uint64_t seed) {
+ const auto sketch = wrapped_compact_theta_sketch::wrap(bytes.data(), bytes.size(), seed);
+ return std::vector<double>{sketch.get_estimate(), sketch.get_lower_bound(num_std_devs), sketch.get_upper_bound(num_std_devs)};
+ }), emscripten::allow_raw_pointers())
+ .class_function("toStringFromBytes", emscripten::optional_override([](const std::string& bytes, uint64_t seed) {
+ return std::string(wrapped_compact_theta_sketch::wrap(bytes.data(), bytes.size(), seed).to_string());
}), emscripten::allow_raw_pointers())
- .function("getEstimate", emscripten::optional_override([](const compact_theta_sketch& self) {
- return self.get_estimate();
- }))
- .function("getLowerBound", emscripten::optional_override([](const compact_theta_sketch& self, uint8_t num_std_devs) {
- return self.get_lower_bound(num_std_devs);
- }))
- .function("getUpperBound", emscripten::optional_override([](const compact_theta_sketch& self, uint8_t num_std_devs) {
- return self.get_upper_bound(num_std_devs);
- }))
- .function("toString", emscripten::optional_override([](const compact_theta_sketch& self) {
- return std::string(self.to_string());
- }))
.class_function("getMaxSerializedSizeBytes", &compact_theta_sketch::get_max_serialized_size_bytes)
;
- emscripten::class_<wrapped_compact_theta_sketch>("wrapped_compact_theta_sketch")
- .constructor(emscripten::optional_override([](intptr_t bytes, size_t size) {
- return new wrapped_compact_theta_sketch(wrapped_compact_theta_sketch::wrap(reinterpret_cast<void*>(bytes), size));
- }))
- .function("getEstimate", emscripten::optional_override([](wrapped_compact_theta_sketch& self) {
- return self.get_estimate();
- }))
- .function("toString", emscripten::optional_override([](wrapped_compact_theta_sketch& self) {
- return std::string(self.to_string());
- }))
- ;
-
emscripten::class_<theta_union>("theta_union")
.constructor(emscripten::optional_override([](uint8_t lg_k, uint64_t seed) {
return new theta_union(theta_union::builder().set_lg_k(lg_k).set_seed(seed).build());
@@ -123,17 +80,9 @@ EMSCRIPTEN_BINDINGS(theta_sketch) {
.function("updateWithCompactSketch", emscripten::optional_override([](theta_union& self, const compact_theta_sketch& sketch) {
self.update(sketch);
}), emscripten::allow_raw_pointers())
- .function("updateWithWrappedSketch", emscripten::optional_override([](theta_union& self, const wrapped_compact_theta_sketch& sketch) {
- self.update(sketch);
- }), emscripten::allow_raw_pointers())
.function("updateWithBytes", emscripten::optional_override([](theta_union& self, const std::string& bytes, uint64_t seed) {
self.update(wrapped_compact_theta_sketch::wrap(bytes.data(), bytes.size(), seed));
}), emscripten::allow_raw_pointers())
- .function("updateWithB64", emscripten::optional_override([](theta_union& 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("updateWithBuffer", emscripten::optional_override([](theta_union& self, intptr_t bytes, size_t size, uint64_t seed) {
self.update(wrapped_compact_theta_sketch::wrap(reinterpret_cast<void*>(bytes), size, seed));
}))
@@ -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()));
}))
;
- emscripten::function("thetaJaccardSimilarity", emscripten::optional_override([](const std::string& sketch1_b64, const std::string& sketch2_b64, uint64_t seed) {
- std::vector<char> bytes1(b64_dec_len(sketch1_b64.data(), sketch1_b64.size()));
- b64_decode(sketch1_b64.data(), sketch1_b64.size(), bytes1.data());
- std::vector<char> bytes2(b64_dec_len(sketch2_b64.data(), sketch2_b64.size()));
- b64_decode(sketch2_b64.data(), sketch2_b64.size(), bytes2.data());
+ emscripten::function("thetaJaccardSimilarity", emscripten::optional_override([](const std::string& bytes1, const std::string& bytes2, uint64_t seed) {
const auto arr = datasketches::theta_jaccard_similarity::jaccard(
wrapped_compact_theta_sketch::wrap(bytes1.data(), bytes1.size(), seed),
wrapped_compact_theta_sketch::wrap(bytes2.data(), bytes2.size(), seed),
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@datasketches.apache.org
For additional commands, e-mail: commits-help@datasketches.apache.org