From 3ae13e2f1b2cad1e5d058df64b4442518f00695e Mon Sep 17 00:00:00 2001 From: Forest Gregg Date: Mon, 18 Dec 2023 23:28:40 -0500 Subject: [PATCH] don't really need deque --- dedupe/branch_and_bound.py | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/dedupe/branch_and_bound.py b/dedupe/branch_and_bound.py index 8b10a2c7..aeb1b1f0 100644 --- a/dedupe/branch_and_bound.py +++ b/dedupe/branch_and_bound.py @@ -1,6 +1,5 @@ from __future__ import annotations -import collections import functools from typing import Any, Iterable, Mapping, Sequence, Tuple @@ -56,10 +55,10 @@ def _covered(partial: Partial) -> int: cheapest: Partial = () start: tuple[Cover, Partial] = (original_cover, ()) - to_explore = collections.deque((start,)) + to_explore = [start] while to_explore and calls: - candidates, partial = to_explore.popleft() + candidates, partial = to_explore.pop() covered = _covered(partial) score = _score(partial) @@ -76,12 +75,12 @@ def _covered(partial: Partial) -> int: order_by = functools.partial(_order_by, candidates) best = max(candidates, key=order_by) - remaining = _uncovered_by(candidates, candidates[best]) - to_explore.append((remaining, partial + (best,))) - reduced = _remove_dominated(candidates, best) to_explore.append((reduced, partial)) + remaining = _uncovered_by(candidates, candidates[best]) + to_explore.append((remaining, partial + (best,))) + elif score < cheapest_score: cheapest = partial cheapest_score = score