{"id":25613556,"url":"https://github.com/sajjon/identified_vec","last_synced_at":"2025-10-18T03:02:54.459Z","repository":{"id":211481080,"uuid":"729280485","full_name":"Sajjon/identified_vec","owner":"Sajjon","description":"Like HashSet but retaining INSERTION order and without `Hash` requirement on the Element type.","archived":false,"fork":false,"pushed_at":"2023-12-22T09:07:53.000Z","size":121,"stargazers_count":5,"open_issues_count":0,"forks_count":1,"subscribers_count":2,"default_branch":"main","last_synced_at":"2025-03-27T09:52:13.264Z","etag":null,"topics":["btreeset","crate","identified-vec","insertion-order","rust","unique","vec"],"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/Sajjon.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null}},"created_at":"2023-12-08T19:49:58.000Z","updated_at":"2024-10-30T08:13:51.000Z","dependencies_parsed_at":"2023-12-13T22:09:33.666Z","dependency_job_id":"9a12437f-0e8b-4129-9b0b-650319054728","html_url":"https://github.com/Sajjon/identified_vec","commit_stats":null,"previous_names":["sajjon/identified_vec"],"tags_count":10,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Sajjon%2Fidentified_vec","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Sajjon%2Fidentified_vec/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Sajjon%2Fidentified_vec/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Sajjon%2Fidentified_vec/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/Sajjon","download_url":"https://codeload.github.com/Sajjon/identified_vec/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248766747,"owners_count":21158301,"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","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":["btreeset","crate","identified-vec","insertion-order","rust","unique","vec"],"created_at":"2025-02-22T01:36:05.973Z","updated_at":"2025-10-18T03:02:49.424Z","avatar_url":"https://github.com/Sajjon.png","language":"Rust","readme":"# `identified_vec`\n\n[![Code Coverage](https://codecov.io/github/Sajjon/identified_vec/graph/badge.svg?token=Em6TayrP8j)](https://codecov.io/github/Sajjon/identified_vec)\n[![Crates.io](https://img.shields.io/crates/v/identified_vec.svg)](https://crates.io/crates/identified_vec)\n[![Documentation](https://docs.rs/identified_vec/badge.svg)](https://docs.rs/identified_vec)\n[![Rust](https://img.shields.io/badge/rust-1.73.0%2B-blue.svg?maxAge=3600)](https://github.com/Sajjon/identified_vec)\n\nA collection of unique identifiable elements which retains **insertion** order, inspired by [Pointfree's Swift Identified Collections](https://github.com/pointfreeco/swift-identified-collections).\n\nSimilar to the standard `Vec`, the `IdentifiedVec` maintain their elements in a particular user-specified order. However, unlike `Vec`, the `IdentifiedVec` introduce the ability to uniquely identify elements, using a hash table to ensure that no two elements have the same identity, and to efficiently look up elements corresponding to specific identifiers.\n\n`IdentifiedVec` is a useful alternative to `Vec` when you need to be able to efficiently access unique elements by a stable identifier. It is also a useful alternative to `BTreeSet`, where the `Ord` trait requirement may be too strict, an a useful alternative to `HashSet` where `Hash` trait requirement may be too strict.\n\nYou can create an identified vec with any element type that implements the `Identifiable` trait.\n\n# Example\n\n```rust\nextern crate identified_vec;\nuse identified_vec::{IsIdentifiedVec, IdentifiedVec, Identifiable, IdentifiedVecOf};\nuse std::cell::RefCell;\n\n#[derive(Eq, PartialEq, Clone, Debug)]\nstruct User {\n    id: \u0026'static str,\n    name: RefCell\u003c\u0026'static str\u003e,\n}\n\nimpl User {\n    fn new(id: \u0026'static str, name: \u0026'static str) -\u003e Self {\n        Self {\n            id,\n            name: RefCell::new(name),\n        }\n    }\n    fn name(\u0026self) -\u003e \u0026'static str {\n        *self.name.borrow()\n    }\n}\n```\n\n## Identifiable\n\n```rust\nimpl Identifiable for User {\n    type ID = \u0026'static str;\n    fn id(\u0026self) -\u003e Self::ID {\n        self.id\n    }\n}\n```\n\n## `from_iter`\n\n```rust\nlet mut users = IdentifiedVecOf::\u003cUser\u003e::from_iter([\n    User::new(\"u_42\", \"Satoshi Nakamoto\"),\n    User::new(\"u_1337\", \"Leia Skywalker\"),\n]);\n\nassert_eq!(\n    users.get(\u0026\"u_42\").map(|u| u.name()),\n    Some(\"Satoshi Nakamoto\")\n);\n\nassert_eq!(\n    users.get_at_index(1).map(|u| u.name()),\n    Some(\"Leia Skywalker\")\n);\n```\n\n## `append` \u0026 `elements()`\n\n```rust\nusers.append(User::new(\"u_237\", \"Alan Turing\"));\nassert_eq!(\n    users.elements(),\n    [\n        User::new(\"u_42\", \"Satoshi Nakamoto\"),\n        User::new(\"u_1337\", \"Leia Skywalker\"),\n        User::new(\"u_237\", \"Alan Turing\"),\n    ]\n    .iter()\n    .collect::\u003cVec\u003c\u0026User\u003e\u003e()\n);\n\n// Element with same ID is not appended:\nusers.append(User::new(\"u_42\", \"Tom Mervolo Dolder\"));\nassert_eq!(\n    users.elements(),\n    [\n        User::new(\"u_42\", \"Satoshi Nakamoto\"),\n        User::new(\"u_1337\", \"Leia Skywalker\"),\n        User::new(\"u_237\", \"Alan Turing\"),\n    ]\n    .iter()\n    .collect::\u003cVec\u003c\u0026User\u003e\u003e()\n);\n```\n\n## `update_or_insert`\n\n```rust\n// Element with same ID replaces existing if an `update_*` method is used:\n// e.g. `update_or_insert`:\nusers.update_or_insert(User::new(\"u_42\", \"Tom Mervolo Dolder\"), 0);\nassert_eq!(\n    users.elements(),\n    [\n        User::new(\"u_42\", \"Tom Mervolo Dolder\"),\n        User::new(\"u_1337\", \"Leia Skywalker\"),\n        User::new(\"u_237\", \"Alan Turing\"),\n    ]\n    .iter()\n    .collect::\u003cVec\u003c\u0026User\u003e\u003e()\n);\n```\n\n## `update_or_append`\n\n```rust\n// or `update_or_append`\nusers.update_or_append(User::new(\"u_237\", \"Marie Curie\"));\nassert_eq!(\n    users.elements(),\n    [\n        User::new(\"u_42\", \"Tom Mervolo Dolder\"),\n        User::new(\"u_1337\", \"Leia Skywalker\"),\n        User::new(\"u_237\", \"Marie Curie\"),\n    ]\n    .iter()\n    .collect::\u003cVec\u003c\u0026User\u003e\u003e()\n);\n```\n\nOr you can provide a closure that describes an element's identity:\n\n```rust\nlet numbers = IdentifiedVec::\u003cu32, u32\u003e::new_identifying_element(|e| *e);\n```\n\n# Motivation\n\nNone of the std collections `BTreeSet` and `HashSet` retain insertion order, `Vec` retains insertion order, however, it allows for duplicates. So if you want a collection of unique elements (Set-like) that does retain insertion order, `IdentifiedVec` suits your needs. Even better, the elements does not need to be to impl `Hash` nor ` Ord`.\n\n## Flags\n\nThis crate has the following Cargo features:\n\n- `serde`: Enables serde serialization support on `IdentifiedVecOf` type (which `Element` impl `Identifiable` trait).\n- `id_prim`: Get impl of trait `Identifiable` for primitives: `i8`,.., `i128`, `u8`, ..., `u128` and `bool` (not so useful, allows for only two elements in `IdentifiedVecOf`, but who am I to discriminate.)\n\n## Implementation Details\n\nAn identified vec consists of a `Vec` of `ID`s keeping insertion order and a `HashMap` of id-element pairs, for constant time lookup of element given an ID.\n\n## License\n\nLicensed under MIT license ([LICENSE-MIT](LICENSE-MIT) or https://opensource.org/licenses/MIT)\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsajjon%2Fidentified_vec","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fsajjon%2Fidentified_vec","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsajjon%2Fidentified_vec/lists"}