PeanutButter
Loading...
Searching...
No Matches
PeanutButter.Utils.MostRecentlyUsedList< T > Class Template Reference

Holds a list of most-recently-used items, up to the provided capacity. New items displace the older ones, and re-adding the same item will reposition that item at the top of the list. More...

Inheritance diagram for PeanutButter.Utils.MostRecentlyUsedList< T >:

Public Member Functions

 MostRecentlyUsedList (int capacity)
 Holds a list of most-recently-used items, up to the provided capacity. New items displace the older ones, and re-adding the same item (test is via .Equals) will reposition that item at the top of the list.
void Add (T item)
 Adds an item to the collection. If the capacity of the collection is exceeded, the last-used value will be evicted.
bool Contains (T item)
 Tests if the provided item is in the list.
IEnumerator< T > GetEnumerator ()

Properties

int Capacity [get]
 The capacity of this list. Once this is reached, adding new items will evict older ones.

Detailed Description

Holds a list of most-recently-used items, up to the provided capacity. New items displace the older ones, and re-adding the same item will reposition that item at the top of the list.

Object equality testing is via .GetHashCode(), for performance reasons - so primitives will "just work", but your own types will require you to implement .GetHashCode() (and .Equals() for completeness' sake) so that the internal dictionary can properly index by the object)

MostRecentlyUsedList<T> is not thread-safe: if you plan on accessing this (read or write) from multiple threads, you must lock it yourself.

Template Parameters
T

Member Function Documentation

◆ Add()

void PeanutButter.Utils.MostRecentlyUsedList< T >.Add ( T item)

Adds an item to the collection. If the capacity of the collection is exceeded, the last-used value will be evicted.

Parameters
item

◆ Contains()

bool PeanutButter.Utils.MostRecentlyUsedList< T >.Contains ( T item)

Tests if the provided item is in the list.

Parameters
item
Returns

The documentation for this class was generated from the following file:
  • source/Utils/PeanutButter.Utils/MostRecentlyUsed.cs