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