| 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 |
#ifndef LRU_INTERNAL_DEFINITIONS_HPP |
| 23 |
#define LRU_INTERNAL_DEFINITIONS_HPP |
| 24 |
|
| 25 |
#include <chrono> |
| 26 |
#include <cstddef> |
| 27 |
#include <functional> |
| 28 |
#include <list> |
| 29 |
#include <tuple> |
| 30 |
#include <unordered_map> |
| 31 |
|
| 32 |
namespace LRU { |
| 33 |
namespace Internal { |
| 34 |
|
| 35 |
/// The default capacity for all caches. |
| 36 |
const std::size_t DEFAULT_CAPACITY = 128; |
| 37 |
|
| 38 |
/// The reference type use to store keys in the order queue. |
| 39 |
template <typename T> |
| 40 |
using Reference = std::reference_wrapper<T>; |
| 41 |
|
| 42 |
/// Compares two References for equality. |
| 43 |
/// |
| 44 |
/// This is necessary because `std::reference_wrapper` does not define any |
| 45 |
/// operator overloads. We do need them, however (e.g. for container |
| 46 |
/// comparison). |
| 47 |
/// |
| 48 |
/// \param first The first reference to compare. |
| 49 |
/// \param second The second reference to compare. |
| 50 |
template <typename T, typename U> |
| 51 |
bool operator==(const Reference<T>& first, const Reference<U>& second) { |
| 52 |
return first.get() == second.get(); |
| 53 |
} |
| 54 |
|
| 55 |
/// Compares two References for inequality. |
| 56 |
/// |
| 57 |
/// This is necessary because `std::reference_wrapper` does not define any |
| 58 |
/// operator overloads. We do need them, however (e.g. for container |
| 59 |
/// comparison). |
| 60 |
/// |
| 61 |
/// \param first The first reference to compare. |
| 62 |
/// \param second The second reference to compare. |
| 63 |
template <typename T, typename U> |
| 64 |
bool operator!=(const Reference<T>& first, const Reference<U>& second) { |
| 65 |
return !(first == second); |
| 66 |
} |
| 67 |
|
| 68 |
/// The default queue type used internally. |
| 69 |
template <typename T> |
| 70 |
using Queue = std::list<Reference<T>>; |
| 71 |
|
| 72 |
/// The default map type used internally. |
| 73 |
template <typename Key, |
| 74 |
typename Information, |
| 75 |
typename HashFunction, |
| 76 |
typename KeyEqual> |
| 77 |
using Map = std::unordered_map<Key, Information, HashFunction, KeyEqual>; |
| 78 |
|
| 79 |
/// The default clock used internally. |
| 80 |
using Clock = std::chrono::steady_clock; |
| 81 |
|
| 82 |
/// The default timestamp (time point) used internally. |
| 83 |
using Timestamp = Clock::time_point; |
| 84 |
} // namespace Internal |
| 85 |
} // namespace LRU |
| 86 |
|
| 87 |
|
| 88 |
#endif // LRU_INTERNAL_DEFINITIONS_HPP |