libhatchet
Loading...
Searching...
No Matches
hxalgorithm.hpp File Reference

Go to the source code of this file.

Classes

class  hxminmax_result< iterator_t_ >

Functions

template<typename iterator_t_, typename callable_t_>
HX_NS_BEGIN_ constexpr bool hxall_of (iterator_t_ begin_, iterator_t_ end_, callable_t_ &&callable_)
template<typename iterator_t_, typename callable_t_>
constexpr bool hxany_of (iterator_t_ begin_, iterator_t_ end_, callable_t_ &&callable_)
template<typename iterator_t_, typename callable_t_>
constexpr hxsize_t hxcount_if (iterator_t_ begin_, iterator_t_ end_, callable_t_ &&callable_)
template<typename T, typename U_>
constexpr T hxexchange (T &obj_, U_ &&new_value_) noexcept
template<typename iterator_t_, typename callable_t_>
constexpr iterator_t_ hxfind_if (iterator_t_ begin_, iterator_t_ end_, callable_t_ &&callable_)
template<typename iterator_t_, typename callable_t_>
constexpr callable_t_ hxfor_each (iterator_t_ begin_, iterator_t_ end_, callable_t_ &&callable_)
template<typename iterator_t_, typename output_iterator_t_, typename less_t_>
constexpr output_iterator_t_ hxmerge (iterator_t_ begin0_, iterator_t_ end0_, iterator_t_ begin1_, iterator_t_ end1_, output_iterator_t_ &&output_, const less_t_ &less_) noexcept
template<typename iterator_t_, typename output_iterator_t_>
constexpr output_iterator_t_ hxmerge (iterator_t_ begin0_, iterator_t_ end0_, iterator_t_ begin1_, iterator_t_ end1_, output_iterator_t_ &&output_) noexcept
template<typename iterator_t_, typename less_t_>
constexpr hxminmax_result< iterator_t_ > hxminmax (iterator_t_ begin_, iterator_t_ end_, const less_t_ &less_)
template<typename iterator_t_>
constexpr hxminmax_result< iterator_t_ > hxminmax (iterator_t_ begin_, iterator_t_ end_)
template<typename iterator_t_, typename output_iterator_t_, typename less_t_>
constexpr output_iterator_t_ hxset_difference (iterator_t_ begin0_, iterator_t_ end0_, iterator_t_ begin1_, iterator_t_ end1_, output_iterator_t_ &&output_, const less_t_ &less_) noexcept
template<typename iterator_t_, typename output_iterator_t_>
constexpr output_iterator_t_ hxset_difference (iterator_t_ begin0_, iterator_t_ end0_, iterator_t_ begin1_, iterator_t_ end1_, output_iterator_t_ &&output_) noexcept
template<typename iterator_t_, typename output_iterator_t_, typename less_t_>
constexpr output_iterator_t_ hxset_intersection (iterator_t_ begin0_, iterator_t_ end0_, iterator_t_ begin1_, iterator_t_ end1_, output_iterator_t_ &&output_, const less_t_ &less_) noexcept
template<typename iterator_t_, typename output_iterator_t_>
constexpr output_iterator_t_ hxset_intersection (iterator_t_ begin0_, iterator_t_ end0_, iterator_t_ begin1_, iterator_t_ end1_, output_iterator_t_ &&output_) noexcept
template<typename iterator_t_, typename output_iterator_t_, typename less_t_>
constexpr output_iterator_t_ hxset_union (iterator_t_ begin0_, iterator_t_ end0_, iterator_t_ begin1_, iterator_t_ end1_, output_iterator_t_ &&output_, const less_t_ &less_) noexcept
template<typename iterator_t_, typename output_iterator_t_>
constexpr output_iterator_t_ hxset_union (iterator_t_ begin0_, iterator_t_ end0_, iterator_t_ begin1_, iterator_t_ end1_, output_iterator_t_ &&output_) noexcept
template<typename iterator_t_, typename equal_t_>
constexpr iterator_t_ hxunique (iterator_t_ begin_, iterator_t_ end_, const equal_t_ &equal_) noexcept
template<typename iterator_t_>
constexpr iterator_t_ hxunique (iterator_t_ begin_, iterator_t_ end_) noexcept

Detailed Description

Searching and set utilities for libhatchet.

Includes support for callables when defining custom key operations. Otherwise T::operator<(const T&) and T::operator==(const T&) are used. The other relational operators are not used.

See hxsort.hpp for sorting algorithms including hxinsertion_sort, hxheapsort and hxsort. hxbinary_search is also over there.

Function Documentation

◆ hxall_of()

template<typename iterator_t_, typename callable_t_>
HX_NS_BEGIN_ constexpr bool hxall_of ( iterator_t_ begin_,
iterator_t_ end_,
callable_t_ && callable_ )
inlineconstexpr

hxall_of - Returns true if the predicate callable returns true for every element in [begin, end).

Returns true for an empty range. Requires a forward-iterator.

◆ hxany_of()

