piranha  0.10
Public Types | Public Member Functions | Protected Attributes | List of all members
piranha::array_key< T, Derived, S > Class Template Reference

Array key. More...

#include <piranha/array_key.hpp>

Public Types

using container_type = small_vector< T, S >
 The internal container type.
 
using value_type = typename container_type::value_type
 Value type.
 
using iterator = typename container_type::iterator
 Iterator type.
 
using const_iterator = typename container_type::const_iterator
 Const iterator type.
 
using size_type = typename container_type::size_type
 Size type.
 

Public Member Functions

 array_key ()=default
 Defaulted default constructor. More...
 
 array_key (const array_key &)=default
 Defaulted copy constructor. More...
 
 array_key (array_key &&)=default
 Defaulted move constructor.
 
template<typename U , init_list_enabler< U > = 0>
 array_key (std::initializer_list< U > list)
 Constructor from initializer list. More...
 
 array_key (const symbol_fset &args)
 Constructor from piranha::symbol_fset. More...
 
template<typename U , typename Derived2 , typename S2 , generic_ctor_enabler< U > = 0>
 array_key (const array_key< U, Derived2, S2 > &other, const symbol_fset &args)
 Constructor from piranha::array_key parametrized on a generic type. More...
 
 ~array_key ()
 Trivial destructor.
 
array_keyoperator= (const array_key &other)=default
 Copy assignment operator. More...
 
array_keyoperator= (array_key &&other)=default
 Move assignment operator. More...
 
iterator begin ()
 Begin iterator. More...
 
iterator end ()
 End iterator. More...
 
const_iterator begin () const
 Begin const iterator. More...
 
const_iterator end () const
 End const iterator. More...
 
size_type size () const
 Size. More...
 
void resize (const size_type &new_size)
 Resize the internal array container. More...
 
value_typeoperator[] (const size_type &i)
 Element access. More...
 
const value_typeoperator[] (const size_type &i) const
 Const element access. More...
 
std::size_t hash () const
 Hash value. More...
 
void push_back (value_type &&x)
 Move-add element at the end. More...
 
void push_back (const value_type &x)
 Copy-add element at the end. More...
 
bool operator== (const array_key &other) const
 Equality operator. More...
 
bool operator!= (const array_key &other) const
 Inequality operator. More...
 
void trim_identify (std::vector< char > &trim_mask, const symbol_fset &args) const
 Identify symbols that can be trimmed. More...
 
Derived trim (const std::vector< char > &trim_mask, const symbol_fset &args) const
 Trim. More...
 
template<typename U = container_type, add_enabler< U > = 0>
void vector_add (array_key &retval, const array_key &other) const
 Vector add. More...
 
template<typename U = container_type, sub_enabler< U > = 0>
void vector_sub (array_key &retval, const array_key &other) const
 Vector sub. More...
 
Derived merge_symbols (const symbol_idx_fmap< symbol_fset > &ins_map, const symbol_fset &args) const
 Merge symbols. More...
 
auto size_begin_end () const -> decltype(m_container.size_begin_end())
 Get size, begin and end iterator (const version). More...
 
auto size_begin_end () -> decltype(m_container.size_begin_end())
 Get size, begin and end iterator. More...
 

Protected Attributes

container_type m_container
 Internal container.
 

Detailed Description

template<typename T, typename Derived, typename S = std::integral_constant<std::size_t, 0u>>
class piranha::array_key< T, Derived, S >

Array key.

This class represents an array-like dense sequence of instances of type T. Interface and semantics mimic those of std::vector. The underlying container used to store the elements is piranha::small_vector. The template argument S is passed as second argument to piranha::small_vector in the definition of the internal container.

This class is intended as a base class for the implementation of a key type, but it does not satisfy all the requirements specified in piranha::is_key.

Type requirements

Exception safety guarantee

Unless otherwise specified, this class provides the strong exception safety guarantee for all operations.

Move semantics

Move semantics is equivalent to the move semantics of piranha::small_vector.

Definition at line 86 of file array_key.hpp.

Constructor & Destructor Documentation

◆ array_key() [1/5]

template<typename T, typename Derived, typename S = std::integral_constant<std::size_t, 0u>>
piranha::array_key< T, Derived, S >::array_key ( )
default

Defaulted default constructor.

The constructed object will be empty.

◆ array_key() [2/5]

template<typename T, typename Derived, typename S = std::integral_constant<std::size_t, 0u>>
piranha::array_key< T, Derived, S >::array_key ( const array_key< T, Derived, S > &  )
default

Defaulted copy constructor.

Exceptions
unspecifiedany exception thrown by the copy constructor of piranha::small_vector.

◆ array_key() [3/5]

template<typename T, typename Derived, typename S = std::integral_constant<std::size_t, 0u>>
template<typename U , init_list_enabler< U > = 0>
piranha::array_key< T, Derived, S >::array_key ( std::initializer_list< U >  list)
inlineexplicit

Constructor from initializer list.

Note
This constructor is enabled only if piranha::small_vector is constructible from list.

list will be forwarded to construct the internal piranha::small_vector.

Parameters
listthe initializer list.
Exceptions
unspecifiedany exception thrown by the corresponding constructor of piranha::small_vector.

Definition at line 139 of file array_key.hpp.

◆ array_key() [4/5]

template<typename T, typename Derived, typename S = std::integral_constant<std::size_t, 0u>>
piranha::array_key< T, Derived, S >::array_key ( const symbol_fset args)
inlineexplicit

Constructor from piranha::symbol_fset.

The key will be created with a number of variables equal to args.size() and filled with elements constructed from the integral constant 0.

Parameters
argsthe piranha::symbol_fset used for construction.
Exceptions
unspecifiedany exception thrown by:

Definition at line 153 of file array_key.hpp.

◆ array_key() [5/5]

template<typename T, typename Derived, typename S = std::integral_constant<std::size_t, 0u>>
template<typename U , typename Derived2 , typename S2 , generic_ctor_enabler< U > = 0>
piranha::array_key< T, Derived, S >::array_key ( const array_key< U, Derived2, S2 > &  other,
const symbol_fset args 
)
inlineexplicit

Constructor from piranha::array_key parametrized on a generic type.

Note
This constructor is enabled only if U can be cast safely to the value type.

Generic constructor for use in piranha::series, when inserting a term of different type. The internal container will be initialised with the contents of the internal container of x (possibly converting the individual contained values through piranha::safe_cast(), if the values are of different type). If the size of x is different from the size of args, a runtime error will be produced.

Parameters
otherthe construction argument.
argsthe reference piranha::symbol_fset.
Exceptions
std::invalid_argumentif the sizes of x and args differ.
unspecifiedany exception thrown by:

Definition at line 185 of file array_key.hpp.

Member Function Documentation

◆ begin() [1/2]

template<typename T, typename Derived, typename S = std::integral_constant<std::size_t, 0u>>
iterator piranha::array_key< T, Derived, S >::begin ( )
inline

Begin iterator.

Returns
iterator to the first element of the internal container.

Definition at line 222 of file array_key.hpp.

◆ begin() [2/2]

template<typename T, typename Derived, typename S = std::integral_constant<std::size_t, 0u>>
const_iterator piranha::array_key< T, Derived, S >::begin ( ) const
inline

Begin const iterator.

Returns
const iterator to the first element of the internal container.

Definition at line 238 of file array_key.hpp.

◆ end() [1/2]

template<typename T, typename Derived, typename S = std::integral_constant<std::size_t, 0u>>
iterator piranha::array_key< T, Derived, S >::end ( )
inline

End iterator.

Returns
iterator one past the last element of the internal container.

Definition at line 230 of file array_key.hpp.

◆ end() [2/2]

template<typename T, typename Derived, typename S = std::integral_constant<std::size_t, 0u>>
const_iterator piranha::array_key< T, Derived, S >::end ( ) const
inline

End const iterator.

Returns
const iterator one past the last element of the internal container.

Definition at line 246 of file array_key.hpp.

◆ hash()

template<typename T, typename Derived, typename S = std::integral_constant<std::size_t, 0u>>
std::size_t piranha::array_key< T, Derived, S >::hash ( ) const
inline

Hash value.

Returns
hash value of the key, computed via piranha::small_vector::hash().
Exceptions
unspecifiedany exception thrown by piranha::small_vector::hash().

Definition at line 296 of file array_key.hpp.

◆ merge_symbols()

template<typename T, typename Derived, typename S = std::integral_constant<std::size_t, 0u>>
Derived piranha::array_key< T, Derived, S >::merge_symbols ( const symbol_idx_fmap< symbol_fset > &  ins_map,
const symbol_fset args 
) const
inline

Merge symbols.

This method will return a copy of this in which the value 0 has been inserted at the positions specified by ins_map. Specifically, before each index appearing in ins_map a number of zeroes equal to the size of the mapped piranha::symbol_fset will be inserted.

For instance, given a piranha::array_key containing the values [1,2,3,4], a symbol set args containing ["c","e","g","h"] and an insertion map ins_map containing the pairs [(0,["a","b"]),(1,["d"]),(2,["f"]),(4,["i"])], the output of this method will be [0,0,1,0,2,0,3,4,0]. That is, the symbols appearing in ins_map are merged into this with a value of zero at the specified positions.

