Class RingBuffer<T>
A circular buffer collection.
Implements
Inherited Members
Namespace: KSharpPlus
Assembly: KSharpPlus.dll
Syntax
public class RingBuffer<T>
Type Parameters
Name | Description |
---|---|
T | Type of elements within this ring buffer. |
Constructors
| Improve this Doc View SourceRingBuffer(Int32)
Creates a new ring buffer with specified size.
Declaration
public RingBuffer(int size)
Parameters
Type | Name | Description |
---|---|---|
Int32 | size | Size of the buffer to create. |
Properties
| Improve this Doc View SourceCapacity
Gets the capacity of this ring buffer.
Declaration
public int Capacity { get; protected set; }
Property Value
Type | Description |
---|---|
Int32 |
Count
Gets the number of items in this ring buffer.
Declaration
public int Count { get; }
Property Value
Type | Description |
---|---|
Int32 |
CurrentIndex
Gets the current index of the buffer items.
Declaration
public int CurrentIndex { get; protected set; }
Property Value
Type | Description |
---|---|
Int32 |
IsReadOnly
Gets whether this ring buffer is read-only.
Declaration
public bool IsReadOnly { get; }
Property Value
Type | Description |
---|---|
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 |
---|---|
Boolean | Whether the buffer contains the item. |
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 |
---|---|---|
Func<T, Boolean> | predicate | Predicate used to check for the item. |
Returns
Type | Description |
---|---|
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. |
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.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 |
---|---|
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 |
---|---|---|
Func<T, Boolean> | predicate | Predicate used to find the item. |
Returns
Type | Description |
---|---|
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 |
---|---|---|
Func<T, 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 |
---|---|
Boolean | Whether an item that matches the predicate was found or not. |
Explicit Interface Implementations
| Improve this Doc View SourceIEnumerable.GetEnumerator()
Returns an enumerator for this ring buffer.
Declaration
IEnumerator IEnumerable.GetEnumerator()
Returns
Type | Description |
---|---|
IEnumerator | Enumerator for this ring buffer. |