Patchwork [2,of,9,RFC] revset: added ordered generatorsets with cached contains method

login
register
mail settings
Submitter Lucas Moscovicz
Date Feb. 12, 2014, 10:39 p.m.
Message ID <9a72b9c402c56b5d23f2.1392244792@dev1037.prn2.facebook.com>
Download mbox | patch
Permalink /patch/3626/
State Superseded
Headers show

Comments

Lucas Moscovicz - Feb. 12, 2014, 10:39 p.m.
# HG changeset patch
# User Lucas Moscovicz <lmoscovicz@fb.com>
# Date 1391796950 28800
#      Fri Feb 07 10:15:50 2014 -0800
# Node ID 9a72b9c402c56b5d23f2aa85b681a287c93201d2
# Parent  31c4cb808b0c3fc6484ecde3be2c9f0bcd5cad0a
revset: added ordered generatorsets with cached contains method

They behave similar to the generatorset but since they have an order they can
return faster when asked for revisions not included.

Patch

diff --git a/mercurial/revset.py b/mercurial/revset.py
--- a/mercurial/revset.py
+++ b/mercurial/revset.py
@@ -2180,6 +2180,50 @@ 
     def set(self):
         return self
 
+class ascgeneratorset(generatorset):
+    def __contains__(self, x):
+        if x in self._pcache:
+            return True
+        if x in self._ncache:
+            return False
+
+        while True:
+            try:
+                l = self._iter.next()
+                self._pcache.add(l)
+                if l == x:
+                    return True
+                if l > x:
+                    self._ncache.add(x)
+                    return False
+            except (StopIteration):
+                break
+
+        self._ncache.add(x)
+        return False
+
+class descgeneratorset(generatorset):
+    def __contains__(self, x):
+        if x in self._pcache:
+            return True
+        if x in self._ncache:
+            return False
+
+        while True:
+            try:
+                l = self._iter.next()
+                self._pcache.add(l)
+                if l == x:
+                    return True
+                if l < x:
+                    self._ncache.add(x)
+                    return False
+            except (StopIteration):
+                break
+
+        self._ncache.add(x)
+        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