Parameters
ins_mapthe insertion map.
argsthe reference symbol set for this.
Returns
a Derived instance resulting from inserting into this zeroes at the positions specified by ins_map.
Exceptions
std::invalid_argumentin the following cases:
  • the size of this is different from the size of args,
  • the size of ins_map is zero,
  • the last index in ins_map is greater than the size of this.
unspecifiedany exception thrown by:

Definition at line 508 of file array_key.hpp.

◆ operator!=()

template<typename T, typename Derived, typename S = std::integral_constant<std::size_t, 0u>>
bool piranha::array_key< T, Derived, S >::operator!= ( const array_key< T, Derived, S > &  other) const
inline

Inequality operator.

Parameters
otherthe comparison argument.
Returns
the negation of operator==().
Exceptions
unspecifiedany exception thrown by the equality operator.

Definition at line 344 of file array_key.hpp.

◆ operator=() [1/2]

template<typename T, typename Derived, typename S = std::integral_constant<std::size_t, 0u>>
array_key& piranha::array_key< T, Derived, S >::operator= ( const array_key< T, Derived, S > &  other)
default

Copy assignment operator.

Parameters
otherthe assignment argument.
Returns
a reference to this.
Exceptions
unspecifiedany exception thrown by the assignment operator of piranha::small_vector.

◆ operator=() [2/2]

template<typename T, typename Derived, typename S = std::integral_constant<std::size_t, 0u>>
array_key& piranha::array_key< T, Derived, S >::operator= ( array_key< T, Derived, S > &&  other)
default

Move assignment operator.

Parameters
otherthe assignment argument.
Returns
a reference to this.

◆ operator==()

template<typename T, typename Derived, typename S = std::integral_constant<std::size_t, 0u>>
bool piranha::array_key< T, Derived, S >::operator== ( const array_key< T, Derived, S > &  other) const
inline

Equality operator.

Parameters
otherthe comparison argument.
Returns
the result of piranha::small_vector::operator==().
Exceptions
unspecifiedany exception thrown by piranha::small_vector::operator==().

Definition at line 332 of file array_key.hpp.

◆ operator[]() [1/2]

template<typename T, typename Derived, typename S = std::integral_constant<std::size_t, 0u>>
value_type& piranha::array_key< T, Derived, S >::operator[] ( const size_type i)
inline

Element access.

Parameters
ithe index of the element to be accessed.
Returns
reference to the element of the container at index i.

Definition at line 276 of file array_key.hpp.

◆ operator[]() [2/2]

template<typename T, typename Derived, typename S = std::integral_constant<std::size_t, 0u>>
const value_type& piranha::array_key< T, Derived, S >::operator[] ( const size_type i) const
inline

Const element access.

Parameters
ithe index of the element to be accessed.
Returns
const reference to the element of the container at index i.

Definition at line 286 of file array_key.hpp.

◆ push_back() [1/2]

template<typename T, typename Derived, typename S = std::integral_constant<std::size_t, 0u>>
void piranha::array_key< T, Derived, S >::push_back ( value_type &&  x)
inline

Move-add element at the end.

Move-add x at the end of the internal container.

Parameters
xthe element to be added to the internal container.
Exceptions
unspecifiedany exception thrown by piranha::small_vector::push_back().

Definition at line 308 of file array_key.hpp.

◆ push_back() [2/2]

template<typename T, typename Derived, typename S = std::integral_constant<std::size_t, 0u>>
void piranha::array_key< T, Derived, S >::push_back ( const value_type x)
inline

Copy-add element at the end.

Copy-add x at the end of the internal container.

Parameters
xthe element to be added to the internal container.
Exceptions
unspecifiedany exception thrown by piranha::small_vector::push_back().

Definition at line 320 of file array_key.hpp.

◆ resize()

template<typename T, typename Derived, typename S = std::integral_constant<std::size_t, 0u>>
void piranha::array_key< T, Derived, S >::resize ( const size_type new_size)
inline

Resize the internal array container.

Equivalent to piranha::small_vector::resize().

Parameters
new_sizethe desired new size for the internal container.
Exceptions
unspecifiedany exception thrown by piranha::small_vector::resize().

Definition at line 266 of file array_key.hpp.

◆ size()

template<typename T, typename Derived, typename S = std::integral_constant<std::size_t, 0u>>
size_type piranha::array_key< T, Derived, S >::size ( ) const
inline

Size.

Returns
number of elements stored within the container.

Definition at line 254 of file array_key.hpp.

◆ size_begin_end() [1/2]

