2 unstable releases
0.2.0 | Jan 5, 2023 |
---|---|
0.1.0 | Jan 4, 2023 |
#2482 in Algorithms
14KB
243 lines
ordered_vec
This little library provides a trait that ensures elements in a vector are pushed in a sorted order, both ascending and descending.
Example
use ordered_vec::OrdVec;
fn main() {
let mut values: Vec<i32> = Vec::new();
values.push_ord_ascending(5);
values.push_ord_ascending(3);
values.push_ord_ascending(7);
values.push_ord_ascending(1);
assert_eq!(values, [1, 3, 5, 7]);
let mut values: Vec<i32> = Vec::new();
values.push_ord_descending(5);
values.push_ord_descending(3);
values.push_ord_descending(7);
values.push_ord_descending(1);
assert_eq!(values, [7, 5, 3, 1]);
}
License
This library is licensed under MIT and Apache-2.0.
lib.rs
:
The OrdVec
trait provides an extension to Vec
to allow for inserting items in order, both
ascending and descending.
Examples
use ordered_vec::OrdVec;
let mut values: Vec<i32> = Vec::new();
values.push_ord_ascending(5);
values.push_ord_ascending(3);
values.push_ord_ascending(7);
values.push_ord_ascending(1);
assert_eq!(values, [1, 3, 5, 7]);
use ordered_vec::OrdVec;
let mut values: Vec<i32> = Vec::new();
values.push_ord_descending(5);
values.push_ord_descending(3);
values.push_ord_descending(7);
values.push_ord_descending(1);
assert_eq!(values, [7, 5, 3, 1]);