libmoost
moost::container::lru< Key, Data, HashFcn > Class Template Reference

an lru is a collection of keys and values, with a max size. Once the max size is reached, further inserted elements push out least recently used elements. More...

#include <lru.hpp>

List of all members.

Public Types

typedef lru_t::value_type value_type
typedef
lru_t::value_type::first_type 
key_type
typedef
lru_t::value_type::second_type 
mapped_type
typedef lru_t::iterator iterator
typedef lru_t::const_iterator const_iterator
typedef lru_t::reference reference
typedef lru_t::const_reference const_reference

Public Member Functions

 lru (size_t max_size=std::numeric_limits< size_t >::max())
 Constructs an lru.
void set_deleted_key (const key_type &deleted_key)
bool get (const key_type &key, mapped_type &value, bool bbump=true)
 Gets a value given a key. Returns false if not in lru.
void put (const key_type &key, const mapped_type &value, evict_func_t evict_func=evict_func_t())
void erase (const key_type &key)
 erase an element from the lru
bool peek (const key_type &key, mapped_type &value)
 gets a value from the lru but doesn't bump it
bool bump (const key_type &key)
bool exists (const key_type &key) const
const_iterator find (const key_type &key) const
iterator find (const key_type &key)
reference front ()
const_reference front () const
reference back ()
const_reference back () const
std::pair< iterator, bool > insert (const key_type &key, const mapped_type &value, evict_func_t evict_func=evict_func_t())
bool bump (iterator itr)
void erase (iterator it)
mapped_type const & operator[] (key_type const &key) const
mapped_typeoperator[] (key_type const &key)
void clear ()
 Clear the lru.
void purge ()
 Purge the lru.
size_t size () const
 Gets the number of elements in the lru.
bool empty () const
 Returns true if empty.
size_t max_size () const
 Gets the max number of elements in the lru.
iterator begin ()
 Gets the beginning of the lru.
const_iterator begin () const
 Gets the beginning of the lru.
iterator end ()
 Gets the end of the lru.
const_iterator end () const
 Gets the end of the lru.

Private Types

typedef std::list< std::pair
< Key, Data > > 
lru_t
typedef
google::sparse_hash_map
< key_type, iterator, HashFcn > 
hm_key_data
typedef boost::function< bool(key_type,
const mapped_type &value)> 
evict_func_t

Private Attributes

lru_t m_lru
hm_key_data m_key_data
size_t m_max_size

Detailed Description

template<class Key, typename Data, typename HashFcn = boost::hash<Key>>
class moost::container::lru< Key, Data, HashFcn >

an lru is a collection of keys and values, with a max size. Once the max size is reached, further inserted elements push out least recently used elements.

Note:
IMPORTANT: don't forget to set the deleted key if you expect anything with key = 0!!!!
IMPORTANT: it's NOT thread safe!

Definition at line 66 of file lru.hpp.


Member Typedef Documentation

template<class Key , typename Data , typename HashFcn = boost::hash<Key>>
typedef lru_t::const_iterator moost::container::lru< Key, Data, HashFcn >::const_iterator

Definition at line 77 of file lru.hpp.

template<class Key , typename Data , typename HashFcn = boost::hash<Key>>
typedef lru_t::const_reference moost::container::lru< Key, Data, HashFcn >::const_reference

Definition at line 79 of file lru.hpp.

template<class Key , typename Data , typename HashFcn = boost::hash<Key>>
typedef boost::function<bool(key_type, const mapped_type & value)> moost::container::lru< Key, Data, HashFcn >::evict_func_t [private]

Definition at line 83 of file lru.hpp.

template<class Key , typename Data , typename HashFcn = boost::hash<Key>>
typedef google::sparse_hash_map< key_type, iterator, HashFcn > moost::container::lru< Key, Data, HashFcn >::hm_key_data [private]

Definition at line 82 of file lru.hpp.

template<class Key , typename Data , typename HashFcn = boost::hash<Key>>
typedef lru_t::iterator moost::container::lru< Key, Data, HashFcn >::iterator

Definition at line 76 of file lru.hpp.

template<class Key , typename Data , typename HashFcn = boost::hash<Key>>
typedef lru_t::value_type::first_type moost::container::lru< Key, Data, HashFcn >::key_type

Definition at line 73 of file lru.hpp.

template<class Key , typename Data , typename HashFcn = boost::hash<Key>>
typedef std::list< std::pair< Key, Data > > moost::container::lru< Key, Data, HashFcn >::lru_t [private]

