Class RingBuffer<T>
A circular buffer collection.
Inheritance
Namespace: DisCatSharp
Assembly: DisCatSharp.dll
Syntax
public class RingBuffer<T> : ICollection<T>, IEnumerable<T>, IEnumerable
Type Parameters
Name | Description |
---|---|
T | Type of elements within this ring buffer. |
Constructors
| Improve this Doc View SourceRingBuffer(IEnumerable<T>)
Creates a new ring buffer, filled with specified elements.
Declaration
public RingBuffer(IEnumerable<T> elements)
Parameters
Type | Name | Description |
---|---|---|
System.Collections.Generic.IEnumerable<T> | elements | Elements to fill the buffer with. |
Exceptions
Type | Condition |
---|---|
System.ArgumentException | |
System.ArgumentOutOfRangeException |
RingBuffer(IEnumerable<T>, Int32)
Creates a new ring buffer, filled with specified elements, and starting at specified index.
Declaration
public RingBuffer(IEnumerable<T> elements, int index)
Parameters
Type | Name | Description |
---|---|---|
System.Collections.Generic.IEnumerable<T> | elements | Elements to fill the buffer with. |
System.Int32 | index | Starting element index. |
Exceptions
Type | Condition |
---|---|
System.ArgumentException | |
System.ArgumentOutOfRangeException |
RingBuffer(Int32)
Creates a new ring buffer with specified size.
Declaration
public RingBuffer(int size)
Parameters
Type | Name | Description |
---|---|---|
System.Int32 | size | Size of the buffer to create. |
Exceptions
Type | Condition |
---|---|
System.ArgumentOutOfRangeException |
Properties
| Improve this Doc View SourceCapacity
Gets the capacity of this ring buffer.
Declaration
public int Capacity { get; protected set; }
Property Value
Type | Description |
---|---|
System.Int32 |
Count
Gets the number of items in this ring buffer.
Declaration
public int Count { get; }
Property Value
Type | Description |
---|---|
System.Int32 |
CurrentIndex
Gets the current index of the buffer items.
Declaration
public int CurrentIndex { get; protected set; }
Property Value
Type | Description |
---|---|
System.Int32 |
InternalBuffer
Gets or sets the internal collection of items.
Declaration
protected T[] InternalBuffer { get; set; }
Property Value
Type | Description |
---|---|
T[] |
IsReadOnly
Gets whether this ring buffer is read-only.
Declaration
public bool IsReadOnly { get; }
Property Value
Type | Description |
---|---|
System.Boolean |
Methods
| Improve this Doc View SourceAdd(T)
Inserts an item into this ring buffer.
Declaration
public void Add(T item)
Parameters
Type | Name | Description |
---|---|---|
T | item | Item to insert. |
Clear()
Clears this ring buffer and resets the current item index.
Declaration
public void Clear()
Contains(T)
Checks whether given item is present in the buffer. This method is not implemented. Use Contains(Func<T, Boolean>) instead.
Declaration
public bool Contains(T item)
Parameters
Type | Name | Description |
---|---|---|
T | item | Item to check for. |
Returns
Type | Description |
---|---|
System.Boolean | Whether the buffer contains the item. |
Exceptions
Type | Condition |
---|---|
System.NotImplementedException |
Contains(Func<T, Boolean>)
Checks whether given item is present in the buffer using given predicate to find it.
Declaration
public bool Contains(Func<T, bool> predicate)
Parameters
Type | Name | Description |
---|---|---|
System.Func<T, System.Boolean> | predicate | Predicate used to check for the item. |
Returns
Type | Description |
---|---|
System.Boolean | Whether the buffer contains the item. |
CopyTo(T[], Int32)
Copies this ring buffer to target array, attempting to maintain the order of items within.
Declaration
public void CopyTo(T[] array, int index)
Parameters
Type | Name | Description |
---|---|---|
T[] | array | Target array. |
System.Int32 | index | Index starting at which to copy the items to. |
GetEnumerator()
Returns an enumerator for this ring buffer.
Declaration
public IEnumerator<T> GetEnumerator()
Returns
Type | Description |
---|---|
System.Collections.Generic.IEnumerator<T> | Enumerator for this ring buffer. |
Remove(T)
Removes an item from the buffer. This method is not implemented. Use Remove(Func<T, Boolean>) instead.
Declaration
public bool Remove(T item)
Parameters
Type | Name | Description |
---|---|---|
T | item | Item to remove. |
Returns
Type | Description |
---|---|
System.Boolean | Whether an item was removed or not. |
Remove(Func<T, Boolean>)
Removes an item from the buffer using given predicate to find it.
Declaration
public bool Remove(Func<T, bool> predicate)
Parameters
Type | Name | Description |
---|---|---|
System.Func<T, System.Boolean> | predicate | Predicate used to find the item. |
Returns
Type | Description |
---|---|
System.Boolean | Whether an item was removed or not. |
TryGet(Func<T, Boolean>, out T)
Gets first item from the buffer that matches the predicate.
Declaration
public bool TryGet(Func<T, bool> predicate, out T item)
Parameters
Type | Name | Description |
---|---|---|
System.Func<T, System.Boolean> | predicate | Predicate used to find the item. |
T | item | Item that matches the predicate, or default value for the type of the items in this ring buffer, if one is not found. |
Returns
Type | Description |
---|---|
System.Boolean | Whether an item that matches the predicate was found or not. |