20#ifndef ARRAY_TUPLE_SKETCH_HPP_
21#define ARRAY_TUPLE_SKETCH_HPP_
29#include "tuple_sketch.hpp"
34template<
typename T,
typename Allocator = std::allocator<T>>
38 using allocator_type = Allocator;
39 using alloc_traits = std::allocator_traits<Allocator>;
41 explicit array(uint8_t size,
const T& value,
const Allocator& allocator = Allocator()):
42 allocator_(allocator), size_(size), array_(allocator_.allocate(size_)) {
43 init_values(value, std::is_trivially_copyable<T>());
45 array(
const array& other):
46 allocator_(other.allocator_),
48 array_(allocator_.allocate(size_))
50 copy_from(other, std::is_trivially_copyable<T>());
52 array(array&& other)
noexcept:
53 allocator_(std::move(other.allocator_)),
57 other.array_ =
nullptr;
61 if (array_ !=
nullptr) {
62 destroy_values(std::is_trivially_destructible<T>());
63 allocator_.deallocate(array_, size_);
66 array& operator=(
const array& other) {
68 std::swap(allocator_, copy.allocator_);
69 std::swap(size_, copy.size_);
70 std::swap(array_, copy.array_);
73 array& operator=(array&& other) {
74 std::swap(allocator_, other.allocator_);
75 std::swap(size_, other.size_);
76 std::swap(array_, other.array_);
79 T& operator[](
size_t index) {
return array_[index]; }
80 T operator[](
size_t index)
const {
return array_[index]; }
81 uint8_t size()
const {
return size_; }
82 T* data() {
return array_; }
83 const T* data()
const {
return array_; }
84 bool operator==(
const array& other)
const {
85 if (size_ != other.size_)
return false;
86 for (uint8_t i = 0; i < size_; ++i)
if (array_[i] != other.array_[i])
return false;
90 void init_values(
const T& value, std::true_type) {
91 std::fill(array_, array_ + size_, value);
93 void init_values(
const T& value, std::false_type) {
94 for (uint8_t i = 0; i < size_; ++i) {
95 alloc_traits::construct(allocator_, array_ + i, value);
98 void copy_from(
const array& other, std::true_type) {
99 std::copy(other.array_, other.array_ + size_, array_);
101 void copy_from(
const array& other, std::false_type) {
102 for (uint8_t i = 0; i < size_; ++i) {
103 alloc_traits::construct(allocator_, array_ + i, other.array_[i]);
106 void destroy_values(std::true_type) {}
107 void destroy_values(std::false_type) {
108 for (uint8_t i = 0; i < size_; ++i) {
109 alloc_traits::destroy(allocator_, array_ + i);
113 Allocator allocator_;
119template<
typename Array,
typename Allocator =
typename Array::allocator_type>
123 allocator_(allocator), num_values_(num_values) {}
124 Array create()
const {
125 return Array(num_values_, 0, allocator_);
127 template<
typename InputArray>
128 void update(Array& array,
const InputArray& update)
const {
129 for (uint8_t i = 0; i < num_values_; ++i) array[i] += update[i];
131 uint8_t get_num_values()
const {
136 Allocator allocator_;
154 typename Allocator =
typename Array::allocator_type
159 using resize_factor =
typename Base::resize_factor;
171 uint64_t seed,
const Policy& policy,
const Allocator& allocator);
175template<
typename Array,
typename Policy,
typename Allocator>
183 builder(
const Policy& policy = Policy(),
const Allocator& allocator = Allocator());
192 typename Allocator =
typename Array::allocator_type
197 using Entry =
typename Base::Entry;
198 using AllocEntry =
typename Base::AllocEntry;
199 using AllocU64 =
typename Base::AllocU64;
200 using vector_bytes =
typename Base::vector_bytes;
202 static const uint8_t SERIAL_VERSION = 1;
203 static const uint8_t SKETCH_FAMILY = 9;
204 static const uint8_t SKETCH_TYPE = 3;
205 enum flags { UNUSED1, UNUSED2, IS_EMPTY, HAS_ENTRIES, IS_ORDERED };
213 template<
typename Sketch>
232 vector_bytes
serialize(
unsigned header_size_bytes = 0)
const;
252 const Allocator& allocator = Allocator());
266#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:194
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:457
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:120
Tuple base builder.
Definition tuple_sketch.hpp:655
Update array tuple sketch builder.
Definition array_tuple_sketch.hpp:176
Update array tuple sketch.
Definition array_tuple_sketch.hpp:156
uint8_t get_num_values() const
Definition array_tuple_sketch_impl.hpp:28
Update Tuple sketch.
Definition tuple_sketch.hpp:222
DataSketches namespace.
Definition binomial_bounds.hpp:38