template<typename iterator_t_, typename callable_t_>
bool hxany_of ( iterator_t_ begin_,
iterator_t_ end_,
callable_t_ && callable_ )
inlineconstexpr

hxany_of - Returns true if the predicate callable returns true for at least one element in [begin, end).

Returns false for an empty range. Requires a forward-iterator.

◆ hxcount_if()

template<typename iterator_t_, typename callable_t_>
hxsize_t hxcount_if ( iterator_t_ begin_,
iterator_t_ end_,
callable_t_ && callable_ )
inlineconstexpr

hxcount_if - Returns the number of elements in [begin, end) for which the predicate callable returns true.

Requires a forward-iterator.

◆ hxexchange()

template<typename T, typename U_>
T hxexchange ( T & obj_,
U_ && new_value_ )
inlineconstexprnoexcept

hxexchange - Replaces obj with new_value and returns the old value of obj.

T must be move-constructible and U must be assignable to T. Useful in constructor initialization lists.

◆ hxfind_if()

template<typename iterator_t_, typename callable_t_>
iterator_t_ hxfind_if ( iterator_t_ begin_,
iterator_t_ end_,
callable_t_ && callable_ )
inlineconstexpr

hxfind_if - Returns an iterator to the first element in [begin, end) for which the predicate callable returns true.

Returns end if no element matches. Requires a forward-iterator.

◆ hxfor_each()

template<typename iterator_t_, typename callable_t_>
callable_t_ hxfor_each ( iterator_t_ begin_,
iterator_t_ end_,
callable_t_ && callable_ )
inlineconstexpr

hxfor_each - Applies the callable to each element in [begin, end) in order.

Returns the callable after it has been applied to every element. Requires a forward-iterator.

◆ hxmerge() [1/2]

template<typename iterator_t_, typename output_iterator_t_>
output_iterator_t_ hxmerge ( iterator_t_ begin0_,
iterator_t_ end0_,
iterator_t_ begin1_,
iterator_t_ end1_,
output_iterator_t_ && output_ )
inlineconstexprnoexcept

hxmerge (specialization) - Performs a stable merge of two ordered ranges [begin0, end0) and [begin1, end1) -> output.

The input arrays must not overlap the destination array. Assumes both [begin0, end0) and [begin1, end1) are ordered by hxless(a,b). Passing a hxvector as an output iterator like this hxmerge<const int*, hxvector<int>&>(...) will append to the array. Returns an output iterator positioned one past the last element written. Requires a random-iterator.

◆ hxmerge() [2/2]

template<typename iterator_t_, typename output_iterator_t_, typename less_t_>
output_iterator_t_ hxmerge ( iterator_t_ begin0_,
iterator_t_ end0_,
iterator_t_ begin1_,
iterator_t_ end1_,
output_iterator_t_ && output_,
const less_t_ & less_ )
inlineconstexprnoexcept

hxmerge - Performs a stable merge of two ordered ranges [begin0, end0) and [begin1, end1) -> output.

The input arrays must not overlap each other or the destination array. Elements are move-assigned out of the input ranges. Passing a hxvector as an output iterator like this hxmerge<const int*, hxvector<int>&>(...) will append to the array. Assumes both [begin0, end0) and [begin1, end1) are ordered by the less callable. Returns an output iterator positioned one past the last element written. Requires a random-iterator.

◆ hxminmax() [1/2]

template<typename iterator_t_>
hxminmax_result< iterator_t_ > hxminmax ( iterator_t_ begin_,
iterator_t_ end_ )
inlineconstexpr

hxminmax (specialization) - An overload of hxminmax that uses hxkey_less over the range [begin, end).

Requires a forward-iterator.

◆ hxminmax() [2/2]

template<typename iterator_t_, typename less_t_>
hxminmax_result< iterator_t_ > hxminmax ( iterator_t_ begin_,
iterator_t_ end_,
const less_t_ & less_ )
inlineconstexpr

hxminmax - Returns an hxminmax_result with iterators to the smallest and largest elements in [begin, end) as determined by less.

Both min and max equal end for an empty range. When multiple elements compare equal and minimal, the first is returned. When multiple elements compare equal and maximal, the first is returned. The less callable defines the less-than ordering relationship. Requires a forward-iterator.

◆ hxset_difference() [1/2]

template<typename iterator_t_, typename output_iterator_t_>
output_iterator_t_ hxset_difference ( iterator_t_ begin0_,
iterator_t_ end0_,
iterator_t_ begin1_,
iterator_t_ end1_,
output_iterator_t_ && output_ )
inlineconstexprnoexcept

hxset_difference (specialization) - Forms the difference of two ordered ranges [begin0, end0) and [begin1, end1) into output using hxless.

The output contains keys that appear in the first range but not the second. The input arrays must not overlap the destination array. Passing a hxvector as an output iterator like this hxset_difference<const int*, hxvector<int>&>(...) will append to the array. Returns an output iterator positioned one past the last element written. Requires a random-iterator.

