Consider changing the representation to avoid Tips.
Suggested by wrengr in #1069 (comment)
I'm thinking
data Set a
= Bin !Int !a !(Set a) !(Set a)
| Two !a !a
| One !a
| Nil -- Invariant: Never a child of Bin
This hopefully improves performance but certainly improves memory usage. Compared to today, for n elements we can avoid storing ~n Tips and ~n/2-2n/3 Ints.
Alternately, as midway between current and the above,
data Set a
= Bin !Int !a !(Set a) !(Set a)
| One !a
| Tip
-- Invariant: Bin _ x Tip Tip is always replaced with One x
This puts the match-on-singleton idea of #1069 into the type. Avoids storing ~2n/3-n Tips and ~n/3-n/2 Ints.
Consider changing the representation to avoid
Tips.Suggested by wrengr in #1069 (comment)
I'm thinking
This hopefully improves performance but certainly improves memory usage. Compared to today, for n elements we can avoid storing ~n
Tips and ~n/2-2n/3Ints.Alternately, as midway between current and the above,
This puts the match-on-singleton idea of #1069 into the type. Avoids storing ~2n/3-n
Tips and ~n/3-n/2Ints.