• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

tstack / lnav / 17589970077-2502

09 Sep 2025 05:00PM UTC coverage: 65.196% (-5.0%) from 70.225%
17589970077-2502

push

github

tstack
[format] add fields for source file/line

Knowing the source file/line context in a log
message can help find log messages when using
log2src.

56 of 70 new or added lines in 2 files covered. (80.0%)

13954 existing lines in 210 files now uncovered.

45516 of 69814 relevant lines covered (65.2%)

404154.37 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

86.21
/src/base/map_util.hh
1
/**
2
 * Copyright (c) 2023, Timothy Stack
3
 *
4
 * All rights reserved.
5
 *
6
 * Redistribution and use in source and binary forms, with or without
7
 * modification, are permitted provided that the following conditions are met:
8
 *
9
 * * Redistributions of source code must retain the above copyright notice, this
10
 * list of conditions and the following disclaimer.
11
 * * Redistributions in binary form must reproduce the above copyright notice,
12
 * this list of conditions and the following disclaimer in the documentation
13
 * and/or other materials provided with the distribution.
14
 * * Neither the name of Timothy Stack nor the names of its contributors
15
 * may be used to endorse or promote products derived from this software
16
 * without specific prior written permission.
17
 *
18
 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ''AS IS'' AND ANY
19
 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
20
 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
21
 * DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE FOR ANY
22
 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
23
 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
24
 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
25
 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
26
 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
27
 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28
 */
29

30
#ifndef lnav_map_util_hh
31
#define lnav_map_util_hh
32

33
#include <functional>
34
#include <map>
35
#include <optional>
36
#include <type_traits>
37
#include <vector>
38

39
namespace lnav::map {
40

41
template<typename C>
42
std::optional<std::conditional_t<
43
    std::is_trivially_copyable_v<typename C::mapped_type>,
44
    typename C::mapped_type,
45
    std::reference_wrapper<std::conditional_t<std::is_const_v<C>,
46
                                              const typename C::mapped_type,
47
                                              typename C::mapped_type>>>>
48
find(C& container, const typename C::key_type& key)
130✔
49
{
50
    auto iter = container.find(key);
130✔
51
    if (iter != container.end()) {
130✔
52
        return std::make_optional(std::ref(iter->second));
12✔
53
    }
54

55
    return std::nullopt;
118✔
56
}
57

58
template<typename K, typename V, typename M = std::map<K, V>>
59
M
60
from_vec(const std::vector<std::pair<K, V>>& container)
61
{
62
    M retval;
63

64
    for (const auto& elem : container) {
65
        retval[elem.first] = elem.second;
66
    }
67

68
    return retval;
69
}
70

71
template<typename K, typename V>
72
class small : public std::vector<std::pair<K, V>> {
73
public:
74
    auto insert(const K& key, const V& value)
996✔
75
    {
76
        auto pos = this->begin();
996✔
77

78
        while (pos != this->end() && pos->first < key) {
996✔
UNCOV
79
            ++pos;
×
80
        }
81
        return this->emplace(pos, std::make_pair(key, value));
996✔
82
    }
83

84
    auto find(const K& key)
2,988✔
85
    {
86
        auto retval = this->begin();
2,988✔
87

88
        while (retval != this->end()
2,988✔
89
               && (retval->first < key || key < retval->first))
2,988✔
90
        {
UNCOV
91
            ++retval;
×
92
        }
93

94
        return retval;
2,988✔
95
    }
96

97
    auto find(const K& key) const
2,023✔
98
    {
99
        auto retval = this->begin();
2,023✔
100

101
        while (retval != this->end()
2,023✔
102
               && (retval->first < key || key < retval->first))
2,023✔
103
        {
UNCOV
104
            ++retval;
×
105
        }
106

107
        return retval;
2,023✔
108
    }
109

110
    V& operator[](const K& key)
1,992✔
111
    {
112
        auto iter = this->find(key);
1,992✔
113
        if (iter != this->end()) {
1,992✔
114
            return iter->second;
×
115
        }
116

117
        this->emplace_back(key, V{});
1,992✔
118

119
        return this->back().second;
1,992✔
120
    }
996✔
121
};
122

123
}  // namespace lnav::map
124

125
#endif
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc