comparison tests/test-ancestor.py @ 23341:bcc3012f8477

ancestor: add a way to add to bases of a missing ancestor object This will be useful for setdiscovery, since with that we incrementally add to our knowledge of common nodes.
author Siddharth Agarwal <sid0@fb.com>
date Fri, 14 Nov 2014 17:21:00 -0800
parents 4178ad511edf
children f710644e1ce9
comparison
equal deleted inserted replaced
23340:83225aff0265 23341:bcc3012f8477
43 43
44 class naiveincrementalmissingancestors(object): 44 class naiveincrementalmissingancestors(object):
45 def __init__(self, ancs, bases): 45 def __init__(self, ancs, bases):
46 self.ancs = ancs 46 self.ancs = ancs
47 self.bases = set(bases) 47 self.bases = set(bases)
48 def addbases(self, newbases):
49 self.bases.update(newbases)
48 def missingancestors(self, revs): 50 def missingancestors(self, revs):
49 res = set() 51 res = set()
50 for rev in revs: 52 for rev in revs:
51 if rev != nullrev: 53 if rev != nullrev:
52 res.update(self.ancs[rev]) 54 res.update(self.ancs[rev])
95 inc = ancestor.incrementalmissingancestors(graph.__getitem__, bases) 97 inc = ancestor.incrementalmissingancestors(graph.__getitem__, bases)
96 # reference slow algorithm 98 # reference slow algorithm
97 naiveinc = naiveincrementalmissingancestors(ancs, bases) 99 naiveinc = naiveincrementalmissingancestors(ancs, bases)
98 seq = [] 100 seq = []
99 for _ in xrange(inccount): 101 for _ in xrange(inccount):
102 if rng.random() < 0.2:
103 newbases = samplerevs(graphnodes)
104 seq.append(('addbases', newbases))
105 inc.addbases(newbases)
106 naiveinc.addbases(newbases)
100 revs = samplerevs(graphnodes) 107 revs = samplerevs(graphnodes)
101 seq.append(('missingancestors', revs)) 108 seq.append(('missingancestors', revs))
102 h = inc.missingancestors(revs) 109 h = inc.missingancestors(revs)
103 r = naiveinc.missingancestors(revs) 110 r = naiveinc.missingancestors(revs)
104 if h != r: 111 if h != r: