LCOV - code coverage report
Current view: top level - gcc/rust/util - bi-map.h (source / functions) Coverage Total Hit
Test: gcc.info Lines: 92.9 % 14 13
Test Date: 2025-11-01 14:47:10 Functions: 77.8 % 9 7
Legend: Lines: hit not hit | Branches: + taken - not taken # not executed Branches: - 0 0

             Branch data     Line data    Source code
       1                 :             : // Copyright (C) 2020-2025 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                 :             : #include "optional.h"
      21                 :             : 
      22                 :             : #ifndef BIMAP_H
      23                 :             : #define BIMAP_H
      24                 :             : 
      25                 :             : // very simple bi-directional hashmap
      26                 :             : template <typename K, typename V> class BiMap
      27                 :             : {
      28                 :             : public:
      29                 :       13500 :   BiMap (std::unordered_map<K, V> &&original) : map (std::move (original))
      30                 :             :   {
      31                 :      648000 :     for (auto &kv : map)
      32                 :     1269000 :       rmap.insert ({kv.second, kv.first});
      33                 :       13500 :   }
      34                 :             : 
      35                 :        7629 :   const tl::optional<const V &> lookup (const K &key) const
      36                 :             :   {
      37                 :        7629 :     auto itr = map.find (key);
      38                 :        7629 :     if (itr == map.end ())
      39                 :          30 :       return tl::nullopt;
      40                 :             : 
      41                 :        7599 :     return itr->second;
      42                 :             :   }
      43                 :       79770 :   const tl::optional<const K &> lookup (const V &key) const
      44                 :             :   {
      45                 :       79770 :     auto itr = rmap.find (key);
      46                 :       79770 :     if (itr == rmap.end ())
      47                 :           0 :       return tl::nullopt;
      48                 :             : 
      49                 :       79770 :     return itr->second;
      50                 :             :   }
      51                 :             : 
      52                 :             : private:
      53                 :             :   std::unordered_map<K, V> map;
      54                 :             :   std::unordered_map<V, K> rmap;
      55                 :             : };
      56                 :             : 
      57                 :             : #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.