ppforest2 v0.1.0
Projection Pursuit Decision Trees and Random Forests
Loading...
Searching...
No Matches
ppforest2::utils Namespace Reference

Utility functions for std::map manipulation. More...

Functions

template<typename K, typename V>
std::map< V, std::set< K > > invert (std::map< K, V > const &map)
 Invert a map: values become keys, original keys are grouped into sets.
 
template<typename K, typename V>
std::set< K > keys (std::map< K, V > const &map)
 Extract all keys from a map as a set.
 
template<typename Size>
std::vector< int > range_vector (Size n)
 Build the sequence [0, 1, ..., n - 1] as std::vector<int>.
 
template<typename K, typename V>
std::set< V > values (std::map< K, V > const &map)
 Extract all values from a map as a set.
 

Detailed Description

Utility functions for std::map manipulation.

Function Documentation

◆ invert()

template<typename K, typename V>
std::map< V, std::set< K > > ppforest2::utils::invert ( std::map< K, V > const & map)

Invert a map: values become keys, original keys are grouped into sets.

Parameters
mapInput map {K → V}.
Returns
Inverted map {V → set<K>}.

◆ keys()

template<typename K, typename V>
std::set< K > ppforest2::utils::keys ( std::map< K, V > const & map)

Extract all keys from a map as a set.

Parameters
mapInput map.
Returns
Set of all keys.

◆ range_vector()

template<typename Size>
std::vector< int > ppforest2::utils::range_vector ( Size n)
inline

Build the sequence [0, 1, ..., n - 1] as std::vector<int>.

Replaces the pattern

std::vector<int> v(n);
std::iota(v.begin(), v.end(), 0);

which appears anywhere we need a permutation buffer or a "select all rows/columns" index list. int is the right element type for every caller in the codebase: Eigen's indexed assignment, Eigen column selection, and the strategy Result types all consume int indices.

Template Parameters
SizeAny integral type (e.g. int, std::size_t, Eigen::Index). Cast to std::size_t for the std::vector constructor.
Parameters
nLength of the resulting sequence (must be >= 0).

◆ values()

template<typename K, typename V>
std::set< V > ppforest2::utils::values ( std::map< K, V > const & map)

Extract all values from a map as a set.

Parameters
mapInput map.
Returns
Set of all values (duplicates collapsed).