Joutsen v0.5.0+12-g5dd5f7e
Classes | Public Member Functions | Protected Member Functions | Properties | List of all members
Joutsen.Collections.Generic.RingBuffer< ItemType > Class Template Reference

Classes

class  RingBufferEnumerator
 The enumerator implementation for the RingBuffer. More...
 

Public Member Functions

 RingBuffer (int capacity)
 Creates a new buffer with the given capacity. More...
 
 RingBuffer (SCG.IEnumerable< ItemType > enumerable, int capacity)
 Creates a new buffer with the given capacity and initial items. More...
 
ItemType Add (ItemType value)
 Adds a value to the buffer. More...
 
SCG.IEnumerable< ItemType > Add (SCG.IEnumerable< ItemType > values)
 Adds multpile values to the buffer. More...
 
bool RemoveLatest ()
 Removes the last added value in the buffer. More...
 
bool RemoveOldest ()
 Removes the oldest value in the buffer. More...
 
void Clear ()
 Clear the buffer of all values. More...
 
SCG.IEnumerator< ItemType > GetEnumerator ()
 Get an Enumerator to iterate over the values of the buffer. More...
 
override String ToString ()
 
- Public Member Functions inherited from Joutsen.Collections.Generic.Indexable< int, ItemType >
IndexType IndexOf (ItemType item)
 Fetches the index of an itemin the list. More...
 
IndexType IndexOf (ItemType item, IEqualityComparer< ItemType > comparer)
 Fetches the index of an item in the list using a custom comparer. More...
 
void Enqueue (ItemType item)
 Adds an item to the front of the queue. More...
 
void Enqueue (SCG.IEnumerable< ItemType > items)
 Adds a number of items to the front of the queue. More...
 
ItemType Dequeue ()
 Fetches and removes the last item in the queue. More...
 
ItemType Peek ()
 Fetches the last value in the queue without removing it. More...
 
void Clear ()
 Removes all the items from the Queue. More...
 
bool Contains (ItemType item, SCG.IEqualityComparer< ItemType > comparer)
 Checks if an item is part of the collection. More...
 
void Add (SCG.IEnumerable< ItemType > items)
 Adds multiple items to the collection. More...
 

Protected Member Functions

ItemType GetValueAt (int index)
 
void SetValueAt (int index, ItemType value)
 

Properties

int Capacity [get]
 The maximum number of values this buffer can contain. More...
 
int Count [get]
 The actual number of values this buffer contains. More...
 
ItemType this[int index] [get]
 Fetches the value at a certain position in the buffer. More...
 
- Properties inherited from Joutsen.Collections.Generic.Indexable< int, ItemType >
int Count [get]
 Determines the number of values in the list. More...
 
ItemType this[IndexType index] [get]
 Fetches the value associated with the index. More...
 
- Properties inherited from Joutsen.Collections.Generic.Queue< ItemType >
int Count [get]
 The number of elements in the queue. More...
 

Constructor & Destructor Documentation

◆ RingBuffer() [1/2]

Joutsen.Collections.Generic.RingBuffer< ItemType >.RingBuffer ( int  capacity)

Creates a new buffer with the given capacity.

Parameters
capacitythe number of values the buffer can contain without overwriting the oldest values

◆ RingBuffer() [2/2]

Joutsen.Collections.Generic.RingBuffer< ItemType >.RingBuffer ( SCG.IEnumerable< ItemType >  enumerable,
int  capacity 
)

Creates a new buffer with the given capacity and initial items.

Parameters
enumerablethe items that should be in the buffer initially. If the number of items exceeds the capacity the first items will be items will be replaced by the later ones
capacitythe number of values the buffer can contain without overwriting the oldest values

Member Function Documentation

◆ Add() [1/2]

ItemType Joutsen.Collections.Generic.RingBuffer< ItemType >.Add ( ItemType  value)

Adds a value to the buffer.

Parameters
valuethe value that is added
Returns
the value that was replaced by the new one if the capacity is exceeded, otherwise the default value for T

◆ Add() [2/2]

SCG.IEnumerable< ItemType > Joutsen.Collections.Generic.RingBuffer< ItemType >.Add ( SCG.IEnumerable< ItemType >  values)

Adds multpile values to the buffer.

Parameters
valuesthe values that are added. If the number of values exceeds the capacity the first items will be items will be replaced by the later ones
Returns
the values that were replaced by the new ones if the capacity is exceeded

Implements Joutsen.Collections.Generic.Collection< ItemType >.

◆ Clear()

void Joutsen.Collections.Generic.RingBuffer< ItemType >.Clear ( )

Clear the buffer of all values.

Implements Joutsen.Collections.Generic.Queue< ItemType >.

◆ GetEnumerator()

SCG.IEnumerator< ItemType > Joutsen.Collections.Generic.RingBuffer< ItemType >.GetEnumerator ( )

Get an Enumerator to iterate over the values of the buffer.

Remarks
The enumerator will iterate over the values starting at the oldest towards the latest.

◆ GetValueAt()

ItemType Joutsen.Collections.Generic.RingBuffer< ItemType >.GetValueAt ( int  index)
protected

◆ RemoveLatest()

bool Joutsen.Collections.Generic.RingBuffer< ItemType >.RemoveLatest ( )

Removes the last added value in the buffer.

◆ RemoveOldest()

bool Joutsen.Collections.Generic.RingBuffer< ItemType >.RemoveOldest ( )

Removes the oldest value in the buffer.

◆ SetValueAt()

void Joutsen.Collections.Generic.RingBuffer< ItemType >.SetValueAt ( int  index,
ItemType  value 
)
protected

◆ ToString()

override String Joutsen.Collections.Generic.RingBuffer< ItemType >.ToString ( )

Property Documentation

◆ Capacity

int Joutsen.Collections.Generic.RingBuffer< ItemType >.Capacity
get

The maximum number of values this buffer can contain.

◆ Count

int Joutsen.Collections.Generic.RingBuffer< ItemType >.Count
get

The actual number of values this buffer contains.

Implements Joutsen.Collections.Generic.Queue< ItemType >.

◆ this[int index]

ItemType Joutsen.Collections.Generic.RingBuffer< ItemType >.this[int index]
get

Fetches the value at a certain position in the buffer.

Parameters
indexthe position of the data to fetch
Remarks
The position of the data can be addressed with positive or negative values. Positive values starting at 0 will fetch a value counted from the front, a negative one from the back. E.g. in a buffer with 5 values (1,2,3,4,5), an index of 2 will fetch the third value (3) and an index of -2 will fetch the second from the back, in this case the forth value (4).