{"id":16238069,"url":"https://github.com/koehlma/sharedvec-rs","last_synced_at":"2025-10-17T05:26:53.596Z","repository":{"id":43093953,"uuid":"469053823","full_name":"koehlma/sharedvec-rs","owner":"koehlma","description":"A fast but limited ordered collection for storing values of a single type.","archived":false,"fork":false,"pushed_at":"2022-05-19T09:52:44.000Z","size":46,"stargazers_count":0,"open_issues_count":1,"forks_count":0,"subscribers_count":2,"default_branch":"main","last_synced_at":"2025-08-17T05:41:01.960Z","etag":null,"topics":["data-structures","rust"],"latest_commit_sha":null,"homepage":"https://docs.rs/sharedvec","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/koehlma.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}},"created_at":"2022-03-12T10:45:17.000Z","updated_at":"2022-03-18T14:15:19.000Z","dependencies_parsed_at":"2022-09-07T17:34:24.541Z","dependency_job_id":null,"html_url":"https://github.com/koehlma/sharedvec-rs","commit_stats":null,"previous_names":["koehlma/stacko-rs"],"tags_count":3,"template":false,"template_full_name":null,"purl":"pkg:github/koehlma/sharedvec-rs","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/koehlma%2Fsharedvec-rs","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/koehlma%2Fsharedvec-rs/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/koehlma%2Fsharedvec-rs/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/koehlma%2Fsharedvec-rs/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/koehlma","download_url":"https://codeload.github.com/koehlma/sharedvec-rs/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/koehlma%2Fsharedvec-rs/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":275623477,"owners_count":25498340,"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-17T02:00:09.119Z","response_time":84,"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"],"created_at":"2024-10-10T13:38:36.982Z","updated_at":"2025-09-17T16:33:58.803Z","avatar_url":"https://github.com/koehlma.png","language":"Rust","funding_links":[],"categories":[],"sub_categories":[],"readme":"# SharedVec    [![Build Status]][actions] [![Latest Version]][crates.io]\n\n[Build Status]: https://img.shields.io/github/workflow/status/koehlma/sharedvec-rs/Pipeline/main?label=tests\n[actions]: https://github.com/koehlma/sharedvec-rs/actions\n[Latest Version]: https://img.shields.io/crates/v/sharedvec.svg\n[crates.io]: https://crates.io/crates/sharedvec\n\n\n`SharedVec` is a **fast but limited ordered collection** for storing values of a single\ntype.\n\n\n## What is a `SharedVec`?\n\n`SharedVec` is a fast and ordered collection, similar to `Vec`, onto which values\ncan be pushed. In contrast to a `Vec`, a `SharedVec` allows pushing values through\na shared reference. Pushing values is an *O(1)* operation and will never relocate\npreviously pushed values, i.e., previous values remain at a stable address in memory.\nThis enables safe pushing through a shared reference.\n\nWhen pushing a value, a `SharedVec` returns a shared reference to the value in\naddition to a *key*. This key does *not* borrow from the `SharedVec` and can be\nused to retrieve the value in *O(1)*. In addition, given an exclusive reference to\nthe `SharedVec`, the key can be used to obtain an exclusive reference to the value\nin *O(1)*. Every key corresponds to an *index* indicating the position of the value\nin the `SharedVec`. Values can also be accessed by their index in *O(log n)*.\nIterating over a `SharedVec` or converting it to a `Vec` will also preserve the\norder in which values have been pushed onto the `SharedVec`.\n\nHere is a list of similar data structures and their differences:\n\n- A [`TypedArena`](https://docs.rs/typed-arena/) does not provide a key and\n  returns an exclusive reference to a value inserted through a shared reference. A\n  key is useful because it exists independently of the `SharedVec` (it does not\n  borrow). It can thus be passed around more freely than a reference and\n  can also be meaningfully serialized (for details see below).\n- A [`Slab`](https://docs.rs/slab) and a [`SlotMap`](https://docs.rs/slotmap) cannot\n  be mutated trough a shared reference. If mutation through a shared reference is\n  not required, you may want to consider those as they are generally much more\n  flexible.\n\n\n## Serialization\n\nUsing the `serde` feature flag, a `SharedVec` and its keys can be serialized with\n[Serde](https://docs.rs/serde).\n\nA `SharedVec` storing values of type `T` is serialized as a sequence of type `T`,\njust as a `Vec` is, and keys are serialized as an index into this sequence. This\nenables external tools to simply treat keys\nas indices into the serialized sequence. Using a previously serialized and then\ndeserialized key for accessing a value without also serializing and then deserializing\nthe corresponding `SharedVec` is an *O(log n)* operation (just as accessing by index).\n\nThis exact serialization behavior is considered part of the stability guarantees.\n\n\n## Example\n\n```rust\nlet vegetables = SharedVec::\u003c\u0026'static str\u003e::new();\n\nlet (cucumber_key, cucumber) = vegetables.push(\"Cucumber\");\nlet (paprika_key, paprika) = vegetables.push(\"Paprika\");\n\nassert_eq!(vegetables[cucumber_key], \"Cucumber\");\n\nassert_eq!(Vec::from(vegetables), vec![\"Cucumber\", \"Paprika\"]);\n```","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fkoehlma%2Fsharedvec-rs","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fkoehlma%2Fsharedvec-rs","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fkoehlma%2Fsharedvec-rs/lists"}