22 #include <boost/intrusive/list.hpp> 23 #include <boost/intrusive/unordered_set.hpp> 24 #include <boost/iterator/iterator_adaptor.hpp> 25 #include <boost/utility.hpp> 96 class THash = std::hash<TKey>,
97 class TKeyEqual = std::equal_to<TKey>>
103 struct KeyValueEqual;
104 typedef boost::intrusive::link_mode<boost::intrusive::safe_link>
link_mode;
105 typedef boost::intrusive::unordered_set<
107 boost::intrusive::hash<KeyHasher>,
108 boost::intrusive::equal<KeyValueEqual>>
111 typedef std::pair<const TKey, TValue>
TPair;
117 template <
typename Value,
typename TIterator>
119 iterator_base<Value, TIterator>,
122 boost::bidirectional_traversal_tag> {
128 return this->base_reference()->pr;
133 typedef iterator_base<TPair, typename NodeList::iterator>
iterator;
134 typedef iterator_base<const TPair, typename NodeList::const_iterator>
136 typedef iterator_base<TPair, typename NodeList::reverse_iterator>
138 typedef iterator_base<const TPair, typename NodeList::const_reverse_iterator>
155 std::size_t clearSize = 1,
156 const THash& keyHash = THash(),
157 const TKeyEqual& keyEqual = TKeyEqual())
193 void setMaxSize(
size_t maxSize, PruneHookCall pruneHook =
nullptr) {
194 if (maxSize != 0 && maxSize <
size()) {
226 TValue&
get(
const TKey& key) {
229 throw_exception<std::out_of_range>(
"Key does not exist");
241 iterator
find(
const TKey& key) {
247 lru_.push_front(*it);
261 throw_exception<std::out_of_range>(
"Key does not exist");
267 auto const& cThis = *
this;
268 return const_cast<TValue&
>(cThis.getWithoutPromotion(key));
299 std::unique_ptr<Node> nptr(node);
300 lru_.erase(
lru_.iterator_to(*node));
318 PruneHookCall pruneHook =
nullptr) {
324 lru_.push_front(*it);
327 auto node =
new Node(key,
std::move(value));
329 lru_.push_front(*node);
354 void clear(PruneHookCall pruneHook =
nullptr) {
379 void prune(std::size_t pruneSize, PruneHookCall pruneHook =
nullptr) {
427 struct Node :
public boost::intrusive::unordered_set_base_hook<link_mode>,
428 public boost::intrusive::list_base_hook<link_mode> {
429 Node(
const TKey& key, TValue&& value)
430 : pr(
std::make_pair(key,
std::
move(value))) {}
437 return hash(node.
pr.first);
448 return equal(lhs, rhs.
pr.first);
451 return equal(lhs.
pr.first, rhs);
454 return equal(lhs.
pr.first, rhs.
pr.first);
470 typename NodeMap::const_iterator
findInIndex(
const TKey& key)
const {
481 std::size_t pruneSize,
482 PruneHookCall pruneHook,
484 auto& ph = (
nullptr == pruneHook) ?
pruneHook_ : pruneHook;
486 for (std::size_t
i = 0;
i < pruneSize && !
lru_.empty();
i++) {
487 auto* node = &(*
lru_.rbegin());
488 std::unique_ptr<Node> nptr(node);
490 lru_.erase(
lru_.iterator_to(*node));
494 ph(node->pr.first,
std::move(node->pr.second));
Node(const TKey &key, TValue &&value)
std::size_t operator()(const Node &node) const
boost::intrusive::unordered_set< Node, boost::intrusive::hash< KeyHasher >, boost::intrusive::equal< KeyValueEqual > > NodeMap
std::size_t nIndexBuckets_
std::hash< std::string > hasher
bool exists(const TKey &key) const
const_reverse_iterator crend() const
constexpr detail::Map< Move > move
size_t getMaxSize() const
const_iterator end() const
TValue & get(const TKey &key)
bool erase(const TKey &key)
—— Concurrent Priority Queue Implementation ——
EvictingCacheMap & operator=(const EvictingCacheMap &)=delete
Value & dereference() const
TValue & getWithoutPromotion(const TKey &key)
bool operator()(const TKey &lhs, const Node &rhs) const
FOLLY_PUSH_WARNING RHS rhs
EvictingCacheMap(std::size_t maxSize, std::size_t clearSize=1, const THash &keyHash=THash(), const TKeyEqual &keyEqual=TKeyEqual())
NodeMap::bucket_traits indexTraits_
const_iterator findWithoutPromotion(const TKey &key) const
iterator_base< TPair, typename NodeList::iterator > iterator
bool Value(const T &value, M matcher)
const_iterator cbegin() const
boost::intrusive::link_mode< boost::intrusive::safe_link > link_mode
const_reverse_iterator rend() const
SSL_SESSION * mapped_type
bool operator()(const Node &lhs, const Node &rhs) const
boost::intrusive::list< Node > NodeList
bool operator()(const Node &lhs, const TKey &rhs) const
std::unique_ptr< typename NodeMap::bucket_type[]> indexBuckets_
NodeMap::const_iterator findInIndex(const TKey &key) const
KeyHasher(const THash &keyHash)
iterator_base< const TPair, typename NodeList::const_reverse_iterator > const_reverse_iterator
iterator_base< TPair, typename NodeList::reverse_iterator > reverse_iterator
void setMaxSize(size_t maxSize, PruneHookCall pruneHook=nullptr)
iterator_base< const TPair, typename NodeList::const_iterator > const_iterator
iterator findWithoutPromotion(const TKey &key)
iterator find(const TKey &key)
void prune(std::size_t pruneSize, PruneHookCall pruneHook=nullptr)
const_reverse_iterator rbegin() const
const_iterator begin() const
uint64_t value(const typename LockFreeRingBuffer< T, Atom >::Cursor &rbcursor)
const_iterator cend() const
iterator_base(TIterator it)
reverse_iterator rbegin()
void clear(PruneHookCall pruneHook=nullptr)
void setClearSize(size_t clearSize)
const TValue & getWithoutPromotion(const TKey &key) const
void pruneWithFailSafeOption(std::size_t pruneSize, PruneHookCall pruneHook, bool failSafe)
std::function< void(TKey, TValue &&)> PruneHookCall
std::pair< const TKey, TValue > TPair
NodeMap::iterator findInIndex(const TKey &key)
KeyValueEqual(const TKeyEqual &keyEqual)
const_reverse_iterator crbegin() const
void setPruneHook(PruneHookCall pruneHook)
static const std::size_t kMinNumIndexBuckets
std::size_t operator()(const TKey &key) const