Comment made by: jbiserkov
Makes sense.
Looking at the (link: https://github.com/clojure/data.int-map/blob/5442570fafa3eb4bbeec3286d67c9295d484fc4f/src/main/java/clojure/data/int_map/IntSet.java#L371 text: code) I wasn't sure whether the check/exception is part of the "public API" or was intended as a "fail early" signal to yourself that an internal invariant has been violated.
Thanks again for the quick response. A note in the README should be enough. Intersection and difference don't throw exceptions since they don't use the merge operation. From my reading of the (link: https://github.com/clojure/data.int-map/blob/9b34590f56db3e92a39eeb8ea31a8e8afbfa09b3/src/main/java/clojure/data/int_map/IntSet.java#L366 text: code) though the resulting sets have the density (leafSize) of the this argument.
Could this be used instead? Is it worth the trouble?
`
return new IntSet(Math.min(leafSize, s.leafSize),
Math.min(log2LeafSize, s.log2LeafSize),
node);
`
The exception could be made more explicit "Cannot compute the union of an int-set and a dense-int-set."
Using the "constructor" names and the name of the operation that failed (union instead of merge) could make it clearer the end-user where the problem is.
Offtopic: This doesn't really affect my program anymore - only the 1st implementation uses union/difference/intersection. The 2nd and 3rd only use disj. The 1st implementation has served it's purpose - making sure the 2nd is correct. Now the 2nd can be used to verify the correctness of the 3rd, over an even more diverse set of inputs, for some of which a dense-set makes sense.