◆ hxset_difference() [2/2]

template<typename iterator_t_, typename output_iterator_t_, typename less_t_>
output_iterator_t_ hxset_difference ( iterator_t_ begin0_,
iterator_t_ end0_,
iterator_t_ begin1_,
iterator_t_ end1_,
output_iterator_t_ && output_,
const less_t_ & less_ )
inlineconstexprnoexcept

hxset_difference - Forms the difference of two ordered ranges [begin0, end0) and [begin1, end1) into output.

The output contains keys that appear in the first range but not the second. The input arrays must not overlap each other or the destination array. Elements from the first range are move-assigned into the output. Passing a hxvector as an output iterator like this hxset_difference<const int*, hxvector<int>&>(...) will append to the array. Assumes both ranges are ordered by the less callable. Returns an output iterator positioned one past the last element written. Requires a random-iterator.

◆ hxset_intersection() [1/2]

template<typename iterator_t_, typename output_iterator_t_>
output_iterator_t_ hxset_intersection ( iterator_t_ begin0_,
iterator_t_ end0_,
iterator_t_ begin1_,
iterator_t_ end1_,
output_iterator_t_ && output_ )
inlineconstexprnoexcept

hxset_intersection (specialization) - Forms the intersection of two ordered ranges [begin0, end0) and [begin1, end1) into output using hxless.

Only keys present in both ranges appear in the output. The input arrays must not overlap the destination array. Passing a hxvector as an output iterator like this hxset_intersection<const int*, hxvector<int>&>(...) will append to the array. Returns an output iterator positioned one past the last element written. Requires a random-iterator.

◆ hxset_intersection() [2/2]

template<typename iterator_t_, typename output_iterator_t_, typename less_t_>
output_iterator_t_ hxset_intersection ( iterator_t_ begin0_,
iterator_t_ end0_,
iterator_t_ begin1_,
iterator_t_ end1_,
output_iterator_t_ && output_,
const less_t_ & less_ )
inlineconstexprnoexcept

hxset_intersection - Forms the intersection of two ordered ranges [begin0, end0) and [begin1, end1) into output.

Only keys present in both ranges appear in the output. The input arrays must not overlap each other or the destination array. Elements from the first range are move-assigned into the output. Passing a hxvector as an output iterator like this hxset_intersection<const int*, hxvector<int>&>(...) will append to the array. Assumes both ranges are ordered by the less callable. Returns an output iterator positioned one past the last element written. Requires a random-iterator.

◆ hxset_union() [1/2]

template<typename iterator_t_, typename output_iterator_t_>
output_iterator_t_ hxset_union ( iterator_t_ begin0_,
iterator_t_ end0_,
iterator_t_ begin1_,
iterator_t_ end1_,
output_iterator_t_ && output_ )
inlineconstexprnoexcept

hxset_union (specialization) - Forms the union of two ordered ranges [begin0, end0) and [begin1, end1) into output using hxless.

A key appearing m times in the first range and n times in the second appears max(m, n) times in the output. The input arrays must not overlap the destination array. Passing a hxvector as an output iterator like this hxset_union<const int*, hxvector<int>&>(...) will append to the array. Returns an output iterator positioned one past the last element written. Requires a random-iterator.

◆ hxset_union() [2/2]

template<typename iterator_t_, typename output_iterator_t_, typename less_t_>
output_iterator_t_ hxset_union ( iterator_t_ begin0_,
iterator_t_ end0_,
iterator_t_ begin1_,
iterator_t_ end1_,
output_iterator_t_ && output_,
const less_t_ & less_ )
inlineconstexprnoexcept

hxset_union - Forms the union of two ordered ranges [begin0, end0) and [begin1, end1) into output.

A key appearing m times in the first range and n times in the second appears max(m, n) times in the output. The input arrays must not overlap each other or the destination array. Elements are move-assigned out of the input ranges. Passing a hxvector as an output iterator like this hxset_union<const int*, hxvector<int>&>(...) will append to the array. Assumes both ranges are ordered by the less callable. Returns an output iterator positioned one past the last element written. Requires a random-iterator.

◆ hxunique() [1/2]

template<typename iterator_t_>
iterator_t_ hxunique ( iterator_t_ begin_,
iterator_t_ end_ )
inlineconstexprnoexcept

hxunique (specialization) - An overload of hxunique that uses hxkey_equal over the range [begin, end).

Requires a forward-iterator.

◆ hxunique() [2/2]

template<typename iterator_t_, typename equal_t_>
iterator_t_ hxunique ( iterator_t_ begin_,
iterator_t_ end_,
const equal_t_ & equal_ )
inlineconstexprnoexcept

hxunique - Removes consecutive duplicate elements from the range [begin, end) using equal to identify duplicates.

Elements are moved into place using move-assignment. Returns an iterator to the new end of the range. Elements past the returned iterator are in a valid but unspecified state. The range must be sorted to remove all duplicates. The equal callable returns true when two elements are considered equal. Requires a forward-iterator.