https://github.com/lucidfrontier45/indexed-vector
A Rust library that implements vector container that can be indexed with specified function.
https://github.com/lucidfrontier45/indexed-vector
data-structures rust
Last synced: 9 months ago
JSON representation
A Rust library that implements vector container that can be indexed with specified function.
- Host: GitHub
- URL: https://github.com/lucidfrontier45/indexed-vector
- Owner: lucidfrontier45
- License: mit
- Created: 2023-03-06T11:50:45.000Z (almost 3 years ago)
- Default Branch: main
- Last Pushed: 2023-03-06T13:39:28.000Z (almost 3 years ago)
- Last Synced: 2025-03-10T14:52:59.321Z (10 months ago)
- Topics: data-structures, rust
- Language: Rust
- Homepage:
- Size: 8.79 KB
- Stars: 1
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
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
```rust
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::>());
// Ivan
dbg!(hash_vec.search(&30).collect::>());
let btree_vec = BTreeIndexedVector::new(users, |user: &User| user.age);
// Tom, Jane and Ivan
dbg!(btree_vec.search_range(10..40).collect::>());
}
```