ring_logger v0.8.1 RingLogger.CircularBuffer View Source
Circular Buffer
This is a modified version of https://github.com/keathley/circular_buffer
that doesn't use :queue
. It creates less garbage than the :queue
version
and is slightly faster in trivial benchmarks. RingLogger currently has other
limitations that make it hard to see these improvements.
When creating a circular buffer you must specify the max size:
cb = CircularBuffer.new(10)
Link to this section Summary
Functions
Checks the buffer to see if its empty
Inserts a new item into the next location of the circular buffer
Creates a new circular buffer with a given size.
Returns the newest element in the buffer
Returns the oldest element in the buffer
Converts a circular buffer to a list.
Link to this section Functions
Checks the buffer to see if its empty
Runs in constant time
Inserts a new item into the next location of the circular buffer
Amortized run time: O(1) Worst case run time: O(n)
Creates a new circular buffer with a given size.
Returns the newest element in the buffer
Runs in constant time.
Returns the oldest element in the buffer
Mostly runs in constant time. Worst case O(n).
Converts a circular buffer to a list.
The list is ordered from oldest to newest elements based on their insertion order.
Worst case run time: O(n)