Skip to content

deployable/node-deployable-ringbuffer

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

21 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Circular buffer stored in an array

Install

npm install @deployable/ringbuffer --save

yarn add @deployable/ringbuffer

Usage

const RingBuffer = require('@deployable/ringbuffer')
const rb = new RingBuffer(5)

// Add items
rb.add('one')
rb.add('two')
rb.add('three')
rb.add('four')
rb.add('five')

// Get the last item
rb.last() // => 'five'

// Get the entire array
rb.toArray() // => [ 'one', 'two', 'three', 'four', 'five' ]

// Oldest on the left will be overwritten
rb.add('six')
rb.toArray() // => [ 'two', 'three', 'four', 'five', 'six' ]

// Clear the buffer down
rb.clear()
rb.toArray() // => [ , , , , ]

License

deployable-ringbuffer is released under the MIT license. Copyright 2016 Matt Hoyle Deployable Ltd

https://github.com/deployable/node-deployable-ringbuffer

About

RingBuffer - Store a limited data set in a circular array

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published