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/07/30 23:30:41 UTC

[incubator-datasketches-cpp] branch hll_cleanup updated (6e3c956 -> 3c347e3)

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

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


    from 6e3c956  type mismatch and const
     new 907b5b4  deallocate instead of delete, more const and cleanup
     new 3c347e3  more const and cleanup

The 2 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.


Summary of changes:
 hll/include/CouponHashSet-internal.hpp | 31 ++++++++++++++-----------------
 hll/include/CouponHashSet.hpp          |  4 +---
 hll/include/CouponList-internal.hpp    | 21 ++++++++++-----------
 hll/include/CouponList.hpp             |  5 -----
 hll/include/HllArray-internal.hpp      | 29 ++++++++++++-----------------
 5 files changed, 37 insertions(+), 53 deletions(-)


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


[incubator-datasketches-cpp] 02/02: more const and cleanup

Posted by al...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

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

commit 3c347e3a9553db3952e7699b91a480c133fedfca
Author: AlexanderSaydakov <Al...@users.noreply.github.com>
AuthorDate: Tue Jul 30 16:30:33 2019 -0700

    more const and cleanup
---
 hll/include/CouponHashSet.hpp       |  4 +---
 hll/include/CouponList-internal.hpp | 21 ++++++++++-----------
 hll/include/CouponList.hpp          |  5 -----
 hll/include/HllArray-internal.hpp   | 29 ++++++++++++-----------------
 4 files changed, 23 insertions(+), 36 deletions(-)

diff --git a/hll/include/CouponHashSet.hpp b/hll/include/CouponHashSet.hpp
index 45e1c06..36f096c 100644
--- a/hll/include/CouponHashSet.hpp
+++ b/hll/include/CouponHashSet.hpp
@@ -56,6 +56,4 @@ class CouponHashSet : public CouponList<A> {
 
 }
 
