Skip to content

Instantly share code, notes, and snippets.

@ChrisCates
Created August 20, 2017 19:58
Show Gist options
  • Save ChrisCates/a4ae88ebac8eb93507a7f735207c1c08 to your computer and use it in GitHub Desktop.
Save ChrisCates/a4ae88ebac8eb93507a7f735207c1c08 to your computer and use it in GitHub Desktop.
Ring Buffer in Node.js
class RingBuffer {
constructor(size) {
this.size = size;
this.pointer = 0;
this.buffer = [];
}
get(key) {
return this.buffer[key];
}
push(item) {
this.buffer[this.pointer] = item;
this.pointer = (this.pointer + 1) % this.size;
return item;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment