This is highly inspired by the F# code in the F# compiler code (FSharp.Core/set.fs)
This code has 100% test coverage, but it doesn't exclude bugs. In fact it uncovered bugs in the coverage tool, so use at your own risk ;)