Crates.io | indexed-vector |
lib.rs | indexed-vector |
version | 0.1.0 |
source | src |
created_at | 2023-03-06 13:39:07.146661 |
updated_at | 2023-03-06 13:39:07.146661 |
description | A Rust library that implements vector container that can be indexed with specified function. |
homepage | |
repository | https://github.com/lucidfrontier45/indexed-vector |
max_upload_size | |
id | 802649 |
size | 9,948 |
A Rust library that implements vector container that can be indexed with specified function.
HashIndexedVector
implements a simple indexed vector with HashMap
BTreeIndexedVector
implements an indexed vector with BTreeMap
. It also supports range query.use indexed_vector::{BTreeIndexedVector, HashIndexedVector, IndexedVector};
#[derive(Clone, Debug)]
struct User {
name: String,
age: u16,
}
fn main() {
let users = vec![
User {
name: "Tom".to_owned(),
age: 20,
},
User {
name: "Jane".to_owned(),
age: 20,
},
User {
name: "Ivan".to_owned(),
age: 30,
},
];
let hash_vec = HashIndexedVector::new(users.clone(), |user: &User| user.age);
// Tom and Jane
dbg!(hash_vec.search(&20).collect::<Vec<_>>());
// Ivan
dbg!(hash_vec.search(&30).collect::<Vec<_>>());
let btree_vec = BTreeIndexedVector::new(users, |user: &User| user.age);
// Tom, Jane and Ivan
dbg!(btree_vec.search_range(10..40).collect::<Vec<_>>());
}