5 unstable releases
0.4.0 | Sep 17, 2020 |
---|---|
0.3.0 | Aug 29, 2020 |
0.1.3 | May 29, 2020 |
#1259 in Data structures
13KB
223 lines
🧸 Mofurun 🧸
🧸🧸🧸🧸🧸🧸🧸🧸🧸🧸🧸🧸🧸🧸🧸🧸🧸🧸🧸🧸🧸
Experimental implementation of Vec
that stores the state of the underlying array using types.
This allows us to optimize some operations based on its state.
🧸🧸🧸🧸🧸🧸🧸🧸🧸🧸🧸🧸🧸🧸🧸🧸🧸🧸🧸🧸🧸
Example
For the simplest case, consider finding the maximum value in a vector.
use mofurun::{sorted_vec::SortedVec, unsorted_vec::UnsortedVec};
pub fn main() {
// Although we began with a sorted vector, we ended up with an unsorted vector.
let s : UnsortedVec<i32> = SortedVec::default()
.push(5)
.push(4)
.push(3)
.push(2)
.push(1)
.push(0);
// Recover sorted vector.
let s : SortedVec<i32> = s.sort();
}
I think there are many, many more containers like this and I am generally interested in the idea of using structs to force the logic of a program.