UNPKG

node-red-contrib-leap-motion

Version:

Node-Red nodes for leap motion

18 lines (15 loc) 436 B
var CircularBuffer = module.exports = function(size) { this.pos = 0; this._buf = []; this.size = size; } CircularBuffer.prototype.get = function(i) { if (i == undefined) i = 0; if (i >= this.size) return undefined; if (i >= this._buf.length) return undefined; return this._buf[(this.pos - i - 1) % this.size]; } CircularBuffer.prototype.push = function(o) { this._buf[this.pos % this.size] = o; return this.pos++; }