Aleph-w  1.9
General library for algorithms and data structures
LocateFunctions< Container, Type > Class Template Reference

#include <ah-dry.H>

Public Member Functions

auto get_it () const
 
auto get_it (size_t pos) const
 
auto get_itor () const
 
Type & nth_ne (const size_t n) noexcept
 
const Type & nth_ne (const size_t n) const noexcept
 
Type & nth (const size_t n)
 
const Type & nth (const size_t n) const
 
template<class Operation >
Type * find_ptr (Operation &operation) noexcept(noexcept(operation))
 
template<class Operation >
const Type * find_ptr (Operation &operation) const noexcept(noexcept(operation))
 
template<class Operation >
const Type * find_ptr (Operation &&operation) const noexcept(noexcept(operation))
 
template<class Operation >
Type * find_ptr (Operation &&operation) noexcept(noexcept(operation))
 
template<class Operation >
size_t find_index (Operation &operation) const noexcept(noexcept(operation))
 
template<class Operation >
size_t find_index (Operation &&operation) const noexcept(noexcept(operation))
 
template<class Operation >
std::tuple< bool, Type > find_item (Operation &operation) noexcept(noexcept(operation))
 
template<class Operation >
std::tuple< bool, Type > find_item (Operation &operation) const noexcept(noexcept(operation))
 
template<class Operation >
std::tuple< bool, Type > find_item (Operation &&operation) noexcept(noexcept(operation))
 
template<class Operation >
std::tuple< bool, Type > find_item (Operation &&operation) const noexcept(noexcept(operation))
 

Detailed Description

template<class Container, typename Type>
class LocateFunctions< Container, Type >

Common sequential searching methods on containers.

This classs implements common sequential searching on containers.

Note
Take in account that any of these searches takes $O(n)$ of complexity for the worst case and that this is independent of type of container. For example, a hash table or a binary search tree, exports its own search that is much more faster that any of these primitives. As an advice: do not use this method inside loops. If you find yourself in this situation, then consider to revise your design and to use another search method. Use these primitives very few times, for algorithms whose complexity is by far greater that $O(n)$ and when you cannot index with an adequate data structure.
Warning
Be very careful about the fact that many of these primitives return pointers or references to container's data. In many cases, alteration of that data will corrupt the internal state of container.

Member Function Documentation

◆ find_index() [1/2]

template<class Container , typename Type >
template<class Operation >
size_t LocateFunctions< Container, Type >::find_index ( Operation &  operation) const
inlinenoexcept

Find the position of an item in the container according to a searching criteria.

find_index(operation) traverses the container and on each item perform operation(item). If the result of operation is true, then the traversal is stopped and the position of the current item (which mathes operation) is returned.

operation must have the following signature:

bool operation(const typename Container::Item_Type & item)
Warning
Frequent use of this method will definitively degrade the performance. Try not to use this method inside loops. In general, if you falls in this situation, the consider your design and use a faster approach.
Parameters
[in]<tt>operation</tt>to be performed on each item for matching a searching criteria.
Returns
the last seen position. If the item is not found, then the number of items is returned.

◆ find_index() [2/2]

template<class Container , typename Type >
template<class Operation >
size_t LocateFunctions< Container, Type >::find_index ( Operation &&  operation) const
inlinenoexcept

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

◆ find_item() [1/4]

template<class Container , typename Type >
template<class Operation >
std::tuple<bool, Type> LocateFunctions< Container, Type >::find_item ( Operation &  operation)
inlinenoexcept

Safe sequential searching of an item matching a criteria.

find_item(operation) traverses the container and on each item perform operation(item). If the result of operation is true, then the traversal is stopped and duple containg a copy of found item is returned.

The method is said safe because returns a copy of item.

operation must have the following signature:

bool operation(const typename Container::Item_Type & item)
Parameters
[in]<tt>operation</tt>to be used as searching criteria
Returns
a duple tuple<bool, Type>. The first field indicates if the item was found and the second contains a copy of found item. If no item is found, then the first field is false and the second is the result of default constructor on the type stored in the container.

◆ find_item() [2/4]

template<class Container , typename Type >
template<class Operation >
std::tuple<bool, Type> LocateFunctions< Container, Type >::find_item ( Operation &  operation) const
inlinenoexcept

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

◆ find_item() [3/4]

template<class Container , typename Type >
template<class Operation >
std::tuple<bool, Type> LocateFunctions< Container, Type >::find_item ( Operation &&  operation)
inlinenoexcept

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

◆ find_item() [4/4]

template<class Container , typename Type >
template<class Operation >
std::tuple<bool, Type> LocateFunctions< Container, Type >::find_item ( Operation &&  operation) const
inlinenoexcept

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

◆ find_ptr() [1/4]

template<class Container , typename Type >
template<class Operation >
Type* LocateFunctions< Container, Type >::find_ptr ( Operation &  operation)
inlinenoexcept

Find a pointer to an item in the container according to a searching criteria.

find_ptr(operation) traverses the container and on each item perform operation(item). If the result of operation is true, then the traversal is stopped and a pointer to the current item (which mathes operation) is returned.

operation must have the following signature:

bool operation(const typename Container::Item_Type & item)
Warning
Frequent use of this method will definitively degrade the performance. Try not to use this method inside loops. In general, if you falls in thie situation, the consider your design and to use an faster approach.
Parameters
[in]<tt>operation</tt>to be performed on each item for matching a searching criteria.
Returns
a valid pointer to an item if this was found or nullptr otherwise.

◆ find_ptr() [2/4]

template<class Container , typename Type >
template<class Operation >
const Type* LocateFunctions< Container, Type >::find_ptr ( Operation &  operation) const
inlinenoexcept

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

◆ find_ptr() [3/4]

template<class Container , typename Type >
template<class Operation >
const Type* LocateFunctions< Container, Type >::find_ptr ( Operation &&  operation) const
inlinenoexcept

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

◆ find_ptr() [4/4]

template<class Container , typename Type >
template<class Operation >
Type* LocateFunctions< Container, Type >::find_ptr ( Operation &&  operation)
inlinenoexcept

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

◆ get_it() [1/2]

template<class Container , typename Type >
auto LocateFunctions< Container, Type >::get_it ( ) const
inline

Return an properly initialized iterator positioned at the first item on the container

◆ get_it() [2/2]

template<class Container , typename Type >
auto LocateFunctions< Container, Type >::get_it ( size_t  pos) const
inline

Return an properly initialized iterator positioned at the pos item on the container

◆ get_itor()

template<class Container , typename Type >
auto LocateFunctions< Container, Type >::get_itor ( ) const
inline

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

◆ nth() [1/2]

template<class Container , typename Type >
Type& LocateFunctions< Container, Type >::nth ( const size_t  n)
inline

Return the n-th item of container.

The notion of ordinal depends of type of container. On list, probably will be the insertion order. On binary search trees will be the nth smaller item. On hash tables will be pseudo random.

Warning
Frequent use of this method will definitively degrade the performance. Try not to use this method inside loops. In general, if you falls in this situation, then consider your design and to use an faster approach.
Parameters
[in]nthe nth item to find
Returns
a valid reference to the item into the container.
Exceptions
out_of_rangeif n is greater or equal that the size of container.

◆ nth() [2/2]

template<class Container , typename Type >
const Type& LocateFunctions< Container, Type >::nth ( const size_t  n) const
inline

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

◆ nth_ne()

template<class Container , typename Type >
const Type& LocateFunctions< Container, Type >::nth_ne ( const size_t  n) const
inlinenoexcept

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.


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

Leandro Rabindranath León