-//#include "CouponHashSet-internal.hpp"
-
-#endif /* _COUPONHASHSET_HPP_ */
\ No newline at end of file
+#endif /* _COUPONHASHSET_HPP_ */
diff --git a/hll/include/CouponList-internal.hpp b/hll/include/CouponList-internal.hpp
index 359f6c2..72155e4 100644
--- a/hll/include/CouponList-internal.hpp
+++ b/hll/include/CouponList-internal.hpp
@@ -124,12 +124,12 @@ CouponList<A>* CouponList<A>::newList(const void* bytes, size_t len) {
 
   TgtHllType tgtHllType = HllSketchImpl<A>::extractTgtHllType(data[HllUtil<A>::MODE_BYTE]);
 
-  const int lgK = (int) data[HllUtil<A>::LG_K_BYTE];
+  const int lgK = data[HllUtil<A>::LG_K_BYTE];
   const bool compact = ((data[HllUtil<A>::FLAGS_BYTE] & HllUtil<A>::COMPACT_FLAG_MASK) ? true : false);
   const bool oooFlag = ((data[HllUtil<A>::FLAGS_BYTE] & HllUtil<A>::OUT_OF_ORDER_FLAG_MASK) ? true : false);
   const bool emptyFlag = ((data[HllUtil<A>::FLAGS_BYTE] & HllUtil<A>::EMPTY_FLAG_MASK) ? true : false);
 
-  const int couponCount = (int) data[HllUtil<A>::LIST_COUNT_BYTE];
+  const int couponCount = data[HllUtil<A>::LIST_COUNT_BYTE];
   const int couponsInArray = (compact ? couponCount : (1 << HllUtil<A>::computeLgArrInts(LIST, couponCount, lgK)));
   const size_t expectedLength = HllUtil<A>::LIST_INT_ARR_START + (couponsInArray * sizeof(int));
   if (len < expectedLength) {
@@ -169,16 +169,15 @@ CouponList<A>* CouponList<A>::newList(std::istream& is) {
     throw std::invalid_argument("Calling list construtor with non-list mode data");
   }
 
-  TgtHllType tgtHllType = HllSketchImpl<A>::extractTgtHllType(listHeader[HllUtil<A>::MODE_BYTE]);
+  const TgtHllType tgtHllType = HllSketchImpl<A>::extractTgtHllType(listHeader[HllUtil<A>::MODE_BYTE]);
 
   const int lgK = (int) listHeader[HllUtil<A>::LG_K_BYTE];
-  //const int lgArrInts = (int) listHeader[HllUtil<A>::LG_ARR_BYTE];
-  bool compact = ((listHeader[HllUtil<A>::FLAGS_BYTE] & HllUtil<A>::COMPACT_FLAG_MASK) ? true : false);
-  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);
+  const bool compact = ((listHeader[HllUtil<A>::FLAGS_BYTE] & HllUtil<A>::COMPACT_FLAG_MASK) ? true : false);
+  const bool oooFlag = ((listHeader[HllUtil<A>::FLAGS_BYTE] & HllUtil<A>::OUT_OF_ORDER_FLAG_MASK) ? true : false);
+  const bool emptyFlag = ((listHeader[HllUtil<A>::FLAGS_BYTE] & HllUtil<A>::EMPTY_FLAG_MASK) ? true : false);
 
   CouponList<A>* sketch = new (clAlloc().allocate(1)) CouponList<A>(lgK, tgtHllType, curMode);
-  const int couponCount = (int) listHeader[HllUtil<A>::LIST_COUNT_BYTE];
+  const int couponCount = listHeader[HllUtil<A>::LIST_COUNT_BYTE];
   sketch->couponCount = couponCount;
   sketch->putOutOfOrderFlag(oooFlag); // should always be false for LIST
 
@@ -186,16 +185,16 @@ CouponList<A>* CouponList<A>::newList(std::istream& is) {
     // For stream processing, need to read entire number written to stream so read
     // pointer ends up set correctly.
     // If not compact, still need to read empty items even though in order.
-    int numToRead = (compact ? couponCount : (1 << sketch->lgCouponArrInts));
+    const int numToRead = (compact ? couponCount : (1 << sketch->lgCouponArrInts));
     is.read((char*)sketch->couponIntArr, numToRead * sizeof(int));
   }
-  
+
   return sketch;
 }
 
 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 {
-  size_t sketchSizeBytes = (compact ? getCompactSerializationBytes() : getUpdatableSerializationBytes()) + 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),
diff --git a/hll/include/CouponList.hpp b/hll/include/CouponList.hpp
index 2782154..dd8b37b 100644
--- a/hll/include/CouponList.hpp
+++ b/hll/include/CouponList.hpp
@@ -55,7 +55,6 @@ class CouponList : public HllSketchImpl<A> {
 
     virtual bool isEmpty() const;
     virtual int getCouponCount() const;
-    //virtual std::unique_ptr<PairIterator<A>> getIterator() const;
     virtual PairIterator_with_deleter<A> getIterator() const;
 
   protected:
@@ -75,8 +74,6 @@ class CouponList : public HllSketchImpl<A> {
     virtual int getLgCouponArrInts() const;
     virtual int* getCouponIntArr() const;
 
-    //virtual CouponList* reset();
-
     int lgCouponArrInts;
     int couponCount;
     bool oooFlag;
@@ -87,6 +84,4 @@ class CouponList : public HllSketchImpl<A> {
 
 }
 
-//#include "CouponList-internal.hpp"
-
 #endif /* _COUPONLIST_HPP_ */
diff --git a/hll/include/HllArray-internal.hpp b/hll/include/HllArray-internal.hpp
index a8fb844..72ece16 100644
--- a/hll/include/HllArray-internal.hpp
+++ b/hll/include/HllArray-internal.hpp
@@ -57,7 +57,7 @@ HllArray<A>::HllArray(const HllArray<A>& that)
   oooFlag = that.isOutOfOrderFlag();
 
   // can determine length, so allocate here
-  int arrayLen = that.getHllByteArrBytes();
+  const int arrayLen = that.getHllByteArrBytes();
   typedef typename std::allocator_traits<A>::template rebind_alloc<uint8_t> uint8Alloc;
   hllByteArr = uint8Alloc().allocate(arrayLen);
   std::copy(that.hllByteArr, that.hllByteArr + arrayLen, hllByteArr);
@@ -77,7 +77,6 @@ HllArray<A>::~HllArray() {
 
   typedef typename std::allocator_traits<A>::template rebind_alloc<uint8_t> uint8Alloc;
   uint8Alloc().deallocate(hllByteArr, hllArrBytes);
-  //delete [] hllByteArr;
 }
 
 template<typename A>
@@ -86,13 +85,10 @@ HllArray<A>* HllArray<A>::copyAs(const TgtHllType tgtHllType) const {
     return static_cast<HllArray*>(copy());
   }
   if (tgtHllType == TgtHllType::HLL_4) {
-    //return Conversions::convertToHll4(*this);
     return HllSketchImplFactory<A>::convertToHll4(*this);
   } else if (tgtHllType == TgtHllType::HLL_6) {
-    //return Conversions::convertToHll6(*this);
     return HllSketchImplFactory<A>::convertToHll6(*this);
   } else { // tgtHllType == HLL_8
-    //return Conversions::convertToHll8(*this);
     return HllSketchImplFactory<A>::convertToHll8(*this);
   }
 }
@@ -114,20 +110,20 @@ HllArray<A>* HllArray<A>::newHll(const void* bytes, size_t len) {
     throw std::invalid_argument("Input array is not an HLL sketch");
   }
 
-  CurMode curMode = HllSketchImpl<A>::extractCurMode(data[HllUtil<A>::MODE_BYTE]);
+  const CurMode curMode = HllSketchImpl<A>::extractCurMode(data[HllUtil<A>::MODE_BYTE]);
   if (curMode != HLL) {
     throw std::invalid_argument("Calling HLL array construtor with non-HLL mode data");
   }
 
-  TgtHllType tgtHllType = HllSketchImpl<A>::extractTgtHllType(data[HllUtil<A>::MODE_BYTE]);
-  bool oooFlag = ((data[HllUtil<A>::FLAGS_BYTE] & HllUtil<A>::OUT_OF_ORDER_FLAG_MASK) ? true : false);
-  bool comapctFlag = ((data[HllUtil<A>::FLAGS_BYTE] & HllUtil<A>::COMPACT_FLAG_MASK) ? true : false);
-  bool startFullSizeFlag = ((data[HllUtil<A>::FLAGS_BYTE] & HllUtil<A>::FULL_SIZE_FLAG_MASK) ? true : false);
+  const TgtHllType tgtHllType = HllSketchImpl<A>::extractTgtHllType(data[HllUtil<A>::MODE_BYTE]);
+  const bool oooFlag = ((data[HllUtil<A>::FLAGS_BYTE] & HllUtil<A>::OUT_OF_ORDER_FLAG_MASK) ? true : false);
+  const bool comapctFlag = ((data[HllUtil<A>::FLAGS_BYTE] & HllUtil<A>::COMPACT_FLAG_MASK) ? true : false);
+  const bool startFullSizeFlag = ((data[HllUtil<A>::FLAGS_BYTE] & HllUtil<A>::FULL_SIZE_FLAG_MASK) ? true : false);
 
   const int lgK = (int) data[HllUtil<A>::LG_K_BYTE];
   const int curMin = (int) data[HllUtil<A>::HLL_CUR_MIN_BYTE];
 
-  int arrayBytes = hllArrBytes(tgtHllType, lgK);
+  const int arrayBytes = hllArrBytes(tgtHllType, lgK);
   if (len < static_cast<size_t>(HllUtil<A>::HLL_BYTE_ARR_START + arrayBytes)) {
     throw std::invalid_argument("Input array too small to hold sketch image");
   }
@@ -185,10 +181,10 @@ HllArray<A>* HllArray<A>::newHll(std::istream& is) {
     throw std::invalid_argument("Calling HLL construtor with non-HLL mode data");
   }
 
-  TgtHllType tgtHllType = HllSketchImpl<A>::extractTgtHllType(listHeader[HllUtil<A>::MODE_BYTE]);
-  bool oooFlag = ((listHeader[HllUtil<A>::FLAGS_BYTE] & HllUtil<A>::OUT_OF_ORDER_FLAG_MASK) ? true : false);
-  bool comapctFlag = ((listHeader[HllUtil<A>::FLAGS_BYTE] & HllUtil<A>::COMPACT_FLAG_MASK) ? true : false);
-  bool startFullSizeFlag = ((listHeader[HllUtil<A>::FLAGS_BYTE] & HllUtil<A>::FULL_SIZE_FLAG_MASK) ? true : false);
+  const TgtHllType tgtHllType = HllSketchImpl<A>::extractTgtHllType(listHeader[HllUtil<A>::MODE_BYTE]);
+  const bool oooFlag = ((listHeader[HllUtil<A>::FLAGS_BYTE] & HllUtil<A>::OUT_OF_ORDER_FLAG_MASK) ? true : false);
+  const bool comapctFlag = ((listHeader[HllUtil<A>::FLAGS_BYTE] & HllUtil<A>::COMPACT_FLAG_MASK) ? true : false);
+  const bool startFullSizeFlag = ((listHeader[HllUtil<A>::FLAGS_BYTE] & HllUtil<A>::FULL_SIZE_FLAG_MASK) ? true : false);
 
   const int lgK = (int) listHeader[HllUtil<A>::LG_K_BYTE];
   const int curMin = (int) listHeader[HllUtil<A>::HLL_CUR_MIN_BYTE];
@@ -214,7 +210,7 @@ HllArray<A>* HllArray<A>::newHll(std::istream& is) {
   is.read((char*)sketch->hllByteArr, sketch->getHllByteArrBytes());
   
   if (auxCount > 0) { // necessarily TgtHllType == HLL_4
-    int auxLgIntArrSize = (int) listHeader[4];
+    int auxLgIntArrSize = listHeader[4];
     AuxHashMap<A>* auxHashMap = AuxHashMap<A>::deserialize(is, lgK, auxCount, auxLgIntArrSize, comapctFlag);
     ((Hll4Array<A>*)sketch)->putAuxHashMap(auxHashMap);
   }
@@ -258,7 +254,6 @@ std::pair<std::unique_ptr<uint8_t, std::function<void(uint8_t*)>>, const size_t>
     bytes += getMemDataStart() + hllByteArrBytes; // start of auxHashMap
     if (auxHashMap != nullptr) {
       if (compact) {
-        //std::unique_ptr<PairIterator<A>> itr = auxHashMap->getIterator();
         PairIterator_with_deleter<A> itr = auxHashMap->getIterator();
         while (itr->nextValid()) {
           const int pairValue = itr->getPair();


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


[incubator-datasketches-cpp] 01/02: deallocate instead of delete, more const and cleanup

Posted by al...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

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

commit 907b5b48a0b5cadb5e80768f099e44a90810e7cb
Author: AlexanderSaydakov <Al...@users.noreply.github.com>
AuthorDate: Tue Jul 30 16:29:32 2019 -0700

    deallocate instead of delete, more const and cleanup
---
 hll/include/CouponHashSet-internal.hpp | 31 ++++++++++++++-----------------
 1 file changed, 14 insertions(+), 17 deletions(-)

diff --git a/hll/include/CouponHashSet-internal.hpp b/hll/include/CouponHashSet-internal.hpp
index 1b2665c..5ac0bb2 100644
--- a/hll/include/CouponHashSet-internal.hpp
+++ b/hll/include/CouponHashSet-internal.hpp
@@ -20,7 +20,6 @@
 #ifndef _COUPONHASHSET_INTERNAL_HPP_
 #define _COUPONHASHSET_INTERNAL_HPP_
 
-//#include "CouponMode.hpp"
 #include "CouponHashSet.hpp"
 
 #include <string>
@@ -79,20 +78,20 @@ CouponHashSet<A>* CouponHashSet<A>::newSet(const void* bytes, size_t len) {
     throw std::invalid_argument("Input stream is not an HLL sketch");
   }
 
-  CurMode curMode = HllSketchImpl<A>::extractCurMode(data[HllUtil<A>::MODE_BYTE]);
+  const CurMode curMode = HllSketchImpl<A>::extractCurMode(data[HllUtil<A>::MODE_BYTE]);
   if (curMode != SET) {
     throw std::invalid_argument("Calling set construtor with non-set mode data");
   }
 
-  TgtHllType tgtHllType = HllSketchImpl<A>::extractTgtHllType(data[HllUtil<A>::MODE_BYTE]);
+  const TgtHllType tgtHllType = HllSketchImpl<A>::extractTgtHllType(data[HllUtil<A>::MODE_BYTE]);
 
-  const int lgK = (int) data[HllUtil<A>::LG_K_BYTE];
+  const int lgK = data[HllUtil<A>::LG_K_BYTE];
   if (lgK <= 7) {
     throw std::invalid_argument("Attempt to deserialize invalid CouponHashSet with lgConfigK <= 7. Found: "
                                 + std::to_string(lgK));
   }   
-  int lgArrInts = (int) data[HllUtil<A>::LG_ARR_BYTE];
-  bool compactFlag = ((data[HllUtil<A>::FLAGS_BYTE] & HllUtil<A>::COMPACT_FLAG_MASK) ? true : false);
+  int lgArrInts = data[HllUtil<A>::LG_ARR_BYTE];
+  const bool compactFlag = ((data[HllUtil<A>::FLAGS_BYTE] & HllUtil<A>::COMPACT_FLAG_MASK) ? true : false);
 
   int couponCount;
   std::memcpy(&couponCount, data + HllUtil<A>::HASH_SET_COUNT_INT, sizeof(couponCount));
@@ -101,7 +100,6 @@ CouponHashSet<A>* CouponHashSet<A>::newSet(const void* bytes, size_t len) {
   }
   // Don't set couponCount in sketch here;
   // we'll set later if updatable, and increment with updates if compact
-  //int couponsInArray = (compactFlag ? couponCount : (1 << sketch->getLgCouponArrInts()));
   const int couponsInArray = (compactFlag ? couponCount : (1 << lgArrInts));
   const size_t expectedLength = HllUtil<A>::HASH_SET_INT_ARR_START + (couponsInArray * sizeof(int));
   if (len < expectedLength) {
@@ -120,7 +118,8 @@ CouponHashSet<A>* CouponHashSet<A>::newSet(const void* bytes, size_t len) {
       sketch->couponUpdate(coupon);
     }
   } else {
-    int* tmp = sketch->couponIntArr;
+    int* oldArr = sketch->couponIntArr;
+    const size_t oldArrLen = 1 << sketch->lgCouponArrInts;
     sketch->lgCouponArrInts = lgArrInts;
     typedef typename std::allocator_traits<A>::template rebind_alloc<int> intAlloc;
     sketch->couponIntArr = intAlloc().allocate(1 << lgArrInts);
@@ -129,7 +128,7 @@ CouponHashSet<A>* CouponHashSet<A>::newSet(const void* bytes, size_t len) {
     std::memcpy(sketch->couponIntArr,
                 data + HllUtil<A>::HASH_SET_INT_ARR_START,
                 couponCount * sizeof(int));
-    delete tmp;
+    intAlloc().deallocate(oldArr, oldArrLen);
   }
 
   return sketch;
@@ -157,15 +156,13 @@ CouponHashSet<A>* CouponHashSet<A>::newSet(std::istream& is) {
 
   TgtHllType tgtHllType = HllSketchImpl<A>::extractTgtHllType(listHeader[HllUtil<A>::MODE_BYTE]);
 
-  const int lgK = (int) listHeader[HllUtil<A>::LG_K_BYTE];
+  const int lgK = listHeader[HllUtil<A>::LG_K_BYTE];
   if (lgK <= 7) {
     throw std::invalid_argument("Attempt to deserialize invalid CouponHashSet with lgConfigK <= 7. Found: "
                                 + std::to_string(lgK));
   }
-  int lgArrInts = (int) listHeader[HllUtil<A>::LG_ARR_BYTE];
-  bool compactFlag = ((listHeader[HllUtil<A>::FLAGS_BYTE] & HllUtil<A>::COMPACT_FLAG_MASK) ? true : false);
-  //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);
+  int lgArrInts = listHeader[HllUtil<A>::LG_ARR_BYTE];
+  const bool compactFlag = ((listHeader[HllUtil<A>::FLAGS_BYTE] & HllUtil<A>::COMPACT_FLAG_MASK) ? true : false);
 
   int couponCount;
   is.read((char*)&couponCount, sizeof(couponCount));
@@ -185,15 +182,15 @@ CouponHashSet<A>* CouponHashSet<A>::newSet(std::istream& is) {
       sketch->couponUpdate(coupon);
     }
   } else {
-    int* tmp = sketch->couponIntArr;
+    int* oldArr = sketch->couponIntArr;
+    const size_t oldArrLen = 1 << sketch->lgCouponArrInts;
     sketch->lgCouponArrInts = lgArrInts;
     typedef typename std::allocator_traits<A>::template rebind_alloc<int> intAlloc;
     sketch->couponIntArr = intAlloc().allocate(1 << lgArrInts);
     sketch->couponCount = couponCount;
     // for stream processing, read entire list so read pointer ends up set correctly
-    //is.read((char*)sketch->couponIntArr, couponCount * sizeof(int));
     is.read((char*)sketch->couponIntArr, (1 << sketch->lgCouponArrInts) * sizeof(int));
-    delete tmp;
+    intAlloc().deallocate(oldArr, oldArrLen);
   } 
 
   return sketch;


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