Turi Create  4.0
Set And Map Utilities

Some mathematical Set and Map routines. More...

Functions

template<typename T >
std::set< T > turi::set_union (const std::set< T > &a, const std::set< T > &b)
 
template<typename T >
std::set< T > turi::set_union (const std::set< T > &a, const T &b)
 
template<typename T >
std::set< T > turi::set_intersect (const std::set< T > &a, const std::set< T > &b)
 
template<typename T >
std::set< T > turi::set_difference (const std::set< T > &a, const std::set< T > &b)
 
template<typename T >
std::set< T > turi::set_difference (const std::set< T > &a, const T &b)
 
template<typename T >
std::pair< std::set< T >, std::set< T > > turi::set_partition (const std::set< T > &s, const std::set< T > &partition)
 
template<typename T >
bool turi::set_disjoint (const std::set< T > &a, const std::set< T > &b)
 
template<typename T >
bool turi::set_equal (const std::set< T > &a, const std::set< T > &b)
 
template<typename T >
bool turi::includes (const std::set< T > &a, const std::set< T > &b)
 
template<typename T >
bool turi::is_subset (const std::set< T > &a, const std::set< T > &b)
 
template<typename T >
bool turi::is_superset (const std::set< T > &a, const std::set< T > &b)
 
template<typename T >
boost::enable_if_c< boost::is_output_streamable< T >::value, std::ostream & >::type turi::operator<< (std::ostream &out, const std::set< T > &s)
 
template<typename T >
boost::enable_if_c< boost::is_output_streamable< T >::value, std::ostream & >::type turi::operator<< (std::ostream &out, const std::vector< T > &v)
 
template<typename Key , typename T >
const T & turi::safe_get (const std::map< Key, T > &map, const Key &key)
 
template<typename Key , typename T >
const T turi::safe_get (const std::map< Key, T > &map, const Key &key, const T default_value)
 
template<typename OldKey , typename NewKey , typename T >
std::map< NewKey, T > turi::rekey (const std::map< OldKey, T > &map, const std::map< OldKey, NewKey > &key_map)
 
template<typename Key , typename OldT , typename NewT >
std::map< Key, NewT > turi::remap (const std::map< Key, OldT > &map, const std::map< OldT, NewT > &val_map)
 
template<typename Key , typename T >
void turi::remap (std::map< Key, T > &map, const std::map< T, T > &val_map)
 
template<typename Key , typename T >
std::map< Key, T > turi::map_union (const std::map< Key, T > &a, const std::map< Key, T > &b)
 
template<typename Key , typename T >
std::map< Key, T > turi::map_intersect (const std::map< Key, T > &a, const std::map< Key, T > &b)
 
template<typename Key , typename T >
std::map< Key, T > turi::map_intersect (const std::map< Key, T > &m, const std::set< Key > &keys)
 
template<typename Key , typename T >
std::map< Key, T > turi::map_difference (const std::map< Key, T > &a, const std::map< Key, T > &b)
 
template<typename Key , typename T >
std::set< Key > turi::keys (const std::map< Key, T > &map)
 
template<typename Key , typename T >
std::vector< Key > turi::keys_as_vector (const std::map< Key, T > &map)
 
template<typename Key , typename T >
std::set< T > turi::values (const std::map< Key, T > &map)
 
template<typename Key , typename T >
std::vector< T > turi::values (const std::map< Key, T > &m, const std::set< Key > &keys)
 
template<typename Key , typename T >
std::vector< T > turi::values (const std::map< Key, T > &m, const std::vector< Key > &keys)
 
template<typename Key >
std::map< Key, Key > turi::make_identity_map (const std::set< Key > &keys)
 
template<typename Key , typename T >
std::ostream & turi::operator<< (std::ostream &out, const std::map< Key, T > &m)
 Writes a map to the supplied stream.
 
std::string turi::trim (const std::string &str)
 
template<typename T >
std::string turi::tostr (const T &t)
 
template<typename T >
turi::fromstr (const std::string &str)
 
std::string turi::pad_number (const size_t number, const size_t npad, const char pad_value='0')
 
std::vector< std::string > turi::strsplit (const std::string &str, const std::string &splitchars, const bool auto_trim=false)
 

Detailed Description

Some mathematical Set and Map routines.

Function Documentation

◆ fromstr()

template<typename T >
T turi::fromstr ( const std::string &  str)

Convenience function for using std streams to convert a string to anything

Definition at line 469 of file stl_util.hpp.

◆ includes()

template<typename T >
bool turi::includes ( const std::set< T > &  a,
const std::set< T > &  b 
)

Returns true if b is included in a

Definition at line 144 of file stl_util.hpp.

◆ is_subset()

template<typename T >
bool turi::is_subset ( const std::set< T > &  a,
const std::set< T > &  b 
)

Returns true if $a b$

Definition at line 152 of file stl_util.hpp.

◆ is_superset()

template<typename T >
bool turi::is_superset ( const std::set< T > &  a,
const std::set< T > &  b 
)

Returns true if $b a$

Definition at line 160 of file stl_util.hpp.

◆ keys()

template<typename Key , typename T >
std::set<Key> turi::keys ( const std::map< Key, T > &  map)

Returns the set of keys in a map

Definition at line 358 of file stl_util.hpp.

◆ keys_as_vector()

template<typename Key , typename T >
std::vector<Key> turi::keys_as_vector ( const std::map< Key, T > &  map)

Get the set of keys in a map as a vector

Definition at line 371 of file stl_util.hpp.

◆ make_identity_map()

template<typename Key >
std::map<Key, Key> turi::make_identity_map ( const std::set< Key > &  keys)

Creates an identity map (a map from elements to themselves)

Definition at line 425 of file stl_util.hpp.

◆ map_difference()

template<typename Key , typename T >
std::map<Key, T> turi::map_difference ( const std::map< Key, T > &  a,
const std::map< Key, T > &  b 
)

Computes the difference between two maps

Definition at line 341 of file stl_util.hpp.

◆ map_intersect() [1/2]

template<typename Key , typename T >
std::map<Key, T> turi::map_intersect ( const std::map< Key, T > &  a,
const std::map< Key, T > &  b 
)

Computes the intersection of two maps

Definition at line 308 of file stl_util.hpp.

◆ map_intersect() [2/2]

template<typename Key , typename T >
std::map<Key, T> turi::map_intersect ( const std::map< Key, T > &  m,
const std::set< Key > &  keys 
)

Returns the entries of a map whose keys show up in the set keys

Definition at line 325 of file stl_util.hpp.

◆ map_union()

template<typename Key , typename T >
std::map<Key, T> turi::map_union ( const std::map< Key, T > &  a,
const std::map< Key, T > &  b 
)

Computes the union of two maps

Definition at line 292 of file stl_util.hpp.

◆ operator<<() [1/2]

template<typename T >
boost::enable_if_c<boost::is_output_streamable<T>::value, std::ostream&>::type turi::operator<< ( std::ostream &  out,
const std::set< T > &  s 
)

Writes a human representation of the set to the supplied stream.

Definition at line 197 of file stl_util.hpp.

◆ operator<<() [2/2]

template<typename T >
boost::enable_if_c<boost::is_output_streamable<T>::value, std::ostream&>::type turi::operator<< ( std::ostream &  out,
const std::vector< T > &  v 
)

Writes a human representation of a vector to the supplied stream.

Definition at line 207 of file stl_util.hpp.

◆ pad_number()

std::string turi::pad_number ( const size_t  number,
const size_t  npad,
const char  pad_value = '0' 
)
inline

Returns a string representation of the number, padded to 'npad' characters using the pad_value character

Definition at line 481 of file stl_util.hpp.

◆ rekey()

template<typename OldKey , typename NewKey , typename T >
std::map<NewKey, T> turi::rekey ( const std::map< OldKey, T > &  map,
const std::map< OldKey, NewKey > &  key_map 
)

Transform each key in the map using the key_map transformation. The resulting map will have the form output[key_map[i]] = map[i]

Definition at line 248 of file stl_util.hpp.

◆ remap() [1/2]

template<typename Key , typename OldT , typename NewT >
std::map<Key, NewT> turi::remap ( const std::map< Key, OldT > &  map,
const std::map< OldT, NewT > &  val_map 
)

Transform each key in the map using the key_map transformation. The resulting map will have the form output[i] = remap[map[i]]

Definition at line 265 of file stl_util.hpp.

◆ remap() [2/2]

template<typename Key , typename T >
void turi::remap ( std::map< Key, T > &  map,
const std::map< T, T > &  val_map 
)

Inplace version of remap

Definition at line 279 of file stl_util.hpp.

◆ safe_get() [1/2]

template<typename Key , typename T >
const T& turi::safe_get ( const std::map< Key, T > &  map,
const Key &  key 
)

constant lookup in a map. assertion failure of key not found in map

Definition at line 219 of file stl_util.hpp.

◆ safe_get() [2/2]

template<typename Key , typename T >
const T turi::safe_get ( const std::map< Key, T > &  map,
const Key &  key,
const T  default_value 
)

constant lookup in a map. If key is not found in map, 'default_value' is returned. Note that this can't return a reference and must return a copy

Definition at line 233 of file stl_util.hpp.

◆ set_difference() [1/2]

template<typename T >
std::set<T> turi::set_difference ( const std::set< T > &  a,
const std::set< T > &  b 
)

computes the difference of two sets.

Definition at line 91 of file stl_util.hpp.

◆ set_difference() [2/2]

template<typename T >
std::set<T> turi::set_difference ( const std::set< T > &  a,
const T &  b 
)

Subtract a value from a set

Definition at line 104 of file stl_util.hpp.

◆ set_disjoint()

template<typename T >
bool turi::set_disjoint ( const std::set< T > &  a,
const std::set< T > &  b 
)

Returns true if the two sets are disjoint

Definition at line 127 of file stl_util.hpp.

◆ set_equal()

template<typename T >
bool turi::set_equal ( const std::set< T > &  a,
const std::set< T > &  b 
)

Returns true if the two sets are equal

Definition at line 135 of file stl_util.hpp.

◆ set_intersect()

template<typename T >
std::set<T> turi::set_intersect ( const std::set< T > &  a,
const std::set< T > &  b 
)

computes the intersect of two sets.

Definition at line 79 of file stl_util.hpp.

◆ set_partition()

template<typename T >
std::pair<std::set<T>,std::set<T> > turi::set_partition ( const std::set< T > &  s,
const std::set< T > &  partition 
)

Partitions a set with a different set. Returns 2 sets: <s in partition, s not in partition>

Definition at line 116 of file stl_util.hpp.

◆ set_union() [1/2]

template<typename T >
std::set<T> turi::set_union ( const std::set< T > &  a,
const std::set< T > &  b 
)

computes the union of two sets.

Definition at line 57 of file stl_util.hpp.

◆ set_union() [2/2]

template<typename T >
std::set<T> turi::set_union ( const std::set< T > &  a,
const T &  b 
)

computes the union of a set and a value.

Definition at line 69 of file stl_util.hpp.

◆ strsplit()

std::vector<std::string> turi::strsplit ( const std::string &  str,
const std::string &  splitchars,
const bool  auto_trim = false 
)
inline

Using splitchars as delimiters, splits the string into a vector of strings. if auto_trim is true, trim() is called on all the extracted strings before returning.

Definition at line 505 of file stl_util.hpp.

◆ tostr()

template<typename T >
std::string turi::tostr ( const T &  t)

Convenience function for using std streams to convert anything to a string

Definition at line 459 of file stl_util.hpp.

◆ trim()

std::string turi::trim ( const std::string &  str)
inline

Removes white space (space and tabs) from the beginning and end of str, returning the resultant string

Definition at line 448 of file stl_util.hpp.

◆ values() [1/3]

template<typename Key , typename T >
std::set<T> turi::values ( const std::map< Key, T > &  map)

Gets the values from a map

Definition at line 386 of file stl_util.hpp.

◆ values() [2/3]

template<typename Key , typename T >
std::vector<T> turi::values ( const std::map< Key, T > &  m,
const std::set< Key > &  keys 
)

Gets a subset of values from a map

Definition at line 399 of file stl_util.hpp.

◆ values() [3/3]

template<typename Key , typename T >
std::vector<T> turi::values ( const std::map< Key, T > &  m,
const std::vector< Key > &  keys 
)

Gets a subset of values from a map

Definition at line 413 of file stl_util.hpp.