[pypy-commit] pypy set-strategies: delegated not_contain_equal_elements method to strategies

l.diekmann noreply at buildbot.pypy.org
Thu Nov 10 13:52:35 CET 2011


Author: Lukas Diekmann <lukas.diekmann at uni-duesseldorf.de>
Branch: set-strategies
Changeset: r49265:a7b6365fb35c
Date: 2011-11-04 15:07 +0100
http://bitbucket.org/pypy/pypy/changeset/a7b6365fb35c/

Log:	delegated not_contain_equal_elements method to strategies

diff --git a/pypy/objspace/std/setobject.py b/pypy/objspace/std/setobject.py
--- a/pypy/objspace/std/setobject.py
+++ b/pypy/objspace/std/setobject.py
@@ -508,7 +508,7 @@
         if self is w_other.strategy:
             strategy = w_set.strategy
             storage = self._difference_unwrapped(w_set, w_other)
-        elif not_contain_equal_elements(self.space, w_set, w_other):
+        elif not w_set.strategy.may_contain_equal_elements(w_other.strategy):
             strategy = w_set.strategy
             storage = w_set.sstorage
         else:
@@ -580,7 +580,7 @@
         if self is w_other.strategy:
             strategy = w_set.strategy
             storage = strategy._intersect_unwrapped(w_set, w_other)
-        elif not_contain_equal_elements(self.space, w_set, w_other):
+        elif not w_set.strategy.may_contain_equal_elements(w_other.strategy):
             strategy = self.space.fromcache(EmptySetStrategy)
             storage = strategy.get_empty_storage()
         else:
@@ -748,6 +748,13 @@
     def is_correct_type(self, w_key):
         return type(w_key) is W_StringObject
 
+    def may_contain_equal_elements(self, strategy):
+        if strategy is self.space.fromcache(IntegerSetStrategy):
+            return False
+        if strategy is self.space.fromcache(EmptySetStrategy):
+            return False
+        return True
+
     def unwrap(self, w_item):
         return self.space.str_w(w_item)
 
@@ -757,7 +764,6 @@
     def iter(self, w_set):
         return StringIteratorImplementation(self.space, self, w_set)
 
-
 class IntegerSetStrategy(AbstractUnwrappedSetStrategy, SetStrategy):
     erase, unerase = rerased.new_erasing_pair("integer")
     erase = staticmethod(erase)
@@ -773,6 +779,13 @@
         from pypy.objspace.std.intobject import W_IntObject
         return type(w_key) is W_IntObject
 
+    def may_contain_equal_elements(self, strategy):
+        if strategy is self.space.fromcache(StringSetStrategy):
+            return False
+        if strategy is self.space.fromcache(EmptySetStrategy):
+            return False
+        return True
+
     def unwrap(self, w_item):
         return self.space.int_w(w_item)
 
@@ -796,6 +809,11 @@
     def is_correct_type(self, w_key):
         return True
 
+    def may_contain_equal_elements(self, strategy):
+        if strategy is self.space.fromcache(EmptySetStrategy):
+            return False
+        return True
+
     def unwrap(self, w_item):
         return w_item
 
@@ -919,22 +937,6 @@
 
 # some helper functions
 
-def not_contain_equal_elements(space, w_set, w_other):
-    # add strategies here for which elements from sets with theses strategies are never equal.
-
-    strategy1 = w_set.strategy
-    strategy2 = w_other.strategy
-
-    if strategy1 is space.fromcache(StringSetStrategy) and strategy2 is space.fromcache(IntegerSetStrategy):
-        return True
-    if strategy1 is space.fromcache(IntegerSetStrategy) and strategy2 is space.fromcache(StringSetStrategy):
-        return True
-
-    if strategy1 is space.fromcache(EmptySetStrategy) or strategy2 is space.fromcache(EmptySetStrategy):
-        # an empty set and another set will never have any equal element
-        return True
-    return False
-
 def newset(space):
     return r_dict(space.eq_w, space.hash_w, force_non_null=True)
 


More information about the pypy-commit mailing list