Diffusion .NET Client Library  6.1.5
 All Classes Namespaces Functions Variables Enumerations Enumerator Properties Events Pages
PushTechnology.ClientInterface.Collections.CircularBuffer< TValue > Class Template Reference

The fixed-size first-in-first-out (FIFO) collection of instances of the same specified type. More...

Inheritance diagram for PushTechnology.ClientInterface.Collections.CircularBuffer< TValue >:

Public Member Functions

 CircularBuffer (int capacity)
 Creates a new CircularBuffer{TValue}. More...
 
void Push (TValue value)
 Inserts an object at the end of the buffer. More...
 
TValue Pop ()
 Removes and returns the object at the beginning of the buffer. More...
 
void Clear ()
 Removes all objects from the buffer. More...
 
void CopyTo (TValue[] array, int offset)
 Copies the buffer to an existing one-dimensional Array, starting at the specified array index. More...
 
IEnumerator< TValue > GetEnumerator ()
 Returns an enumerator that iterates through the buffer. More...
 

Public Attributes

int Count => ( buffer.Length + head - tail ) % buffer.Length
 Returns the number of objects in the buffer. More...
 
int Capacity => buffer.Length - 1
 Returns the number of objects that fit into the buffer. More...
 
object SyncRoot => syncRoot.Value
 Returns the object that can be used to synchronize access to the buffer. More...
 
bool IsSynchronized => false
 Gets Returns the value indicating whether access to the buffer is synchronized (thread safe). More...
 

Detailed Description

The fixed-size first-in-first-out (FIFO) collection of instances of the same specified type.

A circular buffer is a data structure that uses a single, fixed-size buffer as if it were connected end-to-end. This structure lends itself easily to buffering data streams.

Template Parameters
TValueThe type of elements in the buffer.

Constructor & Destructor Documentation

PushTechnology.ClientInterface.Collections.CircularBuffer< TValue >.CircularBuffer ( int  capacity)

Creates a new CircularBuffer{TValue}.

Parameters
capacityThe number of objects this buffer can hold.
Exceptions
ArgumentOutOfRangeExceptionThe given capacity is negative.

Member Function Documentation

void PushTechnology.ClientInterface.Collections.CircularBuffer< TValue >.Clear ( )

Removes all objects from the buffer.

Count is set to zero, and references to other objects from elements of the collection are also released. The Capacity remains unchanged.

This method is an O(n) operation, where n is Count.

void PushTechnology.ClientInterface.Collections.CircularBuffer< TValue >.CopyTo ( TValue[]  array,
int  offset 
)

Copies the buffer to an existing one-dimensional Array, starting at the specified array index.

The elements are copied onto the array in first-in-first-out (FIFO) order, similar to the order of the elements returned by a succession of calls to Pop.

Parameters
arrayThe one-dimensional Array that is the destination of the elements copied from the buffer. The Array must have zero-based indexing.
offsetThe zero-based index in array at which copying begins.
Exceptions
ArgumentNullExceptionThe array is null.
ArgumentOutOfRangeExceptionThe given offset is negative or bigger than the given array . The given array is too small to hold all objects within the buffer.
IEnumerator<TValue> PushTechnology.ClientInterface.Collections.CircularBuffer< TValue >.GetEnumerator ( )

Returns an enumerator that iterates through the buffer.

Returns
The enumerator that can be used to iterate through the buffer.
TValue PushTechnology.ClientInterface.Collections.CircularBuffer< TValue >.Pop ( )

Removes and returns the object at the beginning of the buffer.

The returned objects are in first-in-first-out (FIFO) order. If type TValue is a reference type, null can be pushed onto the buffer as a placeholder, if needed. The buffer is implemented as an array. This method is an O(1) operation.

Returns
The object removed from the beginning of the buffer.
Exceptions
InvalidOperationExceptionThe buffer is empty.
void PushTechnology.ClientInterface.Collections.CircularBuffer< TValue >.Push ( TValue  value)

Inserts an object at the end of the buffer.

If Count already equals the Capacity, the previously pushed objects are overwritten, starting from the beginning of the buffer. The beginning of the buffer is then moved to the next object in the buffer. Therefore the buffer can never hold more items than the given Capacity.

The buffer is implemented as an array. This method is an O(1) operation.

Parameters
valueThe object to push onto the buffer. The value can be null for reference types.

Member Data Documentation

int PushTechnology.ClientInterface.Collections.CircularBuffer< TValue >.Capacity => buffer.Length - 1

Returns the number of objects that fit into the buffer.

int PushTechnology.ClientInterface.Collections.CircularBuffer< TValue >.Count => ( buffer.Length + head - tail ) % buffer.Length

Returns the number of objects in the buffer.

bool PushTechnology.ClientInterface.Collections.CircularBuffer< TValue >.IsSynchronized => false

Gets Returns the value indicating whether access to the buffer is synchronized (thread safe).

Always returns false because this implementation is not thread-safe.

object PushTechnology.ClientInterface.Collections.CircularBuffer< TValue >.SyncRoot => syncRoot.Value

Returns the object that can be used to synchronize access to the buffer.


The documentation for this class was generated from the following file: