Logged In: YES
user_id=283742
I definitely agree that this disjoint set test and an intersection
both have linear time complexity, but the intersection also
has a memory complexity that a disjoint test does not have.
Secondly, in the case of an intersecting set, it short-circuts
the rest of the loop since it already has the answer, halving
the time complexity on average. However, disjoint test
doesn't benefit from the C-loop of filter that the intersection
does.
When I wrote this patch, I was creating some large sets
doing reachability searches, and I wanted to merge the
intersecting ones. I started by examining the length of the
intersection, but the time to allocate the complete result was
bottlenecking things. (400K entries.) Thus I wrote the
disjoint test and things went much faster. But, as you said,
this is neither common nor compelling.
So I assumed it was a common enough function that others
would profit from having it the standard library. It was
certainly all over my set theory classes a few years ago. ;)
Perhaps what we need is more c-loop functions to add to
map, filter and reduce? A function called 'first' would work
wonders here and other places.
|