10#ifndef MCRL2_UTILITIES_DETAIL_CONTAINER_UTILITY_H
11#define MCRL2_UTILITIES_DETAIL_CONTAINER_UTILITY_H
18#include <unordered_set>
29template <
typename Map>
30typename Map::mapped_type
map_element(
const Map& m,
const typename Map::key_type& key)
35 std::ostringstream out;
36 out <<
"missing key in map!";
43template <
typename Map>
44typename Map::mapped_type
mapped_value(
const Map& m,
const typename Map::key_type& key,
const typename Map::mapped_type& undefined_value)
51 return undefined_value;
56template <
typename Container>
57bool contains(
const Container& c,
const typename Container::value_type& v)
59 return std::find(c.begin(), c.end(), v) != c.end();
64bool contains(
const std::set<T>& c,
const typename std::set<T>::value_type& v)
66 return c.find(v) != c.end();
71bool contains(
const std::multiset<T>& c,
const typename std::multiset<T>::value_type& v)
73 return c.find(v) != c.end();
78bool contains(
const std::unordered_set<T>& c,
const typename std::set<T>::value_type& v)
80 return c.find(v) != c.end();
85template <
typename Key,
typename T>
86bool has_key(
const std::map<Key, T>& c,
const Key& v)
88 return c.find(v) != c.end();
93template <
typename Key,
typename T>
94bool has_key(
const std::multimap<Key, T>& c,
const Key& v)
96 return c.find(v) != c.end();
100template <
typename Container>
110template <
typename T,
typename Container>
113 for (
auto i = c.begin(); i != c.end(); ++i)
120template <
typename T,
typename Container>
123 for (
auto i = c.begin(); i != c.end(); ++i)
131template<
typename ContainerT,
typename PredicateT >
132void remove_if(ContainerT& items,
const PredicateT& predicate)
134 for (
auto it = items.begin(); it != items.end();)
138 it = items.erase(it);
148template <
typename InputIterator1,
typename InputIterator2>
151 while (first1 != last1 && first2 != last2)
153 if (*first1 < *first2)
157 else if (*first2 < *first1)
169template <
typename SetContainer1,
typename SetContainer2>
180std::set<T>
set_union(
const std::set<T>& x,
const std::set<T>& y)
183 std::set_union(x.begin(), x.end(), y.begin(), y.end(), std::inserter(result, result.begin()));
195 std::set_difference(x.begin(), x.end(), y.begin(), y.end(), std::inserter(result, result.begin()));
207 std::set_intersection(x.begin(), x.end(), y.begin(), y.end(), std::inserter(result, result.begin()));
218 return std::includes(x.begin(), x.end(), y.begin(), y.end());
225 return std::vector<T>(x.begin(), x.end());
229std::set<T>
as_set(
const std::vector<T>& x)
231 return std::set<T>(x.begin(), x.end());
Standard exception class for reporting runtime errors.
Exception classes for use in libraries and tools.
bool set_includes(const std::set< T > &x, const std::set< T > &y)
Returns if y is included in x.
void set_insert(std::set< T > &s, const Container &c)
std::set< T > set_union(const std::set< T > &x, const std::set< T > &y)
Returns the union of two sets.
bool contains(const atermpp::indexed_set< Key, ThreadSafe, Hash, Equals, Allocator, KeyTable > &c, const typename atermpp::indexed_set< Key, ThreadSafe, Hash, Equals, Allocator, KeyTable >::key_type &v, const std::size_t thread_index=0)
void set_remove(std::set< T > &s, const Container &c)
bool has_empty_intersection(InputIterator1 first1, InputIterator1 last1, InputIterator2 first2, InputIterator2 last2)
Returns true if the sorted ranges [first1, ..., last1) and [first2, ..., last2) have an empty interse...
Container::value_type pick_element(Container &v)
std::vector< T > as_vector(const std::set< T > &x)
bool has_key(const std::map< Key, T > &c, const Key &v)
Returns the value corresponding to the given key in the set m. If the key is not present,...
std::set< T > as_set(const std::vector< T > &x)
Map::mapped_type map_element(const Map &m, const typename Map::key_type &key)
Returns the value corresponding to the given key in the map m. If the key is not present,...
void remove_if(ContainerT &items, const PredicateT &predicate)
Map::mapped_type mapped_value(const Map &m, const typename Map::key_type &key, const typename Map::mapped_type &undefined_value)
std::set< T > set_intersection(const std::set< T > &x, const std::set< T > &y)
Returns the intersection of two sets.
std::set< T > set_difference(const std::set< T > &x, const std::set< T > &y)
Returns the difference of two sets.
A class that takes a linear process specification and checks all tau-summands of that LPS for conflue...