werkzeugkiste::container namespace

Utility functions for standard containers.

Contents

Classes

template<typename T, typename T_nonconst, typename elem_type = typename T::value_type>
class circular_buffer_iterator
Templated STL compatible iterator for the circular_buffer.
template<typename T, int DefaultCapacity = 100, typename Alloc = std::allocator<T>>
class circular_buffer
STL-like circular buffer.
template<class Container>
class Ordering

Functions

template<typename circular_buffer_iterator_t>
auto operator+(const typename circular_buffer_iterator_t::difference_type& a, const circular_buffer_iterator_t& b) -> circular_buffer_iterator_t
template<typename circular_buffer_iterator_t>
auto operator-(const typename circular_buffer_iterator_t::difference_type& a, const circular_buffer_iterator_t& b) -> circular_buffer_iterator_t
template<class Container>
auto SmoothMovingAverage(const Container& data, int window_size) -> Container
template<class Container, typename T = typename Container::value_type>
auto Sum(const Container& values) -> std::enable_if_t<std::is_arithmetic_v<T>, T>
template<class Container, typename T = typename Container::value_type>
auto Mean(const Container& values) -> std::enable_if_t<std::is_arithmetic_v<T>, double>
template<class Container>
void MinMax(const Container& values, typename Container::value_type* val_min = nullptr, typename Container::value_type* val_max = nullptr, std::size_t* idx_min = nullptr, std::size_t* idx_max = nullptr)
template<typename M>
auto GetMapKeys(const M& map) -> std::vector<typename M::key_type>
template<typename Tp>
auto CmpAsc(const Tp& a, const Tp& b) -> bool
A sort comparator for ascending order, which uses operator<.
template<typename Tp>
auto CmpDesc(const Tp& a, const Tp& b) -> bool
A sort comparator for descending order, which uses operator<.
template<class Container>
auto GetSortedIndices(const Container& data, bool(*)(const typename Container::value_type&, const typename Container::value_type&) cmp = CmpAsc<typename Container::value_type>) -> std::vector<std::size_t>
Returns the indices which correspond to a sorted data vector.
template<class Container>
auto ApplyIndexLookup(const Container& data, const std::vector<std::size_t>& indices) -> Container
template<typename TData, typename TKey>
auto SortByExternalKeys(const std::vector<TData>& data, const std::vector<TKey>& keys, bool(*)(const TData&, const TKey&) cmp = CmpAsc<TKey>) -> std::vector<TData>
Returns the data vector sorted by the given external keys.
template<typename Container, typename Tp = std::decay_t<decltype(*begin(std::declval<Container>()))>>
auto FindDuplicates(const Container& container) -> std::map<Tp, std::size_t>
template<typename Container, typename Tp = std::decay_t<decltype(*begin(std::declval<Container>()))>>
auto HasUniqueItems(const Container& container) -> bool
template<typename Tv, typename... Ts>
auto ContainsKey(const std::map<Ts...>& container, const Tv& key) -> bool
Returns true if the given key exists within the map.
template<typename Container, typename Tp = std::decay_t<decltype(*begin(std::declval<Container>()))>>
auto ContainsValue(const Container& container, const Tp& value) -> bool
Returns true if the given element exists within the container.

Function documentation

template<typename circular_buffer_iterator_t>
circular_buffer_iterator_t werkzeugkiste::container::operator+(const typename circular_buffer_iterator_t::difference_type& a, const circular_buffer_iterator_t& b)

template<typename circular_buffer_iterator_t>
circular_buffer_iterator_t werkzeugkiste::container::operator-(const typename circular_buffer_iterator_t::difference_type& a, const circular_buffer_iterator_t& b)

template<class Container>
Container werkzeugkiste::container::SmoothMovingAverage(const Container& data, int window_size)

Smoothes the given data points.

Smoothes the points such that each point is the average over a window of "span" values centered on the processed point. The first and last points won't be smoothed, i.e. the behavior is similar to MATLAB's smooth.

Args: data: Any sequence container which can be accessed sequentially. Must provide size(), push_back() and a value_type. window_size: Length of the smoothing window. Must be odd and >=3 or <=0 (no smoothing). For span 1 and 2, an invalid_argument will be thrown.

Example for span = 5: output[0] = data[0] output[1] = (data[0] + data[1] + data[2]) / 3 output[2] = (data[0] + ... + data[4]) / 5 output[3] = (data[1] + ... + data[5]) / 5

template<class Container, typename T = typename Container::value_type>
std::enable_if_t<std::is_arithmetic_v<T>, T> werkzeugkiste::container::Sum(const Container& values)

Computes the sum of the given STL-like container. The container must hold an arithmetic type (integers, floats, etc.)

template<class Container, typename T = typename Container::value_type>
std::enable_if_t<std::is_arithmetic_v<T>, double> werkzeugkiste::container::Mean(const Container& values)

Computes the mean of the given STL-like container. The container must hold an arithmetic type (integers, floats, etc.)

template<class Container>
void werkzeugkiste::container::MinMax(const Container& values, typename Container::value_type* val_min = nullptr, typename Container::value_type* val_max = nullptr, std::size_t* idx_min = nullptr, std::size_t* idx_max = nullptr)

Computes the minimum & maximum of the given STL-like sequence container. Currently, only random access containers are supported. The underlying value_type must support comparisons via operator<.

template<typename M>
std::vector<typename M::key_type> werkzeugkiste::container::GetMapKeys(const M& map)

Returns the keys from a map container (i.e. any associative container).

template<typename Tp>
bool werkzeugkiste::container::CmpAsc(const Tp& a, const Tp& b)

A sort comparator for ascending order, which uses operator<.

template<typename Tp>
bool werkzeugkiste::container::CmpDesc(const Tp& a, const Tp& b)

A sort comparator for descending order, which uses operator<.

template<class Container>
std::vector<std::size_t> werkzeugkiste::container::GetSortedIndices(const Container& data, bool(*)(const typename Container::value_type&, const typename Container::value_type&) cmp = CmpAsc<typename Container::value_type>)

Returns the indices which correspond to a sorted data vector.

template<class Container>
Container werkzeugkiste::container::ApplyIndexLookup(const Container& data, const std::vector<std::size_t>& indices)

Returns a container obtained by remapping the given data according to the indices.

Requires the input to be a sequence container, i.e. it must provide push_back.

template<typename TData, typename TKey>
std::vector<TData> werkzeugkiste::container::SortByExternalKeys(const std::vector<TData>& data, const std::vector<TKey>& keys, bool(*)(const TData&, const TKey&) cmp = CmpAsc<TKey>)

Returns the data vector sorted by the given external keys.

template<typename Container, typename Tp = std::decay_t<decltype(*begin(std::declval<Container>()))>>
std::map<Tp, std::size_t> werkzeugkiste::container::FindDuplicates(const Container& container)

Returns a map containing all duplicate entries in 'data' along with their their frequencies.

template<typename Container, typename Tp = std::decay_t<decltype(*begin(std::declval<Container>()))>>
bool werkzeugkiste::container::HasUniqueItems(const Container& container)

Returns true if there are no duplicates in the given sequence container.

template<typename Tv, typename... Ts>
bool werkzeugkiste::container::ContainsKey(const std::map<Ts...>& container, const Tv& key)

Returns true if the given key exists within the map.

template<typename Container, typename Tp = std::decay_t<decltype(*begin(std::declval<Container>()))>>
bool werkzeugkiste::container::ContainsValue(const Container& container, const Tp& value)

Returns true if the given element exists within the container.