This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Background: https://www.snellman.net/blog/archive/2016-12-13-ring-buffers/ | |
// Variant with indices modulo 2*capacity as suggested by dizzy57 and Aristotle Pagaltzis | |
size_t read; | |
size_t write; | |
mask(val) { return val % array.capacity; } | |
wrap(val) { return val % (array.capacity * 2); } | |
inc(index) { return wrap(index + 1); } | |
push(val) { assert(!full()); array[mask(write)] = val; write = inc(write); } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
apply plugin: 'java' | |
repositories { | |
mavenCentral() | |
} | |
dependencies { | |
// ... | |
} |