This is an automated email from the ASF dual-hosted git repository. alsay pushed a commit to branch placement_new in repository https://gitbox.apache.org/repos/asf/incubator-datasketches-cpp.git
commit 0359d7898099ede5e10bee9b0daba6128ab01ef3 Author: AlexanderSaydakov <[email protected]> AuthorDate: Mon Jun 24 15:38:52 2019 -0700 serialize header for postgresql --- hll/include/CouponList-internal.hpp | 23 ++++++++--------------- hll/include/CouponList.hpp | 4 ++-- hll/include/HllArray-internal.hpp | 6 +++--- hll/include/HllArray.hpp | 4 ++-- hll/include/HllSketchImpl.hpp | 4 ++-- hll/include/hll.hpp | 2 +- 6 files changed, 18 insertions(+), 25 deletions(-) diff --git a/hll/include/CouponList-internal.hpp b/hll/include/CouponList-internal.hpp index e9635c1..a2111ba 100644 --- a/hll/include/CouponList-internal.hpp +++ b/hll/include/CouponList-internal.hpp @@ -92,16 +92,12 @@ std::function<void(HllSketchImpl<A>*)> CouponList<A>::get_deleter() const { template<typename A> CouponList<A>* CouponList<A>::copy() const { - CouponList<A>* cl = clAlloc().allocate(1); - clAlloc().construct(cl, *this); - return cl; + return new (clAlloc().allocate(1)) CouponList<A>(*this); } template<typename A> CouponList<A>* CouponList<A>::copyAs(const TgtHllType tgtHllType) const { - CouponList<A>* cl = clAlloc().allocate(1); - clAlloc().construct(cl, *this, tgtHllType); - return cl; + return new (clAlloc().allocate(1)) CouponList<A>(*this, tgtHllType); } template<typename A> @@ -142,8 +138,7 @@ CouponList<A>* CouponList<A>::newList(const void* bytes, size_t len) { + ", found: " + std::to_string(len)); } - CouponList<A>* sketch = clAlloc().allocate(1); - clAlloc().construct(sketch, lgK, tgtHllType, curMode); + CouponList<A>* sketch = new (clAlloc().allocate(1)) CouponList<A>(lgK, tgtHllType, curMode); sketch->couponCount = couponCount; sketch->putOutOfOrderFlag(oooFlag); // should always be false for LIST @@ -183,8 +178,7 @@ CouponList<A>* CouponList<A>::newList(std::istream& is) { bool oooFlag = ((listHeader[HllUtil<A>::FLAGS_BYTE] & HllUtil<A>::OUT_OF_ORDER_FLAG_MASK) ? true : false); bool emptyFlag = ((listHeader[HllUtil<A>::FLAGS_BYTE] & HllUtil<A>::EMPTY_FLAG_MASK) ? true : false); - CouponList<A>* sketch = clAlloc().allocate(1); - clAlloc().construct(sketch, lgK, tgtHllType, curMode); + CouponList<A>* sketch = new (clAlloc().allocate(1)) CouponList<A>(lgK, tgtHllType, curMode); const int couponCount = (int) listHeader[HllUtil<A>::LIST_COUNT_BYTE]; sketch->couponCount = couponCount; sketch->putOutOfOrderFlag(oooFlag); // should always be false for LIST @@ -201,15 +195,15 @@ 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) const { - size_t sketchSizeBytes = (compact ? getCompactSerializationBytes() : getUpdatableSerializationBytes()); +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 { + 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(); + uint8_t* bytes = byteArr.get() + 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); @@ -411,8 +405,7 @@ int* CouponList<A>::getCouponIntArr() const { template<typename A> PairIterator_with_deleter<A> CouponList<A>::getIterator() const { typedef typename std::allocator_traits<A>::template rebind_alloc<IntArrayPairIterator<A>> iapiAlloc; - IntArrayPairIterator<A>* itr = iapiAlloc().allocate(1); - iapiAlloc().construct(itr, couponIntArr, 1 << lgCouponArrInts, this->lgConfigK); + IntArrayPairIterator<A>* itr = new (iapiAlloc().allocate(1)) IntArrayPairIterator<A>(couponIntArr, 1 << lgCouponArrInts, this->lgConfigK); return PairIterator_with_deleter<A>( itr, [](PairIterator<A>* ptr) { diff --git a/hll/include/CouponList.hpp b/hll/include/CouponList.hpp index 77454eb..2782154 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) const; + 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 void serialize(std::ostream& os, bool compact) const; virtual ~CouponList(); @@ -89,4 +89,4 @@ class CouponList : public HllSketchImpl<A> { //#include "CouponList-internal.hpp" -#endif /* _COUPONLIST_HPP_ */ \ No newline at end of file +#endif /* _COUPONLIST_HPP_ */ diff --git a/hll/include/HllArray-internal.hpp b/hll/include/HllArray-internal.hpp index 3ad54bf..d6ea6c9 100644 --- a/hll/include/HllArray-internal.hpp +++ b/hll/include/HllArray-internal.hpp @@ -224,15 +224,15 @@ 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) const { - const size_t sketchSizeBytes = (compact ? getCompactSerializationBytes() : getUpdatableSerializationBytes()); +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 { + 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(); + uint8_t* bytes = byteArr.get() + header_size_bytes; AuxHashMap<A>* auxHashMap = getAuxHashMap(); bytes[HllUtil<A>::PREAMBLE_INTS_BYTE] = static_cast<uint8_t>(getPreInts()); diff --git a/hll/include/HllArray.hpp b/hll/include/HllArray.hpp index f01ef40..aa9a87e 100644 --- a/hll/include/HllArray.hpp +++ b/hll/include/HllArray.hpp @@ -39,7 +39,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) const; + 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 void serialize(std::ostream& os, bool compact) const; virtual ~HllArray(); @@ -123,4 +123,4 @@ class HllArray : public HllSketchImpl<A> { //#include "HllArray-internal.hpp" -#endif /* _HLLARRAY_HPP_ */ \ No newline at end of file +#endif /* _HLLARRAY_HPP_ */ diff --git a/hll/include/HllSketchImpl.hpp b/hll/include/HllSketchImpl.hpp index 59e322f..2ebf2e6 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) 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; //static HllSketchImpl* deserialize(std::istream& os); //static HllSketchImpl* deserialize(const void* bytes, size_t len); @@ -90,4 +90,4 @@ class HllSketchImpl { //#include "HllSketchImpl-internal.hpp" -#endif // _HLLSKETCHIMPL_HPP_ \ No newline at end of file +#endif // _HLLSKETCHIMPL_HPP_ diff --git a/hll/include/hll.hpp b/hll/include/hll.hpp index 9b6ccfa..7245bd7 100644 --- a/hll/include/hll.hpp +++ b/hll/include/hll.hpp @@ -61,7 +61,7 @@ class HllSketch final { void reset(); - std::pair<byte_ptr_with_deleter, const size_t> serializeCompact() const; + std::pair<byte_ptr_with_deleter, const size_t> serializeCompact(unsigned header_size_bytes = 0) const; std::pair<byte_ptr_with_deleter, const size_t> serializeUpdatable() const; void serializeCompact(std::ostream& os) const; void serializeUpdatable(std::ostream& os) const; --------------------------------------------------------------------- To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]
