Crates.io | indexedlinkedhashmap |
lib.rs | indexedlinkedhashmap |
version | 3.0.0 |
source | src |
created_at | 2023-06-18 23:34:19.519688 |
updated_at | 2023-11-11 07:41:39.174122 |
description | An indexable LinkedHashMap. The user defines the data structure that controls order. |
homepage | |
repository | https://github.com/brandongraylong/rust-indexedlinkedhashmap |
max_upload_size | |
id | 893672 |
size | 20,315 |
An indexable LinkedHashMap. Written in Rust.
Bring your own ordering data structure. Uses the standard library's HashMap
.
Vec
for keys, you can index easily.BinaryHeap
for keys, it doesn't make much sense to index on certain operations.
ins.set(None, value)
.Ordered
trait at indexedlinkedhashmap::traits::Ordered
.Vec
usageBinaryHeap
usage[dependencies]
indexedlinkedhashmap = "3.0.0"
[dependencies]
indexedlinkedhashmap = { version = "3.0.0", features = [ "collections_ordering_vec", "collections_ordering_binary_heap" ] }
fn main() {
let mut ins = IndexedLinkedHashMap::<Vec<&str>, &str, usize>::new();
assert!(ins.remove("k") == None);
assert!(ins.len() == 0);
assert!(ins.keys().len() == 0);
assert!(ins.values().len() == 0);
ins.set("k", 1);
assert!(
ins.remove("k")
== Some(IndexedLinkedHashMapValue {
index: Some(0),
value: 1
})
);
assert!(ins.len() == 0);
assert!(ins.keys().len() == 0);
assert!(ins.values().len() == 0);
}
fn main() {
let mut ins = IndexedLinkedHashMap::<Vec<&str>, &str, usize>::new();
ins.set("k", 1);
assert!(ins.len() == 1);
assert!(ins.keys().len() == 1);
assert!(ins.values().len() == 1);
assert!(ins.get("k") == Some(&1));
}
#[derive(Clone, Debug)]
struct Line2D {
id: String,
p1: usize,
p2: usize,
}
fn main() {
let mut ins = IndexedLinkedHashMap::<Vec<String>, String, Line2D>::new();
let line = Line2D {
id: String::from("1"),
p1: 0,
p2: 10,
};
ins.set(line.to_owned().id, line);
}
use std::collections::BinaryHeap;
fn main() {
let mut ins = IndexedLinkedHashMap::<BinaryHeap<usize>, usize, bool>::new();
ins.set(2, false);
ins.set(1, true);
assert!(ins.at(Some(1)) == Some(&true));
}
Run cargo test --features collections_ordering_vec,collections_ordering_binary_heap