AIToolbox
A library that offers tools for AI problem solving.
AIToolbox::Factored::FilterMap< T, TrieType > Class Template Reference

This class is a container which uses PartialFactors as keys. More...

#include <AIToolbox/Factored/Utils/FilterMap.hpp>

Public Types

using ItemsContainer = std::vector< T >
 
using Iterable = IndexMap< std::vector< size_t >, ItemsContainer >
 
using ConstIterable = IndexMap< std::vector< size_t >, const ItemsContainer >
 

Public Member Functions

 FilterMap (Factors f)
 Basic constructor. More...
 
 FilterMap (TrieType t, ItemsContainer c)
 Constructor from trie and items. More...
 
Factors getF () const
 This function returns the set factor space for the FilterMap. More...
 
template<typename... Args>
void emplace (const PartialFactors &pf, Args &&... args)
 This function creates an instance of T within the container. More...
 
Iterable filter (const Factors &f)
 This function creates an iterable object over all values matching the input key. More...
 
ConstIterable filter (const Factors &f) const
 This function creates an iterable object over all values matching the input key. More...
 
template<typename TT = TrieType, typename = std::enable_if_t<std::is_same_v<TT, Trie>>>
Iterable filter (const Factors &f, size_t offset)
 This function creates an iterable object over all values matching the input key. More...
 
template<typename TT = TrieType, typename = std::enable_if_t<std::is_same_v<TT, Trie>>>
ConstIterable filter (const Factors &f, size_t offset) const
 This function creates an iterable object over all values matching the input key. More...
 
Iterable filter (const PartialFactors &pf)
 This function creates an iterable object over all values matching the input key. More...
 
ConstIterable filter (const PartialFactors &pf) const
 This function creates an iterable object over all values matching the input key. More...
 
void reserve (size_t size)
 This function reserves the specified space to avoid reallocations. More...
 
size_t size () const
 This function returns the number of values that have been added to the FilterMap. More...
 
ItemsContainer::iterator begin ()
 This function returns the beginning of a range containing all items added to the container. More...
 
ItemsContainer::const_iterator begin () const
 This function returns the beginning of a range containing all items added to the container. More...
 
ItemsContainer::iterator end ()
 This function returns the end of a range containing all items added to the container. More...
 
ItemsContainer::const_iterator end () const
 This function returns the end of a range containing all items added to the container. More...
 
const T & operator[] (size_t id) const
 This function allows direct access to the items in the container. More...
 
T & operator[] (size_t id)
 This function allows direct access to the items in the container. More...
 
const ItemsContainergetContainer () const
 This function provides a direct view on the items contained by the container. More...
 
const TrieType & getTrie () const
 This function returns the underlying trie object. More...
 

Detailed Description

template<typename T, typename TrieType = FasterTrie>
class AIToolbox::Factored::FilterMap< T, TrieType >

This class is a container which uses PartialFactors as keys.

This class stores values using PartialFactors as keys. The values can then be reached using Factors. The result will be an iterable object which will iterate over all values where the key matched the input.

This class does not allow removal of elements.

Template Parameters
TThe type of object to be stored.

Member Typedef Documentation

◆ ConstIterable

template<typename T , typename TrieType = FasterTrie>
using AIToolbox::Factored::FilterMap< T, TrieType >::ConstIterable = IndexMap<std::vector<size_t>, const ItemsContainer>

◆ ItemsContainer

template<typename T , typename TrieType = FasterTrie>
using AIToolbox::Factored::FilterMap< T, TrieType >::ItemsContainer = std::vector<T>

◆ Iterable

template<typename T , typename TrieType = FasterTrie>
using AIToolbox::Factored::FilterMap< T, TrieType >::Iterable = IndexMap<std::vector<size_t>, ItemsContainer>

Constructor & Destructor Documentation

◆ FilterMap() [1/2]

template<typename T , typename TrieType = FasterTrie>
AIToolbox::Factored::FilterMap< T, TrieType >::FilterMap ( Factors  f)
inline

Basic constructor.

This constructor simply initializes the underlying TrieType object with the input factor space.

Parameters
fThe desired factor space.

◆ FilterMap() [2/2]

template<typename T , typename TrieType = FasterTrie>
AIToolbox::Factored::FilterMap< T, TrieType >::FilterMap ( TrieType  t,
ItemsContainer  c 
)
inline

Constructor from trie and items.

This constructor is provided when the user wants to copy two FilterMap of different types but which share the underlying factorization.

With this constructor, the underlying TrieType can be copied, while a new container of items must be provided, of the same size as the input TrieType.

If the two sizes are not equal, the constructor will throw an std::invalid_argument exception.

Parameters
tThe trie to copy.
cThe new items to store.

Member Function Documentation

◆ begin() [1/2]

template<typename T , typename TrieType = FasterTrie>
ItemsContainer::iterator AIToolbox::Factored::FilterMap< T, TrieType >::begin ( )
inline

This function returns the beginning of a range containing all items added to the container.

Returns
The beginning of the range of all items.

◆ begin() [2/2]

template<typename T , typename TrieType = FasterTrie>
ItemsContainer::const_iterator AIToolbox::Factored::FilterMap< T, TrieType >::begin ( ) const
inline

This function returns the beginning of a range containing all items added to the container.

Returns
The beginning of the range of all items.

◆ emplace()

template<typename T , typename TrieType = FasterTrie>
template<typename... Args>
void AIToolbox::Factored::FilterMap< T, TrieType >::emplace ( const PartialFactors pf,
Args &&...  args 
)
inline

This function creates an instance of T within the container.

If very many items must be emplaced in the container, it is recommended to call reserve() beforehand in order to avoid multiple reallocations. In addition, see the Trie documentation on how to most efficiently insert new keys (if speed is very important).

