LCOV - code coverage report
Current view: top level - gcc/rust/util - bi-map.h (source / functions) Coverage Total Hit
Test: gcc.info Lines: 100.0 % 8 8
Test Date: 2024-04-27 14:03:13 Functions: 100.0 % 2 2
Legend: Lines: hit not hit | Branches: + taken - not taken # not executed Branches: - 0 0

             Branch data     Line data    Source code
       1                 :             : // Copyright (C) 2020-2024 Free Software Foundation, Inc.
       2                 :             : 
       3                 :             : // This file is part of GCC.
       4                 :             : 
       5                 :             : // GCC is free software; you can redistribute it and/or modify it under
       6                 :             : // the terms of the GNU General Public License as published by the Free
       7                 :             : // Software Foundation; either version 3, or (at your option) any later
       8                 :             : // version.
       9                 :             : 
      10                 :             : // GCC is distributed in the hope that it will be useful, but WITHOUT ANY
      11                 :             : // WARRANTY; without even the implied warranty of MERCHANTABILITY or
      12                 :             : // FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
      13                 :             : // for more details.
      14                 :             : 
      15                 :             : // You should have received a copy of the GNU General Public License
      16                 :             : // along with GCC; see the file COPYING3.  If not see
      17                 :             : // <http://www.gnu.org/licenses/>.
      18                 :             : 
      19                 :             : #include "rust-system.h"
      20                 :             : 
      21                 :             : #ifndef BIMAP_H
      22                 :             : #define BIMAP_H
      23                 :             : 
      24                 :             : // very simple bi-directional hashmap
      25                 :             : template <typename K, typename V> class BiMap
      26                 :             : {
      27                 :             :   using v_iter = typename std::unordered_map<K, V>::const_iterator;
      28                 :             :   using k_iter = typename std::unordered_map<V, K>::const_iterator;
      29                 :             : 
      30                 :             : public:
      31                 :        7394 :   BiMap (std::unordered_map<K, V> &&original) : map (std::move (original))
      32                 :             :   {
      33                 :      199638 :     for (auto &kv : map)
      34                 :      192244 :       rmap.insert ({kv.second, kv.first});
      35                 :        7394 :   }
      36                 :             : 
      37                 :         346 :   const v_iter lookup (const K &key) const { return map.find (key); }
      38                 :           7 :   const k_iter lookup (const V &key) const { return rmap.find (key); }
      39                 :             : 
      40                 :         346 :   bool is_iter_ok (const v_iter &iter) const { return iter != map.end (); }
      41                 :           7 :   bool is_iter_ok (const k_iter &iter) const { return iter != rmap.end (); }
      42                 :             : 
      43                 :             : private:
      44                 :             :   std::unordered_map<K, V> map;
      45                 :             :   std::unordered_map<V, K> rmap;
      46                 :             : };
      47                 :             : 
      48                 :             : #endif // !BIMAP_H
        

Generated by: LCOV version 2.1-beta

LCOV profile is generated on x86_64 machine using following configure options: configure --disable-bootstrap --enable-coverage=opt --enable-languages=c,c++,fortran,go,jit,lto,rust,m2 --enable-host-shared. GCC test suite is run with the built compiler.