I read Chris Okasaki's "Red-Black Trees in a Functional Setting" (1993) paper ov...

@dthompson@toot.cat

I read Chris Okasaki's "Red-Black Trees in a Functional Setting" (1993) paper over the weekend and it's brilliant. Pretty much all the resources on red-black trees out there describe very imperative algorithms but this paper describes a functional insert algorithm that is much simpler than anything else I've seen.

cs.tufts.edu/~nr/cs257/archive

Unfortunately, Okasaki conveniently leaves out deletion! Red-black tree deletion is mind bending! Thankfully I'm not the first person to notice this. Kimball Germane and Matthew Might published a functional pearl of their own in 2014: "Deletion: The curse of the red-black tree"

matt.might.net/papers/germane2

I'm reading about all of this in an effort to add the balancing properties of red-black trees to the discrete interval encoding trees (diets) in Martin Erwig's "Diets for fat sets" (1993):

web.engr.oregonstate.edu/~erwi

My microbenchmark is showing about a 10% improvement in set membership queries over the unbalanced version with a randomly generated large set. Maybe it's not worth all the effort but I don't really like implementing trees that *could* degenerate to O(n) query time.