Skip to content

Instantly share code, notes, and snippets.

@pervognsen pervognsen/segarray.ion
Last active Feb 28, 2019

What would you like to do?
typedef T = int;
var segs: T**;
var seg: T*;
var segcap = 1;
var segidx = 1;
func grow() {
seg = 0;
asetcap(seg, segcap);
apush(segs, seg);
segcap *= 2;
func add(x: T): usize {
if (alen(seg) == acap(seg)) {
apush(seg, x);
return segidx++;
func get(i: usize): T* {
e := log2(i);
b := pow2(e);
return &segs[e][i-b];
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.