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 2021/07/13 01:02:37 UTC

[datasketches-postgresql] branch wrapped_compact_theta_sketch updated: use wrapped compact for intersection

This is an automated email from the ASF dual-hosted git repository.

alsay pushed a commit to branch wrapped_compact_theta_sketch
in repository https://gitbox.apache.org/repos/asf/datasketches-postgresql.git


The following commit(s) were added to refs/heads/wrapped_compact_theta_sketch by this push:
     new 4143a7a  use wrapped compact for intersection
4143a7a is described below

commit 4143a7a8b7b1a30e8273dca9e7060df7a0025a09
Author: AlexanderSaydakov <Al...@users.noreply.github.com>
AuthorDate: Mon Jul 12 18:02:16 2021 -0700

    use wrapped compact for intersection
---
 src/theta_sketch_c_adapter.cpp  |  4 ++--
 src/theta_sketch_c_adapter.h    |  2 +-
 src/theta_sketch_pg_functions.c | 15 +++------------
 3 files changed, 6 insertions(+), 15 deletions(-)

diff --git a/src/theta_sketch_c_adapter.cpp b/src/theta_sketch_c_adapter.cpp
index 7b09ec9..8f46280 100644
--- a/src/theta_sketch_c_adapter.cpp
+++ b/src/theta_sketch_c_adapter.cpp
@@ -211,9 +211,9 @@ void theta_intersection_delete(void* interptr) {
   }
 }
 
-void theta_intersection_update(void* interptr, const void* sketchptr) {
+void theta_intersection_update(void* interptr, const void* buffer, unsigned length) {
   try {
-    static_cast<theta_intersection_pg*>(interptr)->update(*static_cast<const theta_sketch_pg*>(sketchptr));
+    static_cast<theta_intersection_pg*>(interptr)->update(wrapped_compact_theta_sketch_pg::wrap(buffer, length));
   } catch (std::exception& e) {
     pg_error(e.what());
   }
diff --git a/src/theta_sketch_c_adapter.h b/src/theta_sketch_c_adapter.h
index 4aaf438..4c716c1 100644
--- a/src/theta_sketch_c_adapter.h
+++ b/src/theta_sketch_c_adapter.h
@@ -49,7 +49,7 @@ void* theta_union_get_result(const void* unionptr);
 
 void* theta_intersection_new_default();
 void theta_intersection_delete(void* interptr);
-void theta_intersection_update(void* interptr, const void* sketchptr);
+void theta_intersection_update(void* interptr, const void* buffer, unsigned length);
 void* theta_intersection_get_result(const void* interptr);
 
 void* theta_a_not_b(const void* sketchptr1, const void* sketchptr2);
diff --git a/src/theta_sketch_pg_functions.c b/src/theta_sketch_pg_functions.c
index 2ef8517..c6678f4 100644
--- a/src/theta_sketch_pg_functions.c
+++ b/src/theta_sketch_pg_functions.c
@@ -165,7 +165,6 @@ Datum pg_theta_sketch_to_string(PG_FUNCTION_ARGS) {
 Datum pg_theta_sketch_intersection_agg(PG_FUNCTION_ARGS) {
   void* interptr;
   bytea* sketch_bytes;
-  void* sketchptr;
 
   MemoryContext oldcontext;
   MemoryContext aggcontext;
@@ -188,9 +187,7 @@ Datum pg_theta_sketch_intersection_agg(PG_FUNCTION_ARGS) {
   }
 
   sketch_bytes = PG_GETARG_BYTEA_P(1);
-  sketchptr = theta_sketch_deserialize(VARDATA(sketch_bytes), VARSIZE(sketch_bytes) - VARHDRSZ);
-  theta_intersection_update(interptr, sketchptr);
-  theta_sketch_delete(sketchptr);
+  theta_intersection_update(interptr, VARDATA(sketch_bytes), VARSIZE(sketch_bytes) - VARHDRSZ);
 
   MemoryContextSwitchTo(oldcontext);
 
@@ -362,8 +359,6 @@ Datum pg_theta_sketch_union(PG_FUNCTION_ARGS) {
 Datum pg_theta_sketch_intersection(PG_FUNCTION_ARGS) {
   const bytea* bytes_in1;
   const bytea* bytes_in2;
-  void* sketchptr1;
-  void* sketchptr2;
   void* interptr;
   void* sketchptr;
   struct ptr_with_size bytes_out;
@@ -371,15 +366,11 @@ Datum pg_theta_sketch_intersection(PG_FUNCTION_ARGS) {
   interptr = theta_intersection_new_default();
   if (!PG_ARGISNULL(0)) {
     bytes_in1 = PG_GETARG_BYTEA_P(0);
-    sketchptr1 = theta_sketch_deserialize(VARDATA(bytes_in1), VARSIZE(bytes_in1) - VARHDRSZ);
-    theta_intersection_update(interptr, sketchptr1);
-    theta_sketch_delete(sketchptr1);
+    theta_intersection_update(interptr, VARDATA(bytes_in1), VARSIZE(bytes_in1) - VARHDRSZ);
   }
   if (!PG_ARGISNULL(1)) {
     bytes_in2 = PG_GETARG_BYTEA_P(1);
-    sketchptr2 = theta_sketch_deserialize(VARDATA(bytes_in2), VARSIZE(bytes_in2) - VARHDRSZ);
-    theta_intersection_update(interptr, sketchptr2);
-    theta_sketch_delete(sketchptr2);
+    theta_intersection_update(interptr, VARDATA(bytes_in2), VARSIZE(bytes_in2) - VARHDRSZ);
   }
   sketchptr = theta_intersection_get_result(interptr);
   theta_intersection_delete(interptr);

---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@datasketches.apache.org
For additional commands, e-mail: commits-help@datasketches.apache.org