changeset 20643:7fc371d2e5a3

revset: added ordered generatorset classes with __contains__ method They stop iterating as soon as they go past the value they are looking for, so, for values not in the generator they return faster.
author Lucas Moscovicz <lmoscovicz@fb.com>
date Thu, 27 Feb 2014 17:27:03 -0800
parents 0dc7a50345c2
children 779ceb84f4f7
files mercurial/revset.py
diffstat 1 files changed, 34 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- a/mercurial/revset.py	Tue Feb 25 20:29:46 2014 +0100
+++ b/mercurial/revset.py	Thu Feb 27 17:27:03 2014 -0800
@@ -2296,6 +2296,40 @@
     def set(self):
         return self
 
+class ascgeneratorset(generatorset):
+    """ Same structure as generatorset but stops iterating after it goes past
+    the value when asked for membership and the element is not contained
+    """
+    def __contains__(self, x):
+        if x in self._cache:
+            return self._cache[x]
+
+        for l in self:
+            if l == x:
+                return True
+            if l > x:
+                break
+
+        self._cache[x] = False
+        return False
+
+class descgeneratorset(generatorset):
+    """ Same structure as generatorset but stops iterating after it goes past
+    the value when asked for membership and the element is not contained
+    """
+    def __contains__(self, x):
+        if x in self._cache:
+            return self._cache[x]
+
+        for l in self:
+            if l == x:
+                return True
+            if l < x:
+                break
+
+        self._cache[x] = False
+        return False
+
 class spanset(object):
     """Duck type for baseset class which represents a range of revisions and
     can work lazily and without having all the range in memory