Class RingBuffer<T>

Type Parameters

  • T

Hierarchy

  • RingBuffer

Constructors

  • Creates a new ring buffer.

    Type Parameters

    • T

    Parameters

    • size: number

      Maximum size of the circular buffer.

    Returns RingBuffer<T>

Methods

  • Pushes new items to this buffer. (like Array#push)

    Parameters

    • Rest ...items: T[]

      Items to push to this buffer.

    Returns void

  • Clears the the buffer. Removes all items.

    Returns void

  • Imports an array to this buffer. (overwrites)

    Parameters

    • data: T[]

      JavaScript standard array.

    • resize: boolean = false

      If true, sets the maximum size to the input data array length.

    Returns void

  • Returns the item on specific index.

    Parameters

    • index: number

      Index of item.

    Returns undefined | T

  • Returns the current buffer size. The underlying array length.

    Returns number

  • Returns the first item. Same as #get(0).

    Returns undefined | T

  • Return the first n items as an array.

    Parameters

    • n: number

      Number of items to return.

    Returns T[]

  • Returns the last item. Same as #get(-1) or #get(length - 1).

    Returns undefined | T

  • Return the last n items as an array.

    Parameters

    • n: number

      Number of items to return.

    Returns T[]

  • Returns the next internal index position.

    Returns number

  • Returns the maximum size.

    Returns number

  • Returns true if the buffer is empty.

    Returns boolean

  • Returns true if the maximum size is reached.

    Returns boolean

  • Removes one or more items form the buffer.

    Parameters

    • index: number

      Start index of the item to remove.

    • count: number = 1

      The count of items to remove. (default: 1)

    Returns T[]

  • Removes the first item. Like #remove(0).

    Returns T

  • Removes the last item. Like #remove(-1).

    Returns T

  • Resizes the circular buffer.

    Parameters

    • newSize: number

      The new maximum size.

    Returns void

  • Converts the ring buffer to a JavaScript standard array.

    Returns T[]

  • Create a new ring buffer from an array.

    Type Parameters

    • T

    Parameters

    • data: T[]

      Array to import.

    • size: number = 0

      Optional size. Otherwise same size as the input data array.

    Returns RingBuffer<T>