hpx/cache/entries/lfu_entry.hpp#

See Public API for a list of names and headers that are part of the public HPX API.

namespace hpx
namespace util
namespace cache
namespace entries
template<typename Value>
class lfu_entry : public hpx::util::cache::entries::entry<Value, lfu_entry<Value>>#
#include <hpx/cache/entries/lfu_entry.hpp>

The lfu_entry type can be used to store arbitrary values in a cache. Using this type as the cache’s entry type makes sure that the least frequently used entries are discarded from the cache first.

Note

The lfu_entry conforms to the CacheEntry concept.

Note

This type can be used to model a ‘most frequently used’ cache policy if it is used with a std::greater as the caches’ UpdatePolicy (instead of the default std::less).

Template Parameters

Value – The data type to be stored in a cache. It has to be default constructible, copy constructible and less_than_comparable.

Public Functions

lfu_entry() = default#

Any cache entry has to be default constructible.

inline explicit lfu_entry(Value const &val) noexcept(std::is_nothrow_constructible_v<base_type, Value const&>)#

Construct a new instance of a cache entry holding the given value.

inline explicit lfu_entry(Value &&val) noexcept#

Construct a new instance of a cache entry holding the given value.

inline bool touch() noexcept#

The function touch is called by a cache holding this instance whenever it has been requested (touched).

In the case of the LFU entry we store the reference count tracking the number of times this entry has been requested. This which will be used to compare the age of an entry during the invocation of the operator<().

Returns

This function should return true if the cache needs to update it’s internal heap. Usually this is needed if the entry has been changed by touch() in a way influencing the sort order as mandated by the cache’s UpdatePolicy

inline constexpr unsigned long const &get_access_count() const noexcept#

Private Types

using base_type = entry<Value, lfu_entry<Value>>#

Private Members

unsigned long ref_count_ = 0#

Friends

inline friend bool operator<(lfu_entry const &lhs, lfu_entry const &rhs) noexcept#

Compare the ‘age’ of two entries. An entry is ‘older’ than another entry if it has been accessed less frequently (LFU).