datasketches-cpp
Public Member Functions | Static Public Member Functions | List of all members
var_opt_union< T, A > Class Template Reference

Provides a unioning operation over var_opt_sketch objects. More...

#include <var_opt_union.hpp>

Public Member Functions

void update (const var_opt_sketch< T, A > &sk)
 Updates this union with the given sketch This method takes an lvalue. More...
 
void update (var_opt_sketch< T, A > &&sk)
 Updates this union with the given sketch This method takes an rvalue. More...
 
var_opt_sketch< T, A > get_result () const
 Gets the varopt sketch resulting from the union of any input sketches. More...
 
void reset ()
 Resets the union to its default, empty state.
 
template<typename SerDe = serde<T>>
size_t get_serialized_size_bytes (const SerDe &sd=SerDe()) const
 Computes size needed to serialize the current state of the union. More...
 
template<typename SerDe = serde<T>>
vector_bytes serialize (unsigned header_size_bytes=0, const SerDe &sd=SerDe()) const
 NOTE: This method may be deprecated in a future version. More...
 
template<typename SerDe = serde<T>>
void serialize (std::ostream &os, const SerDe &sd=SerDe()) const
 NOTE: This method may be deprecated in a future version. More...
 
string< A > to_string () const
 Prints a summary of the union as a string. More...
 

Static Public Member Functions

template<typename SerDe = serde<T>>
static var_opt_union deserialize (std::istream &is, const SerDe &sd=SerDe(), const A &allocator=A())
 NOTE: This method may be deprecated in a future version. More...
 
template<typename SerDe = serde<T>>
static var_opt_union deserialize (const void *bytes, size_t size, const SerDe &sd=SerDe(), const A &allocator=A())
 NOTE: This method may be deprecated in a future version. More...
 

Detailed Description

template<typename T, typename A = std::allocator<T>>
class datasketches::var_opt_union< T, A >

Provides a unioning operation over var_opt_sketch objects.

This union allows the sample size k to float, possibly increasing or decreasing as warranted by the available data.

The union currently allows serialization and deserialization, even though transporting union objects seems to be an anti-pattern with most sketches. We currently provide it here because the get_result() call may need to discard samples and decrease k in order to return a valid sketch, even if future calls to update() would allow k to remain larger.

The (de)serialization methods may be deprecated and subsequently removed in future versions.

author Kevin Lang author Jon Malkin

Member Function Documentation

◆ update() [1/2]

void update ( const var_opt_sketch< T, A > &  sk)

Updates this union with the given sketch This method takes an lvalue.

Parameters
ska sketch to add to the union

◆ update() [2/2]

void update ( var_opt_sketch< T, A > &&  sk)

Updates this union with the given sketch This method takes an rvalue.

Parameters
ska sketch to add to the union

◆ get_result()

var_opt_sketch< T, A > get_result

Gets the varopt sketch resulting from the union of any input sketches.

Returns
a varopt sketch

◆ get_serialized_size_bytes()

size_t get_serialized_size_bytes ( const SerDe &  sd = SerDe()) const

Computes size needed to serialize the current state of the union.

This version is for all other types and can be expensive since every item needs to be looked at.

Parameters
sdinstance of a SerDe
Returns
size in bytes needed to serialize this sketch

◆ serialize() [1/2]

vector_bytes serialize ( unsigned  header_size_bytes = 0,
const SerDe &  sd = SerDe() 
) const

NOTE: This method may be deprecated in a future version.

This method serializes the sketch as a vector of bytes. An optional header can be reserved in front of the sketch. It is a blank space of a given size. This header is used in Datasketches PostgreSQL extension.

Parameters
header_size_bytesspace to reserve in front of the sketch
sdinstance of a SerDe

◆ serialize() [2/2]

void serialize ( std::ostream &  os,
const SerDe &  sd = SerDe() 
) const

NOTE: This method may be deprecated in a future version.

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

Parameters
osoutput stream
sdinstance of a SerDe

◆ deserialize() [1/2]

static var_opt_union deserialize ( std::istream &  is,
const SerDe &  sd = SerDe(),
const A &  allocator = A() 
)
static

NOTE: This method may be deprecated in a future version.

This method deserializes a union from a given stream.

Parameters
isinput stream
sdinstance of a SerDe
allocatorinstance of an Allocator
Returns
an instance of a union

◆ deserialize() [2/2]

static var_opt_union deserialize ( const void *  bytes,
size_t  size,
const SerDe &  sd = SerDe(),
const A &  allocator = A() 
)
static

NOTE: This method may be deprecated in a future version.

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

Parameters
bytespointer to the array of bytes
sizethe size of the array
sdinstance of a SerDe
allocatorinstance of an Allocator
Returns
an instance of a union

◆ to_string()

string< A > to_string

Prints a summary of the union as a string.

Returns
the summary as a string

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