LCOV - code coverage report
Current view: top level - data/include/mcrl2/data/detail/rewrite - nfs_array.h (source / functions) Hit Total Coverage
Test: mcrl2_coverage.info.cleaned Lines: 15 15 100.0 %
Date: 2020-09-16 00:45:56 Functions: 4 4 100.0 %
Legend: Lines: hit not hit

          Line data    Source code
       1             : // Author(s): Sjoerd Cranen, Jan Friso Groote
       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/data/detail/rewrite/nfs_array.h
      10             : /// \brief This is an array in which it is recorded which arguments 
      11             : ///        are normal forms and which are not.
      12             : 
      13             : #ifndef MCRL2_DATA_NFS_ARRAY_H
      14             : #define MCRL2_DATA_NFS_ARRAY_H
      15             : 
      16             : #include <cstddef>
      17             : #include <cstring>
      18             : #include <cassert>
      19             : #include <vector>
      20             : 
      21             : 
      22             : namespace mcrl2
      23             : {
      24             : namespace data
      25             : {
      26             : namespace detail
      27             : {
      28             : 
      29        1277 : class nfs_array : public std::vector<bool>
      30             : {
      31             : public:
      32        1277 :   nfs_array(std::size_t size)
      33        1277 :     : std::vector<bool>(size, false)
      34        1277 :   { }
      35             : 
      36         233 :   void fill(bool val = true)
      37             :   {
      38         233 :     assign(size(), val);
      39         233 :   }
      40             : 
      41             :   ///
      42             :   /// \brief next iterates to the next combination of booleans (in terms of bit vectors:
      43             :   ///        if the nfs_array represents integer i, it computes i + 1).
      44             :   /// \return true if the operation was successful, false if an overflow occurred (i.e.,
      45             :   ///        if the bit vector was is_filled(), in which case after calling next(), it is
      46             :   ///        is_clear().
      47             :   ///
      48             :   bool next()
      49             :   {
      50             :     std::size_t index = 0;
      51             :     while (index < size())
      52             :     {
      53             :       if (at(index))
      54             :       {
      55             :         at(index) = false;
      56             :         ++index;
      57             :       }
      58             :       else
      59             :       {
      60             :         at(index) = true;
      61             :         return true;
      62             :       }
      63             :     }
      64             :     return false;
      65             :   }
      66             : 
      67         310 :   operator std::size_t() const
      68             :   {
      69         310 :     assert(8 * sizeof(std::size_t) > size());
      70         310 :     std::size_t result = 0;
      71         310 :     std::size_t mask = 1;
      72         900 :     for (std::size_t i = 0; i < size(); ++i, mask <<= 1)
      73             :     {
      74         590 :       if (at(i))
      75             :       {
      76         590 :         result |= mask;
      77             :       }
      78             :     }
      79         310 :     return result;
      80             :   }
      81             : 
      82             :   bool is_clear() const
      83             :   {
      84             :     for(std::vector<bool>::const_iterator i=begin(); i!=end(); ++i)
      85             :     {
      86             :       if (*i)
      87             :       {
      88             :         return false;
      89             :       }
      90             :     }
      91             :     return true;
      92             :   }
      93             : 
      94             :   bool is_filled() const
      95             :   {
      96             :     for(std::vector<bool>::const_iterator i=begin(); i!=end(); ++i)
      97             :     {
      98             :       if (!*i)
      99             :       {
     100             :         return false;
     101             :       }
     102             :     }
     103             :     return true;
     104             :   }
     105             : };
     106             : 
     107             : }
     108             : }
     109             : }
     110             : 
     111             : #endif // MCRL2_DATA_NFS_ARRAY_H

Generated by: LCOV version 1.13