Closed prdoyle closed 2 years ago
I suppose a.intersect(b)
could be implemented as a.minusAll(a.minusAll(b))
with the right asymptotic complexity.
Yeah that implementation sounds good I think? Or just iterating over a
and checking each element against b
, while adding to a new set. (And in either case we iterate on the smaller set, so we get logarithmic on the larger set.) Either way is O(mlgn) I think, not sure if we can do better than that.
intersection
method to PSet
, with a default
implementationOk sounds reasonable. Could even be a default method in the interface if you like those.
Oh yeah good idea, this library only recently switched to Java 8, now we get to use nice things like default
!
PSet offers
plusAll
(set union) andminusAll
(set difference) but no set intersection.I have code that currently uses
retainAll
(which is set intersection) and I'm not sure how to do it efficiently.The original Stephen Adams paper only hints at how to implement this, but I think I could give it a shot.