LCOV - code coverage report
Current view: top level - utilities/include/mcrl2/utilities/detail - join.h (source / functions) Hit Total Coverage
Test: mcrl2_coverage.info.cleaned Lines: 13 13 100.0 %
Date: 2020-02-13 00:44:47 Functions: 15 21 71.4 %
Legend: Lines: hit not hit

          Line data    Source code
       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             : //
       9             : /// \file mcrl2/utilities/detail/join.h
      10             : /// \brief Generic join and split functions.
      11             : 
      12             : #ifndef MCRL2_UTILITIES_DETAIL_JOIN_H
      13             : #define MCRL2_UTILITIES_DETAIL_JOIN_H
      14             : 
      15             : namespace mcrl2
      16             : {
      17             : 
      18             : namespace utilities
      19             : {
      20             : 
      21             : namespace detail
      22             : {
      23             : 
      24             : /// \brief Splits a binary tree T into a sequence, and writes the result to the output range
      25             : /// given by an output iterator.
      26             : /// \param t The tree that has to be split.
      27             : /// \param i The output iterator.
      28             : /// \param match If this functions returns true in a node, the node will be split.
      29             : /// \param lhs Function for getting the left subtree of a node.
      30             : /// \param rhs Function for getting the right subtree of a node.
      31             : template <typename T, typename OutputIterator, typename MatchFunction, typename AccessorFunction1, typename AccessorFunction2>
      32       21900 : void split(const T& t, OutputIterator i, MatchFunction match, AccessorFunction1 lhs, AccessorFunction2 rhs)
      33             : {
      34       21900 :   if (match(t))
      35             :   {
      36        8291 :     split(lhs(t), i, match, lhs, rhs);
      37        8291 :     split(rhs(t), i, match, lhs, rhs);
      38             :   }
      39             :   else
      40             :   {
      41       13609 :     *i++ = t;
      42             :   }
      43       21900 : }
      44             : 
      45             : /// \brief Given a sequence [t1, t2, ..., tn] of elements of type T, returns
      46             : /// op(t1, op(t2, ...), tn)))).
      47             : /// \param empty_sequence_result The value that is returned when the sequence is empty.
      48             : /// \param first [first, last) is the range of elements.
      49             : /// \param last
      50             : /// \param op An operator
      51             : /// \return The joined sequence
      52             : template <typename T, typename FwdIt, typename BinaryOperation>
      53        4958 : T join(FwdIt first, FwdIt last, BinaryOperation op, T empty_sequence_result)
      54             : {
      55        4958 :   if (first == last)
      56             :   {
      57        1051 :     return empty_sequence_result;
      58             :   }
      59        7814 :   T result = *first++;
      60       16477 :   while (first != last)
      61             :   {
      62        6285 :     result = op(result, *first++);
      63             :   }
      64        3907 :   return result;
      65             : }
      66             : 
      67             : } // namespace detail
      68             : 
      69             : } // namespace utilities
      70             : 
      71             : } // namespace mcrl2
      72             : 
      73             : #endif // MCRL2_UTILITIES_DETAIL_JOIN_H

Generated by: LCOV version 1.13