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/27 17:26:18 UTC
(datasketches-bigquery) branch b64_cleanup created (now 5a5c560)
This is an automated email from the ASF dual-hosted git repository.
alsay pushed a change to branch b64_cleanup
in repository https://gitbox.apache.org/repos/asf/datasketches-bigquery.git
at 5a5c560 removing unused base64 code and other minor cleanup
This branch includes the following new commits:
new 5a5c560 removing unused base64 code and other minor cleanup
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: removing unused base64 code and other minor cleanup
Posted by al...@apache.org.
This is an automated email from the ASF dual-hosted git repository.
alsay pushed a commit to branch b64_cleanup
in repository https://gitbox.apache.org/repos/asf/datasketches-bigquery.git
commit 5a5c560e828f63568e90613a6674ddeac39dcbbc
Author: AlexanderSaydakov <Al...@users.noreply.github.com>
AuthorDate: Fri Sep 27 10:25:45 2024 -0700
removing unused base64 code and other minor cleanup
---
base64.hpp | 113 -------------------------------------------
cpc/cpc_sketch.cpp | 4 +-
hll/hll_sketch.cpp | 4 +-
kll/kll_sketch.cpp | 4 +-
theta/theta_sketch.cpp | 19 ++++----
tuple/tuple_sketch_int64.cpp | 6 +--
6 files changed, 18 insertions(+), 132 deletions(-)
diff --git a/base64.hpp b/base64.hpp
deleted file mode 100644
index 829761d..0000000
--- a/base64.hpp
+++ /dev/null
@@ -1,113 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-
-#ifndef BASE64_HPP_
-#define BASE64_HPP_
-
-static const char bin_to_b64[] = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
-
-static const char b64_to_bin[128] = {
- 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
- 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
- 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 62, 0, 0, 0, 63,
- 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 0, 0, 0, 0, 0, 0,
- 0, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14,
- 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 0, 0, 0, 0, 0,
- 0, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40,
- 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 0, 0, 0, 0, 0
-};
-
-// with full padding
-// produces exactly b64_enc_len(srclen) chars
-// no \0 termination
-static inline void b64_encode(const char* src, unsigned srclen, char* dst) {
- unsigned buf = 0;
- int pos = 2;
-
- while (srclen--) {
- buf |= (unsigned char)*(src++) << ((pos--) << 3);
-
- if (pos < 0) {
- *dst++ = bin_to_b64[(buf >> 18) & 0x3f];
- *dst++ = bin_to_b64[(buf >> 12) & 0x3f];
- *dst++ = bin_to_b64[(buf >> 6) & 0x3f];
- *dst++ = bin_to_b64[buf & 0x3f];
- pos = 2;
- buf = 0;
- }
- }
- if (pos != 2) {
- *dst++ = bin_to_b64[(buf >> 18) & 0x3f];
- *dst++ = bin_to_b64[(buf >> 12) & 0x3f];
- *dst++ = (pos == 0) ? bin_to_b64[(buf >> 6) & 0x3f] : '=';
- *dst++ = '=';
- }
-}
-
-// supports no padding or partial padding (one =)
-// ignores invalid chars (fills zeros instead)
-// produces exactly b64_dec_len(src, srclen) bytes
-static inline void b64_decode(const char* src, unsigned srclen, char* dst) {
- unsigned buf = 0;
- char c;
- int bits = 0;
- int pos = 0;
- int pad = 0;
-
- while (srclen--) {
- c = *src++;
- if (c == ' ' || c == '\t' || c == '\n' || c == '\r') continue;
- bits = 0;
- if (c != '=') {
- if (c > 0 && c < 127) bits = b64_to_bin[(int)c];
- } else {
- pad++;
- }
- buf = (buf << 6) | bits;
- pos++;
- if (pos == 4) {
- *dst++ = (buf >> 16) & 0xff;
- if (pad < 2) *dst++ = (buf >> 8) & 0xff;
- if (pad == 0) *dst++ = buf & 0xff;
- buf = 0;
- pos = 0;
- }
- }
- // no padding or partial padding. pos must be 2 or 3
- if (pos == 2) {
- *dst++ = (buf >> 4) & 0xff;
- } else if (pos == 3) {
- *dst++ = (buf >> 10) & 0xff;
- if (pad == 0) *dst++ = (buf >> 2) & 0xff;
- }
-}
-
-// with padding
-static inline unsigned b64_enc_len(unsigned srclen) {
- return ((srclen + 2) / 3) * 4;
-}
-
-static inline unsigned b64_dec_len(const char* src, unsigned srclen) {
- unsigned pad = 0;
- if (srclen > 0 && src[srclen - 1] == '=') pad++;
- if (srclen > 1 && src[srclen - 2] == '=') pad++;
- return ((srclen * 3) >> 2) - pad;
-}
-
-#endif
diff --git a/cpc/cpc_sketch.cpp b/cpc/cpc_sketch.cpp
index bb70a64..72a56a2 100644
--- a/cpc/cpc_sketch.cpp
+++ b/cpc/cpc_sketch.cpp
@@ -62,10 +62,10 @@ EMSCRIPTEN_BINDINGS(cpc_sketch) {
}))
.function("updateWithSketch", emscripten::optional_override([](datasketches::cpc_union& self, const datasketches::cpc_sketch& sketch) {
self.update(sketch);
- }), emscripten::allow_raw_pointers())
+ }))
.function("updateWithBytes", emscripten::optional_override([](datasketches::cpc_union& self, const std::string& bytes, uint64_t seed) {
self.update(datasketches::cpc_sketch::deserialize(bytes.data(), bytes.size(), seed));
- }), emscripten::allow_raw_pointers())
+ }))
.function("getResultAsUint8Array", emscripten::optional_override([](datasketches::cpc_union& self) {
auto bytes = self.get_result().serialize();
return Uint8Array.new_(emscripten::typed_memory_view(bytes.size(), bytes.data()));
diff --git a/hll/hll_sketch.cpp b/hll/hll_sketch.cpp
index 35b7f92..7353fbb 100644
--- a/hll/hll_sketch.cpp
+++ b/hll/hll_sketch.cpp
@@ -65,10 +65,10 @@ EMSCRIPTEN_BINDINGS(hll_sketch) {
}))
.function("updateWithSketch", emscripten::optional_override([](datasketches::hll_union& self, const datasketches::hll_sketch& sketch) {
self.update(sketch);
- }), emscripten::allow_raw_pointers())
+ }))
.function("updateWithBytes", emscripten::optional_override([](datasketches::hll_union& self, const std::string& bytes) {
self.update(datasketches::hll_sketch::deserialize(bytes.data(), bytes.size()));
- }), emscripten::allow_raw_pointers())
+ }))
.function("getResultAsUint8Array", emscripten::optional_override([](datasketches::hll_union& self, const std::string& tgt_type_str) {
auto bytes = self.get_result(convert_tgt_type(tgt_type_str)).serialize_compact();
return Uint8Array.new_(emscripten::typed_memory_view(bytes.size(), bytes.data()));
diff --git a/kll/kll_sketch.cpp b/kll/kll_sketch.cpp
index 95addfa..06f3ea1 100644
--- a/kll/kll_sketch.cpp
+++ b/kll/kll_sketch.cpp
@@ -46,7 +46,7 @@ EMSCRIPTEN_BINDINGS(kll_sketch_float) {
}))
.function("mergeBytes", emscripten::optional_override([](kll_sketch_float& self, const std::string& bytes) {
self.merge(kll_sketch_float::deserialize(bytes.data(), bytes.size()));
- }), emscripten::allow_raw_pointers())
+ }))
.function("mergeBuffer", emscripten::optional_override([](kll_sketch_float& self, intptr_t bytes, size_t size) {
self.merge(kll_sketch_float::deserialize(reinterpret_cast<void*>(bytes), size));
}))
@@ -67,7 +67,7 @@ EMSCRIPTEN_BINDINGS(kll_sketch_float) {
return self.get_CDF(split_points.data(), split_points.size(), inclusive);
}))
.function("toString", emscripten::optional_override([](const kll_sketch_float& self) {
- return std::string(self.to_string());
+ return self.to_string();
}))
;
diff --git a/theta/theta_sketch.cpp b/theta/theta_sketch.cpp
index 5ec9664..4794130 100644
--- a/theta/theta_sketch.cpp
+++ b/theta/theta_sketch.cpp
@@ -59,14 +59,14 @@ EMSCRIPTEN_BINDINGS(theta_sketch) {
emscripten::class_<compact_theta_sketch>("compact_theta_sketch")
.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("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())
+ return wrapped_compact_theta_sketch::wrap(bytes.data(), bytes.size(), seed).to_string();
+ }))
.class_function("getMaxSerializedSizeBytes", &compact_theta_sketch::get_max_serialized_size_bytes)
;
@@ -76,13 +76,13 @@ EMSCRIPTEN_BINDINGS(theta_sketch) {
}))
.function("updateWithUpdateSketch", emscripten::optional_override([](theta_union& self, const update_theta_sketch& sketch) {
self.update(sketch);
- }), emscripten::allow_raw_pointers())
+ }))
.function("updateWithCompactSketch", emscripten::optional_override([](theta_union& self, const 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("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));
}))
@@ -109,7 +109,7 @@ EMSCRIPTEN_BINDINGS(theta_sketch) {
;
emscripten::function("thetaIntersectionCompressed", emscripten::optional_override([](const std::string& bytes1, const std::string& bytes2, uint64_t seed) {
- auto intersection = theta_intersection(seed);
+ theta_intersection 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();
@@ -118,8 +118,7 @@ EMSCRIPTEN_BINDINGS(theta_sketch) {
;
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(
+ const auto bytes = theta_a_not_b(seed).compute(
wrapped_compact_theta_sketch::wrap(bytes1.data(), bytes1.size(), seed),
wrapped_compact_theta_sketch::wrap(bytes2.data(), bytes2.size(), seed)
).serialize_compressed();
diff --git a/tuple/tuple_sketch_int64.cpp b/tuple/tuple_sketch_int64.cpp
index 18ae010..f33bcd6 100644
--- a/tuple/tuple_sketch_int64.cpp
+++ b/tuple/tuple_sketch_int64.cpp
@@ -126,7 +126,7 @@ EMSCRIPTEN_BINDINGS(tuple_sketch_int64) {
return compact_tuple_sketch_int64::deserialize(sketch_bytes.data(), sketch_bytes.size(), seed).get_estimate();
}))
.class_function("toString", emscripten::optional_override([](const std::string& sketch_bytes, uint64_t seed) {
- return std::string(compact_tuple_sketch_int64::deserialize(sketch_bytes.data(), sketch_bytes.size(), seed).to_string());
+ return compact_tuple_sketch_int64::deserialize(sketch_bytes.data(), sketch_bytes.size(), seed).to_string();
}))
.class_function("filterLowHigh", emscripten::optional_override([](const std::string& sketch_bytes, int low, int high, uint64_t seed) {
auto bytes = compact_tuple_sketch_int64::deserialize(
@@ -143,10 +143,10 @@ EMSCRIPTEN_BINDINGS(tuple_sketch_int64) {
}))
.function("updateWithCompactSketch", emscripten::optional_override([](tuple_union_int64& self, const compact_tuple_sketch_int64& sketch) {
self.update(sketch);
- }), emscripten::allow_raw_pointers())
+ }))
.function("updateWithBytes", emscripten::optional_override([](tuple_union_int64& self, const std::string& bytes, uint64_t seed) {
self.update(compact_tuple_sketch_int64::deserialize(bytes.data(), bytes.size(), seed));
- }), emscripten::allow_raw_pointers())
+ }))
.function("getResultAsUint8Array", emscripten::optional_override([](tuple_union_int64& self) {
auto bytes = self.get_result().serialize();
return Uint8Array.new_(emscripten::typed_memory_view(bytes.size(), bytes.data()));
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@datasketches.apache.org
For additional commands, e-mail: commits-help@datasketches.apache.org