From 328860c8ba572fd9b8032e6ed07704d79f62234e Mon Sep 17 00:00:00 2001 From: Max Kellermann Date: Sat, 15 Mar 2014 23:29:07 +0100 Subject: util/CircularBuffer: add method GetSpace() --- src/util/CircularBuffer.hxx | 12 ++++++++++++ 1 file changed, 12 insertions(+) (limited to 'src/util/CircularBuffer.hxx') diff --git a/src/util/CircularBuffer.hxx b/src/util/CircularBuffer.hxx index 0321b91f6..da6f412a5 100644 --- a/src/util/CircularBuffer.hxx +++ b/src/util/CircularBuffer.hxx @@ -107,6 +107,18 @@ public: : capacity - head + tail; } + /** + * Returns the number of elements that can be added to this + * buffer. + */ + constexpr size_type GetSpace() const { + /* space = capacity - size - 1 */ + return (head <= tail + ? capacity - tail + head + : head - tail) + - 1; + } + /** * Prepares writing. Returns a buffer range which may be written. * When you are finished, call Append(). -- cgit v1.2.3