test-ancestor: move naive missing ancestor algorithm into a class
authorSiddharth Agarwal <sid0@fb.com>
Fri, 14 Nov 2014 23:50:01 -0800
changeset 23335 3f28e8cb3066
parent 23334 59e6e5dd3605
child 23336 4178ad511edf
test-ancestor: move naive missing ancestor algorithm into a class This mirrors the change to the real missing ancestor algorithm in a previous patch.
tests/test-ancestor.py
--- a/tests/test-ancestor.py	Fri Nov 14 23:44:38 2014 -0800
+++ b/tests/test-ancestor.py	Fri Nov 14 23:50:01 2014 -0800
@@ -41,15 +41,19 @@
             ancs[i].update(ancs[p])
     return ancs
 
-def naivemissingancestors(ancs, revs, bases):
-    res = set()
-    for rev in revs:
-        if rev != nullrev:
-            res.update(ancs[rev])
-    for base in bases:
-        if base != nullrev:
-            res.difference_update(ancs[base])
-    return sorted(res)
+class naiveincrementalmissingancestors(object):
+    def __init__(self, ancs, bases):
+        self.ancs = ancs
+        self.bases = set(bases)
+    def missingancestors(self, revs):
+        res = set()
+        for rev in revs:
+            if rev != nullrev:
+                res.update(self.ancs[rev])
+        for base in self.bases:
+            if base != nullrev:
+                res.difference_update(self.ancs[base])
+        return sorted(res)
 
 def test_missingancestors(seed, rng):
     # empirically observed to take around 1 second
@@ -91,7 +95,8 @@
             inc = ancestor.incrementalmissingancestors(graph.__getitem__, bases)
             h = inc.missingancestors(revs)
             # reference slow algorithm
-            r = naivemissingancestors(ancs, revs, bases)
+            naiveinc = naiveincrementalmissingancestors(ancs, bases)
+            r = naiveinc.missingancestors(revs)
             if h != r:
                 err(seed, graph, bases, revs, h, r)