20 #ifndef ARRAY_TUPLE_SKETCH_HPP_
21 #define ARRAY_TUPLE_SKETCH_HPP_
27 #include "tuple_sketch.hpp"
32 template<
typename T,
typename Allocator = std::allocator<T>>
36 using allocator_type = Allocator;
38 explicit array(uint8_t size, T value,
const Allocator& allocator = Allocator()):
39 allocator_(allocator), size_(size), array_(allocator_.allocate(size_)) {
40 std::fill(array_, array_ + size_, value);
42 array(
const array& other):
43 allocator_(other.allocator_),
45 array_(allocator_.allocate(size_))
47 std::copy(other.array_, other.array_ + size_, array_);
49 array(array&& other) noexcept:
50 allocator_(std::move(other.allocator_)),
54 other.array_ =
nullptr;
57 if (array_ !=
nullptr) allocator_.deallocate(array_, size_);
59 array& operator=(
const array& other) {
61 std::swap(allocator_, copy.allocator_);
62 std::swap(size_, copy.size_);
63 std::swap(array_, copy.array_);
66 array& operator=(array&& other) {
67 std::swap(allocator_, other.allocator_);
68 std::swap(size_, other.size_);
69 std::swap(array_, other.array_);
72 T& operator[](
size_t index) {
return array_[index]; }
73 T operator[](
size_t index)
const {
return array_[index]; }
74 uint8_t size()
const {
return size_; }
75 T* data() {
return array_; }
76 const T* data()
const {
return array_; }
77 bool operator==(
const array& other)
const {
78 for (uint8_t i = 0; i < size_; ++i)
if (array_[i] != other.array_[i])
return false;
88 template<
typename Array,
typename Allocator =
typename Array::allocator_type>
92 allocator_(allocator), num_values_(num_values) {}
93 Array create()
const {
94 return Array(num_values_, 0, allocator_);
96 template<
typename InputArray>
97 void update(Array& array,
const InputArray& update)
const {
98 for (uint8_t i = 0; i < num_values_; ++i) array[i] += update[i];
100 uint8_t get_num_values()
const {
105 Allocator allocator_;
123 typename Allocator =
typename Array::allocator_type
128 using resize_factor =
typename Base::resize_factor;
140 uint64_t seed,
const Policy& policy,
const Allocator& allocator);
144 template<
typename Array,
typename Policy,
typename Allocator>
152 builder(
const Policy& policy = Policy(),
const Allocator& allocator = Allocator());
161 typename Allocator =
typename Array::allocator_type
166 using Entry =
typename Base::Entry;
167 using AllocEntry =
typename Base::AllocEntry;
168 using AllocU64 =
typename Base::AllocU64;
169 using vector_bytes =
typename Base::vector_bytes;
171 static const uint8_t SERIAL_VERSION = 1;
172 static const uint8_t SKETCH_FAMILY = 9;
173 static const uint8_t SKETCH_TYPE = 3;
174 enum flags { UNUSED1, UNUSED2, IS_EMPTY, HAS_ENTRIES, IS_ORDERED };
182 template<
typename Sketch>
201 vector_bytes
serialize(
unsigned header_size_bytes = 0)
const;
221 const Allocator& allocator = Allocator());
235 #include "array_tuple_sketch_impl.hpp"
array tuple A-not-B
Definition: array_tuple_a_not_b.hpp:33
array tuple intersection
Definition: array_tuple_intersection.hpp:37
array tuple union
Definition: array_tuple_union.hpp:54
Compact array tuple sketch.
Definition: array_tuple_sketch.hpp:163
uint8_t get_num_values() const
Definition: array_tuple_sketch_impl.hpp:65
void serialize(std::ostream &os) const
This method serializes the sketch into a given stream in a binary form.
Definition: array_tuple_sketch_impl.hpp:70
compact_array_tuple_sketch(const Sketch &other, bool ordered=true)
Copy constructor.
static compact_array_tuple_sketch deserialize(std::istream &is, uint64_t seed=DEFAULT_SEED, const Allocator &allocator=Allocator())
This method deserializes a sketch from a given stream.
Definition: array_tuple_sketch_impl.hpp:144
Compact Tuple sketch.
Definition: tuple_sketch.hpp:416
virtual bool is_empty() const
Definition: tuple_sketch_impl.hpp:329
virtual bool is_ordered() const
Definition: tuple_sketch_impl.hpp:334
default array tuple update policy
Definition: array_tuple_sketch.hpp:89
Tuple base builder.
Definition: tuple_sketch.hpp:614
Update array tuple sketch builder.
Definition: array_tuple_sketch.hpp:145
Update array tuple sketch.
Definition: array_tuple_sketch.hpp:125
uint8_t get_num_values() const
Definition: array_tuple_sketch_impl.hpp:28
Update Tuple sketch.
Definition: tuple_sketch.hpp:217
DataSketches namespace.
Definition: binomial_bounds.hpp:38