class documentation
class RingBuffer(Generic[
Known subclasses: acme.runtime.Logging.ACMERingBufferLogHandler, acme.services.RequestManager.RequestRingBuffer
Constructor: RingBuffer(size)
A simple ring buffer implementation that allows for fixed-size storage of items. It overwrites the oldest item when the buffer is full.
Calling functions need to maintain their own index to track the current position in the buffer. This is useful where an arbitrary number of functions need to access the buffer concurrently, and each function needs to maintain its own position without interfering with others.
| Method | __getitem__ |
Get an item from the buffer by index. |
| Method | __init__ |
Initialize a ring buffer with a fixed size. |
| Method | append |
Add an item to the ring buffer. If the buffer is full, the oldest item is removed. |
| Method | increment |
Increment the head in a circular manner. |
| Method | next |
Increment an index in a circular manner without modifying the current index. |
| Instance Variable | buffer |
The internal storage for the ring buffer, initialized with None values. |
| Instance Variable | capacity |
The maximum number of items the buffer can hold. |
| Instance Variable | head |
The current head index of the ring buffer, initialized to -1 indicating an empty buffer. |
Get an item from the buffer by index.
| Parameters | |
index:int | The index of the item to retrieve. |
| Returns | |
T | None | The item at the specified index, or None if the index is out of bounds. |
overridden in
acme.runtime.Logging.ACMERingBufferLogHandler, acme.services.RequestManager.RequestRingBufferInitialize a ring buffer with a fixed size.
| Parameters | |
size:int | The maximum number of items the buffer can hold. |
Add an item to the ring buffer. If the buffer is full, the oldest item is removed.
| Parameters | |
item:T | The item to add to the buffer. |