indexed-vector

Crates.ioindexed-vector
lib.rsindexed-vector
version0.1.0
sourcesrc
created_at2023-03-06 13:39:07.146661
updated_at2023-03-06 13:39:07.146661
descriptionA Rust library that implements vector container that can be indexed with specified function.
homepage
repositoryhttps://github.com/lucidfrontier45/indexed-vector
max_upload_size
id802649
size9,948
杜世橋 Du Shiqiao (lucidfrontier45)

documentation

README

indexed-vector

A Rust library that implements vector container that can be indexed with specified function.

Implemented Structs

  • HashIndexedVector implements a simple indexed vector with HashMap
  • BTreeIndexedVector implements an indexed vector with BTreeMap. It also supports range query.

Example

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<_>>());
}
Commit count: 9

cargo fmt