A queue that can dequeue and get(i) in O(1) and grow arbitrarily large. A linked list is fast at dequeue but slow at get(i). An array is the reverse. This is O(1) for both operations.

List grows until you dequeue last element at end of buffer. Then it resets to start filling at 0 again. If adds/removes are balanced, the buffer will not grow too large.

No iterator stuff as that's not how we'll use it.

Type parameters

  • T

Hierarchy

Index

Properties

Accessors

Methods

Properties

_data

_data: List<T> = new List<T>()

dynamically-sized buffer of elements

_p

_p: number = 0

index of next element to fill

range

range: number = 0

How deep have we gone?

Accessors

count

  • get count(): number
  • Returns number

Methods

clear

  • clear(): void
  • Returns void

dequeue

  • dequeue(): T
  • Get and remove first element in queue

    Returns T

enqueue

  • enqueue(o: T): void
  • Parameters

    • o: T

    Returns void

get

  • get(i: number): T
  • Return element {@code i} elements ahead of current element. {@code i==0} gets current element. This is not an absolute index into {@link #data} since {@code p} defines the start of the real list.

    Parameters

    • i: number

    Returns T

peek

  • peek(): T
  • Returns T

toString

  • toString(): string
  • Return string of current buffer contents; non-destructive

    Returns string

Generated using TypeDoc