Definition at line 69 of file lru.hpp.

template<class Key , typename Data , typename HashFcn = boost::hash<Key>>
typedef lru_t::value_type::second_type moost::container::lru< Key, Data, HashFcn >::mapped_type

Definition at line 74 of file lru.hpp.

template<class Key , typename Data , typename HashFcn = boost::hash<Key>>
typedef lru_t::reference moost::container::lru< Key, Data, HashFcn >::reference

Definition at line 78 of file lru.hpp.

template<class Key , typename Data , typename HashFcn = boost::hash<Key>>
typedef lru_t::value_type moost::container::lru< Key, Data, HashFcn >::value_type

Definition at line 72 of file lru.hpp.


Constructor & Destructor Documentation

template<class Key , typename Data , typename HashFcn = boost::hash<Key>>
moost::container::lru< Key, Data, HashFcn >::lru ( size_t  max_size = std::numeric_limits<size_t>::max()) [inline]

Constructs an lru.

Definition at line 92 of file lru.hpp.


Member Function Documentation

template<class Key , typename Data , typename HashFcn = boost::hash<Key>>
reference moost::container::lru< Key, Data, HashFcn >::back ( ) [inline]

Definition at line 186 of file lru.hpp.

template<class Key , typename Data , typename HashFcn = boost::hash<Key>>
const_reference moost::container::lru< Key, Data, HashFcn >::back ( ) const [inline]

Definition at line 191 of file lru.hpp.

template<class Key , typename Data , typename HashFcn = boost::hash<Key>>
iterator moost::container::lru< Key, Data, HashFcn >::begin ( ) [inline]

Gets the beginning of the lru.

Definition at line 311 of file lru.hpp.

template<class Key , typename Data , typename HashFcn = boost::hash<Key>>
const_iterator moost::container::lru< Key, Data, HashFcn >::begin ( ) const [inline]

Gets the beginning of the lru.

Definition at line 317 of file lru.hpp.

template<class Key , typename Data , typename HashFcn = boost::hash<Key>>
bool moost::container::lru< Key, Data, HashFcn >::bump ( const key_type key) [inline]

Definition at line 146 of file lru.hpp.

Here is the call graph for this function:

Here is the caller graph for this function:

template<class Key , typename Data , typename HashFcn = boost::hash<Key>>
bool moost::container::lru< Key, Data, HashFcn >::bump ( iterator  itr) [inline]

Definition at line 242 of file lru.hpp.

template<class Key , typename Data , typename HashFcn = boost::hash<Key>>
void moost::container::lru< Key, Data, HashFcn >::clear ( ) [inline]

Clear the lru.

Definition at line 275 of file lru.hpp.

Here is the caller graph for this function:

template<class Key , typename Data , typename HashFcn = boost::hash<Key>>
bool moost::container::lru< Key, Data, HashFcn >::empty ( ) const [inline]

Returns true if empty.

Definition at line 299 of file lru.hpp.

template<class Key , typename Data , typename HashFcn = boost::hash<Key>>
iterator moost::container::lru< Key, Data, HashFcn >::end ( ) [inline]

Gets the end of the lru.

Definition at line 323 of file lru.hpp.

template<class Key , typename Data , typename HashFcn = boost::hash<Key>>
const_iterator moost::container::lru< Key, Data, HashFcn >::end ( ) const [inline]

Gets the end of the lru.

Definition at line 329 of file lru.hpp.

template<class Key , typename Data , typename HashFcn = boost::hash<Key>>
void moost::container::lru< Key, Data, HashFcn >::erase ( const key_type key) [inline]

erase an element from the lru

Definition at line 131 of file lru.hpp.

Here is the call graph for this function:

Here is the caller graph for this function:

template<class Key , typename Data , typename HashFcn = boost::hash<Key>>
void moost::container::lru< Key, Data, HashFcn >::erase ( iterator  it) [inline]

Definition at line 248 of file lru.hpp.

template<class Key , typename Data , typename HashFcn = boost::hash<Key>>
bool moost::container::lru< Key, Data, HashFcn >::exists ( const key_type key) const [inline]

Definition at line 156 of file lru.hpp.

Here is the call graph for this function:

template<class Key , typename Data , typename HashFcn = boost::hash<Key>>
const_iterator moost::container::lru< Key, Data, HashFcn >::find ( const key_type key) const [inline]

