Debian Codegraph @

src/3rdParty/lru-cache/include/lru/key-statistics.hpp

raw
1 /// The MIT License (MIT)
2 /// Copyright (c) 2016 Peter Goldsborough
3 ///
4 /// Permission is hereby granted, free of charge, to any person obtaining a copy
5 /// of this software and associated documentation files (the "Software"), to
6 /// deal in the Software without restriction, including without limitation the
7 /// rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
8 /// sell copies of the Software, and to permit persons to whom the Software is
9 /// furnished to do so, subject to the following conditions:
10 ///
11 /// The above copyright notice and this permission notice shall be included in
12 /// all copies or substantial portions of the Software.
13 ///
14 /// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15 /// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16 /// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17 /// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18 /// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
19 /// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
20 /// IN THE SOFTWARE.
21
22
23 #ifndef LRU_KEY_STATISTICS_HPP
24 #define LRU_KEY_STATISTICS_HPP
25
26 #include <cstddef>
27
28 namespace LRU {
29
30 /// Stores statistics for a single key.
31 ///
32 /// The statistics stored are the total number of hits and the total number of
33 /// misses. The total number of acccesses (the sum of hits and misses) may be
34 /// accessed as well.
35 struct KeyStatistics {
36 using size_t = std::size_t;
37
38 /// Constructor.
39 ///
40 /// \param hits_ The initial number of hits for the key.
41 /// \param misses_ The initial number of misses for the key.
42 explicit KeyStatistics(size_t hits_ = 0, size_t misses_ = 0)
43 : hits(hits_), misses(misses_) {
44 }
45
46 /// \returns The total number of accesses made for the key.
47 /// \details This is the sum of the hits and misses.
48 size_t accesses() const noexcept {
49 return hits + misses;
50 }
51
52 /// Resets the statistics for a key (sets them to zero).
53 void reset() {
54 hits = 0;
55 misses = 0;
56 }
57
58 /// The number of hits for the key.
59 size_t hits;
60
61 /// The number of misses for the key.
62 size_t misses;
63 };
64
65 } // namespace LRU
66
67 #endif // LRU_KEY_STATISTICS_HPP