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 2019/12/16 18:27:31 UTC

[incubator-datasketches-cpp] branch api_vector updated: return vector from serialize

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

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


The following commit(s) were added to refs/heads/api_vector by this push:
     new e6717cd  return vector from serialize
e6717cd is described below

commit e6717cd5c5c5558da6c6b744647f348f5e7ca1b1
Author: AlexanderSaydakov <Al...@users.noreply.github.com>
AuthorDate: Mon Dec 16 10:27:14 2019 -0800

    return vector from serialize
---
 hll/include/CouponList-internal.hpp | 13 ++++---------
 hll/include/CouponList.hpp          |  2 +-
 hll/include/HllArray-internal.hpp   | 13 ++++---------
 hll/include/HllArray.hpp            |  2 +-
 hll/include/HllSketch-internal.hpp  |  6 ++----
 hll/include/HllSketchImpl.hpp       |  2 +-
 hll/include/HllUnion-internal.hpp   |  4 ++--
 hll/include/hll.hpp                 | 11 ++++++-----
 hll/test/CouponHashSetTest.cpp      | 21 +++++++++++----------
 hll/test/CouponListTest.cpp         | 17 +++++++++--------
 hll/test/HllArrayTest.cpp           | 19 ++++++++++---------
 hll/test/HllUnionTest.cpp           |  8 ++++----
 hll/test/ToFromByteArrayTest.cpp    | 22 +++++++++++-----------
 13 files changed, 66 insertions(+), 74 deletions(-)

diff --git a/hll/include/CouponList-internal.hpp b/hll/include/CouponList-internal.hpp
index bf877be..ed9cde8 100644
--- a/hll/include/CouponList-internal.hpp
+++ b/hll/include/CouponList-internal.hpp
@@ -193,15 +193,10 @@ CouponList<A>* CouponList<A>::newList(std::istream& is) {
 }
 
 template<typename A>
-std::pair<std::unique_ptr<uint8_t, std::function<void(uint8_t*)>>, const size_t> CouponList<A>::serialize(bool compact, unsigned header_size_bytes) const {
+vector_u8<A> CouponList<A>::serialize(bool compact, unsigned header_size_bytes) const {
   const size_t sketchSizeBytes = (compact ? getCompactSerializationBytes() : getUpdatableSerializationBytes()) + header_size_bytes;
-  typedef typename std::allocator_traits<A>::template rebind_alloc<uint8_t> uint8Alloc;
-  std::unique_ptr<uint8_t, std::function<void(uint8_t*)>> byteArr(
-    uint8Alloc().allocate(sketchSizeBytes),
-    [sketchSizeBytes](uint8_t* p){ uint8Alloc().deallocate(p, sketchSizeBytes); }
-  );
-
-  uint8_t* bytes = byteArr.get() + header_size_bytes;
+  vector_u8<A> byteArr(sketchSizeBytes);
+  uint8_t* bytes = byteArr.data() + header_size_bytes;
 
   bytes[HllUtil<A>::PREAMBLE_INTS_BYTE] = static_cast<uint8_t>(getPreInts());
   bytes[HllUtil<A>::SER_VER_BYTE] = static_cast<uint8_t>(HllUtil<A>::SER_VER);
@@ -239,7 +234,7 @@ std::pair<std::unique_ptr<uint8_t, std::function<void(uint8_t*)>>, const size_t>
       throw std::runtime_error("Impossible condition when serializing");
   }
 
-  return std::make_pair(std::move(byteArr), sketchSizeBytes);
+  return byteArr;
 }
 
 template<typename A>
diff --git a/hll/include/CouponList.hpp b/hll/include/CouponList.hpp
index cb5016c..bcdfedf 100644
--- a/hll/include/CouponList.hpp
+++ b/hll/include/CouponList.hpp
@@ -37,7 +37,7 @@ class CouponList : public HllSketchImpl<A> {
 
     static CouponList* newList(const void* bytes, size_t len);
     static CouponList* newList(std::istream& is);
-    virtual std::pair<std::unique_ptr<uint8_t, std::function<void(uint8_t*)>>, const size_t> serialize(bool compact, unsigned header_size_bytes) const;
+    virtual vector_u8<A> serialize(bool compact, unsigned header_size_bytes) const;
     virtual void serialize(std::ostream& os, bool compact) const;
 
     virtual ~CouponList();
diff --git a/hll/include/HllArray-internal.hpp b/hll/include/HllArray-internal.hpp
index 16dfa38..ee68371 100644
--- a/hll/include/HllArray-internal.hpp
+++ b/hll/include/HllArray-internal.hpp
@@ -219,15 +219,10 @@ HllArray<A>* HllArray<A>::newHll(std::istream& is) {
 }
 
 template<typename A>
-std::pair<std::unique_ptr<uint8_t, std::function<void(uint8_t*)>>, const size_t> HllArray<A>::serialize(bool compact, unsigned header_size_bytes) const {
+vector_u8<A> HllArray<A>::serialize(bool compact, unsigned header_size_bytes) const {
   const size_t sketchSizeBytes = (compact ? getCompactSerializationBytes() : getUpdatableSerializationBytes()) + header_size_bytes;
-  typedef typename std::allocator_traits<A>::template rebind_alloc<uint8_t> uint8Alloc;
-  std::unique_ptr<uint8_t, std::function<void(uint8_t*)>> byteArr(
-    uint8Alloc().allocate(sketchSizeBytes),
-    [sketchSizeBytes](uint8_t* p){ uint8Alloc().deallocate(p, sketchSizeBytes); }
-    );
-
-  uint8_t* bytes = byteArr.get() + header_size_bytes;
+  vector_u8<A> byteArr(sketchSizeBytes);
+  uint8_t* bytes = byteArr.data() + header_size_bytes;
   AuxHashMap<A>* auxHashMap = getAuxHashMap();
 
   bytes[HllUtil<A>::PREAMBLE_INTS_BYTE] = static_cast<uint8_t>(getPreInts());
@@ -270,7 +265,7 @@ std::pair<std::unique_ptr<uint8_t, std::function<void(uint8_t*)>>, const size_t>
     }
   }
 
-  return std::make_pair(std::move(byteArr), sketchSizeBytes);
+  return byteArr;
 }
 
 template<typename A>
