{"id":24280684,"url":"https://github.com/kneasle/shortlist","last_synced_at":"2025-09-24T23:31:39.994Z","repository":{"id":57667260,"uuid":"302708814","full_name":"kneasle/shortlist","owner":"kneasle","description":"An efficient data structure to track the largest items pushed to it.","archived":false,"fork":false,"pushed_at":"2021-06-28T17:24:11.000Z","size":46,"stargazers_count":3,"open_issues_count":0,"forks_count":2,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-08-25T00:04:32.167Z","etag":null,"topics":["data-structures","rust","rust-library","shortlist"],"latest_commit_sha":null,"homepage":"","language":"Rust","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/kneasle.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGE_LOG.md","contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2020-10-09T17:22:47.000Z","updated_at":"2022-10-12T02:57:08.000Z","dependencies_parsed_at":"2022-09-02T14:22:28.881Z","dependency_job_id":null,"html_url":"https://github.com/kneasle/shortlist","commit_stats":null,"previous_names":[],"tags_count":2,"template":false,"template_full_name":null,"purl":"pkg:github/kneasle/shortlist","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kneasle%2Fshortlist","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kneasle%2Fshortlist/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kneasle%2Fshortlist/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kneasle%2Fshortlist/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/kneasle","download_url":"https://codeload.github.com/kneasle/shortlist/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kneasle%2Fshortlist/sbom","scorecard":{"id":564397,"data":{"date":"2025-08-11","repo":{"name":"github.com/kneasle/shortlist","commit":"4b5bb71d284f1ada5c936fc8d84fa9bf560ca400"},"scorecard":{"version":"v5.2.1-40-gf6ed084d","commit":"f6ed084d17c9236477efd66e5b258b9d4cc7b389"},"score":3.4,"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":"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":"Dangerous-Workflow","score":10,"reason":"no dangerous workflow patterns detected","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":"Pinned-Dependencies","score":0,"reason":"dependency not pinned by hash detected -- score normalized to 0","details":["Warn: GitHub-owned GitHubAction not pinned by hash: .github/workflows/tests.yml:18: update your workflow using https://app.stepsecurity.io/secureworkflow/kneasle/shortlist/tests.yml/master?enable=pin","Info:   0 out of   1 GitHub-owned GitHubAction 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":"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":"Token-Permissions","score":0,"reason":"detected GitHub workflow tokens with excessive permissions","details":["Warn: no topLevel permission defined: .github/workflows/tests.yml:1","Info: no jobLevel write permissions found"],"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":"Code-Review","score":0,"reason":"Found 0/30 approved changesets -- score normalized to 0","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":"SAST","score":0,"reason":"no SAST tool detected","details":["Warn: no pull requests merged into dev branch"],"documentation":{"short":"Determines if the project uses static code analysis.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#sast"}},{"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":"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":"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:0","Info: FSF or OSI recognized license: MIT License: LICENSE:0"],"documentation":{"short":"Determines if the project has defined a license.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#license"}},{"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"}}]},"last_synced_at":"2025-08-20T14:34:34.814Z","repository_id":57667260,"created_at":"2025-08-20T14:34:34.814Z","updated_at":"2025-08-20T14:34:34.814Z"},"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":276834244,"owners_count":25712965,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","status":"online","status_checked_at":"2025-09-24T02:00:09.776Z","response_time":97,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"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":["data-structures","rust","rust-library","shortlist"],"created_at":"2025-01-16T02:25:23.982Z","updated_at":"2025-09-24T23:31:39.685Z","avatar_url":"https://github.com/kneasle.png","language":"Rust","funding_links":[],"categories":[],"sub_categories":[],"readme":"# shortlist\n\n[![Crates.io](https://img.shields.io/crates/v/shortlist.svg)](https://crates.io/crates/shortlist)\n[![Docs.rs](https://docs.rs/shortlist/badge.svg)](https://docs.rs/shortlist)\n\nA data structure to track the largest items pushed to it with no heap allocations and `O(1)`\namortized time per push.\n\n## Features\n- Time complexity for pushing is `O(1)` amortized and `O(log n)` worst case (if the inputs are\n  already sorted)\n- No heap allocations except when creating a new `Shortlist`\n- 0 dependencies, and only ~150 lines of source code\n- No `unsafe`\n\n## The Problem\nSuppose that you are running a brute force search over a very large search space, but want to\nkeep more than just the single best item - for example, you want to find the best 100 items out\nof a search of a billion options.\n\nI.e. you want to implement the following function:\n```rust\nfn get_best\u003cT: Ord\u003e(\n    big_computation: impl Iterator\u003cItem = T\u003e,\n    n: usize\n) -\u003e Vec\u003cT\u003e {\n    // Somehow get the `n` largest items produced by `big_computation` ...\n}\n```\n\n## A bad solution\nThe naive approach to this would be to store every item that we searched.  Then once the search\nis complete, sort this list and then take however many items we need from the end of the list.\nThis corresponds to roughly the following code:\n```rust\nfn get_best\u003cT: Ord\u003e(\n    big_computation: impl Iterator\u003cItem = T\u003e,\n    n: usize\n) -\u003e Vec\u003cT\u003e {\n    // Collect all the results into a big sorted vec\n    let mut giant_vec: Vec\u003cT\u003e = big_computation.collect();\n    giant_vec.sort();\n    // Return the last and therefore biggest n items with some iterator magic\n    giant_vec.drain(..).rev().take(n).rev().collect()\n}\n\n```\n\nBut this is massively inefficient in (at least) two ways:\n- Sorting very large lists is very slow, and we are sorting potentially billions of items that\n  we will never need.\n- For any decently large search space, storing these items will likely crash the computer by\n  making it run out of memory.\n\n## The solution used by this crate\nThis is where using a `Shortlist` is useful.\n\nA `Shortlist` is a data structure that will dynamically keep a 'shortlist' of the best items\ngiven to it so far, with `O(1)` amortized time for pushing new items.  It will also only perform\none heap allocation when the `Shortlist` is created and every subsequent operation will be\nallocation free.  Therefore, to the user of this library the code becomes:\n```rust\nuse shortlist::Shortlist;\n\nfn get_best\u003cT: Ord\u003e(\n    big_computation: impl Iterator\u003cItem = T\u003e,\n    n: usize\n) -\u003e Vec\u003cT\u003e {\n    // Create a new Shortlist that will take at most `n` items\n    let mut shortlist = Shortlist::new(n);\n    // Feed it all the results from `big_computation`\n    for v in big_computation {\n        shortlist.push(v);\n    }\n    // Return the shortlisted values as a sorted vec\n    shortlist.into_sorted_vec()\n}\n\n```\n\nOr as a one-liner:\n```rust\nuse shortlist::Shortlist;\n\nfn get_best\u003cT: Ord\u003e(big_computation: impl Iterator\u003cItem = T\u003e, n: usize) -\u003e Vec\u003cT\u003e {\n    Shortlist::from_iter(n, big_computation).into_sorted_vec()\n}\n\n```\n\nIn both cases, the code will make exactly one heap allocation (to reserve space for the\n`Shortlist`).\n\nLicense: MIT\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fkneasle%2Fshortlist","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fkneasle%2Fshortlist","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fkneasle%2Fshortlist/lists"}