mCRL2
Loading...
Searching...
No Matches
sequence_algorithm.h
Go to the documentation of this file.
1// Author(s): Wieger Wesselink
2// Copyright: see the accompanying file COPYING or copy at
3// https://github.com/mCRL2org/mCRL2/blob/master/COPYING
4//
5// Distributed under the Boost Software License, Version 1.0.
6// (See accompanying file LICENSE_1_0.txt or copy at
7// http://www.boost.org/LICENSE_1_0.txt)
8//
11
12#ifndef MCRL2_DATA_DETAIL_SEQUENCE_ALGORITHM_H
13#define MCRL2_DATA_DETAIL_SEQUENCE_ALGORITHM_H
14
15#include <algorithm>
16#include <iterator>
17#include <set>
18#include <vector>
19
20namespace mcrl2
21{
22
23namespace data
24{
25
26namespace detail
27{
28
33template <typename Iterator>
34bool sequence_contains_duplicates(Iterator first, Iterator last)
35{
36 // TODO: this implementation is not particularly efficient
37 std::set<typename std::iterator_traits<Iterator>::value_type> s(first, last);
38 return s.size() < static_cast <std::size_t>(std::distance(first, last));
39}
40
47template <typename Iterator1, typename Iterator2>
48bool sequences_do_overlap(Iterator1 first1, Iterator1 last1, Iterator2 first2, Iterator2 last2)
49{
50 typedef typename std::iterator_traits<Iterator1>::value_type value_type;
51 std::set<value_type> s1(first1, last1);
52 std::set<value_type> s2(first2, last2);
53 std::vector<value_type> intersection;
54 std::set_intersection(s1.begin(), s1.end(), s2.begin(), s2.end(), std::back_inserter(intersection));
55 return !intersection.empty();
56}
57
63template <typename Iterator, typename T>
64bool sequence_is_subset_of_set(Iterator first, Iterator last, const std::set<T>& s)
65{
66 for (Iterator i = first; i != last; ++i)
67 {
68 if (s.find(*i) == s.end())
69 {
70 return false;
71 }
72 }
73 return true;
74}
75
79template <class Container>
80std::set<typename Container::value_type> make_set(const Container& c)
81{
82 std::set<typename Container::value_type> result;
83 std::copy(c.begin(), c.end(), std::inserter(result, result.begin()));
84 return result;
85}
86
91template <typename Sequence>
92bool sequence_empty_intersection(Sequence s1, Sequence s2)
93{
94 for (typename Sequence::const_iterator i = s1.begin(); i != s1.end(); ++i)
95 {
96 if (std::find(s2.begin(), s2.end(), *i) != s2.end())
97 {
98 return false;
99 }
100 }
101 return true;
102}
103
104} // namespace detail
105
106} // namespace data
107
108} // namespace mcrl2
109
110#endif // MCRL2_DATA_DETAIL_SEQUENCE_ALGORITHM_H
bool empty() const
Returns true if the term has no arguments.
Definition aterm.h:158
bool sequence_empty_intersection(Sequence s1, Sequence s2)
Determines if the unordered sequences s1 and s2 have an empty intersection.
bool sequence_contains_duplicates(Iterator first, Iterator last)
Returns true if the sequence [first, last) contains duplicates.
bool sequence_is_subset_of_set(Iterator first, Iterator last, const std::set< T > &s)
Returns true if all elements of the range [first, last) are element of the set s.
bool sequences_do_overlap(Iterator1 first1, Iterator1 last1, Iterator2 first2, Iterator2 last2)
Returns true if the two sequences [first1, last1) and [first2, last2) have a non empty intersection.
std::set< typename Container::value_type > make_set(const Container &c)
Makes a set of the given container.
A class that takes a linear process specification and checks all tau-summands of that LPS for conflue...
Definition indexed_set.h:72