• 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

4.35
/src/base/lrucache.hpp
1
/*
2
 * File:   lrucache.hpp
3
 * Author: Alexander Ponomarev
4
 *
5
 * Created on June 20, 2013, 5:09 PM
6
 */
7

8
#ifndef _LRUCACHE_HPP_INCLUDED_
9
#define _LRUCACHE_HPP_INCLUDED_
10

11
#include <cstddef>
12
#include <list>
13
#include <map>
14
#include <optional>
15
#include <stdexcept>
16

17
namespace cache {
18

19
template<typename key_t, typename value_t>
20
class lru_cache {
21
public:
22
    typedef typename std::pair<key_t, value_t> key_value_pair_t;
23
    typedef typename std::list<key_value_pair_t>::iterator list_iterator_t;
24

25
    lru_cache(size_t max_size) : _max_size(max_size) {}
579✔
26

UNCOV
27
    void put(const key_t& key, const value_t& value)
×
28
    {
UNCOV
29
        auto it = _cache_items_map.find(key);
×
UNCOV
30
        _cache_items_list.push_front(key_value_pair_t(key, value));
×
UNCOV
31
        if (it != _cache_items_map.end()) {
×
32
            _cache_items_list.erase(it->second);
×
33
            _cache_items_map.erase(it);
×
34
        }
UNCOV
35
        _cache_items_map[key] = _cache_items_list.begin();
×
36

UNCOV
37
        if (_cache_items_map.size() > _max_size) {
×
38
            auto last = _cache_items_list.end();
×
39
            last--;
×
40
            _cache_items_map.erase(last->first);
×
41
            _cache_items_list.pop_back();
×
42
        }
43
    }
44

UNCOV
45
    std::optional<value_t> get(const key_t& key)
×
46
    {
UNCOV
47
        auto it = _cache_items_map.find(key);
×
UNCOV
48
        if (it == _cache_items_map.end()) {
×
UNCOV
49
            return std::nullopt;
×
50
        }
51

UNCOV
52
        _cache_items_list.splice(
×
UNCOV
53
            _cache_items_list.begin(), _cache_items_list, it->second);
×
UNCOV
54
        return it->second->second;
×
55
    }
56

57
    bool exists(const key_t& key) const
58
    {
59
        return _cache_items_map.find(key) != _cache_items_map.end();
60
    }
61

62
    size_t size() const { return _cache_items_map.size(); }
63

64
    void set_max_size(size_t max_size) { this->_max_size = max_size; }
65

UNCOV
66
    void clear()
×
67
    {
UNCOV
68
        this->_cache_items_map.clear();
×
UNCOV
69
        this->_cache_items_list.clear();
×
70
    }
71

72
private:
73
    std::list<key_value_pair_t> _cache_items_list;
74
    std::map<key_t, list_iterator_t> _cache_items_map;
75
    size_t _max_size;
76
};
77

78
}  // namespace cache
79

80
#endif /* _LRUCACHE_HPP_INCLUDED_ */
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