LCOV - code coverage report
Current view: top level - atermpp/include/mcrl2/atermpp/standard_containers - indexed_set.h (source / functions) Hit Total Coverage
Test: mcrl2_coverage.info.cleaned Lines: 15 15 100.0 %
Date: 2024-05-01 03:37:31 Functions: 10 11 90.9 %
Legend: Lines: hit not hit

          Line data    Source code
       1             : // Author(s): 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             : #ifndef MCRL2_ATERMPP_INDEXED_SET_H
      10             : #define MCRL2_ATERMPP_INDEXED_SET_H
      11             : 
      12             : #include "mcrl2/atermpp/detail/thread_aterm_pool.h"
      13             : #include "mcrl2/atermpp/standard_containers/deque.h"
      14             : #include "mcrl2/utilities/detail/container_utility.h"
      15             : #include "mcrl2/utilities/indexed_set.h"
      16             : #include "mcrl2/utilities/shared_mutex.h"
      17             : 
      18             : 
      19             : namespace atermpp
      20             : {
      21             : 
      22             : /// \brief A set that assigns each element an unique index, and protects its internal terms en masse.
      23             : template<typename Key,
      24             :          bool ThreadSafe = false,
      25             :          typename Hash = std::hash<Key>,
      26             :          typename Equals = std::equal_to<Key>,
      27             :          typename Allocator = std::allocator<Key>,
      28             :          typename KeyTable = atermpp::deque<Key > >
      29             : class indexed_set: public mcrl2::utilities::indexed_set<Key, ThreadSafe, Hash, Equals, Allocator, KeyTable>
      30             : {
      31             :   typedef mcrl2::utilities::indexed_set<Key, ThreadSafe, Hash, Equals, Allocator, KeyTable> super;
      32             : 
      33             : public:
      34             :   typedef typename super::size_type size_type;
      35             : 
      36             :   /// \brief Constructor of an empty indexed set. Starts with a hashtable of size 128.
      37          83 :   indexed_set()
      38          83 :   {}
      39             : 
      40             :   /// \brief Constructor of an empty indexed set. Starts with a hashtable of size 128.
      41         339 :   indexed_set(std::size_t number_of_threads)
      42         339 :     : super(number_of_threads)
      43         339 :   {}
      44             : 
      45             :   /// \brief Constructor of an empty index set. Starts with a hashtable of the indicated size. 
      46             :   /// \param initial_hashtable_size The initial size of the hashtable.
      47             :   /// \param hash The hash function.
      48             :   /// \param equals The comparison function for its elements.
      49             : 
      50             :   indexed_set(std::size_t number_of_threads,
      51             :               std::size_t initial_hashtable_size,
      52             :               const typename super::hasher& hash = typename super::hasher(),
      53             :               const typename super::key_equal& equals = typename super::key_equal()) 
      54             :     : super(number_of_threads, initial_hashtable_size, hash, equals)
      55             :   {}
      56             :   
      57         210 :   void clear(std::size_t thread_index=0)
      58             :   {
      59         210 :     mcrl2::utilities::shared_guard guard = detail::g_thread_term_pool().lock_shared();
      60         210 :     super::clear(thread_index);
      61         210 :   }
      62             : 
      63       14613 :   std::pair<size_type, bool> insert(const Key& key, std::size_t thread_index=0)
      64             :   {
      65       14613 :     mcrl2::utilities::shared_guard guard = detail::g_thread_term_pool().lock_shared();
      66       29226 :     return super::insert(key, thread_index);
      67       14613 :   }
      68             : };
      69             : 
      70             : } // end namespace atermppp
      71             : 
      72             : namespace mcrl2 {
      73             : 
      74             : namespace utilities {
      75             : 
      76             : namespace detail {
      77             : 
      78             : // Specialization of a function defined in mcrl2/utilities/detail/container_utility.h.
      79             : // In utilities, atermpp is not known. 
      80             : template<typename Key,
      81             :          bool ThreadSafe = false,
      82             :          typename Hash = std::hash<Key>,
      83             :          typename Equals = std::equal_to<Key>,
      84             :          typename Allocator = std::allocator<Key>,
      85             :          typename KeyTable = atermpp::deque<Key > >
      86        5733 : bool contains(const atermpp::indexed_set<Key, ThreadSafe, Hash, Equals, Allocator, KeyTable>& c, 
      87             :               const typename atermpp::indexed_set<Key, ThreadSafe, Hash, Equals, Allocator, KeyTable>::key_type& v,
      88             :               const std::size_t thread_index=0)
      89             : {
      90        5733 :   return c.find(v, thread_index) != c.end(thread_index);
      91             : }
      92             : 
      93             : } // namespace detail
      94             : 
      95             : } // namespace utilities
      96             : 
      97             : } // namespace mcrl2
      98             : 
      99             : 
     100             : 
     101             : #endif // MCRL2_ATERMPP_INDEXED_SET_H

Generated by: LCOV version 1.14