CircularBuffer
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.
Реализует: ICircularBuffer<T>, IList<T>, ICollection<T>, IEnumerable<T>, IEnumerable
Конструкторы
public CircularBuffer(int capacity)
circularBuffer = CircularBuffer(capacity)
Initializes a new instance of the CircularBuffer class.
- capacity
- Buffer capacity. Must be positive.
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.
Свойства
public virtual int Capacity { get; set; }
value = circularBuffer.Capacity
circularBuffer.Capacity = value
Maximum capacity of the buffer.
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
Методы
public T Back()
result = circularBuffer.Back()
Element at the back of the buffer - this[Size - 1].
Возвращает: The value of the element of type T at the back of the buffer.
private void Decrement(int index)
circularBuffer.Decrement(index)
Decrements the provided index variable by one, wrapping around if necessary.
- index
public T Front()
result = circularBuffer.Front()
Element at the front of the buffer - this[0].
Возвращает: The value of the element of type T at the front of the buffer.
public IEnumerator<T> GetEnumerator()
result = circularBuffer.GetEnumerator()
Returns an enumerator that iterates through this buffer.
Возвращает: An enumerator that can be used to iterate this collection.
private void Increment(int index)
circularBuffer.Increment(index)
Increments the provided index variable by one, wrapping around if necessary.
- index
private int InternalIndex(int index)
result = circularBuffer.InternalIndex(index)
Converts the index in the argument to an index in _buffer
- index
- External index.
Возвращает: The transformed index.
public virtual void PopBack()
circularBuffer.PopBack()
Removes the element at the back of the buffer. Decreasing the Buffer size by 1.
public virtual void PopFront()
circularBuffer.PopFront()
Removes the element at the front of the buffer. Decreasing the Buffer size by 1.
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
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
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)
Возвращает: A new array with a copy of the buffer contents.
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.
Возвращает: An IList with 2 segments corresponding to the buffer content.
Поля
private int _end
value = circularBuffer._end
The _end. Index after the last element in the buffer.
private int _start
value = circularBuffer._start
The _start. Index of the first element in buffer.