topological-sort
Performs topological sorting.
0.3.1
25M downloads/mo
#1872 most downloaded on crates.io
gifnksm/topological-sort-rs
What this package is like to depend on
Last release 16 days ago
07 Aug 2026
Ships unpredictably
gaps range from 4 weeks to 4.5 years
Nearly every release is documented
notes for 16 of 16 stable releases
Nothing withdrawn
no release was ever pulled
12 years old
16 releases · first in 2015
2 releases in the last 12 months
see the full history below
Release timeline
16 releases · Jan 2015 to Aug 2026Releases
latest 16-
0.3.107 Aug 2026Release notes
Open source → -
0.3.005 Aug 2026Release notes
Open source →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
Release notes
Open source →Added
- Added
TopologicalSort::items()andTopologicalSort::into_items()to iterate over all remaining items, including ones that are still blocked by unresolved dependencies or cycles. - Implemented
Extend<DependencyLink<T>>forTopologicalSort<T>, allowing dependency links to be appended withextend(). - Added
TopologicalSort::pop_iter(), which returns aPopIter<'_, T>that repeatedly callspop(). - Added
TopologicalSort::pop_batch(), which removes and returns the current batch of ready items and can collect into any collection implementingDefault + Extend<T>. - Added
TopologicalSort::peek_batch(), which iterates over the current batch of ready items. - Added
TopologicalSort::remove(), which removes a specified item only when it has no remaining dependencies. - Added
CHANGELOG.md.
Changed
- (Breaking Change)
TopologicalSort::add_dependency()andTopologicalSort::add_link()now returntruewhen they add a new dependency link andfalsewhen that link already existed. - Raised the minimum supported Rust version to Rust 1.88.0.
- Adjusted
TopologicalSort<T>debug output to use a more collection-like representation of dependency relationships. - 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().-
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 single
pop_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().-
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>.- Rationale:
The tuple order was the inverse of
TopologicalSort::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:
The tuple order was the inverse of
- (Breaking Change) Removed
impl FromIterator<T> for TopologicalSort<T>.- 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>. Destructive iteration now requires an explicitTopologicalSort::pop_iter()call.- Rationale:
Iterating
TopologicalSortremoves 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:
Iterating
- Added
-
0.2.218 Jul 2022Release notes
Open source →Changed
- Marked the crate as passively maintained.
- Updated release automation.
- Moved release-time configuration into Cargo metadata.
- Removed the tag-triggered GitHub Actions publish workflow.
Full Changelog: v0.2.1...v0.2.2
Release notes
Open source →Changed
- Marked the crate as passively maintained.
- Updated release automation.
- Moved release-time configuration into Cargo metadata.
- Removed the tag-triggered GitHub Actions publish workflow.
-
0.2.117 Jul 2022Release notes
Open source →What's Changed
Fixed
- Fixed the manifest to use the supported
rust-versionkey for declaring the MSRV.
Other Pull Requests
Full Changelog: v0.2.0...v0.2.1
Release notes
Open source →Fixed
- Fixed the manifest to use the supported
rust-versionkey for declaring the MSRV.
- Fixed the manifest to use the supported
-
0.2.016 Jul 2022Release notes
Open source →What's Changed
Added
- Implemented
DefaultforTopologicalSort<T>, allowing construction withTopologicalSort::default(). (#20 by @gifnksm)
Changed
- Migrated the crate to Rust 2018 and declared Rust 1.43.1 as the minimum supported Rust version. (#24, #25 by @gifnksm)
- Expanded project automation and test coverage.
Other Pull Rrequests
- Fix travis by @gifnksm in #17
- Update crates.io badge, listed version number, and links by @atouchet in #19
- update dependencies by @gifnksm in #23
- Bump version to v0.2.0 by @gifnksm in #26
New Contributors
Full Changelog: v0.1.0...v0.2.0
Release notes
Open source →Added
- Implemented
DefaultforTopologicalSort<T>, allowing construction withTopologicalSort::default().
Changed
- Migrated the crate to Rust 2018 and declared Rust 1.43.1 as the minimum supported Rust version.
- Expanded project automation and test coverage.
- Added property-based tests covering ordering and cycle detection behavior.
- Added GitHub Actions CI, release automation, and Dependabot configuration.
- Removed the Travis CI configuration.
- Implemented
-
0.1.003 Jan 2018Release notes
Open source →What's Changed
Changed
- Updated CI configuration and made ignored return values explicit to satisfy newer Rust warnings. (#16 by @gifnksm)
Full Changelog: v0.0.10...v0.1.0
Release notes
Open source →Changed
- Updated CI configuration and made ignored return values explicit to satisfy newer Rust warnings.
-
0.0.1010 Sep 2017Release notes
Open source →What's Changed
Changed
- Changed
TopologicalSort::insert()andTopologicalSort::add_dependency()to accept arguments implementingInto<T>. (#14 by @mathstuf)
Full Changelog: v0.0.9...v0.0.10
Release notes
Open source →Changed
- Changed
TopologicalSort::insert()andTopologicalSort::add_dependency()to accept arguments implementingInto<T>.
- Changed
-
0.0.929 May 2017Release notes
Open source →What's Changed
Added
- Added the
DependencyLink<T>type andTopologicalSort::add_link()for registering dependency edges as values. (#11 by @mathstuf) - Implemented
From<(T, T)>forDependencyLink<T>, allowing dependency links to be created from tuples. (#11 by @mathstuf) - Implemented
FromIterator<DependencyLink<T>>forTopologicalSort<T>, allowing a sorter to be built from an iterator of dependency links. (#11 by @mathstuf) - Implemented
CloneforTopologicalSort<T>andCopy,Clone, andDebugforDependencyLink<T>. (#13 by @gifnksm)
Changed
- Documentation moved to docs.rs. (#10 by @mathstuf, #12 by @gifnksm )
- Updated project tooling.
- Switched CI from
travis-cargohelpers to direct Cargo commands.
- Switched CI from
Removed
Full Changelog: v0.0.8...v0.0.9
Release notes
Open source →Added
- Added the
DependencyLink<T>type andTopologicalSort::add_link()for registering dependency edges as values. - Implemented
From<(T, T)>forDependencyLink<T>, allowing dependency links to be created from tuples. - Implemented
FromIterator<DependencyLink<T>>forTopologicalSort<T>, allowing a sorter to be built from an iterator of dependency links. - Implemented
CloneforTopologicalSort<T>andCopy,Clone, andDebugforDependencyLink<T>.
Changed
- Documentation moved to docs.rs.
- Updated project tooling.
- Switched CI from
travis-cargohelpers to direct Cargo commands.
- Switched CI from
Removed
- Removed Travis-based GitHub Pages documentation publishing.
- Added the
-
0.0.801 May 2017Release notes
Open source →What's Changed
Added
- Implemented
fmt::DebugforTopologicalSort<T>. (#7 by @purpleposeidon) - Added
TopologicalSort::peek()andTopologicalSort::peek_all()to inspect items that are ready to pop without removing them. (#7 by @purpleposeidon)
New Contributors
- @purpleposeidon made their first contribution in #7
Full Changelog: v0.0.7...v0.0.8
Release notes
Open source →Added
- Implemented
fmt::DebugforTopologicalSort<T>. - Added
TopologicalSort::peek()andTopologicalSort::peek_all()to inspect items that are ready to pop without removing them.
- Implemented
-
0.0.708 Aug 2016Release notes
Open source →What's Changed
Added
- Added
TopologicalSort::insert()to register elements that have no dependencies. (#6 by @fenhl) - Implemented
FromIterator<T>for partially ordered element types, deriving dependency edges frompartial_cmp(). (#6 by @fenhl)
New Contributors
Full Changelog: v0.0.6...v0.0.7
Release notes
Open source →Added
- Added
TopologicalSort::insert()to register elements that have no dependencies. - Implemented
FromIterator<T>for partially ordered element types, deriving dependency edges frompartial_cmp().
- Added
-
0.0.611 Jan 2016Release notes
Open source →Added
- Added Apache-2.0 as an alternative license alongside MIT.
Changed
- Renamed the crate for use as
topological_sortin code and documentation. - Updated project tooling for newer Rust versions.
- Migrated CI to
travis-cargo, expanded testing to nightly, beta, and stable Rust, and enabled documentation and coverage reporting.
- Migrated CI to
Fixed
- Updated documentation examples to use the correct
topological_sortcrate name.
-
0.0.529 Mar 2015Release notes
Open source →Changed
- Updated the crate for
rustc 1.0.0-nightly (199bdcfef 2015-03-26).- Removed the now-unneeded
std_miscfeature gate.
- Removed the now-unneeded
- This removed the last nightly-only feature gate, so this release became buildable on stable Rust once Rust 1.0 shipped on 2015-05-15.
- Updated the crate for
-
0.0.421 Feb 2015Release notes
Open source →Changed
- Updated the crate for
rustc 1.0.0-nightly (522d09dfe 2015-02-19).- Switched generic bounds back to plain
Hash. - Added the
std_miscfeature gate.
- Switched generic bounds back to plain
- Updated the crate for
-
0.0.309 Jan 2015Release notes
Open source →Changed
- Updated the crate for
rustc 1.0.0-dev (20bce4481 2015-01-09 04:14:53 +0000).- (Breaking Change) Changed
TopologicalSort::len()to returnusizeinstead ofuint. - (Breaking Change) Changed the public trait bounds on
TopologicalSort<T>and itsIteratorimplementation fromHashtoHash<Hasher>.
- (Breaking Change) Changed
- Updated the crate for
-
0.0.207 Jan 2015Release notes
Open source →Changed
- Updated the crate for
rustc 1.0.0-dev (9e4e524e0 2015-01-07 05:31:23 +0000).- Removed the crate-level
associated_typesfeature gate after associated types no longer required opting in.
- Removed the crate-level
- Updated the crate for
-
0.0.106 Jan 2015Release notes
Open source →- First release
<!-- next-url --> [Unreleased]: https://github.com/gifnksm/topological-sort-rs/compare/v0.3.1...HEAD [0.3.1]: https://github.com/gifnksm/topological-sort-rs/compare/v0.3.0...v0.3.1 [0.3.0]: https://github.com/gifnksm/topological-sort-rs/compare/v0.2.2...v0.3.0 [0.2.2]: https://github.com/gifnksm/topological-sort-rs/compare/v0.2.1...v0.2.2 [0.2.1]: https://github.com/gifnksm/topological-sort-rs/compare/v0.2.0...v0.2.1 [0.2.0]: https://github.com/gifnksm/topological-sort-rs/compare/v0.1.0...v0.2.0 [0.1.0]: https://github.com/gifnksm/topological-sort-rs/compare/v0.0.10...v0.1.0 [0.0.10]: https://github.com/gifnksm/topological-sort-rs/compare/v0.0.9...v0.0.10 [0.0.9]: https://github.com/gifnksm/topological-sort-rs/compare/v0.0.8...v0.0.9 [0.0.8]: https://github.com/gifnksm/topological-sort-rs/compare/v0.0.7...v0.0.8 [0.0.7]: https://github.com/gifnksm/topological-sort-rs/compare/v0.0.6...v0.0.7 [0.0.6]: https://github.com/gifnksm/topological-sort-rs/compare/v0.0.5...v0.0.6 [0.0.5]: https://github.com/gifnksm/topological-sort-rs/compare/v0.0.4...v0.0.5 [0.0.4]: https://github.com/gifnksm/topological-sort-rs/compare/v0.0.3...v0.0.4 [0.0.3]: https://github.com/gifnksm/topological-sort-rs/compare/v0.0.2...v0.0.3 [0.0.2]: https://github.com/gifnksm/topological-sort-rs/compare/v0.0.1...v0.0.2 [0.0.1]: https://github.com/gifnksm/topological-sort-rs/releases/tag/v0.0.1