[Zope-CVS] CVS: Packages/pypes/pypes - identity.py:1.8

Casey Duncan casey at zope.com
Wed Feb 18 00:08:12 EST 2004


Update of /cvs-repository/Packages/pypes/pypes
In directory cvs.zope.org:/tmp/cvs-serv30834

Modified Files:
	identity.py 
Log Message:
Implement multiUnion and multiIntersection functions for identity sets


=== Packages/pypes/pypes/identity.py 1.7 => 1.8 ===
--- Packages/pypes/pypes/identity.py:1.7	Tue Feb 10 22:57:45 2004
+++ Packages/pypes/pypes/identity.py	Wed Feb 18 00:08:09 2004
@@ -23,7 +23,8 @@
 from types import IntType
 from zope.interface import implements
 from BTrees.IIBTree \
-    import IITreeSet, multiunion, union, intersection, difference
+    import IITreeSet, union, intersection, difference
+from BTrees import IIBTree
 from BTrees.IOBTree import IOBTree
 from BTrees.Length import Length
 from pypes import services
@@ -262,7 +263,42 @@
     
     def __ne__(self, other):
         return not self.issubset(other) or not self.issuperset(other)
+        
+        
+## Multi-set operations ##
 
+
+def multiUnion(identity_sets):
+    """Return an identity set which is the union of the sequence of identity
+    sets specified
+    """
+    if identity_sets:
+        dbconn = getattr(identity_sets[0], '_p_jar', None)
+    else:
+        return IdentitySet()
+    idunion = IIBTree.multiunion([set._idset for set in identity_sets])
+    return IdentitySet.fromIdSet(idunion, dbconn)
+
+
+def multiIntersection(identity_sets):
+    """Return an identity set which is the intersection of the sequence of 
+    identity sets specified
+    """
+    if identity_sets:
+        dbconn = getattr(identity_sets[0], '_p_jar', None)
+    else:
+        return IdentitySet()
+    idsect = None
+    for set in identity_sets:
+        if not set:
+            # Short circuit on empty set
+            return IdentitySet()
+        idsect = intersection(idsect, set._idset)
+        if not idsect:
+            # Short circuit on empty intersect
+            return IdentitySet()
+    return IdentitySet.fromIdSet(idsect, dbconn)
+                
 
 ## Id Event Messsage Types ##
 




More information about the Zope-CVS mailing list