mthb-circular-buffer
TypeScript icon, indicating that this package has built-in type declarations

0.0.45 • Public • Published

CircularBuffer

GitHub issues github languages

import { CircularBuffer } from 'mthb-circular-buffer';

Allow OverFlow = true

var circularBuffer = new CircularBuffer(2 /*length*/, true /*allowOverFlow*/);
circularBuffer.push(1);
circularBuffer.push(2);
console.log(circularBuffer.size()); // 2
circularBuffer.push(3);
console.log(circularBuffer.size()); // 2
console.log(circularBuffer.pop());  // 2
console.log(circularBuffer.pop());  // 3
console.log(circularBuffer.size()); // 0

Allow OverFlow = false

var circularBuffer = new CircularBuffer(2 /*length*/, false /*allowOverFlow*/);
circularBuffer.push(1);
circularBuffer.push(2);
console.log(circularBuffer.pop()); // 1
console.log(circularBuffer.pop()); // 2
circularBuffer.push(3);
circularBuffer.push(4);
circularBuffer.push(5); // throw "overflow"

Description and Big O

Function Big O Description
push O(1) push item to circular buffer
pop O(1) pop item of circular buffer
size O(1) size of circular buffer
export O(n) pop all items of circular buffer
clear O(n) clear all items of circular buffer

/mthb-circular-buffer/

    Package Sidebar

    Install

    npm i mthb-circular-buffer

    Weekly Downloads

    3

    Version

    0.0.45

    License

    MIT

    Unpacked Size

    5.9 kB

    Total Files

    4

    Last publish

    Collaborators

    • magni.thor