Skip to content

Instantly share code, notes, and snippets.

@eholk
Created August 25, 2011 23:07
Show Gist options
  • Select an option

  • Save eholk/1172267 to your computer and use it in GitHub Desktop.

Select an option

Save eholk/1172267 to your computer and use it in GitHub Desktop.
tag treemap<@K, @V> {
empty;
node(K, V,
{
mutable left : @treemap<K,V>,
mutable right : @treemap<K,V>
});
}
fn insert<@K, @V>(m : &mutable treemap<K, V>, k : K, v : V) {
alt m {
empty. {
m = node(k, v, {mutable left : @empty, mutable right : @empty});
}
node(kk, _, n) {
if k < kk { insert(*n.left, k, v); }
else { insert(*n.right, k, v); }
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment