LCOV - code coverage report
Current view: top level - lts/include/mcrl2/lts/detail - bithashtable.h (source / functions) Hit Total Coverage
Test: mcrl2_coverage.info.cleaned Lines: 2 20 10.0 %
Date: 2020-07-11 00:44:39 Functions: 2 7 28.6 %
Legend: Lines: hit not hit

          Line data    Source code
       1             : // Author(s): Muck van Weerdenburg
       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/lts/bithashtable.h
      10             : 
      11             : #ifndef MCRL2_LTS_DETAIL_BITHASHTABLE_H
      12             : #define MCRL2_LTS_DETAIL_BITHASHTABLE_H
      13             : 
      14             : #include "mcrl2/lps/next_state_generator.h"
      15             : 
      16             : namespace mcrl2
      17             : {
      18             : namespace lts
      19             : {
      20             : 
      21         187 : class bit_hash_table
      22             : {
      23             :   private:
      24             :     std::vector < bool > m_bit_hash_table;
      25             :     std::unordered_map<std::size_t, std::size_t> m_number_translator;
      26             : 
      27           0 :     std::size_t calc_hash(const lps::state& state)
      28             :     {
      29             :       std::hash<atermpp::aterm> hasher;
      30           0 :       return hasher(state) % m_bit_hash_table.size();
      31             :     }
      32             : 
      33             :   public:
      34         187 :     bit_hash_table()=default;
      35             : 
      36           0 :     bit_hash_table(const std::size_t size) :
      37           0 :       m_bit_hash_table(size,false)
      38           0 :     {};
      39             : 
      40             : 
      41           0 :     void add_states(lps::next_state_generator::transition_t::state_probability_list states)
      42             :     {
      43           0 :       for(lps::next_state_generator::transition_t::state_probability_list::const_iterator i=states.begin(); i!=states.end(); ++i)
      44             :       {
      45           0 :         add_state(i->state());
      46             :       }
      47           0 :     }
      48             : 
      49           0 :     std::pair<std::size_t, bool> add_state(const lps::state& state)
      50             :     {
      51           0 :       std::size_t i = calc_hash(state);
      52           0 :       bool is_new = !m_bit_hash_table[i];
      53           0 :       if (is_new)
      54             :       { 
      55           0 :         m_bit_hash_table[i] = true;
      56           0 :         std::size_t new_index=m_number_translator.size();
      57           0 :         m_number_translator[i]=new_index;
      58           0 :         return std::pair<std::size_t, bool>(new_index, true);
      59             :       }
      60             :       else
      61             :       {
      62           0 :         return std::pair<std::size_t, bool>(m_number_translator.at(i), false);
      63             :       }
      64             :     }
      65             : 
      66             :     std::size_t state_index(const lps::state& state)
      67             :     {
      68             :       assert(m_bit_hash_table[calc_hash(state)]);
      69             :       return m_number_translator.at(calc_hash(state));
      70             :     }
      71             : };
      72             : 
      73             : 
      74             : }
      75             : }
      76             : 
      77             : #endif // MCRL2_LTS_DETAIL_BITHASHTABLE_H
      78             : 

Generated by: LCOV version 1.13