diff --git a/hll/include/HllArray.hpp b/hll/include/HllArray.hpp
index df4afb0..206869a 100644
--- a/hll/include/HllArray.hpp
+++ b/hll/include/HllArray.hpp
@@ -38,7 +38,7 @@ class HllArray : public HllSketchImpl<A> {
     static HllArray* newHll(const void* bytes, size_t len);
     static HllArray* newHll(std::istream& is);
 
-    virtual std::pair<std::unique_ptr<uint8_t, std::function<void(uint8_t*)>>, const size_t> serialize(bool compact, unsigned header_size_bytes) const;
+    virtual vector_u8<A> serialize(bool compact, unsigned header_size_bytes) const;
     virtual void serialize(std::ostream& os, bool compact) const;
 
     virtual ~HllArray();
diff --git a/hll/include/HllSketch-internal.hpp b/hll/include/HllSketch-internal.hpp
index 6965668..f11d7a3 100644
--- a/hll/include/HllSketch-internal.hpp
+++ b/hll/include/HllSketch-internal.hpp
@@ -237,14 +237,12 @@ void hll_sketch_alloc<A>::serialize_updatable(std::ostream& os) const {
 }
 
 template<typename A>
-std::pair<std::unique_ptr<uint8_t, std::function<void(uint8_t*)>>, const size_t>
-hll_sketch_alloc<A>::serialize_compact(unsigned header_size_bytes) const {
+vector_u8<A> hll_sketch_alloc<A>::serialize_compact(unsigned header_size_bytes) const {
   return sketch_impl->serialize(true, header_size_bytes);
 }
 
 template<typename A>
-std::pair<std::unique_ptr<uint8_t, std::function<void(uint8_t*)>>, const size_t>
-hll_sketch_alloc<A>::serialize_updatable() const {
+vector_u8<A> hll_sketch_alloc<A>::serialize_updatable() const {
   return sketch_impl->serialize(false, 0);
 }
 
diff --git a/hll/include/HllSketchImpl.hpp b/hll/include/HllSketchImpl.hpp
index 46c4d2d..0e9f2b3 100644
--- a/hll/include/HllSketchImpl.hpp
+++ b/hll/include/HllSketchImpl.hpp
@@ -35,7 +35,7 @@ class HllSketchImpl {
     virtual ~HllSketchImpl();
 
     virtual void serialize(std::ostream& os, bool compact) const = 0;
-    virtual std::pair<std::unique_ptr<uint8_t, std::function<void(uint8_t*)>>, const size_t> serialize(bool compact, unsigned header_size_bytes) const = 0;
+    virtual vector_u8<A> serialize(bool compact, unsigned header_size_bytes) const = 0;
 
     virtual HllSketchImpl* copy() const = 0;
     virtual HllSketchImpl* copyAs(target_hll_type tgtHllType) const = 0;
diff --git a/hll/include/HllUnion-internal.hpp b/hll/include/HllUnion-internal.hpp
index 60e40cf..be6320a 100644
--- a/hll/include/HllUnion-internal.hpp
+++ b/hll/include/HllUnion-internal.hpp
@@ -151,12 +151,12 @@ void hll_union_alloc<A>::coupon_update(const int coupon) {
 }
 
 template<typename A>
-std::pair<std::unique_ptr<uint8_t, std::function<void(uint8_t*)>>, const size_t> hll_union_alloc<A>::serialize_compact() const {
+vector_u8<A> hll_union_alloc<A>::serialize_compact() const {
   return gadget.serialize_compact();
 }
 
 template<typename A>
-std::pair<std::unique_ptr<uint8_t, std::function<void(uint8_t*)>>, const size_t> hll_union_alloc<A>::serialize_updatable() const {
+vector_u8<A> hll_union_alloc<A>::serialize_updatable() const {
   return gadget.serialize_updatable();
 }
 
diff --git a/hll/include/hll.hpp b/hll/include/hll.hpp
index a7e1ff5..c5dc6db 100644
--- a/hll/include/hll.hpp
+++ b/hll/include/hll.hpp
@@ -104,7 +104,8 @@ class HllSketchImpl;
 template<typename A>
 class hll_union_alloc;
 
-using byte_ptr_with_deleter = std::unique_ptr<uint8_t, std::function<void(uint8_t*)>>;
+template<typename A> using AllocU8 = typename std::allocator_traits<A>::template rebind_alloc<uint8_t>;
+template<typename A> using vector_u8 = std::vector<uint8_t, AllocU8<A>>;
 
 template<typename A = std::allocator<char> >
 class hll_sketch_alloc final {
@@ -167,13 +168,13 @@ class hll_sketch_alloc final {
      * where feasible to eliminate unused storage in the serialized image.
      * @param header_size_bytes Allows for PostgreSQL integration
      */
-    std::pair<byte_ptr_with_deleter, const size_t> serialize_compact(unsigned header_size_bytes = 0) const;
+    vector_u8<A> serialize_compact(unsigned header_size_bytes = 0) const;
 
     /**
      * Serializes the sketch to a byte array, retaining all internal 
      * data structures in their current form.
      */
-    std::pair<byte_ptr_with_deleter, const size_t> serialize_updatable() const;
+    vector_u8<A> serialize_updatable() const;
 
     /**
      * Serializes the sketch to an ostream, compacting data structures
@@ -553,13 +554,13 @@ class hll_union_alloc {
      * where feasible to eliminate unused storage in the serialized image.
      * @param header_size_bytes Allows for PostgreSQL integration
      */
-    std::pair<byte_ptr_with_deleter, const size_t> serialize_compact() const;
+    vector_u8<A> serialize_compact() const;
   
     /**
      * Serializes the sketch to a byte array, retaining all internal 
      * data structures in their current form.
      */
-    std::pair<byte_ptr_with_deleter, const size_t> serialize_updatable() const;
+    vector_u8<A> serialize_updatable() const;
 
     /**
      * Serializes the sketch to an ostream, compacting data structures
diff --git a/hll/test/CouponHashSetTest.cpp b/hll/test/CouponHashSetTest.cpp
index c5b1ea1..5ed9e03 100644
--- a/hll/test/CouponHashSetTest.cpp
+++ b/hll/test/CouponHashSetTest.cpp
@@ -43,53 +43,54 @@ class CouponHashSetTest : public CppUnit::TestFixture {
     for (int i = 0; i < 24; ++i) {
       sk1.update(i);
     }
-    std::pair<std::unique_ptr<uint8_t, std::function<void(uint8_t*)>>, const size_t> sketchBytes = sk1.serialize_updatable();
-    uint8_t* bytes = sketchBytes.first.get();
+    auto sketchBytes = sk1.serialize_updatable();
+    uint8_t* bytes = sketchBytes.data();
+    const size_t size = sketchBytes.size();
 
     bytes[HllUtil<>::PREAMBLE_INTS_BYTE] = 0;
     // fail in HllSketchImpl
     CPPUNIT_ASSERT_THROW_MESSAGE("Failed to detect error in preInts byte",
-                                 hll_sketch::deserialize(bytes, sketchBytes.second),
+                                 hll_sketch::deserialize(bytes, size),
                                  std::invalid_argument);
     // fail in CouponHashSet
     CPPUNIT_ASSERT_THROW_MESSAGE("Failed to detect error in preInts byte",
-                                 CouponHashSet<>::newSet(bytes, sketchBytes.second),
+                                 CouponHashSet<>::newSet(bytes, size),
                                  std::invalid_argument);
     bytes[HllUtil<>::PREAMBLE_INTS_BYTE] = HllUtil<>::HASH_SET_PREINTS;
 
     bytes[HllUtil<>::SER_VER_BYTE] = 0;
     CPPUNIT_ASSERT_THROW_MESSAGE("Failed to detect error in serialization version byte",
-                                 hll_sketch::deserialize(bytes, sketchBytes.second),
+                                 hll_sketch::deserialize(bytes, size),
                                  std::invalid_argument);
     bytes[HllUtil<>::SER_VER_BYTE] = HllUtil<>::SER_VER;
 
     bytes[HllUtil<>::FAMILY_BYTE] = 0;
     CPPUNIT_ASSERT_THROW_MESSAGE("Failed to detect error in family id byte",
-                                 hll_sketch::deserialize(bytes, sketchBytes.second),
+                                 hll_sketch::deserialize(bytes, size),
                                  std::invalid_argument);
     bytes[HllUtil<>::FAMILY_BYTE] = HllUtil<>::FAMILY_ID;
 
     bytes[HllUtil<>::LG_K_BYTE] = 6;
     CPPUNIT_ASSERT_THROW_MESSAGE("Failed to detect too small a lgK for Set mode",
-                                 hll_sketch::deserialize(bytes, sketchBytes.second),
+                                 hll_sketch::deserialize(bytes, size),
                                  std::invalid_argument);
     bytes[HllUtil<>::LG_K_BYTE] = lgK;
 
     uint8_t tmp = bytes[HllUtil<>::MODE_BYTE];
     bytes[HllUtil<>::MODE_BYTE] = 0x10; // HLL_6, LIST
     CPPUNIT_ASSERT_THROW_MESSAGE("Failed to detect error in mode byte",
-                                 hll_sketch::deserialize(bytes, sketchBytes.second),
+                                 hll_sketch::deserialize(bytes, size),
                                  std::invalid_argument);
     bytes[HllUtil<>::MODE_BYTE] = tmp;
 
     tmp = bytes[HllUtil<>::LG_ARR_BYTE];
     bytes[HllUtil<>::LG_ARR_BYTE] = 0;
-    hll_sketch::deserialize(bytes, sketchBytes.second);
+    hll_sketch::deserialize(bytes, size);
     // should work fine despite the corruption
     bytes[HllUtil<>::LG_ARR_BYTE] = tmp;
 
     CPPUNIT_ASSERT_THROW_MESSAGE("Failed to detect error in serialized length",
-                                 hll_sketch::deserialize(bytes, sketchBytes.second - 1),
+                                 hll_sketch::deserialize(bytes, size - 1),
                                  std::invalid_argument);
     CPPUNIT_ASSERT_THROW_MESSAGE("Failed to detect error in serialized length",
                                  hll_sketch::deserialize(bytes, 3),
diff --git a/hll/test/CouponListTest.cpp b/hll/test/CouponListTest.cpp
index 31e6722..e970ffa 100644
--- a/hll/test/CouponListTest.cpp
+++ b/hll/test/CouponListTest.cpp
@@ -134,40 +134,41 @@ class CouponListTest : public CppUnit::TestFixture {
     hll_sketch sk1(lgK);
     sk1.update(1);
     sk1.update(2);
-    std::pair<byte_ptr_with_deleter, const size_t> sketchBytes = sk1.serialize_compact();
-    uint8_t* bytes = sketchBytes.first.get();
+    auto sketchBytes = sk1.serialize_compact();
+    uint8_t* bytes = sketchBytes.data();
+    const size_t size = sketchBytes.size();
 
     bytes[HllUtil<>::PREAMBLE_INTS_BYTE] = 0;
     CPPUNIT_ASSERT_THROW_MESSAGE("Failed to detect error in preInts byte",
-                                 hll_sketch::deserialize(bytes, sketchBytes.second),
+                                 hll_sketch::deserialize(bytes, size),
                                  std::invalid_argument);
     CPPUNIT_ASSERT_THROW_MESSAGE("Failed to detect error in preInts byte",
-                                 CouponList<>::newList(bytes, sketchBytes.second),
+                                 CouponList<>::newList(bytes, size),
                                  std::invalid_argument);
 
     bytes[HllUtil<>::PREAMBLE_INTS_BYTE] = HllUtil<>::LIST_PREINTS;
 
     bytes[HllUtil<>::SER_VER_BYTE] = 0;
     CPPUNIT_ASSERT_THROW_MESSAGE("Failed to detect error in serialization version byte",
-                                 hll_sketch::deserialize(bytes, sketchBytes.second),
+                                 hll_sketch::deserialize(bytes, size),
                                  std::invalid_argument);
     bytes[HllUtil<>::SER_VER_BYTE] = HllUtil<>::SER_VER;
 
     bytes[HllUtil<>::FAMILY_BYTE] = 0;
     CPPUNIT_ASSERT_THROW_MESSAGE("Failed to detect error in family id byte",
-                                 hll_sketch::deserialize(bytes, sketchBytes.second),
+                                 hll_sketch::deserialize(bytes, size),
                                  std::invalid_argument);
     bytes[HllUtil<>::FAMILY_BYTE] = HllUtil<>::FAMILY_ID;
 
     uint8_t tmp = bytes[HllUtil<>::MODE_BYTE];
     bytes[HllUtil<>::MODE_BYTE] = 0x01; // HLL_4, SET
     CPPUNIT_ASSERT_THROW_MESSAGE("Failed to detect error in mode byte",
-                                 hll_sketch::deserialize(bytes, sketchBytes.second),
+                                 hll_sketch::deserialize(bytes, size),
                                  std::invalid_argument);
     bytes[HllUtil<>::MODE_BYTE] = tmp;
 
     CPPUNIT_ASSERT_THROW_MESSAGE("Failed to detect error in serialized length",
-                                 hll_sketch::deserialize(bytes, sketchBytes.second - 1),
+                                 hll_sketch::deserialize(bytes, size - 1),
                                  std::invalid_argument);
 
     CPPUNIT_ASSERT_THROW_MESSAGE("Failed to detect error in serialized length",
diff --git a/hll/test/HllArrayTest.cpp b/hll/test/HllArrayTest.cpp
index e941b5b..2f75625 100644
--- a/hll/test/HllArrayTest.cpp
+++ b/hll/test/HllArrayTest.cpp
@@ -118,45 +118,46 @@ class HllArrayTest : public CppUnit::TestFixture {
     for (int i = 0; i < 50; ++i) {
       sk1.update(i);
     }
-    std::pair<byte_ptr_with_deleter, size_t> sketchBytes = sk1.serialize_compact();
-    uint8_t* bytes = sketchBytes.first.get();
+    auto sketchBytes = sk1.serialize_compact();
+    uint8_t* bytes = sketchBytes.data();
+    const size_t size = sketchBytes.size();
 
     bytes[HllUtil<>::PREAMBLE_INTS_BYTE] = 0;
     CPPUNIT_ASSERT_THROW_MESSAGE("Failed to detect error in preInts byte",
-                                 hll_sketch::deserialize(bytes, sketchBytes.second),
+                                 hll_sketch::deserialize(bytes, size),
                                  std::invalid_argument);
     CPPUNIT_ASSERT_THROW_MESSAGE("Failed to detect error in preInts byte",
-                                 HllArray<>::newHll(bytes, sketchBytes.second),
+                                 HllArray<>::newHll(bytes, size),
                                  std::invalid_argument);
     bytes[HllUtil<>::PREAMBLE_INTS_BYTE] = HllUtil<>::HLL_PREINTS;
 
     bytes[HllUtil<>::SER_VER_BYTE] = 0;
     CPPUNIT_ASSERT_THROW_MESSAGE("Failed to detect error in serialization version byte",
-                                 hll_sketch::deserialize(bytes, sketchBytes.second),
+                                 hll_sketch::deserialize(bytes, size),
                                  std::invalid_argument);
     bytes[HllUtil<>::SER_VER_BYTE] = HllUtil<>::SER_VER;
 
     bytes[HllUtil<>::FAMILY_BYTE] = 0;
     CPPUNIT_ASSERT_THROW_MESSAGE("Failed to detect error in family id byte",
-                                 hll_sketch::deserialize(bytes, sketchBytes.second),
+                                 hll_sketch::deserialize(bytes, size),
                                  std::invalid_argument);
     bytes[HllUtil<>::FAMILY_BYTE] = HllUtil<>::FAMILY_ID;
 
     uint8_t tmp = bytes[HllUtil<>::MODE_BYTE];
     bytes[HllUtil<>::MODE_BYTE] = 0x10; // HLL_6, LIST
     CPPUNIT_ASSERT_THROW_MESSAGE("Failed to detect error in mode byte",
-                                 hll_sketch::deserialize(bytes, sketchBytes.second),
+                                 hll_sketch::deserialize(bytes, size),
                                  std::invalid_argument);
     bytes[HllUtil<>::MODE_BYTE] = tmp;
 
     tmp = bytes[HllUtil<>::LG_ARR_BYTE];
     bytes[HllUtil<>::LG_ARR_BYTE] = 0;
-    hll_sketch::deserialize(bytes, sketchBytes.second);
+    hll_sketch::deserialize(bytes, size);
     // should work fine despite the corruption
     bytes[HllUtil<>::LG_ARR_BYTE] = tmp;
 
     CPPUNIT_ASSERT_THROW_MESSAGE("Failed to detect error in serialized length",
-                                 hll_sketch::deserialize(bytes, sketchBytes.second - 1),
+                                 hll_sketch::deserialize(bytes, size - 1),
                                  std::invalid_argument);
     CPPUNIT_ASSERT_THROW_MESSAGE("Failed to detect error in serialized length",
                                  hll_sketch::deserialize(bytes, 3),
diff --git a/hll/test/HllUnionTest.cpp b/hll/test/HllUnionTest.cpp
index f173cf5..47a1170 100644
--- a/hll/test/HllUnionTest.cpp
+++ b/hll/test/HllUnionTest.cpp
@@ -225,8 +225,8 @@ class HllUnionTest : public CppUnit::TestFixture {
     hll_union dstU = hll_union::deserialize(ss);
     checkUnionEquality(srcU, dstU);
 
-    std::pair<byte_ptr_with_deleter, const size_t> bytes1 = srcU.serialize_compact();
-    dstU = hll_union::deserialize(bytes1.first.get(), bytes1.second);
+    auto bytes1 = srcU.serialize_compact();
+    dstU = hll_union::deserialize(bytes1.data(), bytes1.size());
     checkUnionEquality(srcU, dstU);
 
     ss.clear();
@@ -234,8 +234,8 @@ class HllUnionTest : public CppUnit::TestFixture {
     dstU = hll_union::deserialize(ss);
     checkUnionEquality(srcU, dstU);
 
-    std::pair<byte_ptr_with_deleter, const size_t> bytes2 = srcU.serialize_updatable();
-    dstU = hll_union::deserialize(bytes2.first.get(), bytes2.second);
+    auto bytes2 = srcU.serialize_updatable();
+    dstU = hll_union::deserialize(bytes2.data(), bytes2.size());
     checkUnionEquality(srcU, dstU);
   } 
 
diff --git a/hll/test/ToFromByteArrayTest.cpp b/hll/test/ToFromByteArrayTest.cpp
index 8fd2102..62c8ce9 100644
--- a/hll/test/ToFromByteArrayTest.cpp
+++ b/hll/test/ToFromByteArrayTest.cpp
@@ -43,20 +43,20 @@ class ToFromByteArrayTest : public CppUnit::TestFixture {
     
     std::stringstream ss1;
     sk.serialize_updatable(ss1);
-    std::pair<byte_ptr_with_deleter, size_t> ser1 = sk.serialize_updatable();
+    auto ser1 = sk.serialize_updatable();
 
     std::stringstream ss;
     sk.serialize_updatable(ss);
     std::string str = ss.str();
 
 
-    hll_sketch sk2 = hll_sketch::deserialize(ser1.first.get(), ser1.second);
-    std::pair<byte_ptr_with_deleter, size_t> ser2 = sk.serialize_updatable();
+    hll_sketch sk2 = hll_sketch::deserialize(ser1.data(), ser1.size());
+    auto ser2 = sk.serialize_updatable();
 
-    CPPUNIT_ASSERT_EQUAL(ser1.second, ser2.second);
-    int len = ser1.second;
-    uint8_t* b1 = ser1.first.get();
-    uint8_t* b2 = ser2.first.get();
+    CPPUNIT_ASSERT_EQUAL(ser1.size(), ser2.size());
+    int len = ser1.size();
+    uint8_t* b1 = ser1.data();
+    uint8_t* b2 = ser2.data();
 
     for (int i = 0; i < len; ++i) {
       CPPUNIT_ASSERT_EQUAL(b1[i], b2[i]);
@@ -142,8 +142,8 @@ class ToFromByteArrayTest : public CppUnit::TestFixture {
     hll_sketch dst = hll_sketch::deserialize(ss);
     checkSketchEquality(src, dst);
 
-    std::pair<byte_ptr_with_deleter, const size_t> bytes1 = src.serialize_compact();
-    dst = hll_sketch::deserialize(bytes1.first.get(), bytes1.second);
+    auto bytes1 = src.serialize_compact();
+    dst = hll_sketch::deserialize(bytes1.data(), bytes1.size());
     checkSketchEquality(src, dst);
 
     ss.clear();
@@ -151,8 +151,8 @@ class ToFromByteArrayTest : public CppUnit::TestFixture {
     dst = hll_sketch::deserialize(ss);
     checkSketchEquality(src, dst);
 
-    std::pair<byte_ptr_with_deleter, const size_t> bytes2 = src.serialize_updatable();
-    dst = hll_sketch::deserialize(bytes2.first.get(), bytes2.second);
+    auto bytes2 = src.serialize_updatable();
+    dst = hll_sketch::deserialize(bytes2.data(), bytes2.size());
     checkSketchEquality(src, dst);
   }
 


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