ztsdb
Classes | Typedefs | Functions | Variables
arr Namespace Reference

Contains the classes and functions that implement a multidimentional array type. More...

Classes

struct  AllocFactory
 
struct  Array
 
struct  baseallocator
 
struct  BoolIndex
 
struct  convert_cons_t
 
struct  cow_ptr
 
struct  Dname
 
struct  DtimeIndex
 
struct  flexallocator
 
struct  FlexAllocFactory
 
struct  Index
 
struct  intersect_helper
 
struct  intersect_helper< tz::interval, tz::interval >
 
struct  intersect_idx_helper
 
struct  IntervalIndex
 
struct  IntIndex_T
 
struct  IntIndexNeg_T
 
struct  LengthMismatch
 
struct  memallocator
 
struct  MemAllocFactory
 
struct  mmapallocator
 
struct  MmapAllocFactory
 
struct  NameIndex
 
struct  noinit_t
 
struct  NullIndex
 
struct  PseudoArray
 
struct  PseudoVector
 
struct  PseudoVectorTz
 
struct  RawVector
 
struct  rsv_t
 
struct  seq_n_t
 
struct  seq_to_t
 
struct  setdiff_helper
 
struct  setdiff_helper< tz::interval, tz::interval >
 
struct  setdiff_idx_helper
 
struct  setdiff_idx_helper< I, Global::dtime, tz::interval >
 
struct  TypeName
 Lets us define a compile time mapping from type to string. More...
 
struct  TypeNumber
 
struct  union_helper
 
struct  union_helper< tz::interval, tz::interval >
 
struct  union_idx_helper
 
struct  UnorderedIndex
 
struct  Vector
 
struct  Vector< val::Value, O >
 
struct  vector_const_iterator
 
struct  vector_iterator
 
struct  ZString
 
struct  zts
 

Typedefs

typedef uint64_t idx_type
 
using IntIndex = IntIndex_T< size_t >
 
using IntIndexNeg = IntIndexNeg_T< size_t >
 
using zstring = ZString<>
 
using VECTOR_ALLOC_GROWTH = std::ratio< 4, 3 >
 

Functions

template<typename V >
bool checksize (const V &v)
 
template<typename V1 , typename V2 >
bool checksize (const V1 &v1, const V2 &v2)
 
template<typename V1 , typename V2 , typename... U>
bool checksize (const V1 &v1, const V2 &v2, const U &... u)
 
template<typename V >
bool checkdims (const V &v)
 
template<typename V1 , typename V2 >
bool checkdims (const V1 &v1, const V2 &v2)
 
template<typename V1 , typename V2 , typename... U>
bool checkdims (const V1 &v1, const V2 &v2, const U &... u)
 
void createDir (const zstring &dirname)
 Create a directory if dirname is not "".

 
void buildNames (vector< unique_ptr< Dname >> &names, const Vector< idx_type > dim, const AllocFactory &allocf, const vector< Vector< zstring >> names_p={Vector< zstring >()})
 
template<typename R , typename T >
std::vector< R > stdvector (const Array< T > u)
 Vectorize to a std::vector of type R.
 
template<typename R , typename T >
Vector< R > arrvector (const Array< T > u)
 Vectorize to a arr::Vector of type R.
 
template<typename T >
Array< T > vectorize (const Array< T > &u)
 provide a const version of the above that works only with arrays that have 1 col LLL More...
 
template<>
Array< arr::zstringvectorize (const Array< arr::zstring > &u)
 
template<typename T , typename O = std::less<T>>
Array< T, O > transpose (const Array< T, O > &t)
 
template<typename T , typename O = std::less<T>>
Array< T, O > & drop (Array< T, O > &a)
 
template<typename T , typename R , typename OT = std::less<T>, typename OR = std::less<R>>
Array< R, OR > applyf (const Array< T, OT > &t, function< R(T)> f)
 
template<typename T , typename U , typename R , class F , typename OU = std::less<U>, typename OR = std::less<R>>
Array< R, OR > apply_scalar (T t, const Array< U, OU > &u)
 
template<typename U , typename T , typename R , class F , typename OU = std::less<U>, typename OR = std::less<R>>
Array< R, OR > apply_scalar (const Array< U, OU > &u, T t)
 
template<typename T , typename O >
void setv_checkbefore (Array< T, O > &a, idx_type i, T t)
 
template<typename T , typename O >
void setv (Array< T, O > &a, idx_type i, T t)
 
template<typename F , typename R , typename O , typename U1 , typename ... U>
Array< R, O > apply (const U1 u1, const U &... u)
 
template<typename F , typename R , typename O , typename U1 , typename ... U>
Array< R, O > apply_samesize (const U1 u1, const U &... u)
 
template<typename T , typename U , typename R , class F , typename OT = std::less<T>, typename OU = std::less<U>, typename OR = std::less<R>>
Array< R, OR > apply (const Array< T, OT > &t, const Array< U, OU > &u)
 
template<typename T , typename U , typename R , class F , typename A , typename OU = std::less<U>, typename OR = std::less<R>>
Array< R, OR > apply_attrib_scalar_post (T t, const Array< U, OU > &u, const A &a)
 
template<typename U , typename T , typename R , class F , typename A , typename OU = std::less<U>, typename OR = std::less<R>>
Array< R, OR > apply_attrib_scalar_pre (const Array< U, OU > &u, T t, const A &a)
 
template<typename T , typename U , typename R , class F , typename A , typename OT = std::less<T>, typename OR = std::less<R>, typename OU = std::less<U>>
Array< R, OR > apply_attrib (const Array< T, OT > &t, const Array< U, OU > &u, const A &a)
 
template<typename T , typename O = std::less<T>>
Array< T, O > maxcol (const Array< T, O > &t)
 
template<typename T , typename R , template< class > class F, typename O = std::less<T>>
cumul (const Array< T, O > &t, const R &init)
 
template<typename T , typename R , template< class > class F, typename O = std::less<T>>
cumul_until (const Array< T, O > &t, const R &init, const R &until)
 among other things, this allows to implement an 'all' and 'any' function.
 
template<typename T , typename O = std::less<T>>
vector< T > toStdVector (const Array< T, O > &a)
 
template<typename T , typename O = std::less<T>>
Array< T, O > array_from_vector (Vector< T, O > &&data)
 Construct an array moving a vector.
 
template<typename T >
Array< T > & rollmean_inplace (Array< T > &a, idx_type window, idx_type nbvalid)
 
template<typename T >
Array< T > & rollmin_inplace (Array< T > &a, idx_type window, idx_type nbvalid)
 
template<typename T >
Array< T > & rollmax_inplace (Array< T > &a, idx_type window, idx_type nbvalid)
 
template<typename T >
Array< T > & rollvar_inplace (Array< T > &a, idx_type window, idx_type nbvalid)
 
template<typename T >
Array< T > & locf_inplace (Array< T > &a, ssize_t n)
 
template<typename T >
Array< T > & move_inplace (Array< T > &a, ssize_t n)
 
template<typename T >
Array< T > & rotate_inplace (Array< T > &a, ssize_t n)
 
template<typename T >
Array< T > & diff_inplace (Array< T > &a, ssize_t n)
 
template<typename T >
Array< T > rollcov (const Array< T > &x, const Array< T > &y, idx_type window, idx_type nbvalid)
 
template<typename T , typename F >
Array< T > & cumul_inplace (Array< T > &a, bool rev)
 
template<typename T >
Array< T > & rev_inplace (Array< T > &a)
 
template<>
val::Value convert (const double &u)
 these are the set of "conversions" of a type to itself More...
 
template<>
val::Value convert (const bool &u)
 conversions to double.
 
template<>
val::Value convert (const Global::dtime &u)
 
template<>
val::Value convert (const Global::duration &u)
 
template<>
val::Value convert (const tz::period &u)
 
template<>
val::Value convert (const tz::interval &u)
 
template<>
val::Value convert (const arr::zstring &u)
 conversions to period. More...
 
template<>
arr::zstring getInitValue ()
 
template<typename T , typename U >
convert (const U &u)
 the default case is that a conversion is not allowed.
 
template<>
arr::zstring convert (const std::string &u)
 
template<typename T , typename... Args>
cow_ptr< T > make_cow (unsigned flags, Args &&... args)
 
template<typename T >
cow_ptr< Array< T > > readcsv_array (const string &file, bool header, const char sep, const string &mmapfile)
 
template<typename T >
void writecsv_array (const Array< T > &a, const string &file, bool header, const char sep)
 
cow_ptr< ztsreadcsv_zts (const string &file, bool header, const char sep, const string &mmapfile, const string &fmt="%Y-%m-%d %H:%M:%S[.%s] %Z", const string &tz="")
 
void writecsv_zts (const zts &z, const string &file, bool header, const char sep)
 
template<typename I , typename T , typename U >
void subassign_generic (const I &idx, Vector< T > &rv, const U &v, idx_type &vj)
 
template<typename I , typename T , typename U >
void subassignScalar_generic (const I &idx, Vector< T > &rv, U u)
 
template<int U>
std::ostream & operator<< (std::ostream &os, const ZString< U > &s)
 
template<int U>
ZString< U > operator+ (const ZString< U > &s1, const ZString< U > &s2)
 
template<int U>
ZString< U > operator+ (const ZString< U > &s1, const char *s2)
 
template<int U>
ZString< U > operator+ (const char *s1, const ZString< U > &s2)
 
template<int U>
ZString< U > operator+ (const ZString< U > &s1, const std::string &s2)
 
template<int U>
ZString< U > operator+ (const std::string &s1, const ZString< U > &s2)
 
template<int U>
bool operator== (const ZString< U > &s1, const ZString< U > &s2)
 
template<int U>
bool operator!= (const ZString< U > &s1, const ZString< U > &s2)
 
template<int U>
bool operator<= (const ZString< U > &s1, const ZString< U > &s2)
 
template<int U>
bool operator< (const ZString< U > &s1, const ZString< U > &s2)
 
template<int U>
bool operator>= (const ZString< U > &s1, const ZString< U > &s2)
 
template<int U>
bool operator> (const ZString< U > &s1, const ZString< U > &s2)
 
template<int U>
bool operator== (const ZString< U > &s1, const char *s2)
 
template<int U>
bool operator!= (const ZString< U > &s1, const char *s2)
 
template<int U>
bool operator<= (const ZString< U > &s1, const char *s2)
 
template<int U>
bool operator< (const ZString< U > &s1, const char *s2)
 
template<int U>
bool operator>= (const ZString< U > &s1, const char *s2)
 
template<int U>
bool operator> (const ZString< U > &s1, const char *s2)
 
 TYPE_NB (val::Value, 7)
 
 TYPE_NAME (val::Value, "Value")
 
template<>
val::Value convert (const val::Value &u)
 
template<typename T >
bool operator== (const cow_ptr< Array< T >> &a1, const cow_ptr< Array< T >> &a2)
 
bool operator== (const val::SpZts &a1, const val::SpZts &a2)
 
bool operator== (const val::SpVI &a1, const val::SpVI &a2)
 
bool operator!= (const val::Value &v1, const val::Value &v2)
 
template<>
void setv (Vector< val::Value > &v, size_t i, const val::Value &t)
 
template<>
void setv_checkbefore (Vector< val::Value > &v, size_t i, const val::Value &t)
 
 TYPE_NB (double, 0)
 
 TYPE_NB (bool, 1)
 
 TYPE_NB (Global::dtime, 2)
 
 TYPE_NB (arr::zstring, 3)
 
 TYPE_NB (Global::duration, 4)
 
 TYPE_NB (tz::interval, 5)
 
 TYPE_NB (tz::period, 6)
 
 TYPE_NAME (double, "double")
 
 TYPE_NAME (bool, "logical")
 
 TYPE_NAME (Global::dtime, "time")
 
 TYPE_NAME (arr::zstring, "character")
 
 TYPE_NAME (Global::duration, "duration")
 
 TYPE_NAME (tz::interval, "interval")
 
 TYPE_NAME (tz::period, "period")
 
size_t growCapacity (size_t n)
 
template<typename T >
size_t getTotalSize (size_t n)
 
size_t getTypeNumber (const std::string &filename)
 
template<typename T , typename O >
bool operator== (const Vector< T, O > &v1, const Vector< T, O > &v2)
 Member equal.
 
template<>
bool operator== (const Vector< double > &v1, const Vector< double > &v2)
 
template<typename T , typename O >
bool operator!= (const Vector< T, O > &v1, const Vector< T, O > &v2)
 
template<typename T , typename O >
void setv (Vector< T, O > &v, size_t i, const T &t)
 
template<typename T , typename O >
void setv_checkbefore (Vector< T, O > &v, size_t i, const T &t)
 
template<typename T , typename O >
void setv_nocheck (Vector< T, O > &v, size_t i, const T &t)
 
template<typename T , typename U >
Vector< T > intersect (const Vector< T > &v1, const Vector< U > &v2)
 
template<typename T , typename U , typename I >
std::pair< Vector< I >, Vector< I > > intersect_idx (const Vector< T > &v1, const Vector< U > &v2)
 
template<typename T , typename U >
Vector< T > _union (const Vector< T > &v1, const Vector< U > &v2)
 
template<typename T , typename U , typename I >
std::pair< Vector< I >, Vector< I > > union_idx (const Vector< T > &v1, const Vector< U > &v2)
 
template<typename T , typename U >
Vector< T > setdiff (const Vector< T > &v1, const Vector< U > &v2)
 
template<typename T , typename U , typename I >
std::pair< Vector< I >, Vector< I > > setdiff_idx (const Vector< T > &v1, const Vector< U > &v2)
 
template<typename T , typename U , typename I , template< typename > class NANF>
std::pair< Vector< I >, Vector< I > > union_idx (const Vector< T > &v1, const Vector< U > &v2)
 
size_t getHeaderLength (const std::vector< std::string > &name)
 
int writeHeader (Global::buflen_pair &buf, Global::MsgType msgtype, const std::vector< std::string > &names)
 
template<typename T >
Global::buflen_pair make_append_msg (const std::vector< std::string > &names, const arr::Array< T > &a)
 
template<typename T >
Global::buflen_pair make_append_msg (const std::vector< std::string > &names, const Vector< T > &v)
 
Global::buflen_pair make_append_msg (const std::vector< std::string > &names, const Vector< Global::dtime > &idx, const Vector< double > &v)
 
Global::buflen_pair make_append_msg (const std::vector< string > &name, const arr::zts &z)
 
Global::buflen_pair make_append_msg (const std::vector< std::string > &name, const std::vector< Global::dtime > &idx, const std::vector< double > &v)
 
Global::buflen_pair make_append_msg (const std::vector< std::string > &name, const arr::zts &z)
 
template<typename DS , typename DE >
zts align_closest (const zts &ts, const Array< Global::dtime > &y, const DS &start, const DE &end)
 alignment functions:
 
template<typename F , typename DS , typename DE >
zts align_func (const zts &ts, const Array< Global::dtime > &y, const DS &start, const DE &end)
 align_func
 
template<typename F >
void op (const zts &x, zts &y)
 
template<typename I , typename NANF , typename DS , typename DE >
arr::Vector< I > align_idx (const arr::Vector< Global::dtime > &x, const arr::Vector< Global::dtime > &y, const DS &start, const DE &end)
 
template<typename T , typename NANF , typename DS , typename DE >
void align_closest (const arr::Vector< Global::dtime > &x, const arr::Vector< Global::dtime > &y, const arr::Vector< T > &xdata, arr::Vector< T > &ydata, const DS &start, const DE &end)
 
template<typename T , typename F , typename DS , typename DE >
void align_func (const arr::Vector< Global::dtime > &x, const arr::Vector< Global::dtime > &y, const arr::Vector< T > &xdata, arr::Vector< T > &ydata, const DS &start, const DE &end)
 
template<typename T , typename F >
void op_zts (const arr::Vector< Global::dtime > &x, const arr::Vector< Global::dtime > &y, const arr::Vector< T > &xdata, arr::Vector< T > &ydata)
 

Variables

constexpr seq_to_t seq_to { }
 
constexpr seq_n_t seq_n { }
 
constexpr convert_cons_t convert_cons {}
 
const unsigned NOFLAGS = 0x00
 
const unsigned REF = 0x01
 
const unsigned LOCKED = 0x02
 
const unsigned CONSTREF = 0x04
 
const unsigned TMP = 0x08
 
const unsigned LAST = 0x10
 
const size_t DEFAULT_STRING_SIZE = 128
 
const size_t VECTOR_INITIAL_ALLOC = 1024
 
constexpr rsv_t rsv {}
 
constexpr noinit_t noinit_tag {}
 

Detailed Description

Contains the classes and functions that implement a multidimentional array type.

New 'Vector' class rather than 'std::vector' because:

  1. We need a representation that can easily and efficiently be memory mapped
  2. We want to be able to create uninitialized vectors so that we don't have to go through twice some potentially very large vectors (a specific use-case is on receipt of fragmented arrays over TCP).

Provides a C++ interface to append data to arrays and time series. This interface will send messsages to a ztsdb instance. These messages bypass the interpreter, so they have decent performance.

Typedef Documentation

◆ IntIndex

using arr::IntIndex = typedef IntIndex_T<size_t>

variant type for the different types of indices that index into an array. We use Variant rather than a base class with virtual functions for performance reasons as it is not acceptable to pay a (virtual) function call for each index/element retrieval. The downside is that a variant cannot be extended, so we need to come up with all the index types here. This in particular has the unfortunate consequence to tie Dtime and Interval classes to Array.

