v0.3.0
What's Changed
Added
- Added
TopologicalSort::items()andTopologicalSort::into_items()to iterate over all remaining items, including ones that are still blocked by unresolved dependencies or cycles. (#70 by @gifnksm) - Implemented
Extend<DependencyLink<T>>forTopologicalSort<T>, allowing dependency links to be appended withextend(). (#63 by @gifnksm) - Added
TopologicalSort::pop_iter(), which returns aPopIter<'_, T>that repeatedly callspop(). (#64 by @gifnksm) - Added
TopologicalSort::pop_batch(), which removes and returns the current batch of ready items and can collect into any collection implementingDefault + Extend<T>. (#66, #71 by @gifnksm) - Added
TopologicalSort::peek_batch(), which iterates over the current batch of ready items. (#66, #71 by @gifnksm) - Added
TopologicalSort::remove(), which removes a specified item only when it has no remaining dependencies. (#68 by @gifnksm) - Added
CHANGELOG.md. (#51 by @gifnksm)
Changed
- (Breaking Change)
TopologicalSort::add_dependency()andTopologicalSort::add_link()now returntruewhen they add a new dependency link andfalsewhen that link already existed. (#39 by @szabgab) - Raised the minimum supported Rust version to Rust 1.88.0. (#29 by @gifnksm)
- Adjusted
TopologicalSort<T>debug output to use a more collection-like representation of dependency relationships. (#58 by @gifnksm) - Added
#[must_use]toTopologicalSort::new(),len(),is_empty(),peek(), andpeek_batch(), which may produce new warnings when their return values are ignored.
Deprecated
- Deprecated
TopologicalSort::pop_all()in favor ofTopologicalSort::pop_batch(). (#66, #72 by @gifnksm)-
Rationale:
The old name could be taken to mean that the method would keep popping items until no more progress was possible.
However, it only removed the current batch of items that had no remaining dependencies at the time of the call.
The new name makes that batch-oriented behavior explicit and helps avoid using a singlepop_all()call as a cycle check.pop_batch()also avoids unnecessary intermediate collection work.
Callers can now collect directly into their chosen container instead of always receiving aVec. -
Migration notes:
- Replace
ts.pop_all()withts.pop_batch::<Vec<_>>()when you still want aVec. - If you intended to keep popping until no more progress is possible, use
ts.pop_iter()instead, for examplelet items: Vec<_> = ts.pop_iter().collect();.
- Replace
-
- Deprecated
TopologicalSort::peek_all()in favor ofTopologicalSort::peek_batch(). (#66, #72 by @gifnksm)-
Rationale:
The old name could be taken to mean that the method would inspect every item that would become ready as popping progressed.
However, it only inspected the current batch of items that had no remaining dependencies at the time of the call.
The new name makes that batch-oriented behavior explicit.peek_batch()also avoids unnecessary allocation when callers only need to inspect or stream the ready items. -
Migration notes:
- Replace
ts.peek_all()withts.peek_batch().collect::<Vec<_>>()when you still wantVec<&T>. - If you want owned copied values from
peek_batch(), usets.peek_batch().copied().collect::<Vec<_>>()forCopytypes orts.peek_batch().cloned().collect::<Vec<_>>()forClonetypes.
- Replace
-
Removed
- (Breaking Change) Removed
impl From<(T, T)> for DependencyLink<T>. (#57 by @gifnksm)- Rationale:
The tuple order was the inverse ofTopologicalSort::add_dependency(prec, succ)andDependencyLink { prec, succ }, which made it easy to invert a dependency link by mistake. - Migration notes:
- Replace
ts.add_link((succ, prec).into())withts.add_link(DependencyLink { prec, succ }). - Replace
DependencyLink::from((succ, prec))withDependencyLink { prec, succ }. - Replace
.map(DependencyLink::from)on(succ, prec)tuples with.map(|(succ, prec)| DependencyLink { prec, succ }).
- Replace
- Rationale:
- (Breaking Change) Removed
impl FromIterator<T> for TopologicalSort<T>. (#61 by @ginksm)- Rationale:
TopologicalSort::from_iter(iter)oriter.collect::<TopologicalSort<T>>()compared each item with all previously seen items usingpartial_cmp()and inferred dependency links from every comparable pair.
That behavior was not intuitive forfrom_iter(), which readers could reasonably expect to just gather items or to derive relationships only from something more local such as adjacent pairs.
It also madefrom_iter()unexpectedlyO(n^2)instead of theO(n)work that a collection-style operation usually suggests. - Migration notes:
- There is no direct replacement for
items.into_iter().collect::<TopologicalSort<_>>(). - If
partial_cmp()defines a total order for your values and you only needed to iterate them in order, collect them into aVecand sort it directly instead of usingTopologicalSort. - If you intended to model dependency links, construct the graph explicitly with
TopologicalSort::new()plusinsert(),add_dependency(), and/oradd_link().
- There is no direct replacement for
- Rationale:
- (Breaking Change) Removed
impl Iterator for TopologicalSort<T>. (#64 by @gifnksm)
Destructive iteration now requires an explicitTopologicalSort::pop_iter()call.- Rationale:
IteratingTopologicalSortremoves items from the sort.
ImplementingIteratorforTopologicalSortexposed methods such ascount(),find(), andfilter()directly on the sort itself.
OnTopologicalSort, those methods look like inspection or search operations, even though calling them could destructively advance or consume the sort.
Requiringpop_iter()makes that destructive step explicit. - Migration notes:
- Replace
ts.next()withts.pop()when consuming one item at a time. - Replace iteration through
TopologicalSortitself withts.pop_iter(). - Replace direct iterator adapter calls on
TopologicalSortwith calls onts.pop_iter()instead.
- Replace
- Rationale:
Other Changes
-
Strengthen linting and add must_use annotations by @gifnksm in #60
-
Use extract_if in ready-node removal paths by @gifnksm in #69
-
Dependency updates
- Bump actions/checkout from 3 to 4 by @dependabot[bot] in #28
- Bump codecov/codecov-action from 3 to 4 by @dependabot[bot] in #31
- Bump codecov/codecov-action from 4 to 5 by @dependabot[bot] in #35
- Bump quickcheck_macros 1.0.0→1.2.0 and raise MSRV to 1.85.0 by @gifnksm with @Copilot in #44
- Bump quickcheck_macros from 1.0.0 to 1.2.0 by @dependabot[bot] in #43
- Bump codecov/codecov-action from 5 to 6 by @dependabot[bot] in #46
- Bump actions/checkout from 4 to 6 by @dependabot[bot] in #45
- Bump codecov/codecov-action from 6 to 7 by @dependabot[bot] in #47
- Bump quickcheck from 1.0.3 to 1.1.0 by @dependabot[bot] in #48
- Bump actions/checkout from 6 to 7 by @dependabot[bot] in #49
- chore: update dependencies by @gifnksm-update-bot[bot] in #53
New Contributors
- @dependabot[bot] made their first contribution in #28
- @vladh made their first contribution in #33
- @gifnksm with @Copilot made their first contribution in #44
- @szabgab made their first contribution in #37
- @gifnksm-update-bot[bot] made their first contribution in #53
Full Changelog: v0.2.2...v0.3.0