mCRL2
Loading...
Searching...
No Matches
join.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_UTILITIES_DETAIL_JOIN_H
13#define MCRL2_UTILITIES_DETAIL_JOIN_H
14
15#include <iterator>
16
17namespace mcrl2
18{
19
20namespace utilities
21{
22
23namespace detail
24{
25
33template <typename T, typename OutputIterator, typename MatchFunction, typename AccessorFunction1, typename AccessorFunction2>
34void split(const T& t, OutputIterator i, MatchFunction match, AccessorFunction1 lhs, AccessorFunction2 rhs)
35{
36 if (match(t))
37 {
38 split(lhs(t), i, match, lhs, rhs);
39 split(rhs(t), i, match, lhs, rhs);
40 }
41 else
42 {
43 *i++ = t;
44 }
45}
46
54template <typename T, typename FwdIt, typename BinaryOperation>
55T join(FwdIt first, FwdIt last, BinaryOperation op, T empty_sequence_result)
56{
57 if (first == last)
58 {
59 return empty_sequence_result;
60 }
61 T result = *first++;
62 while (first != last)
63 {
64 result = op(result, *first++);
65 }
66 return result;
67}
68
75template <typename T, typename RndIt, typename BinaryOperation>
76T join_balanced(RndIt first, RndIt last, BinaryOperation op)
77{
78 auto n = std::distance(first, last);
79 if (n == 1)
80 {
81 return *first;
82 }
83 if (n == 2)
84 {
85 return op(*first, *(first + 1));
86 }
87 auto d = n / 2;
88 auto left = join_balanced<T, RndIt, BinaryOperation>(first, first + d, op);
89 auto right = join_balanced<T, RndIt, BinaryOperation>(first + d, last, op);
90 return op(left, right);
91}
92
93} // namespace detail
94
95} // namespace utilities
96
97} // namespace mcrl2
98
99#endif // MCRL2_UTILITIES_DETAIL_JOIN_H
T join(FwdIt first, FwdIt last, BinaryOperation op, T empty_sequence_result)
Given a sequence [t1, t2, ..., tn] of elements of type T, returns op(t1, op(t2, .....
Definition join.h:55
T join_balanced(RndIt first, RndIt last, BinaryOperation op)
Given a non-empty sequence [t1, t2, ..., tn] of elements of type T, returns op(op(t1,...
Definition join.h:76
void split(const T &t, OutputIterator i, MatchFunction match, AccessorFunction1 lhs, AccessorFunction2 rhs)
Splits a binary tree T into a sequence, and writes the result to the output range given by an output ...
Definition join.h:34
A class that takes a linear process specification and checks all tau-summands of that LPS for conflue...
Definition indexed_set.h:72