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 21:48:45 UTC
[incubator-datasketches-cpp] branch hll_cleanup updated: converted
copyAs to copy constructor
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
The following commit(s) were added to refs/heads/hll_cleanup by this push:
new 9deb839 converted copyAs to copy constructor
9deb839 is described below
commit 9deb8397dfa9c22aae6d0f281c20ebe94e669526
Author: AlexanderSaydakov <Al...@users.noreply.github.com>
AuthorDate: Tue Jul 30 14:48:37 2019 -0700
converted copyAs to copy constructor
---
hll/include/HllSketch-internal.hpp | 11 +++++------
hll/include/HllUnion-internal.hpp | 2 +-
hll/include/hll.hpp | 2 +-
hll/test/CrossCountingTest.cpp | 12 ++++++------
hll/test/HllSketchTest.cpp | 6 +++---
5 files changed, 16 insertions(+), 17 deletions(-)
diff --git a/hll/include/HllSketch-internal.hpp b/hll/include/HllSketch-internal.hpp
index 88f055b..5d8296c 100644
--- a/hll/include/HllSketch-internal.hpp
+++ b/hll/include/HllSketch-internal.hpp
@@ -84,6 +84,11 @@ HllSketch<A>::HllSketch(const HllSketch<A>& that) :
{}
template<typename A>
+HllSketch<A>::HllSketch(const HllSketch<A>& that, TgtHllType tgtHllType) :
+ hllSketchImpl(that.hllSketchImpl->copyAs(tgtHllType))
+{}
+
+template<typename A>
HllSketch<A>::HllSketch(HllSketch<A>&& that) noexcept :
hllSketchImpl(nullptr)
{
@@ -109,12 +114,6 @@ HllSketch<A> HllSketch<A>::operator=(HllSketch<A>&& other) {
}
template<typename A>
-HllSketch<A> HllSketch<A>::copyAs(const TgtHllType tgtHllType) const {
- HllSketch<A> sketch(hllSketchImpl->copyAs(tgtHllType));
- return sketch; // no move so copy elision can work
-}
-
-template<typename A>
void HllSketch<A>::reset() {
// TODO: need to allow starting from a full-sized sketch
// (either here or in other implementation)
diff --git a/hll/include/HllUnion-internal.hpp b/hll/include/HllUnion-internal.hpp
index 7ba198c..670fdfa 100644
--- a/hll/include/HllUnion-internal.hpp
+++ b/hll/include/HllUnion-internal.hpp
@@ -72,7 +72,7 @@ static std::ostream& operator<<(std::ostream& os, const HllUnion<A>& hllUnion) {
template<typename A>
HllSketch<A> HllUnion<A>::getResult(TgtHllType tgtHllType) const {
- return std::move(gadget.copyAs(tgtHllType));
+ return hll_sketch(gadget, tgtHllType);
}
template<typename A>
diff --git a/hll/include/hll.hpp b/hll/include/hll.hpp
index f69458d..93b11f8 100644
--- a/hll/include/hll.hpp
+++ b/hll/include/hll.hpp
@@ -50,13 +50,13 @@ class HllSketch final {
static HllSketch deserialize(std::istream& is);
static HllSketch deserialize(const void* bytes, size_t len);
HllSketch(const HllSketch<A>& that);
+ HllSketch(const HllSketch<A>& that, TgtHllType tgtHllType);
HllSketch(HllSketch<A>&& that) noexcept;
~HllSketch();
HllSketch operator=(const HllSketch<A>& other);
HllSketch operator=(HllSketch<A>&& other);
- HllSketch copyAs(TgtHllType tgtHllType) const;
void reset();
diff --git a/hll/test/CrossCountingTest.cpp b/hll/test/CrossCountingTest.cpp
index 23504fc..9b2bb23 100644
--- a/hll/test/CrossCountingTest.cpp
+++ b/hll/test/CrossCountingTest.cpp
@@ -70,27 +70,27 @@ class CrossCountingTest : public CppUnit::TestFixture {
CPPUNIT_ASSERT_EQUAL(csum, s4csum);
// Conversions
- hll_sketch sk4to6 = sk4.copyAs(HLL_6);
+ hll_sketch sk4to6(sk4, HLL_6);
csum = computeChecksum(sk4to6);
CPPUNIT_ASSERT_EQUAL(csum, s4csum);
- hll_sketch sk4to8 = sk4.copyAs(HLL_8);
+ hll_sketch sk4to8(sk4, HLL_8);
csum = computeChecksum(sk4to8);
CPPUNIT_ASSERT_EQUAL(csum, s4csum);
- hll_sketch sk6to4 = sk6.copyAs(HLL_4);
+ hll_sketch sk6to4(sk6, HLL_4);
csum = computeChecksum(sk6to4);
CPPUNIT_ASSERT_EQUAL(csum, s4csum);
- hll_sketch sk6to8 = sk6.copyAs(HLL_8);
+ hll_sketch sk6to8(sk6, HLL_8);
csum = computeChecksum(sk6to8);
CPPUNIT_ASSERT_EQUAL(csum, s4csum);
- hll_sketch sk8to4 = sk8.copyAs(HLL_4);
+ hll_sketch sk8to4(sk8, HLL_4);
csum = computeChecksum(sk8to4);
CPPUNIT_ASSERT_EQUAL(csum, s4csum);
- hll_sketch sk8to6 = sk8.copyAs(HLL_6);
+ hll_sketch sk8to6(sk8, HLL_6);
csum = computeChecksum(sk8to6);
CPPUNIT_ASSERT_EQUAL(csum, s4csum);
}
diff --git a/hll/test/HllSketchTest.cpp b/hll/test/HllSketchTest.cpp
index 828989d..b2e8b51 100644
--- a/hll/test/HllSketchTest.cpp
+++ b/hll/test/HllSketchTest.cpp
@@ -107,19 +107,19 @@ class hllSketchTest : public CppUnit::TestFixture {
for (int i = 0; i < n1; ++i) {
src.update(i + base);
}
- hll_sketch dst = src.copyAs(dstType);
+ hll_sketch dst(src, dstType);
CPPUNIT_ASSERT_DOUBLES_EQUAL(dst.getEstimate(), src.getEstimate(), 0.0);
for (int i = n1; i < n2; ++i) {
src.update(i + base);
}
- dst = src.copyAs(dstType);
+ dst = hll_sketch(src, dstType);
CPPUNIT_ASSERT_DOUBLES_EQUAL(dst.getEstimate(), src.getEstimate(), 0.0);
for (int i = n2; i < n3; ++i) {
src.update(i + base);
}
- dst = src.copyAs(dstType);
+ dst = hll_sketch(src, dstType);
CPPUNIT_ASSERT_DOUBLES_EQUAL(dst.getEstimate(), src.getEstimate(), 0.0);
}
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@datasketches.apache.org
For additional commands, e-mail: commits-help@datasketches.apache.org