{"id":13822419,"url":"https://github.com/benashford/rust-lazysort","last_synced_at":"2026-04-02T01:39:51.359Z","repository":{"id":23370842,"uuid":"26732161","full_name":"benashford/rust-lazysort","owner":"benashford","description":"Iterate in a lazily achieved sorted order","archived":false,"fork":false,"pushed_at":"2018-10-16T20:18:33.000Z","size":71,"stargazers_count":59,"open_issues_count":2,"forks_count":11,"subscribers_count":2,"default_branch":"master","last_synced_at":"2026-01-02T09:25:26.054Z","etag":null,"topics":["algorithm","iterator","quicksort","rust","sort"],"latest_commit_sha":null,"homepage":"","language":"Rust","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/benashford.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE-APACHE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2014-11-16T23:36:51.000Z","updated_at":"2024-09-15T20:39:50.000Z","dependencies_parsed_at":"2022-08-05T22:16:22.560Z","dependency_job_id":null,"html_url":"https://github.com/benashford/rust-lazysort","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/benashford/rust-lazysort","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/benashford%2Frust-lazysort","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/benashford%2Frust-lazysort/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/benashford%2Frust-lazysort/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/benashford%2Frust-lazysort/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/benashford","download_url":"https://codeload.github.com/benashford/rust-lazysort/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/benashford%2Frust-lazysort/sbom","scorecard":{"id":231390,"data":{"date":"2025-08-11","repo":{"name":"github.com/benashford/rust-lazysort","commit":"be2db80af0759f02019c5246edf855ce0b8bdf7f"},"scorecard":{"version":"v5.2.1-40-gf6ed084d","commit":"f6ed084d17c9236477efd66e5b258b9d4cc7b389"},"score":2.9,"checks":[{"name":"Maintained","score":0,"reason":"0 commit(s) and 0 issue activity found in the last 90 days -- score normalized to 0","details":null,"documentation":{"short":"Determines if the project is \"actively maintained\".","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#maintained"}},{"name":"Token-Permissions","score":-1,"reason":"No tokens found","details":null,"documentation":{"short":"Determines if the project's workflows follow the principle of least privilege.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#token-permissions"}},{"name":"Dangerous-Workflow","score":-1,"reason":"no workflows found","details":null,"documentation":{"short":"Determines if the project's GitHub Action workflows avoid dangerous patterns.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#dangerous-workflow"}},{"name":"Packaging","score":-1,"reason":"packaging workflow not detected","details":["Warn: no GitHub/GitLab publishing workflow detected."],"documentation":{"short":"Determines if the project is published as a package that others can easily download, install, easily update, and uninstall.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#packaging"}},{"name":"Binary-Artifacts","score":10,"reason":"no binaries found in the repo","details":null,"documentation":{"short":"Determines if the project has generated executable (binary) artifacts in the source repository.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#binary-artifacts"}},{"name":"Code-Review","score":1,"reason":"Found 2/18 approved changesets -- score normalized to 1","details":null,"documentation":{"short":"Determines if the project requires human code review before pull requests (aka merge requests) are merged.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#code-review"}},{"name":"CII-Best-Practices","score":0,"reason":"no effort to earn an OpenSSF best practices badge detected","details":null,"documentation":{"short":"Determines if the project has an OpenSSF (formerly CII) Best Practices Badge.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#cii-best-practices"}},{"name":"Security-Policy","score":0,"reason":"security policy file not detected","details":["Warn: no security policy file detected","Warn: no security file to analyze","Warn: no security file to analyze","Warn: no security file to analyze"],"documentation":{"short":"Determines if the project has published a security policy.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#security-policy"}},{"name":"Vulnerabilities","score":10,"reason":"0 existing vulnerabilities detected","details":null,"documentation":{"short":"Determines if the project has open, known unfixed vulnerabilities.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#vulnerabilities"}},{"name":"License","score":10,"reason":"license file detected","details":["Info: project has a license file: LICENSE-APACHE:0","Info: FSF or OSI recognized license: Apache License 2.0: LICENSE-APACHE:0"],"documentation":{"short":"Determines if the project has defined a license.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#license"}},{"name":"Fuzzing","score":0,"reason":"project is not fuzzed","details":["Warn: no fuzzer integrations found"],"documentation":{"short":"Determines if the project uses fuzzing.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#fuzzing"}},{"name":"Signed-Releases","score":-1,"reason":"no releases found","details":null,"documentation":{"short":"Determines if the project cryptographically signs release artifacts.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#signed-releases"}},{"name":"Branch-Protection","score":0,"reason":"branch protection not enabled on development/release branches","details":["Warn: branch protection not enabled for branch 'master'"],"documentation":{"short":"Determines if the default and release branches are protected with GitHub's branch protection settings.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#branch-protection"}},{"name":"Pinned-Dependencies","score":0,"reason":"dependency not pinned by hash detected -- score normalized to 0","details":["Warn: containerImage not pinned by hash: devbox/Dockerfile:1","Info:   0 out of   1 containerImage dependencies pinned"],"documentation":{"short":"Determines if the project has declared and pinned the dependencies of its build process.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#pinned-dependencies"}},{"name":"SAST","score":0,"reason":"SAST tool is not run on all commits -- score normalized to 0","details":["Warn: 0 commits out of 15 are checked with a SAST tool"],"documentation":{"short":"Determines if the project uses static code analysis.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#sast"}}]},"last_synced_at":"2025-08-17T04:55:42.160Z","repository_id":23370842,"created_at":"2025-08-17T04:55:42.160Z","updated_at":"2025-08-17T04:55:42.160Z"},"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":31294036,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-04-02T01:05:07.454Z","status":"ssl_error","status_checked_at":"2026-04-02T00:56:46.496Z","response_time":53,"last_error":"SSL_connect returned=1 errno=0 peeraddr=140.82.121.6:443 state=error: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["algorithm","iterator","quicksort","rust","sort"],"created_at":"2024-08-04T08:01:59.526Z","updated_at":"2026-04-02T01:39:51.342Z","avatar_url":"https://github.com/benashford.png","language":"Rust","funding_links":[],"categories":["Rust"],"sub_categories":[],"readme":"# Lazysort\n\n[![Build Status](https://travis-ci.org/benashford/rust-lazysort.svg?branch=master)](https://travis-ci.org/benashford/rust-lazysort)\n[![](http://meritbadge.herokuapp.com/lazysort)](https://crates.io/crates/lazysort)\n[![](https://img.shields.io/crates/d/lazysort.svg)](https://crates.io/crates/lazysort)\n[![](https://img.shields.io/crates/dv/lazysort.svg)](https://crates.io/crates/lazysort)\n[![](https://docs.rs/lazysort/badge.svg)](https://docs.rs/lazysort/)\n\nAdds a method to iterators that returns a sorted iterator over the data.  The sorting is achieved lazily using a quicksort algorithm.\n\nAvailable via [crates.io](https://crates.io/crates/lazysort).\n\n## Usage\n\n```rust\nextern crate lazysort;\n\nuse lazysort::Sorted;\n\nuse lazysort::SortedBy;\n\nuse lazysort::SortedPartial;\n```\n\nThe `Sorted` trait adds a method `sorted` to all `Iterator\u003cT: Ord\u003e` which returns an iterator over the same data in default order.\n\nThe `SortedBy` trait adds a method `sorted_by` to all `Iterator\u003cT\u003e` which returns an iterator over the same data ordered according to the provided closure/function of type `Fn(\u0026T, \u0026T) -\u003e Ordering`\n\nThe `SortedPartial` trait adds two methods `sorted_partial_first` and `sorted_partial_last` to all `Iterator\u003cT: PartialOrd\u003e` which returns an iterator over the same data in the default order.  The difference between the two is whether non-comparable values go first or last in the results.\n\nFor example:\n\n```rust\nlet data: Vec\u003cuint\u003e = vec![9, 1, 3, 4, 4, 2, 4];\nfor x in data.iter().sorted() {\n\tprintln!(\"{}\", x);\n}\n```\n\nWill print: 1, 2, 3, 4, 4, 4, 9\n\nA more complex example.  Sort strings by length, then in default string order:\n\n```rust\nlet before: Vec\u003c\u0026str\u003e = vec![\"a\", \"cat\", \"sat\", \"on\", \"the\", \"mat\"];\nbefore.iter().sorted_by(|a, b| {\n    match a.len().cmp(\u0026b.len()) {\n        Equal =\u003e a.cmp(b),\n        x =\u003e x\n    }\n})\n```\n\nThis returns an iterator which yields: `a`, `on`, `cat`, `mat`, `sat`, `the`.\n\n## Implementation details and performance\n\nThe algorithm is essentially the same as described in my blog post [using a lazy sort as an example of Clojure's lazy sequences](http://benashford.github.io/blog/2014/03/22/the-power-of-lazy-sequences/).  But made to fit in with Rust's iterators.\n\nThe full sequence from the parent iterator is read, then each call to `next` returns the next value in the sorted sequence.  The sort is done element-by-element so the full order is only realised by iterating all the way through to the end.\n\nThe algorithm is the quicksort, but depth-first; upon each call to `next` it does the work necessary to find the next item then pauses the state until the next call to `next`.\n\nTo test performance we compare it against sorting the full vector, using the `sort` function from the standard library, and also against `std::collections::BinaryHeap`.\n\nFirst we compare what happens when sorting the entire vector:\n\n```\ntest benches::c_heap_bench     ... bench:   3,703,166 ns/iter (+/- 454,189)\ntest benches::c_lazy_bench     ... bench:   3,961,047 ns/iter (+/- 603,083)\ntest benches::c_standard_bench ... bench:   3,093,873 ns/iter (+/- 430,401)\n```\n\nThere are differences between the three, and not surprisingly the built-in sort is fastest.\n\nThese benchmarks are for sorting 50,000 random `uint`s in the range 0 \u003c= x \u003c 1000000.  Run `cargo bench` to run them.\n\nSo what's the point of lazy sorting?  As per the linked blog post, they're useful when you do not need or intend to need every value; for example you may only need the first 1,000 ordered values from a larger set.\n\nComparing the lazy approach `data.iter().sorted().take(x)` vs a standard approach of sorting a vector then taking the first `x` values gives the following.\n\nThe first 1,000 out of 50,000:\n\n```\ntest benches::a_heap_bench     ... bench:     366,767 ns/iter (+/- 55,393)\ntest benches::a_lazy_bench     ... bench:     171,923 ns/iter (+/- 52,784)\ntest benches::a_standard_bench ... bench:   3,055,734 ns/iter (+/- 348,407)\n```\n\nThe lazy approach is quite a bit faster; this is due to the 50,000 only being sorted enough to identify the first 1,000, the rest remain unsorted.  `BinaryHeap` is also quite fast, for the same reason.\n\nThe first 10,000 out of 50,000:\n\n```\ntest benches::b_heap_bench     ... bench:   1,126,774 ns/iter (+/- 156,833)\ntest benches::b_lazy_bench     ... bench:     993,954 ns/iter (+/- 208,188)\ntest benches::b_standard_bench ... bench:   3,054,598 ns/iter (+/- 285,970)\n```\n\nThe lazy approach is still faster in this situation.\n\n## License\n\nLicensed under either of\n\n* Apache License, Version 2.0 ([LICENSE-APACHE](LICENSE-APACHE) or http://www.apache.org/licenses/LICENSE-2.0)\n* MIT license ([LICENSE-MIT](LICENSE-MIT) or http://opensource.org/licenses/MIT)\n\nat your option.\n\n### Contribution\n\nUnless you explicitly state otherwise, any contribution intentionally submitted\nfor inclusion in the work by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without any\nadditional terms or conditions.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbenashford%2Frust-lazysort","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fbenashford%2Frust-lazysort","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbenashford%2Frust-lazysort/lists"}