datasketches-cpp
Public Member Functions | Static Public Member Functions | List of all members
compact_theta_sketch_alloc< Allocator > Class Template Reference

Compact Theta sketch. More...

#include <theta_sketch.hpp>

Inheritance diagram for compact_theta_sketch_alloc< Allocator >:
theta_sketch_alloc< std::allocator< uint64_t > > base_theta_sketch_alloc< std::allocator< uint64_t > >

Public Member Functions

template<typename Other >
 compact_theta_sketch_alloc (const Other &other, bool ordered)
 Copy constructor. More...
 
 compact_theta_sketch_alloc (const compact_theta_sketch_alloc &other)=default
 Copy constructor. More...
 
 compact_theta_sketch_alloc (compact_theta_sketch_alloc &&other) noexcept=default
 Move constructor. More...
 
compact_theta_sketch_allocoperator= (const compact_theta_sketch_alloc &other)=default
 Copy assignment. More...
 
compact_theta_sketch_allocoperator= (compact_theta_sketch_alloc &&other)=default
 Move assignment. More...
 
virtual Allocator get_allocator () const
 
virtual bool is_empty () const
 
virtual bool is_ordered () const
 
virtual uint64_t get_theta64 () const
 
virtual uint32_t get_num_retained () const
 
virtual uint16_t get_seed_hash () const
 
size_t get_serialized_size_bytes (bool compressed=false) const
 Computes size in bytes required to serialize the current state of the sketch. More...
 
void serialize (std::ostream &os) const
 This method serializes the sketch into a given stream in a binary form. More...
 
vector_bytes serialize (unsigned header_size_bytes=0) const
 This method serializes the sketch as a vector of bytes. More...
 
void serialize_compressed (std::ostream &os) const
 This method serializes the sketch into a given stream in a compressed binary form. More...
 
vector_bytes serialize_compressed (unsigned header_size_bytes=0) const
 This method serializes the sketch as a vector of bytes. More...
 
virtual iterator begin ()
 Iterator over hash values in this sketch. More...
 
virtual iterator end ()
 Iterator pointing past the valid range. More...
 
virtual const_iterator begin () const
 Const iterator over hash values in this sketch. More...
 
virtual const_iterator end () const
 Const iterator pointing past the valid range. More...
 
- Public Member Functions inherited from base_theta_sketch_alloc< std::allocator< uint64_t > >
double get_estimate () const
 
double get_lower_bound (uint8_t num_std_devs) const
 Returns the approximate lower error bound given a number of standard deviations. More...
 
double get_upper_bound (uint8_t num_std_devs) const
 Returns the approximate upper error bound given a number of standard deviations. More...
 
bool is_estimation_mode () const
 
double get_theta () const
 
virtual string< std::allocator< uint64_t > > to_string (bool print_items=false) const
 Provides a human-readable summary of this sketch as a string. More...
 

Static Public Member Functions

static size_t get_max_serialized_size_bytes (uint8_t lg_k)
 Computes maximum serialized size in bytes. More...
 
static compact_theta_sketch_alloc deserialize (std::istream &is, uint64_t seed=DEFAULT_SEED, const Allocator &allocator=Allocator())
 This method deserializes a sketch from a given stream. More...
 
static compact_theta_sketch_alloc deserialize (const void *bytes, size_t size, uint64_t seed=DEFAULT_SEED, const Allocator &allocator=Allocator())
 This method deserializes a sketch from a given array of bytes. More...
 

Detailed Description

template<typename Allocator = std::allocator<uint64_t>>
class datasketches::compact_theta_sketch_alloc< Allocator >

Compact Theta sketch.

This is an immutable form of the Theta sketch, the form that can be serialized and deserialized.

Constructor & Destructor Documentation

◆ compact_theta_sketch_alloc() [1/3]

compact_theta_sketch_alloc ( const Other &  other,
bool  ordered 
)

Copy constructor.

Constructs a compact sketch from any other type of Theta sketch

Parameters
othersketch to be constructed from
orderedif true make the resulting sketch ordered

◆ compact_theta_sketch_alloc() [2/3]

compact_theta_sketch_alloc ( const compact_theta_sketch_alloc< Allocator > &  other)
default

Copy constructor.

Parameters
othersketch to be copied

◆ compact_theta_sketch_alloc() [3/3]

compact_theta_sketch_alloc ( compact_theta_sketch_alloc< Allocator > &&  other)
defaultnoexcept

Move constructor.

Parameters
othersketch to be moved

Member Function Documentation

◆ operator=() [1/2]

compact_theta_sketch_alloc& operator= ( const compact_theta_sketch_alloc< Allocator > &  other)
default

Copy assignment.

Parameters
othersketch to be copied
Returns
reference to this sketch

◆ operator=() [2/2]

