##// END OF EJS Templates
setdiscovery: drop the 'always' argument to '_updatesample'...
Pierre-Yves David -
r23814:6a5877a7 default
parent child Browse files
Show More
@@ -45,7 +45,7 b' from i18n import _'
45 import random
45 import random
46 import util, dagutil
46 import util, dagutil
47
47
48 def _updatesample(dag, nodes, sample, always, quicksamplesize=0):
48 def _updatesample(dag, nodes, sample, quicksamplesize=0):
49 """update an existing sample to match the expected size
49 """update an existing sample to match the expected size
50
50
51 The sample is updated with nodes exponentially distant from each head of the
51 The sample is updated with nodes exponentially distant from each head of the
@@ -58,7 +58,6 b' def _updatesample(dag, nodes, sample, al'
58 :dag: a dag object from dagutil
58 :dag: a dag object from dagutil
59 :nodes: set of nodes we want to discover (if None, assume the whole dag)
59 :nodes: set of nodes we want to discover (if None, assume the whole dag)
60 :sample: a sample to update
60 :sample: a sample to update
61 :always: set of notable nodes that will be part of the sample anyway
62 :quicksamplesize: optional target size of the sample"""
61 :quicksamplesize: optional target size of the sample"""
63 # if nodes is empty we scan the entire graph
62 # if nodes is empty we scan the entire graph
64 if nodes:
63 if nodes:
@@ -77,10 +76,9 b' def _updatesample(dag, nodes, sample, al'
77 if d > factor:
76 if d > factor:
78 factor *= 2
77 factor *= 2
79 if d == factor:
78 if d == factor:
80 if curr not in always: # need this check for the early exit below
79 sample.add(curr)
81 sample.add(curr)
80 if quicksamplesize and (len(sample) >= quicksamplesize):
82 if quicksamplesize and (len(sample) >= quicksamplesize):
81 return
83 return
84 seen.add(curr)
82 seen.add(curr)
85 for p in dag.parents(curr):
83 for p in dag.parents(curr):
86 if not nodes or p in nodes:
84 if not nodes or p in nodes:
@@ -100,18 +98,17 b' def _takequicksample(dag, nodes, size):'
100 always, sample, desiredlen = _setupsample(dag, nodes, size)
98 always, sample, desiredlen = _setupsample(dag, nodes, size)
101 if sample is None:
99 if sample is None:
102 return always
100 return always
103 _updatesample(dag, None, sample, always, quicksamplesize=desiredlen)
101 sample = always
104 sample.update(always)
102 _updatesample(dag, None, sample, quicksamplesize=size)
105 return sample
103 return sample
106
104
107 def _takefullsample(dag, nodes, size):
105 def _takefullsample(dag, nodes, size):
108 sample = always = dag.headsetofconnecteds(nodes)
106 sample = dag.headsetofconnecteds(nodes)
109 # update from heads
107 # update from heads
110 _updatesample(dag, nodes, sample, always)
108 _updatesample(dag, nodes, sample)
111 # update from roots
109 # update from roots
112 _updatesample(dag.inverse(), nodes, sample, always)
110 _updatesample(dag.inverse(), nodes, sample)
113 assert sample
111 assert sample
114 sample.update(always)
115 sample = _limitsample(sample, size)
112 sample = _limitsample(sample, size)
116 if len(sample) < size:
113 if len(sample) < size:
117 more = size - len(sample)
114 more = size - len(sample)
General Comments 0
You need to be logged in to leave comments. Login now