Function Documentation

◆ align_closest()

template<typename T , typename NANF , typename DS , typename DE >
void arr::align_closest ( const arr::Vector< Global::dtime > &  x,
const arr::Vector< Global::dtime > &  y,
const arr::Vector< T > &  xdata,
arr::Vector< T > &  ydata,
const DS &  start,
const DE &  end 
)

This is the same algorithm as 'align_idx', except that instead of returning a vector of indices, the vector 'ydata' is modified in place with the data pulled from x.

◆ apply()

template<typename F , typename R , typename O , typename U1 , typename ... U>
Array<R,O> arr::apply ( const U1  u1,
const U &...  u 
)

Apply F to all parameters. Assumes same size, but not necessarily same dimensions. We pay a performance penalty for the generality.

◆ buildNames()

void arr::buildNames ( vector< unique_ptr< Dname >> &  names,
const Vector< idx_type >  dim,
const AllocFactory allocf,
const vector< Vector< zstring >>  names_p = {Vector<zstring>()} 
)

Create the name vectors using the mmap 'dirname' directory. If 'dirname' is "", uses a standard allocator rather than a mmap one.

◆ checkdims()

template<typename V >
bool arr::checkdims ( const V &  v)
inline

Check that all paramters have compatible dimensions for column by column manipulation. The function is correct in presence of various dimensions of size one. Parameters must implement functions 'ncols' and 'size'.

◆ checksize()

template<typename V >
bool arr::checksize ( const V &  v)
inline

Check that all parameters have the same size. All parameters must implement the function 'size'.

◆ convert() [1/2]

template<>
tz::interval arr::convert ( const arr::zstring u)
inline

conversions to period.

conversions to interval.

conversions to time.

◆ convert() [2/2]

template<>
Global::duration arr::convert ( const double &  u)
inline

these are the set of "conversions" of a type to itself

convert to string.

convert to zstring.

conversions to duration.

conversions to bool.

conversions to string.

conversions to zstring.

◆ operator==()

template<>
bool arr::operator== ( const Vector< double > &  v1,
const Vector< double > &  v2 
)
inline

Member equal. NaN correct, but will not work with strings for example.

◆ rollcov()

template<typename T >
Array<T> arr::rollcov ( const Array< T > &  x,
const Array< T > &  y,
idx_type  window,
idx_type  nbvalid 
)

window (or rolling window) function to compute the covariance on a sliding window. In addition to the window size 'window', an additional parameter 'nbvalid' specifies how many observations are needed to consider the calculation valid. If the number of missing (i.e. NaN) values is larger than 'window' - 'nbvalid' then NaN will be returned for that window.

◆ rollmax_inplace()

template<typename T >
Array<T>& arr::rollmax_inplace ( Array< T > &  a,
idx_type  window,
idx_type  nbvalid 
)

window (or rolling window) function to compute the maximum on that sliding window. In addition to the window size 'window', an additional parameter 'nbvalid' specifies how many observations are needed to consider the calculation valid. If the number of missing (i.e. NA) values is larger than 'window' - 'nbvalid' then NA will be returned for that window.

◆ rollmean_inplace()

template<typename T >
Array<T>& arr::rollmean_inplace ( Array< T > &  a,
idx_type  window,
idx_type  nbvalid 
)

window (or rolling window) function to compute the mean on that sliding window. This function does not use Kahan summation.

◆ rollmin_inplace()

template<typename T >
Array<T>& arr::rollmin_inplace ( Array< T > &  a,
idx_type  window,
idx_type  nbvalid 
)

window (or rolling window) function to compute the minimum on a sliding window. In addition to the window size 'window', an additional parameter 'nbvalid' specifies how many observations are needed to consider the calculation valid. If the number of missing (i.e. NaN) values is larger than 'window' - 'nbvalid' then NaN will be returned for that window.

◆ rollvar_inplace()

template<typename T >
Array<T>& arr::rollvar_inplace ( Array< T > &  a,
idx_type  window,
idx_type  nbvalid 
)

window (or rolling window) function to compute the variance on that sliding window. The variance formula used is the unbiased estimator with divisor = n-1. This function does not use Kahan summation.

◆ vectorize()

template<typename T >
Array<T> arr::vectorize ( const Array< T > &  u)

provide a const version of the above that works only with arrays that have 1 col LLL

Return an array that is a vector of length 'n'