mirror of
https://git.launchpad.net/~ubuntu-release/britney/+git/britney2-ubuntu
synced 2025-02-13 07:27:04 +00:00
Avoid O(n^2) duplication handling when building hints
Use a set to filter out seen items to avoid doing O(n^2) de-duplication. For very large hints, this can take considerable time. Using "seen_items" to build the actual hints on the (unverified) assumption that Python can do something "smart" to turn a set into a frozenset faster than it can with a list. Signed-off-by: Niels Thykier <niels@thykier.net>
This commit is contained in:
parent
72eb6af711
commit
843952d627
14
britney.py
14
britney.py
@ -2865,20 +2865,26 @@ class Britney(object):
|
|||||||
items = [(e, excuse.ver[1])]
|
items = [(e, excuse.ver[1])]
|
||||||
orig_size = 1
|
orig_size = 1
|
||||||
looped = False
|
looped = False
|
||||||
|
seen_items = set()
|
||||||
|
seen_items.update(items)
|
||||||
|
|
||||||
for item, ver in items:
|
for item, ver in items:
|
||||||
# excuses which depend on "item" or are depended on by it
|
# excuses which depend on "item" or are depended on by it
|
||||||
items.extend( (x, excuses[x].ver[1]) for x in excuses if \
|
new_items = [(x, excuses[x].ver[1]) for x in excuses if \
|
||||||
(item in excuses[x].deps or x in excuses[item].deps) \
|
(item in excuses[x].deps or x in excuses[item].deps) \
|
||||||
and (x, excuses[x].ver[1]) not in items )
|
and (x, excuses[x].ver[1]) not in seen_items]
|
||||||
|
items.extend(new_items)
|
||||||
|
seen_items.update(new_items)
|
||||||
|
|
||||||
if not looped and len(items) > 1:
|
if not looped and len(items) > 1:
|
||||||
orig_size = len(items)
|
orig_size = len(items)
|
||||||
h = frozenset(items)
|
h = frozenset(seen_items)
|
||||||
if h not in seen_hints:
|
if h not in seen_hints:
|
||||||
mincands.append(h)
|
mincands.append(h)
|
||||||
seen_hints.add(h)
|
seen_hints.add(h)
|
||||||
looped = True
|
looped = True
|
||||||
if len(items) != orig_size:
|
if len(items) != orig_size:
|
||||||
h = frozenset(items)
|
h = frozenset(seen_items)
|
||||||
if h != mincands[-1] and h not in seen_hints:
|
if h != mincands[-1] and h not in seen_hints:
|
||||||
candidates.append(h)
|
candidates.append(h)
|
||||||
seen_hints.add(h)
|
seen_hints.add(h)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user