Skip to content
API Documentation
BastionGuard™
fastfilter::LRUCache Struct Reference

#include <fast_filter.h>

Public Member Functions

 LRUCache (size_t c=100000)
bool get (uint64_t k, bool &out)
void put (uint64_t k, bool v)

Public Attributes

size_t cap
std::list< uint64_t > order
std::unordered_map< uint64_t, std::pair< bool, std::list< uint64_t >::iterator > > map

Detailed Description

Definition at line 138 of file fast_filter.h.

Constructor & Destructor Documentation

◆ LRUCache()

fastfilter::LRUCache::LRUCache ( size_t c = 100000)
inlineexplicit

Definition at line 140 of file fast_filter.h.

140: cap(c){}

References cap.

Member Function Documentation

◆ get()

bool fastfilter::LRUCache::get ( uint64_t k,
bool & out )
inline

Definition at line 141 of file fast_filter.h.

141{ auto it = map.find(k); if(it==map.end()) return false; order.erase(it->second.second); order.push_front(k); it->second.second = order.begin(); out = it->second.first; return true; }
std::unordered_map< uint64_t, std::pair< bool, std::list< uint64_t >::iterator > > map
std::list< uint64_t > order

References map, and order.

Referenced by fastfilter::Engine::check_url().

◆ put()

void fastfilter::LRUCache::put ( uint64_t k,
bool v )
inline

Definition at line 142 of file fast_filter.h.

142{ auto it = map.find(k); if(it!=map.end()){ it->second.first=v; order.erase(it->second.second); order.push_front(k); it->second.second=order.begin(); return;} if(map.size()>=cap){ uint64_t ev = order.back(); order.pop_back(); map.erase(ev);} order.push_front(k); map.emplace(k, std::make_pair(v, order.begin())); }

References cap, map, and order.

Referenced by fastfilter::Engine::check_url().

Member Data Documentation

◆ cap

size_t fastfilter::LRUCache::cap

Definition at line 139 of file fast_filter.h.

Referenced by LRUCache(), and put().

◆ map

std::unordered_map<uint64_t, std::pair<bool,std::list<uint64_t>::iterator> > fastfilter::LRUCache::map

Definition at line 139 of file fast_filter.h.

Referenced by get(), and put().

◆ order

std::list<uint64_t> fastfilter::LRUCache::order

Definition at line 139 of file fast_filter.h.

Referenced by get(), and put().


The documentation for this struct was generated from the following file: