This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

classification
Title: sets.BaseSet.isdisjointset(other)
Type: Stage:
Components: Library (Lib) Versions: Python 2.3
process
Status: closed Resolution: rejected
Dependencies: Superseder:
Assigned To: Nosy List: rhettinger, shane_holloway, tim.peters
Priority: normal Keywords: patch

Created on 2002-10-19 05:20 by shane_holloway, last changed 2022-04-10 16:05 by admin. This issue is now closed.

Files
File name Uploaded Description Edit
sets.patch shane_holloway, 2002-10-19 05:20 isdisjointset method patch
Messages (7)
msg41403 - (view) Author: Shane Holloway (shane_holloway) Date: 2002-10-19 05:20
Provides an optimized test for disjoint sets without 
creating an intersection, and returning after finding first 
shared element.
msg41404 - (view) Author: Tim Peters (tim.peters) * (Python committer) Date: 2002-10-19 06:33
Logged In: YES 
user_id=31435

In what sense is this optimized?  People usually 
mean "speed" when they use that word without qualification, 
but this surely runs much slower (most of the time) if the 
sets are in fact disjoint.  OTOH, I'm sure it does run much 
faster (most of the time) if the sets have the same 
elements.

If a method is merely provided for speed in *some* cases, 
it's generally a hard sell.  It would help your case if the 
docs here spelled out exactly when and why someone 
would want to use the new method; else it appears 
mysteriously redundant.
msg41405 - (view) Author: Raymond Hettinger (rhettinger) * (Python committer) Date: 2002-10-22 05:54
Logged In: YES 
user_id=80475

In general, I'm a fan of early-out routines, but I agree with 
Tim, unless this patch solves a compelling common case 
and is clear about when and whether it can be used to 
advantage, the filter based itersection method remains the 
best solution for the general case.

Unless a compelling, common use case can be shown, I 
recommend that we don't fatten the interface further.
msg41406 - (view) Author: Shane Holloway (shane_holloway) Date: 2002-10-22 18:32
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.

msg41407 - (view) Author: Raymond Hettinger (rhettinger) * (Python committer) Date: 2002-12-12 23:17
Logged In: YES 
user_id=80475

Here is an alternative implementation:

>>> def isdisjoint(a,b):
...     return len(a) != len(a|b)

The underlying dict.copy() and dict.update() help give this 
a speed advantage.
msg41408 - (view) Author: Raymond Hettinger (rhettinger) * (Python committer) Date: 2003-01-30 01:12
Logged In: YES 
user_id=80475

Can this be closed due to lack of interest?
msg41409 - (view) Author: Shane Holloway (shane_holloway) Date: 2003-02-02 06:36
Logged In: YES 
user_id=283742

Closing this is fine with me.  =)  I learned a lot in the
process, if nothing else!  Thanks to all who gave it a look.
History
Date User Action Args
2022-04-10 16:05:46adminsetgithub: 37341
2002-10-19 05:20:57shane_hollowaycreate