Definition at line 164 of file lru.hpp.

Here is the caller graph for this function:

template<class Key , typename Data , typename HashFcn = boost::hash<Key>>
iterator moost::container::lru< Key, Data, HashFcn >::find ( const key_type key) [inline]

Definition at line 170 of file lru.hpp.

template<class Key , typename Data , typename HashFcn = boost::hash<Key>>
reference moost::container::lru< Key, Data, HashFcn >::front ( ) [inline]

Definition at line 176 of file lru.hpp.

template<class Key , typename Data , typename HashFcn = boost::hash<Key>>
const_reference moost::container::lru< Key, Data, HashFcn >::front ( ) const [inline]

Definition at line 181 of file lru.hpp.

template<class Key , typename Data , typename HashFcn = boost::hash<Key>>
bool moost::container::lru< Key, Data, HashFcn >::get ( const key_type key,
mapped_type value,
bool  bbump = true 
) [inline]

Gets a value given a key. Returns false if not in lru.

Definition at line 106 of file lru.hpp.

Here is the call graph for this function:

template<class Key , typename Data , typename HashFcn = boost::hash<Key>>
std::pair<iterator, bool> moost::container::lru< Key, Data, HashFcn >::insert ( const key_type key,
const mapped_type value,
evict_func_t  evict_func = evict_func_t() 
) [inline]

Definition at line 196 of file lru.hpp.

Here is the call graph for this function:

Here is the caller graph for this function:

template<class Key , typename Data , typename HashFcn = boost::hash<Key>>
size_t moost::container::lru< Key, Data, HashFcn >::max_size ( ) const [inline]

Gets the max number of elements in the lru.

Definition at line 305 of file lru.hpp.

template<class Key , typename Data , typename HashFcn = boost::hash<Key>>
mapped_type const& moost::container::lru< Key, Data, HashFcn >::operator[] ( key_type const &  key) const [inline]

Definition at line 257 of file lru.hpp.

Here is the call graph for this function:

template<class Key , typename Data , typename HashFcn = boost::hash<Key>>
mapped_type& moost::container::lru< Key, Data, HashFcn >::operator[] ( key_type const &  key) [inline]

Definition at line 264 of file lru.hpp.

Here is the call graph for this function:

template<class Key , typename Data , typename HashFcn = boost::hash<Key>>
bool moost::container::lru< Key, Data, HashFcn >::peek ( const key_type key,
mapped_type value 
) [inline]

gets a value from the lru but doesn't bump it

Definition at line 140 of file lru.hpp.

template<class Key , typename Data , typename HashFcn = boost::hash<Key>>
void moost::container::lru< Key, Data, HashFcn >::purge ( ) [inline]

Purge the lru.

Definition at line 282 of file lru.hpp.

Here is the call graph for this function:

template<class Key , typename Data , typename HashFcn = boost::hash<Key>>
void moost::container::lru< Key, Data, HashFcn >::put ( const key_type key,
const mapped_type value,
evict_func_t  evict_func = evict_func_t() 
) [inline]

Puts a value into the lru, and evicts an old value if necessary. Any candidate for eviction is passed to the evict function, and only evicted if the function evaluates true

Definition at line 125 of file lru.hpp.

Here is the call graph for this function:

template<class Key , typename Data , typename HashFcn = boost::hash<Key>>
void moost::container::lru< Key, Data, HashFcn >::set_deleted_key ( const key_type deleted_key) [inline]

Definition at line 97 of file lru.hpp.

Here is the caller graph for this function:

template<class Key , typename Data , typename HashFcn = boost::hash<Key>>
size_t moost::container::lru< Key, Data, HashFcn >::size ( ) const [inline]

Gets the number of elements in the lru.

Definition at line 293 of file lru.hpp.


Member Data Documentation

template<class Key , typename Data , typename HashFcn = boost::hash<Key>>
hm_key_data moost::container::lru< Key, Data, HashFcn >::m_key_data [private]

Definition at line 86 of file lru.hpp.

template<class Key , typename Data , typename HashFcn = boost::hash<Key>>
lru_t moost::container::lru< Key, Data, HashFcn >::m_lru [private]

Definition at line 85 of file lru.hpp.

template<class Key , typename Data , typename HashFcn = boost::hash<Key>>
size_t moost::container::lru< Key, Data, HashFcn >::m_max_size [private]

Definition at line 87 of file lru.hpp.


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