containers.cyclicbuffer

Cyclic Buffer

Authors

Nickolay Bukreyev

  • Declaration

    struct CyclicBuffer(T, Allocator = Mallocator, bool supportGC = shouldAddGCRange!T);

    Array that provides constant time (amortized) appending and popping at either end, as well as random access to the elements.

    Parameters

    T

    the array element type

    Allocator

    the allocator to use. Defaults to Mallocator.

    supportGC

    true if the container should support holding references to GC-allocated memory.

    • Declaration

      this();

      No default construction if an allocator must be provided.

    • Declaration

      pure nothrow @nogc @safe this(Allocator allocator);

      Use the given allocator for allocations.

    • Declaration

      void clear();

      Removes all contents from the buffer.

    • Declaration

      size_t reserve(size_t newCapacity);

      Ensures capacity is at least as large as specified.

    • Declaration

      void insertFront(U)(U value) if (isImplicitlyConvertible!(U, T));

      Inserts the given item into the start of the buffer.

    • Declaration

      void insertBack(U)(U value) if (isImplicitlyConvertible!(U, T));
      alias insert = insertBack;
      alias insertAnywhere = insertBack;
      alias put = insertBack;

      Inserts the given item into the end of the buffer.

    • Declaration

      void removeFront();
      alias popFront = removeFront;

      Removes the item at the start of the buffer.

    • Declaration

      void removeBack();
      alias popBack = removeBack;

      Removes the item at the end of the buffer.

    • Declaration

      pure nothrow @property ref @safe auto front(this This)();

      Accesses to the item at the start of the buffer.

    • Declaration

      pure nothrow @property ref @safe auto back(this This)();

      Accesses to the item at the end of the buffer.

    • Declaration

      pure nothrow ref @safe auto opIndex(this This)(size_t i);

      buffer[i]

    • Declaration

      pure nothrow @nogc @safe Range!This opIndex(this This)();

      buffer[]

    • Declaration

      const pure nothrow @nogc @safe size_t[2] opSlice(size_t k : 0)(size_t i, size_t j);
      pure nothrow @safe Range!This opIndex(this This)(size_t[2] indices);

      buffer[i .. j]

    • Declaration

      const pure nothrow @nogc @property @safe size_t length();
      alias opDollar = length;

      Return Value

      the number of items in the buffer.

    • Declaration

      const pure nothrow @nogc @property @safe size_t capacity();

      Return Value

      maximal number of items the buffer can hold without reallocation.

    • Declaration

      const pure nothrow @nogc @property @safe bool empty();

      Return Value

      whether or not the CyclicBuffer is empty.