template<typename T, typename Derived, typename S = std::integral_constant<std::size_t, 0u>>
auto piranha::array_key< T, Derived, S >::size_begin_end ( ) const -> decltype(m_container.size_begin_end())
inline

Get size, begin and end iterator (const version).

Returns
the output of the piranha::small_vector::size_begin_end() method called on the internal piranha::small_vector container.

Definition at line 525 of file array_key.hpp.

◆ size_begin_end() [2/2]

template<typename T, typename Derived, typename S = std::integral_constant<std::size_t, 0u>>
auto piranha::array_key< T, Derived, S >::size_begin_end ( ) -> decltype(m_container.size_begin_end())
inline

Get size, begin and end iterator.

Returns
the output of the piranha::small_vector::size_begin_end() method called on the internal piranha::small_vector container.

Definition at line 534 of file array_key.hpp.

◆ trim()

template<typename T, typename Derived, typename S = std::integral_constant<std::size_t, 0u>>
Derived piranha::array_key< T, Derived, S >::trim ( const std::vector< char > &  trim_mask,
const symbol_fset args 
) const
inline

Trim.

This method is used in piranha::series::trim(). The input mask trim_mask is a vector of boolean flags signalling (with nonzero values) elements of this to be removed. The method will return a copy of this in which the specified elements have been removed.

For instance, if this contains the values [0,5,3,0,4] and trim_mask contains the values [false,false,false,true,false], then the output of this method will be the array of values [0,5,3,4] (that is, the fourth element has been removed as indicated by a true value in trim_mask's fourth element).

Parameters
trim_maska mask indicating which elements will be removed.
argsthe reference piranha::symbol_fset.
Returns
a trimmed copy of this.
Exceptions
std::invalid_argumentif the sizes of this or trim_mask differ from the size of args.
unspecifiedany exception thrown by push_back().

Definition at line 409 of file array_key.hpp.

◆ trim_identify()

template<typename T, typename Derived, typename S = std::integral_constant<std::size_t, 0u>>
void piranha::array_key< T, Derived, S >::trim_identify ( std::vector< char > &  trim_mask,
const symbol_fset args 
) const
inline

Identify symbols that can be trimmed.

This method is used in piranha::series::trim(). The input parameter trim_mask is a vector of boolean flags (i.e., a mask) which signals which elements in args are candidates for trimming: a nonzero value means that the symbol at the corresponding position is a candidate for trimming, while a zero value means that the symbol is not a candidate for trimming. This method will set to zero those values in trim_mask for which the corresponding element in this is nonzero.

For instance, if this contains the values [0,5,3,0,4] and trim_mask originally contains the values [1,1,0,1,0], after a call to this method trim_mask will contain [1,0,0,1,0] (that is, the second element was set from 1 to 0 as the corresponding element in this has a value of 5 and thus it must not be trimmed).

Parameters
trim_maska mask signalling candidate elements for trimming.
argsthe reference piranha::symbol_fset.
Exceptions
std::invalid_argumentif the sizes of this or trim_mask differ from the size of args.
unspecifiedany exception thrown by piranha::math::is_zero().

Definition at line 367 of file array_key.hpp.

◆ vector_add()

template<typename T, typename Derived, typename S = std::integral_constant<std::size_t, 0u>>
template<typename U = container_type, add_enabler< U > = 0>
void piranha::array_key< T, Derived, S >::vector_add ( array_key< T, Derived, S > &  retval,
const array_key< T, Derived, S > &  other 
) const
inline

Vector add.

Note
This method is enabled only if the call to piranha::small_vector::add() is well-formed.

Equivalent to calling piranha::small_vector::add() on the internal containers of this and of the arguments.

Parameters
retvalthe piranha::array_key that will hold the result of the addition.
otherthe piranha::array_key that will be added to this.
Exceptions
unspecifiedany exception thrown by piranha::small_vector::add().

Definition at line 459 of file array_key.hpp.

◆ vector_sub()

template<typename T, typename Derived, typename S = std::integral_constant<std::size_t, 0u>>
template<typename U = container_type, sub_enabler< U > = 0>
void piranha::array_key< T, Derived, S >::vector_sub ( array_key< T, Derived, S > &  retval,
const array_key< T, Derived, S > &  other 
) const
inline

Vector sub.

Note
This method is enabled only if the call to piranha::small_vector::sub() is well-formed.

Equivalent to calling piranha::small_vector::sub() on the internal containers of this and of the arguments.

Parameters
retvalthe piranha::array_key that will hold the result of the subtraction.
otherthe piranha::array_key that will be subtracted from this.
Exceptions
unspecifiedany exception thrown by piranha::small_vector::sub().

Definition at line 478 of file array_key.hpp.


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