compact_theta_sketch_alloc& operator= ( compact_theta_sketch_alloc< Allocator > &&  other)
default

Move assignment.

Parameters
othersketch to be moved
Returns
reference to this sketch

◆ get_allocator()

A get_allocator
virtual

◆ is_empty()

bool is_empty
virtual
Returns
true if this sketch represents an empty set (not the same as no retained entries!)

Implements base_theta_sketch_alloc< std::allocator< uint64_t > >.

◆ is_ordered()

bool is_ordered
virtual
Returns
true if retained entries are ordered

Implements base_theta_sketch_alloc< std::allocator< uint64_t > >.

◆ get_theta64()

uint64_t get_theta64
virtual
Returns
theta as a positive integer between 0 and LLONG_MAX

Implements base_theta_sketch_alloc< std::allocator< uint64_t > >.

◆ get_num_retained()

uint32_t get_num_retained
virtual
Returns
the number of retained entries in the sketch

Implements base_theta_sketch_alloc< std::allocator< uint64_t > >.

◆ get_seed_hash()

uint16_t get_seed_hash
virtual
Returns
hash of the seed that was used to hash the input

Implements base_theta_sketch_alloc< std::allocator< uint64_t > >.

◆ get_max_serialized_size_bytes()

size_t get_max_serialized_size_bytes ( uint8_t  lg_k)
static

Computes maximum serialized size in bytes.

Parameters
lg_knominal number of entries in the sketch

◆ get_serialized_size_bytes()

size_t get_serialized_size_bytes ( bool  compressed = false) const

Computes size in bytes required to serialize the current state of the sketch.

Computing compressed size is expensive. It takes iterating over all retained hashes, and the actual serialization will have to look at them again.

Parameters
compressedif true compressed size is returned (if applicable)

◆ serialize() [1/2]

void serialize ( std::ostream &  os) const

This method serializes the sketch into a given stream in a binary form.

Parameters
osoutput stream

◆ serialize() [2/2]

auto serialize ( unsigned  header_size_bytes = 0) const

This method serializes the sketch as a vector of bytes.

An optional header can be reserved in front of the sketch. It is an uninitialized space of a given size. This header is used in Datasketches PostgreSQL extension.

Parameters
header_size_bytesspace to reserve in front of the sketch

◆ serialize_compressed() [1/2]

void serialize_compressed ( std::ostream &  os) const

This method serializes the sketch into a given stream in a compressed binary form.

Compression is applied to ordered sketches except empty and single item. For unordered, empty and single item sketches this method is equivalent to serialize()

Parameters
osoutput stream

◆ serialize_compressed() [2/2]

auto serialize_compressed ( unsigned  header_size_bytes = 0) const

This method serializes the sketch as a vector of bytes.

An optional header can be reserved in front of the sketch. It is an uninitialized space of a given size. This header is used in Datasketches PostgreSQL extension. Compression is applied to ordered sketches except empty and single item. For unordered, empty and single item sketches this method is equivalent to serialize()

Parameters
header_size_bytesspace to reserve in front of the sketch

◆ begin() [1/2]

auto begin
virtual

Iterator over hash values in this sketch.

Returns
begin iterator

Implements theta_sketch_alloc< std::allocator< uint64_t > >.

◆ end() [1/2]

auto end
virtual

Iterator pointing past the valid range.

Not to be incremented or dereferenced.

Returns
end iterator

Implements theta_sketch_alloc< std::allocator< uint64_t > >.

◆ begin() [2/2]

auto begin
virtual

Const iterator over hash values in this sketch.

Returns
begin iterator

Implements theta_sketch_alloc< std::allocator< uint64_t > >.

◆ end() [2/2]

auto end
virtual

Const iterator pointing past the valid range.

Not to be incremented or dereferenced.

Returns
end iterator

Implements theta_sketch_alloc< std::allocator< uint64_t > >.

◆ deserialize() [1/2]

static compact_theta_sketch_alloc deserialize ( std::istream &  is,
uint64_t  seed = DEFAULT_SEED,
const Allocator &  allocator = Allocator() 
)
static

This method deserializes a sketch from a given stream.

Parameters
isinput stream
seedthe seed for the hash function that was used to create the sketch
allocatorinstance of an Allocator
Returns
an instance of the sketch

◆ deserialize() [2/2]

static compact_theta_sketch_alloc deserialize ( const void *  bytes,
size_t  size,
uint64_t  seed = DEFAULT_SEED,
const Allocator &  allocator = Allocator() 
)
static

This method deserializes a sketch from a given array of bytes.

Parameters
bytespointer to the array of bytes
sizethe size of the array
seedthe seed for the hash function that was used to create the sketch
allocatorinstance of an Allocator
Returns
an instance of the sketch

The documentation for this class was generated from the following files: