LCOV - code coverage report
Current view: top level - atermpp/include/mcrl2/atermpp - set_operations.h (source / functions) Hit Total Coverage
Test: mcrl2_coverage.info.cleaned Lines: 15 19 78.9 %
Date: 2020-09-16 00:45:56 Functions: 3 3 100.0 %
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/atermpp/set_operations.h
      10             : /// \brief Set operations on term lists.
      11             : 
      12             : #ifndef MCRL2_ATERMPP_SET_OPERATIONS_H
      13             : #define MCRL2_ATERMPP_SET_OPERATIONS_H
      14             : 
      15             : #include "mcrl2/atermpp/aterm_list.h"
      16             : 
      17             : namespace atermpp
      18             : {
      19             : 
      20             : /// \brief Returns the union of v and w.
      21             : /// \param v A term list.
      22             : /// \param w A term list.
      23             : /// \return The union of the term lists, interpreted as sets.
      24             : template <typename Term>
      25           1 : term_list<Term> term_list_union(const term_list<Term>& v, const term_list<Term>& w)
      26             : {
      27           1 :   if (v.empty())
      28             :   {
      29           0 :     return w;
      30             :   }
      31           1 :   if (w.empty())
      32             :   {
      33           0 :     return v;
      34             :   }
      35           2 :   std::set<Term> result;
      36           1 :   result.insert(v.begin(), v.end());
      37           1 :   result.insert(w.begin(), w.end());
      38           1 :   return term_list<Term>(result.begin(), result.end());
      39             : }
      40             : 
      41             : /// \brief Returns v minus w.
      42             : /// \param v A term list.
      43             : /// \param w A term list.
      44             : /// \return The difference of the term lists, interpreted as sets.
      45             : template <typename Term>
      46           7 : term_list<Term> term_list_difference(const term_list<Term>& v, const term_list<Term>& w)
      47             : {
      48           7 :   if (w.empty())
      49             :   {
      50           0 :     return v;
      51             :   }
      52           7 :   if (v.empty())
      53             :   {
      54           0 :     return v;
      55             :   }
      56          14 :   std::set<Term> result;
      57           7 :   result.insert(v.begin(), v.end());
      58          15 :   for (typename term_list<Term>::const_iterator i = w.begin(); i != w.end(); ++i)
      59             :   {
      60           8 :     result.erase(*i);
      61             :   }
      62           7 :   return term_list<Term>(result.begin(), result.end());
      63             : }
      64             : 
      65             : } // namespace atermpp
      66             : 
      67             : #endif // MCRL2_ATERMPP_SET_OPERATIONS_H

Generated by: LCOV version 1.13