See also
Trie::insert()
Parameters
pfThe key where the value should be stored.
argsThe arguments needed to emplace the new value.

◆ end() [1/2]

template<typename T , typename TrieType = FasterTrie>
ItemsContainer::iterator AIToolbox::Factored::FilterMap< T, TrieType >::end ( )
inline

This function returns the end of a range containing all items added to the container.

Returns
The end of the range of all items.

◆ end() [2/2]

template<typename T , typename TrieType = FasterTrie>
ItemsContainer::const_iterator AIToolbox::Factored::FilterMap< T, TrieType >::end ( ) const
inline

This function returns the end of a range containing all items added to the container.

Returns
The end of the range of all items.

◆ filter() [1/6]

template<typename T , typename TrieType = FasterTrie>
Iterable AIToolbox::Factored::FilterMap< T, TrieType >::filter ( const Factors f)
inline

This function creates an iterable object over all values matching the input key.

Note that the input may be shorter than the overall Factor domain. In any case, we assume the search will begin from the zero element.

Parameters
fThe key that must be matched.
Returns
An iterable object over all values matching the input.

◆ filter() [2/6]

template<typename T , typename TrieType = FasterTrie>
ConstIterable AIToolbox::Factored::FilterMap< T, TrieType >::filter ( const Factors f) const
inline

This function creates an iterable object over all values matching the input key.

Note that the input may be shorter than the overall Factor domain. In any case, we assume the search will begin from the zero element.

Parameters
fThe key that must be matched.
Returns
An iterable object over all values matching the input.

◆ filter() [3/6]

template<typename T , typename TrieType = FasterTrie>
template<typename TT = TrieType, typename = std::enable_if_t<std::is_same_v<TT, Trie>>>
Iterable AIToolbox::Factored::FilterMap< T, TrieType >::filter ( const Factors f,
size_t  offset 
)
inline

This function creates an iterable object over all values matching the input key.

See also
Trie::filter(const Factors&, size_t)

This method can only be used if the underlying TrieType supports it.

Parameters
fThe key that must be matched.
offsetThe offset of the key, if smaller than the factor space.
Returns
An iterable object over all values matching the input.

◆ filter() [4/6]

template<typename T , typename TrieType = FasterTrie>
template<typename TT = TrieType, typename = std::enable_if_t<std::is_same_v<TT, Trie>>>
ConstIterable AIToolbox::Factored::FilterMap< T, TrieType >::filter ( const Factors f,
size_t  offset 
) const
inline

This function creates an iterable object over all values matching the input key.

See also
Trie::filter(const Factors&, size_t)

This method can only be used if the underlying TrieType supports it.

Parameters
fThe key that must be matched.
offsetThe offset of the key, if smaller than the factor space.
Returns
An iterable object over all values matching the input.

◆ filter() [5/6]

template<typename T , typename TrieType = FasterTrie>
Iterable AIToolbox::Factored::FilterMap< T, TrieType >::filter ( const PartialFactors pf)
inline

This function creates an iterable object over all values matching the input key.

See also
Trie::filter(const PartialFactors&)

This method can only be used if the underlying TrieType supports it.

Parameters
pfThe key that must be matched.
Returns
An iterable object over all values matching the input.

◆ filter() [6/6]

template<typename T , typename TrieType = FasterTrie>
ConstIterable AIToolbox::Factored::FilterMap< T, TrieType >::filter ( const PartialFactors pf) const
inline

This function creates an iterable object over all values matching the input key.

See also
Trie::filter(const PartialFactors&)

This method can only be used if the underlying TrieType supports it.

Parameters
pfThe key that must be matched.
Returns
An iterable object over all values matching the input.

◆ getContainer()

template<typename T , typename TrieType = FasterTrie>
const ItemsContainer& AIToolbox::Factored::FilterMap< T, TrieType >::getContainer ( ) const
inline

This function provides a direct view on the items contained by the container.

Returns
The underlying data container.

◆ getF()

template<typename T , typename TrieType = FasterTrie>
Factors AIToolbox::Factored::FilterMap< T, TrieType >::getF ( ) const
inline

This function returns the set factor space for the FilterMap.

Returns
The set factor space.

◆ getTrie()

template<typename T , typename TrieType = FasterTrie>
const TrieType& AIToolbox::Factored::FilterMap< T, TrieType >::getTrie ( ) const
inline

This function returns the underlying trie object.

This function is provided in case one wants to manually access and call the underlying trie.

Returns
The trie associated with this container.

◆ operator[]() [1/2]

template<typename T , typename TrieType = FasterTrie>
T& AIToolbox::Factored::FilterMap< T, TrieType >::operator[] ( size_t  id)
inline

This function allows direct access to the items in the container.

No bound checking is performed.

Parameters
idThe id of the item.
Returns
A reference to the accessed item.

◆ operator[]() [2/2]

template<typename T , typename TrieType = FasterTrie>
const T& AIToolbox::Factored::FilterMap< T, TrieType >::operator[] ( size_t  id) const
inline

This function allows direct access to the items in the container.

No bound checking is performed.

Parameters
idThe id of the item.
Returns
A constant reference to the accessed item.

◆ reserve()

template<typename T , typename TrieType = FasterTrie>
void AIToolbox::Factored::FilterMap< T, TrieType >::reserve ( size_t  size)
inline

This function reserves the specified space to avoid reallocations.

Parameters
sizeThe minimum number of elements we should reserve space for.

◆ size()

template<typename T , typename TrieType = FasterTrie>
size_t AIToolbox::Factored::FilterMap< T, TrieType >::size ( ) const
inline

This function returns the number of values that have been added to the FilterMap.

Returns
The number of container values.

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