renamed classes for convenience and consistency
diff --git a/tuple/include/array_of_doubles_sketch.hpp b/tuple/include/array_of_doubles_sketch.hpp
index e5b61a8..c2049d3 100644
--- a/tuple/include/array_of_doubles_sketch.hpp
+++ b/tuple/include/array_of_doubles_sketch.hpp
@@ -51,10 +51,10 @@
};
// forward declaration
-template<typename A> class compact_array_of_doubles_sketch;
+template<typename A> class compact_array_of_doubles_sketch_alloc;
template<typename A = std::allocator<std::vector<double>>>
-class update_array_of_doubles_sketch: public update_tuple_sketch<std::vector<double>, std::vector<double>,
+class update_array_of_doubles_sketch_alloc: public update_tuple_sketch<std::vector<double>, std::vector<double>,
array_of_doubles_update_policy<A>, A> {
public:
using Base = update_tuple_sketch<std::vector<double>, std::vector<double>, array_of_doubles_update_policy<A>, A>;
@@ -62,24 +62,27 @@
class builder;
- compact_array_of_doubles_sketch<A> compact(bool ordered = true) const;
+ compact_array_of_doubles_sketch_alloc<A> compact(bool ordered = true) const;
uint8_t get_num_values() const;
private:
// for builder
- update_array_of_doubles_sketch(uint8_t lg_cur_size, uint8_t lg_nom_size, resize_factor rf, uint64_t theta,
+ update_array_of_doubles_sketch_alloc(uint8_t lg_cur_size, uint8_t lg_nom_size, resize_factor rf, uint64_t theta,
uint64_t seed, const array_of_doubles_update_policy<A>& policy, const A& allocator);
};
+// alias with the default allocator for convenience
+using update_array_of_doubles_sketch = update_array_of_doubles_sketch_alloc<>;
+
template<typename A>
-class update_array_of_doubles_sketch<A>::builder: public Base::builder {
+class update_array_of_doubles_sketch_alloc<A>::builder: public Base::builder {
public:
builder(const array_of_doubles_update_policy<A>& policy = array_of_doubles_update_policy<A>(), const A& allocator = A());
- update_array_of_doubles_sketch<A> build() const;
+ update_array_of_doubles_sketch_alloc<A> build() const;
};
template<typename A = std::allocator<std::vector<double>>>
-class compact_array_of_doubles_sketch: public compact_tuple_sketch<std::vector<double>, A> {
+class compact_array_of_doubles_sketch_alloc: public compact_tuple_sketch<std::vector<double>, A> {
public:
using Base = compact_tuple_sketch<std::vector<double>, A>;
using Entry = typename Base::Entry;
@@ -93,23 +96,26 @@
enum flags { UNUSED1, UNUSED2, IS_EMPTY, HAS_ENTRIES, IS_ORDERED };
template<typename Sketch>
- compact_array_of_doubles_sketch(const Sketch& other, bool ordered = true);
+ compact_array_of_doubles_sketch_alloc(const Sketch& other, bool ordered = true);
uint8_t get_num_values() const;
void serialize(std::ostream& os) const;
vector_bytes serialize(unsigned header_size_bytes = 0) const;
- static compact_array_of_doubles_sketch deserialize(std::istream& is, uint64_t seed = DEFAULT_SEED, const A& allocator = A());
- static compact_array_of_doubles_sketch deserialize(const void* bytes, size_t size, uint64_t seed = DEFAULT_SEED,
+ static compact_array_of_doubles_sketch_alloc deserialize(std::istream& is, uint64_t seed = DEFAULT_SEED, const A& allocator = A());
+ static compact_array_of_doubles_sketch_alloc deserialize(const void* bytes, size_t size, uint64_t seed = DEFAULT_SEED,
const A& allocator = A());
// for internal use
- compact_array_of_doubles_sketch(bool is_empty, bool is_ordered, uint16_t seed_hash, uint64_t theta, std::vector<Entry, AllocEntry>&& entries, uint8_t num_values);
+ compact_array_of_doubles_sketch_alloc(bool is_empty, bool is_ordered, uint16_t seed_hash, uint64_t theta, std::vector<Entry, AllocEntry>&& entries, uint8_t num_values);
private:
uint8_t num_values_;
};
+// alias with the default allocator for convenience
+using compact_array_of_doubles_sketch = compact_array_of_doubles_sketch_alloc<>;
+
} /* namespace datasketches */
#include "array_of_doubles_sketch_impl.hpp"
diff --git a/tuple/include/array_of_doubles_sketch_impl.hpp b/tuple/include/array_of_doubles_sketch_impl.hpp
index b6371f2..cb8e857 100644
--- a/tuple/include/array_of_doubles_sketch_impl.hpp
+++ b/tuple/include/array_of_doubles_sketch_impl.hpp
@@ -20,51 +20,51 @@
namespace datasketches {
template<typename A>
-update_array_of_doubles_sketch<A>::update_array_of_doubles_sketch(uint8_t lg_cur_size, uint8_t lg_nom_size, resize_factor rf,
+update_array_of_doubles_sketch_alloc<A>::update_array_of_doubles_sketch_alloc(uint8_t lg_cur_size, uint8_t lg_nom_size, resize_factor rf,
uint64_t theta, uint64_t seed, const array_of_doubles_update_policy<A>& policy, const A& allocator):
Base(lg_cur_size, lg_nom_size, rf, theta, seed, policy, allocator) {}
template<typename A>
-uint8_t update_array_of_doubles_sketch<A>::get_num_values() const {
+uint8_t update_array_of_doubles_sketch_alloc<A>::get_num_values() const {
return this->policy_.get_num_values();
}
template<typename A>
-compact_array_of_doubles_sketch<A> update_array_of_doubles_sketch<A>::compact(bool ordered) const {
- return compact_array_of_doubles_sketch<A>(*this, ordered);
+compact_array_of_doubles_sketch_alloc<A> update_array_of_doubles_sketch_alloc<A>::compact(bool ordered) const {
+ return compact_array_of_doubles_sketch_alloc<A>(*this, ordered);
}
// builder
template<typename A>
-update_array_of_doubles_sketch<A>::builder::builder(const array_of_doubles_update_policy<A>& policy, const A& allocator):
+update_array_of_doubles_sketch_alloc<A>::builder::builder(const array_of_doubles_update_policy<A>& policy, const A& allocator):
Base::builder(policy, allocator) {}
template<typename A>
-update_array_of_doubles_sketch<A> update_array_of_doubles_sketch<A>::builder::build() const {
- return update_array_of_doubles_sketch<A>(this->starting_lg_size(), this->lg_k_, this->rf_, this->starting_theta(), this->seed_, this->policy_, this->allocator_);
+update_array_of_doubles_sketch_alloc<A> update_array_of_doubles_sketch_alloc<A>::builder::build() const {
+ return update_array_of_doubles_sketch_alloc<A>(this->starting_lg_size(), this->lg_k_, this->rf_, this->starting_theta(), this->seed_, this->policy_, this->allocator_);
}
// compact sketch
template<typename A>
template<typename S>
-compact_array_of_doubles_sketch<A>::compact_array_of_doubles_sketch(const S& other, bool ordered):
+compact_array_of_doubles_sketch_alloc<A>::compact_array_of_doubles_sketch_alloc(const S& other, bool ordered):
Base(other, ordered), num_values_(other.get_num_values()) {}
template<typename A>
-compact_array_of_doubles_sketch<A>::compact_array_of_doubles_sketch(bool is_empty, bool is_ordered,
+compact_array_of_doubles_sketch_alloc<A>::compact_array_of_doubles_sketch_alloc(bool is_empty, bool is_ordered,
uint16_t seed_hash, uint64_t theta, std::vector<Entry, AllocEntry>&& entries, uint8_t num_values):
Base(is_empty, is_ordered, seed_hash, theta, std::move(entries)), num_values_(num_values) {}
template<typename A>
-uint8_t compact_array_of_doubles_sketch<A>::get_num_values() const {
+uint8_t compact_array_of_doubles_sketch_alloc<A>::get_num_values() const {
return num_values_;
}
template<typename A>
-void compact_array_of_doubles_sketch<A>::serialize(std::ostream& os) const {
+void compact_array_of_doubles_sketch_alloc<A>::serialize(std::ostream& os) const {
const uint8_t preamble_longs = 1;
os.write(reinterpret_cast<const char*>(&preamble_longs), sizeof(preamble_longs));
const uint8_t serial_version = SERIAL_VERSION;
@@ -98,7 +98,7 @@
}
template<typename A>
-auto compact_array_of_doubles_sketch<A>::serialize(unsigned header_size_bytes) const -> vector_bytes {
+auto compact_array_of_doubles_sketch_alloc<A>::serialize(unsigned header_size_bytes) const -> vector_bytes {
const uint8_t preamble_longs = 1;
const size_t size = header_size_bytes + 16 // preamble and theta
+ (this->entries_.size() > 0 ? 8 : 0)
@@ -139,7 +139,7 @@
}
template<typename A>
-compact_array_of_doubles_sketch<A> compact_array_of_doubles_sketch<A>::deserialize(std::istream& is, uint64_t seed, const A& allocator) {
+compact_array_of_doubles_sketch_alloc<A> compact_array_of_doubles_sketch_alloc<A>::deserialize(std::istream& is, uint64_t seed, const A& allocator) {
uint8_t preamble_longs;
is.read(reinterpret_cast<char*>(&preamble_longs), sizeof(preamble_longs));
uint8_t serial_version;
@@ -180,11 +180,11 @@
if (!is.good()) throw std::runtime_error("error reading from std::istream");
const bool is_empty = flags_byte & (1 << flags::IS_EMPTY);
const bool is_ordered = flags_byte & (1 << flags::IS_ORDERED);
- return compact_array_of_doubles_sketch(is_empty, is_ordered, seed_hash, theta, std::move(entries), num_values);
+ return compact_array_of_doubles_sketch_alloc(is_empty, is_ordered, seed_hash, theta, std::move(entries), num_values);
}
template<typename A>
-compact_array_of_doubles_sketch<A> compact_array_of_doubles_sketch<A>::deserialize(const void* bytes, size_t size, uint64_t seed, const A& allocator) {
+compact_array_of_doubles_sketch_alloc<A> compact_array_of_doubles_sketch_alloc<A>::deserialize(const void* bytes, size_t size, uint64_t seed, const A& allocator) {
ensure_minimum_memory(size, 16);
const char* ptr = static_cast<const char*>(bytes);
uint8_t preamble_longs;
@@ -228,7 +228,7 @@
}
const bool is_empty = flags_byte & (1 << flags::IS_EMPTY);
const bool is_ordered = flags_byte & (1 << flags::IS_ORDERED);
- return compact_array_of_doubles_sketch(is_empty, is_ordered, seed_hash, theta, std::move(entries), num_values);
+ return compact_array_of_doubles_sketch_alloc(is_empty, is_ordered, seed_hash, theta, std::move(entries), num_values);
}
} /* namespace datasketches */
diff --git a/tuple/test/array_of_doubles_sketch_test.cpp b/tuple/test/array_of_doubles_sketch_test.cpp
index 5a1518e..63dcea3 100644
--- a/tuple/test/array_of_doubles_sketch_test.cpp
+++ b/tuple/test/array_of_doubles_sketch_test.cpp
@@ -35,7 +35,7 @@
#endif
TEST_CASE("aod sketch: serialization compatibility with java - empty", "[tuple_sketch]") {
- auto update_sketch = update_array_of_doubles_sketch<>::builder().build();
+ auto update_sketch = update_array_of_doubles_sketch::builder().build();
REQUIRE(update_sketch.is_empty());
REQUIRE(update_sketch.get_num_retained() == 0);
auto compact_sketch = update_sketch.compact();
@@ -44,7 +44,7 @@
std::ifstream is;
is.exceptions(std::ios::failbit | std::ios::badbit);
is.open(inputPath + "aod_1_compact_empty_from_java.sk", std::ios::binary);
- auto compact_sketch_from_java = compact_array_of_doubles_sketch<>::deserialize(is);
+ auto compact_sketch_from_java = compact_array_of_doubles_sketch::deserialize(is);
REQUIRE(compact_sketch.get_num_retained() == compact_sketch_from_java.get_num_retained());
REQUIRE(compact_sketch.get_theta() == Approx(compact_sketch_from_java.get_theta()).margin(1e-10));
REQUIRE(compact_sketch.get_estimate() == Approx(compact_sketch_from_java.get_estimate()).margin(1e-10));
@@ -53,7 +53,7 @@
}
TEST_CASE("aod sketch: serialization compatibility with java - empty configured for three values", "[tuple_sketch]") {
- auto update_sketch = update_array_of_doubles_sketch<>::builder(3).build();
+ auto update_sketch = update_array_of_doubles_sketch::builder(3).build();
REQUIRE(update_sketch.is_empty());
REQUIRE(update_sketch.get_num_retained() == 0);
REQUIRE(update_sketch.get_num_values() == 3);
@@ -63,7 +63,7 @@
std::ifstream is;
is.exceptions(std::ios::failbit | std::ios::badbit);
is.open(inputPath + "aod_3_compact_empty_from_java.sk", std::ios::binary);
- auto compact_sketch_from_java = compact_array_of_doubles_sketch<>::deserialize(is);
+ auto compact_sketch_from_java = compact_array_of_doubles_sketch::deserialize(is);
REQUIRE(compact_sketch.get_num_values() == compact_sketch_from_java.get_num_values());
REQUIRE(compact_sketch.get_num_retained() == compact_sketch_from_java.get_num_retained());
REQUIRE(compact_sketch.get_theta() == Approx(compact_sketch_from_java.get_theta()).margin(1e-10));
@@ -73,7 +73,7 @@
}
TEST_CASE("aod sketch: serialization compatibility with java - non-empty no entries", "[tuple_sketch]") {
- auto update_sketch = update_array_of_doubles_sketch<>::builder().set_p(0.01).build();
+ auto update_sketch = update_array_of_doubles_sketch::builder().set_p(0.01).build();
std::vector<double> a = {1};
update_sketch.update(1, a);
REQUIRE_FALSE(update_sketch.is_empty());
@@ -84,7 +84,7 @@
std::ifstream is;
is.exceptions(std::ios::failbit | std::ios::badbit);
is.open(inputPath + "aod_1_compact_non_empty_no_entries_from_java.sk", std::ios::binary);
- auto compact_sketch_from_java = compact_array_of_doubles_sketch<>::deserialize(is);
+ auto compact_sketch_from_java = compact_array_of_doubles_sketch::deserialize(is);
REQUIRE(compact_sketch.get_num_retained() == compact_sketch_from_java.get_num_retained());
REQUIRE(compact_sketch.get_theta() == Approx(compact_sketch_from_java.get_theta()).margin(1e-10));
REQUIRE(compact_sketch.get_estimate() == Approx(compact_sketch_from_java.get_estimate()).margin(1e-10));
@@ -93,7 +93,7 @@
}
TEST_CASE("aod sketch: serialization compatibility with java - estimation mode", "[tuple_sketch]") {
- auto update_sketch = update_array_of_doubles_sketch<>::builder().build();
+ auto update_sketch = update_array_of_doubles_sketch::builder().build();
std::vector<double> a = {1};
for (int i = 0; i < 8192; ++i) update_sketch.update(i, a);
auto compact_sketch = update_sketch.compact();
@@ -102,7 +102,7 @@
std::ifstream is;
is.exceptions(std::ios::failbit | std::ios::badbit);
is.open(inputPath + "aod_1_compact_estimation_from_java.sk", std::ios::binary);
- auto compact_sketch_from_java = compact_array_of_doubles_sketch<>::deserialize(is);
+ auto compact_sketch_from_java = compact_array_of_doubles_sketch::deserialize(is);
REQUIRE(compact_sketch.get_num_retained() == compact_sketch_from_java.get_num_retained());
REQUIRE(compact_sketch.get_theta() == Approx(compact_sketch_from_java.get_theta()).margin(1e-10));
REQUIRE(compact_sketch.get_estimate() == Approx(compact_sketch_from_java.get_estimate()).margin(1e-10));
@@ -115,7 +115,7 @@
// sketch from Java is not ordered
// transform it to ordered so that iteration sequence would match exactly
- compact_array_of_doubles_sketch<> ordered_sketch_from_java(compact_sketch_from_java, true);
+ compact_array_of_doubles_sketch ordered_sketch_from_java(compact_sketch_from_java, true);
auto it = ordered_sketch_from_java.begin();
for (const auto& entry: compact_sketch) {
REQUIRE(entry == *it);
@@ -124,7 +124,7 @@
}
TEST_CASE("aod sketch: serialization compatibility with java - exact mode with two values", "[tuple_sketch]") {
- auto update_sketch = update_array_of_doubles_sketch<>::builder(2).build();
+ auto update_sketch = update_array_of_doubles_sketch::builder(2).build();
std::vector<double> a = {1, 2};
for (int i = 0; i < 1000; ++i) update_sketch.update(i, a);
auto compact_sketch = update_sketch.compact();
@@ -134,7 +134,7 @@
std::ifstream is;
is.exceptions(std::ios::failbit | std::ios::badbit);
is.open(inputPath + "aod_2_compact_exact_from_java.sk", std::ios::binary);
- auto compact_sketch_from_java = compact_array_of_doubles_sketch<>::deserialize(is);
+ auto compact_sketch_from_java = compact_array_of_doubles_sketch::deserialize(is);
REQUIRE(compact_sketch.get_num_retained() == compact_sketch_from_java.get_num_retained());
REQUIRE(compact_sketch.get_theta() == Approx(compact_sketch_from_java.get_theta()).margin(1e-10));
REQUIRE(compact_sketch.get_estimate() == Approx(compact_sketch_from_java.get_estimate()).margin(1e-10));
@@ -147,7 +147,7 @@
// sketch from Java is not ordered
// transform it to ordered so that iteration sequence would match exactly
- compact_array_of_doubles_sketch<> ordered_sketch_from_java(compact_sketch_from_java, true);
+ compact_array_of_doubles_sketch ordered_sketch_from_java(compact_sketch_from_java, true);
auto it = ordered_sketch_from_java.begin();
for (const auto& entry: compact_sketch) {
REQUIRE(entry.first == (*it).first);
@@ -159,7 +159,7 @@
}
TEST_CASE("aod sketch: stream serialize deserialize - estimation mode", "[tuple_sketch]") {
- auto update_sketch = update_array_of_doubles_sketch<>::builder(2).build();
+ auto update_sketch = update_array_of_doubles_sketch::builder(2).build();
std::vector<double> a = {1, 2};
for (int i = 0; i < 8192; ++i) update_sketch.update(i, a);
auto compact_sketch = update_sketch.compact();
@@ -167,7 +167,7 @@
std::stringstream ss;
ss.exceptions(std::ios::failbit | std::ios::badbit);
compact_sketch.serialize(ss);
- auto deserialized_sketch = compact_array_of_doubles_sketch<>::deserialize(ss);
+ auto deserialized_sketch = compact_array_of_doubles_sketch::deserialize(ss);
REQUIRE(compact_sketch.get_num_retained() == deserialized_sketch.get_num_retained());
REQUIRE(compact_sketch.get_theta() == Approx(deserialized_sketch.get_theta()).margin(1e-10));
REQUIRE(compact_sketch.get_estimate() == Approx(deserialized_sketch.get_estimate()).margin(1e-10));
@@ -189,7 +189,7 @@
}
TEST_CASE("aod sketch: bytes to stream serialize deserialize - estimation mode", "[tuple_sketch]") {
- auto update_sketch = update_array_of_doubles_sketch<>::builder(2).build();
+ auto update_sketch = update_array_of_doubles_sketch::builder(2).build();
std::vector<double> a = {1, 2};
for (int i = 0; i < 8192; ++i) update_sketch.update(i, a);
auto compact_sketch = update_sketch.compact();
@@ -198,7 +198,7 @@
std::stringstream ss;
ss.exceptions(std::ios::failbit | std::ios::badbit);
ss.write(reinterpret_cast<const char*>(bytes.data()), bytes.size());
- auto deserialized_sketch = compact_array_of_doubles_sketch<>::deserialize(ss);
+ auto deserialized_sketch = compact_array_of_doubles_sketch::deserialize(ss);
REQUIRE(compact_sketch.get_num_retained() == deserialized_sketch.get_num_retained());
REQUIRE(compact_sketch.get_theta() == Approx(deserialized_sketch.get_theta()).margin(1e-10));
REQUIRE(compact_sketch.get_estimate() == Approx(deserialized_sketch.get_estimate()).margin(1e-10));
@@ -220,13 +220,13 @@
}
TEST_CASE("aod sketch: bytes serialize deserialize - estimation mode", "[tuple_sketch]") {
- auto update_sketch = update_array_of_doubles_sketch<>::builder(2).build();
+ auto update_sketch = update_array_of_doubles_sketch::builder(2).build();
std::vector<double> a = {1, 2};
for (int i = 0; i < 8192; ++i) update_sketch.update(i, a);
auto compact_sketch = update_sketch.compact();
auto bytes = compact_sketch.serialize();
- auto deserialized_sketch = compact_array_of_doubles_sketch<>::deserialize(bytes.data(), bytes.size());
+ auto deserialized_sketch = compact_array_of_doubles_sketch::deserialize(bytes.data(), bytes.size());
REQUIRE(compact_sketch.get_num_retained() == deserialized_sketch.get_num_retained());
REQUIRE(compact_sketch.get_theta() == Approx(deserialized_sketch.get_theta()).margin(1e-10));
REQUIRE(compact_sketch.get_estimate() == Approx(deserialized_sketch.get_estimate()).margin(1e-10));
@@ -250,10 +250,10 @@
TEST_CASE("aod union: half overlap", "[tuple_sketch]") {
std::vector<double> a = {1};
- auto update_sketch1 = update_array_of_doubles_sketch<>::builder().build();
+ auto update_sketch1 = update_array_of_doubles_sketch::builder().build();
for (int i = 0; i < 1000; ++i) update_sketch1.update(i, a);
- auto update_sketch2 = update_array_of_doubles_sketch<>::builder().build();
+ auto update_sketch2 = update_array_of_doubles_sketch::builder().build();
for (int i = 500; i < 1500; ++i) update_sketch2.update(i, a);
auto u = tuple_union<std::vector<double>, array_of_doubles_union_policy>::builder().build();