CircularBuffer

Ecng.Collections

Circular buffer. When writing to a full buffer: PushBack -> removes this[0] / Front() PushFront -> removes this[Size-1] / Back() this implementation is inspired by http://www.boost.org/doc/libs/1_53_0/libs/circular_buffer/doc/circular_buffer.html because I liked their interface.

Implementa: ICircularBuffer<T>, IList<T>, ICollection<T>, IEnumerable<T>, IEnumerable

Construtores

CircularBuffer
public CircularBuffer(int capacity)
circularBuffer = CircularBuffer(capacity)

Initializes a new instance of the CircularBuffer class.

capacity
Buffer capacity. Must be positive.
CircularBuffer
public CircularBuffer(int capacity, T[] items)
circularBuffer = CircularBuffer(capacity, items)

Initializes a new instance of the CircularBuffer class.

capacity
Buffer capacity. Must be positive.
items
Items to fill buffer with. Items length must be less than capacity. Suggestion: use Skip(x).Take(y).ToArray() to build this argument from any enumerable.

Propriedades

Capacity
public virtual int Capacity { get; set; }
value = circularBuffer.Capacity
circularBuffer.Capacity = value

Maximum capacity of the buffer.

Count
public int Count { get; }
value = circularBuffer.Count

Gets the number of cached assemblies.

Item
public virtual T Item { get; set; }
value = circularBuffer.Item
circularBuffer.Item = value

Gets the IPoint at the specified index, which merges the X,Y and higher order values into a single point

Métodos

Back
public T Back()
result = circularBuffer.Back()

Element at the back of the buffer - this[Size - 1].

Retorna: The value of the element of type T at the back of the buffer.

Clear
public virtual void Clear()
circularBuffer.Clear()

Clears all cached assemblies.

Decrement
private void Decrement(int index)
circularBuffer.Decrement(index)

Decrements the provided index variable by one, wrapping around if necessary.

index
Front
public T Front()
result = circularBuffer.Front()

Element at the front of the buffer - this[0].

Retorna: The value of the element of type T at the front of the buffer.

GetEnumerator
public IEnumerator<T> GetEnumerator()
result = circularBuffer.GetEnumerator()

Returns an enumerator that iterates through this buffer.

Retorna: An enumerator that can be used to iterate this collection.

Increment
private void Increment(int index)
circularBuffer.Increment(index)

Increments the provided index variable by one, wrapping around if necessary.

index
InternalIndex
private int InternalIndex(int index)
result = circularBuffer.InternalIndex(index)

Converts the index in the argument to an index in _buffer

index
External index.

Retorna: The transformed index.

PopBack
public virtual void PopBack()
circularBuffer.PopBack()

Removes the element at the back of the buffer. Decreasing the Buffer size by 1.

PopFront
public virtual void PopFront()
circularBuffer.PopFront()

Removes the element at the front of the buffer. Decreasing the Buffer size by 1.

PushBack
public virtual void PushBack(T item)
circularBuffer.PushBack(item)

Pushes a new element to the back of the buffer. Back()/this[Size-1] will now return this element. When the buffer is full, the element at Front()/this[0] will be popped to allow for this new element to fit.

item
Item to push to the back of the buffer
PushFront
public virtual void PushFront(T item)
circularBuffer.PushFront(item)

Pushes a new element to the front of the buffer. Front()/this[0] will now return this element. When the buffer is full, the element at Back()/this[Size-1] will be popped to allow for this new element to fit.

item
Item to push to the front of the buffer
ToArray
public T[] ToArray()
result = circularBuffer.ToArray()

Copies the buffer contents to an array, according to the logical contents of the buffer (i.e. independent of the internal order/contents)

Retorna: A new array with a copy of the buffer contents.

ToArraySegments
public IList<ArraySegment<T>> ToArraySegments()
result = circularBuffer.ToArraySegments()

Get the contents of the buffer as 2 ArraySegments. Respects the logical contents of the buffer, where each segment and items in each segment are ordered according to insertion. Fast: does not copy the array elements. Useful for methods like Send(IList<ArraySegment<Byte>>). Segments may be empty.

Retorna: An IList with 2 segments corresponding to the buffer content.

Campos

_count
private int _count
value = circularBuffer._count

The _size. Buffer size.

_end
private int _end
value = circularBuffer._end

The _end. Index after the last element in the buffer.

_start
private int _start
value = circularBuffer._start

The _start. Index of the first element in buffer.