Crates.io | alist |
lib.rs | alist |
version | 0.1.0 |
source | src |
created_at | 2024-11-17 17:07:08.65632 |
updated_at | 2024-11-17 17:07:08.65632 |
description | Association list offering fast lookups while preserving insertion order |
homepage | |
repository | https://github.com/daddinuz/alist |
max_upload_size | |
id | 1451408 |
size | 120,124 |
alist
is a Rust crate that implements association lists, inspired by Lisp, as lightweight alternative to HashMap
and BTreeMap
.
The list is backed by a Vec
of key-value pairs and preserves the order of insertion.
It offers unique features like bookmarks for efficient item retrieval and is particularly well-suited for small datasets
or cases where insertion order matters.
alist
predictable and easy to iterate over.HashMap
or BTreeMap
, alist
requires keys to only implement Eq
.retain
, clear
, and shrink
.alist
Hash
or Ord
.Add alist
to your Cargo.toml
:
cargo add alist
or edit your Cargo.toml manually by adding:
[dependencies]
alist = "0.1"
AList
and Adding Itemsuse alist::AList;
let mut alist = AList::new();
alist.insert("key1", 42);
alist.insert("key2", 99);
assert_eq!(alist.get("key1"), Some(&42));
assert_eq!(alist.len(), 2);
Using the Bookmark API:
use alist::{AList, Bookmark};
let mut alist = AList::new();
alist.insert("key1", 42);
alist.insert("key2", 99);
// Bookmarks' lifetime is independant of that of alists
let mut bookmark = alist.bookmark("key1").unwrap();
// Fast retrieval using bookmark
assert_eq!(alist.get(&mut bookmark), Some(&42));
This crate contains no unsafe code.
All tests run under miri and the tests cover about 50% of the code.
You can generate the coverage report using tarpaulin.
Contributions are always welcome! If you have ideas for new operations or improvements, feel free to open an issue or submit a pull request.
This crate is licensed under the MIT License. See LICENSE for more details.