Simple circular byte buffer. This implementation is not thread-safe. In particular, none of these functions is guaranteed to be re-entrant.
Ring buffer type.
The buffer is empty when head == tail.
The buffer is full when the head is one byte in front of the tail, modulo buffer length.
One byte is left free to distinguish empty from full.
Public Members
- uint8 * buf
Buffer items are stored into.
- uint16 head
Index of the next item to remove.
- uint16 tail
Index where the next item will get inserted.
- uint16 size
Buffer capacity minus one.
Initialise a ring buffer.
| Parameters: |
|
|---|
Return the number of elements stored in the ring buffer.
| Parameters: |
|
|---|
Returns true if and only if the ring buffer is full.
| Parameters: |
|
|---|
Returns true if and only if the ring buffer is empty.
| Parameters: |
|
|---|
Append element onto the end of a ring buffer.
| Parameters: |
|
|---|
Remove and return the first item from a ring buffer.
| Parameters: |
|
|---|
Attempt to remove the first item from a ring buffer.
If the ring buffer is nonempty, removes and returns its first item. If it is empty, does nothing and returns a negative value.
| Parameters: |
|
|---|
Attempt to insert an element into a ring buffer.
| Parameters: |
|
|---|---|
| Side Effects:: | If rb is not full, appends element onto buffer. |
| Return: | If element was appended, then true; otherwise, false. |
Append an item onto the end of a non-full ring buffer.
If the buffer is full, removes its first item, then inserts the new element at the end.
| Parameters: |
|
|---|---|
| Return: | On success, returns -1. If an element was popped, returns the popped value. |
Discard all items from a ring buffer.
| Parameters: |
|
|---|