Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix naming of RingBuffer.pop(Front/Back). #5

Merged
merged 1 commit into from
Feb 13, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 14 additions & 14 deletions source/vibe/container/ringbuffer.d
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@ module vibe.container.ringbuffer;
`length`, `front` and `back` properties, as well as slice and index based
random access.

Both, FIFO and LIFO operation modes are supported, using `popFront` and
`popBack`.
Both, FIFO and LIFO operation modes are supported, using `removeFront` and
`removeBack`.
*/
struct RingBuffer(T, size_t N = 0, bool INITIALIZE = true) {
import std.traits : hasElaborateDestructor, isCopyable;
Expand Down Expand Up @@ -105,7 +105,7 @@ struct RingBuffer(T, size_t N = 0, bool INITIALIZE = true) {
/// Removes all elements.
void clear()
{
popFrontN(length);
removeFrontN(length);
assert(m_fill == 0);
m_start = 0;
}
Expand Down Expand Up @@ -138,7 +138,7 @@ struct RingBuffer(T, size_t N = 0, bool INITIALIZE = true) {
void putN(size_t n) { assert(m_fill+n <= m_buffer.length); m_fill += n; }

/// Removes the first element from the buffer.
void popFront()
void removeFront()
{
assert(!empty);
static if (hasElaborateDestructor!T)
Expand All @@ -148,7 +148,7 @@ struct RingBuffer(T, size_t N = 0, bool INITIALIZE = true) {
}

/// Removes the first N elements from the buffer.
void popFrontN(size_t n)
void removeFrontN(size_t n)
{
assert(length >= n);
static if (hasElaborateDestructor!T) {
Expand All @@ -160,7 +160,7 @@ struct RingBuffer(T, size_t N = 0, bool INITIALIZE = true) {
}

/// Removes the last element from the buffer.
void popBack()
void removeBack()
{
assert(!empty);
static if (hasElaborateDestructor!T)
Expand All @@ -169,7 +169,7 @@ struct RingBuffer(T, size_t N = 0, bool INITIALIZE = true) {
}

/// Removes the last N elements from the buffer.
void popBackN(size_t n)
void removeBackN(size_t n)
{
assert(length >= n);
static if (hasElaborateDestructor!T) {
Expand Down Expand Up @@ -257,7 +257,7 @@ struct RingBuffer(T, size_t N = 0, bool INITIALIZE = true) {
move(m_buffer[m_start + i], dst[i]);
}
}
popFrontN(dst.length);
removeFrontN(dst.length);
}

/// Enables `foreach` iteration over all elements.
Expand Down Expand Up @@ -354,7 +354,7 @@ struct RingBuffer(T, size_t N = 0, bool INITIALIZE = true) {
@safe unittest {
import std.range : isInputRange, isOutputRange;

static assert(isInputRange!(RingBuffer!int) && isOutputRange!(RingBuffer!int, int));
static assert(isInputRange!(RingBuffer!int.Range) && isOutputRange!(RingBuffer!int, int));

RingBuffer!(int, 5) buf;
assert(buf.length == 0 && buf.freeSpace == 5); buf.put(1); // |1 . . . .
Expand All @@ -364,9 +364,9 @@ struct RingBuffer(T, size_t N = 0, bool INITIALIZE = true) {
assert(buf.length == 4 && buf.freeSpace == 1); buf.put(5); // |1 2 3 4 5
assert(buf.length == 5 && buf.freeSpace == 0);
assert(buf.front == 1);
buf.popFront(); // .|2 3 4 5
buf.removeFront(); // .|2 3 4 5
assert(buf.front == 2);
buf.popFrontN(2); // . . .|4 5
buf.removeFrontN(2); // . . .|4 5
assert(buf.front == 4);
assert(buf.length == 2 && buf.freeSpace == 3);
buf.put([6, 7, 8]); // 6 7 8|4 5
Expand All @@ -381,7 +381,7 @@ struct RingBuffer(T, size_t N = 0, bool INITIALIZE = true) {
assert(dst[0 .. 2] == [1, 2]);

buf.put([0, 0, 0, 1, 2]); //|0 0 0 1 2
buf.popFrontN(2); //. .|0 1 2
buf.removeFrontN(2); //. .|0 1 2
buf.put([3, 4]); // 3 4|0 1 2
foreach(i, item; buf) {
assert(i == item);
Expand All @@ -408,7 +408,7 @@ struct RingBuffer(T, size_t N = 0, bool INITIALIZE = true) {
assert(*pcnt == 2);
s = S.init;
assert(*pcnt == 1);
buf.popBack();
buf.removeBack();
assert(*pcnt == 0);
buf.put(S(pcnt));
assert(*pcnt == 1);
Expand All @@ -423,7 +423,7 @@ struct RingBuffer(T, size_t N = 0, bool INITIALIZE = true) {
buf.put(S(pcnt));
buf.put(S(pcnt));
assert(*pcnt == 2);
buf.popFrontN(2);
buf.removeFrontN(2);
assert(*pcnt == 0);
buf.put(S(pcnt));
buf.put(S(pcnt));
Expand Down
Loading