Gapbuffer
Gap buffer implementation
Install / Use
/learn @jaz303/GapbufferREADME
gapbuffer
This is a pure Javascript implementation of a gap buffer, an array-backed data structure optimised for insertion and deletion operations which are clustered near the same location.
API
// create a new gap buffer with a gap-size of 128
var gb = new GapBuffer(128);
// insert some objects
gb.insert(0, "foo");
gb.insert(1, "bar");
// read them back
gb.get(0); // => "foo"
gb.get(1); // => "bar"
gb.get(2); // => undefined
// get the number of items in the buffer
gb.length; // => 2
// convert to array
gb.asArray(); // => ["foo", "bar"]
// clear the buffer
gb.clear();
gb.asArray(); // => []
Benchmarks
Based on a random insert-only fuzz test, this implementation trounces a naive array-based approach:
gap buffer
Raw:
> 0.05699304684828451
Average (mean) 0.05699304684828451
array
Raw:
> 0.006028963138919368
Average (mean) 0.006028963138919368
Winner: gap buffer
Compared with next highest (array), it's:
89.42% faster
9.45 times as fast
0.98 order(s) of magnitude faster
QUITE A BIT FASTER
Related Skills
node-connect
339.1kDiagnose OpenClaw node connection and pairing failures for Android, iOS, and macOS companion apps
frontend-design
83.8kCreate distinctive, production-grade frontend interfaces with high design quality. Use this skill when the user asks to build web components, pages, or applications. Generates creative, polished code that avoids generic AI aesthetics.
openai-whisper-api
339.1kTranscribe audio via OpenAI Audio Transcriptions API (Whisper).
commit-push-pr
83.8kCommit, push, and open a PR
