BestRouteArchive
BestRouteArchive(repository: TrajectoryRepository, capacity: int) -> NoneBounded, leak-free holder of the highest-priority full routes.
A side structure separate from the per-cell retention buckets. It holds its own whole-path repository reference to each admitted route, so a best route's bytes survive even after every per-cell bucket entry referencing it has been evicted by ordinary route_quality churn. Capacity bounds extra memory: admitting a better route when full evicts and releases the worst, so the archive pins at most capacity shared routes and nothing is held indefinitely. The retention hot path is untouched, so common start cells never throttle the archive.
Invariant (regression-locked by test_best_route_archived_and_bc_clones_slice): a recorded route whose priority beats the worst archived route is retained and remains materialisable until a higher-priority route displaces it, regardless of bucket churn. A win — a huge value in the route-level priority score — therefore reaches and stays in the archive without any is_win flag.
Initialize the archive.
Parameters:
repository(TrajectoryRepository) – The repository whose routes are retained/released.capacity(int) – The maximum number of routes to keep;<= 0disables the archive.
Properties
capacity
capacity: intGet the maximum number of routes the archive retains.
count
count: intGet the number of routes currently archived.
max_priority
max_priority: float | NoneGet the highest archived priority, or None when the archive is empty.
Methods
admit
admit(trajectory_id: int, priority: float, group: Any = 0) -> NoneOffer one freshly recorded route to the archive.
Parameters:
trajectory_id(int) – The route's trajectory id.priority(float) – The route-level priority score.group(Any) – The route's archive group (for example cavern); each group keeps its own top-capacity.
clear
clear() -> NoneRelease every retained route reference and empty the archive.
priorities
priorities() -> dict[int, float]Return each archived route's priority keyed by trajectory id.
rebuild_from_repository
rebuild_from_repository(group_of: Callable[[int], Any] | None = None) -> NoneRebuild the archive as the top-capacity routes by stored priority, per group.
Parameters:
group_of(Callable[[int], Any] | None) – Maps a trajectory id to its archive group;Noneputs every route in one group (the original global top-capacitybehaviour).
route_ids
route_ids() -> list[int]Return the trajectory ids of every archived route.