Skip to main content

Class CircularBuffer<T>

Represents a fixed-length circular (LIFO) buffer

Assembly: Meadow.Contracts.dll
View Source
Declaration
public class CircularBuffer<T> : IEnumerable<T>, IEnumerable

Implements:
System.Collections.Generic.IEnumerable<<T>>, System.Collections.IEnumerable

Properties

MaxElements

Gets the maximum number of elements the buffer can hold.

View Source
Declaration
public int MaxElements { get; }

ExceptOnOverrun

When set to true, overrun conditions will throw an exception. Default is false.

View Source
Declaration
public bool ExceptOnOverrun { get; set; }

ExceptOnUnderrun

When set to true, underrun conditions will throw an exception. Default is false.

View Source
Declaration
public bool ExceptOnUnderrun { get; set; }

HasOverrun

Returns true when an overrun condition has occurred.

View Source
Declaration
public bool HasOverrun { get; set; }

HasUnderrun

Returns true when an underrun condition has occurred.

View Source
Declaration
public bool HasUnderrun { get; set; }

IsFull

Returns true if the buffer's Count equals its MaxElements.

View Source
Declaration
public bool IsFull { get; }

Count

Gets the current count of elements in the buffer

View Source
Declaration
public int Count { get; }

HighWaterLevel

The HighWater event will fire when the buffer contains this many (or more) elements.

View Source
Declaration
public int HighWaterLevel { get; set; }

LowWaterLevel

The LowWater event will fire when the buffer contains this many (or less) elements.

View Source
Declaration
public int LowWaterLevel { get; set; }

this[int]

Returns an indexer for numeric index-based retrieval from the buffer

View Source
Declaration
public T this[int index] { get; }

Methods

Clear()

Empties all elements from the buffer

View Source
Declaration
public void Clear()

Append(IEnumerable<T>)

Appends a set of items to the buffer

View Source
Declaration
public void Append(IEnumerable<T> items)
Parameters
TypeNameDescription
System.Collections.Generic.IEnumerable<<T>>itemsthe items to append

Append(T[], int, int)

Appends a set of items to the buffer

View Source
Declaration
public void Append(T[] items, int offset, int count)
Parameters
TypeNameDescription
<T>[]itemsThe source for the items to append
System.Int32offsetThe offset into the source to begin the append
System.Int32countThe number of source items to append

Append(T)

Adds an element to the head of the buffer

View Source
Declaration
public void Append(T item)
Parameters
TypeName
<T>item

AppendWaitOne(int)

Synchronously waits for an item to be appended to the buffer

View Source
Declaration
public bool AppendWaitOne(int millisecondsTimeout)
Returns

System.Boolean

Parameters
TypeNameDescription
System.Int32millisecondsTimeoutThe amount of time to wait for an item to be appended

Remove()

Removes the element from the tail of the buffer, if one exists

View Source
Declaration
public T? Remove()
Returns

<T>

Peek()

Returns the element currently at the head of the buffer, if one exists, without removing it

View Source
Declaration
public T? Peek()
Returns

<T>

OnOverrun()

This method is called when a buffer overrun occurs

View Source
Declaration
public virtual void OnOverrun()

OnUnderrun()

This method is called when a buffer underrun occurs

View Source
Declaration
public virtual void OnUnderrun()

Last(Func<T, bool>, T?)

Find the next element that matches the provided function criteria starting with the head item.

View Source
Declaration
public T? Last(Func<T, bool> findFunction, T? defaultValue = default)
Returns

<T>

Parameters
TypeNameDescription
System.Func<<T>,System.Boolean>findFunction
<T>defaultValueThe value to return if find function finds nothing

First(Func<T, bool>, T?)

Find the next element that matches the provided function criteria starting with the tail item.

View Source
Declaration
public T? First(Func<T, bool> findFunction, T? defaultValue = default)
Returns

<T>

Parameters
TypeNameDescription
System.Func<<T>,System.Boolean>findFunction
<T>defaultValueThe value to return if find function finds nothing

Contains(T)

Determine if the buffer contains a specified value

View Source
Declaration
public bool Contains(T searchFor)
Returns

System.Boolean

Parameters
TypeName
<T>searchFor

Remove(int)

Removes the requested number of elements from the buffer

View Source
Declaration
public T?[] Remove(int count)
Returns

<T>[]

Parameters
TypeName
System.Int32count

MoveItemsTo(T[], int, int)

Removes items from the buffer and places them in a target array

View Source
Declaration
public int MoveItemsTo(T[] destination, int index, int count)
Returns

System.Int32: The actual number of items moved

Parameters
TypeNameDescription
<T>[]destinationThe destination array for the move
System.Int32indexThe beginning index of the destination
System.Int32countThe desired number of items to move

GetEnumerator()

Returns an enumerator that iterates through the collection.

View Source
Declaration
public IEnumerator<T> GetEnumerator()
Returns

System.Collections.Generic.IEnumerator<<T>>: An enumerator that can be used to iterate through the collection.## Events

ItemAdded

Event raised when an item is added to the buffer

View Source
Declaration
public event EventHandler ItemAdded
Event Type

System.EventHandler

Overrun

Fires when an element is added to the buffer when it is already full

View Source
Declaration
public event EventHandler Overrun
Event Type

System.EventHandler

Underrun

Fires when an attempt is made to remove an item from an empty buffer

View Source
Declaration
public event EventHandler Underrun
Event Type

System.EventHandler

HighWater

Fires when the number of elements reaches a non-zero HighWaterLevel value on an Enqueue call. This event fires only once when passing upward across the boundary.

View Source
Declaration
public event EventHandler HighWater
Event Type

System.EventHandler

LowWater

Fires when the number of elements reaches a non-zero LowWaterLevel value on a Remove call. This event fires only once when passing downward across the boundary.

View Source
Declaration
public event EventHandler LowWater
Event Type

System.EventHandler

Implements

  • System.Collections.Generic.IEnumerable<<T>>
  • System.Collections.IEnumerable

Extension Methods

  • System.Collections.Generic.IEnumerable{`0}.Meadow.ExtensionMethods.Contains``1({T}[])
  • System.Collections.Generic.IEnumerable{`0}.Meadow.ExtensionMethods.FirstIndexOf``1({T}[])