Algorithms and data structures for JS/TS
  • Introduction
  • GETTING STARTED
    • TS
    • Node.js
    • ES Modules
    • Browsers
  • PUBLIC API
    • How to read
    • Linked lists
      • SinglyLinkedList
      • DoublyLinkedList
      • CircularlyLinkedList
    • Stacks and queues
      • LinkedStack
      • LinkedQueue
      • LinkedDeque
      • CircularQueue
      • CircularArrayBuffer
      • UnsortedPriorityQueue
      • SortedPriorityQueue
      • AdaptableHeapPriorityQueue
    • Maps
      • SortedMap
      • MaximaSet
      • AVLTreeMap
      • SplayTreeMap
      • RedBlackTreeMap
    • Trees
      • GeneralTree
      • LinkedBinaryTree
      • PreorderTreeTraversal
      • InorderTreeTraversal
      • PostorderTreeTraversal
      • EulerTourTreeTraversal
    • Searches
      • Binary search
      • Quick select
    • Text processing
      • Longest common subsequence
      • Boyer-Moore
      • Knuth-Morris-Pratt
    • Position
    • Locator
    • Comparators
  • CONTRIBUTION NOTES
    • How to contribute
    • Project structure
  • Changelog
Powered by GitBook
On this page
  • new CircularArrayBuffer()
  • length
  • maxLength
  • clear()
  • dequeue()
  • enqueue()
  • getFirst()
  • isEmpty()
  • isFull()
  • isOverwritable()

Was this helpful?

  1. PUBLIC API
  2. Stacks and queues

CircularArrayBuffer

Array-based implementation of circular FIFO data structure.

new CircularArrayBuffer()

/**
 * Creates an instance of CircularArrayBuffer.
 *
 * @param len Buffer total capacity.
 * @param elements List of elements to create the buffer with.
 * @param overwritable Flag allowing to overwrite the buffer if it is full. Is FALSE by default.
 */
constructor(len: number, elements: T[] = [], protected overwritable = false)

length

/**
 * Number of elements in the queue.
 *
 * @readonly
 */
get length(): number;

maxLength

/**
 * Maximum size of a sequence the buffer can store without overwriting itself.
 *
 * @readonly
 */
get maxLength(): number;

clear()

/**
 * Clears the queue.
 */
clear(): void;

dequeue()

/**
 * Removes the first element from the front of the queue and returns it.
 * Throws an error if the queue is empty.
 *
 * @returns Removed element.
 */
dequeue(): T;

enqueue()

/**
 * Adds element at the rear of the queue.
 *
 * @param element Element to add.
 */
enqueue(element: T): void;

getFirst()

/**
 * Gets element from the front of the queue without its removal.
 *
 * @returns Queue element.
 */
getFirst(): T;

isEmpty()

/**
 * Checks whether the queue is empty or not.
 *
 * @returns TRUE if the queue is empty, FALSE otherwise.
 */
isEmpty(): boolean;

isFull()

/**
 * Checks whether the buffer can store any more values without overwriting itself.
 *
 * @returns TRUE if the buffer is full, FALSE otherwise.
 */
isFull(): boolean;

isOverwritable()

/**
 * Checks whether the buffer can store any more values without overwriting itself.
 *
 * @returns TRUE if the buffer is full, FALSE otherwise.
 */
isFull(): boolean;
PreviousCircularQueueNextUnsortedPriorityQueue

Last updated 5 years ago

Was this helpful?