Skip to content

Instantly share code, notes, and snippets.

@mcejp
mcejp / ring_buffer.c
Created December 6, 2023 10:59
Ring buffer with Array + two indices mod 2N
// 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); }
@lukhnos
lukhnos / build.gradle
Created July 10, 2015 06:03
A typical Java project gradle setup that combines META-INF/services in the "super JAR"
apply plugin: 'java'
repositories {
mavenCentral()
}
dependencies {
// ...
}