Crates.io | subranges |
lib.rs | subranges |
version | 0.3.3 |
source | src |
created_at | 2020-10-27 12:03:24.450757 |
updated_at | 2023-10-13 08:59:16.109527 |
description | Library to manage non-interssecting integer intervals |
homepage | |
repository | https://github.com/F3kilo/subrange |
max_upload_size | |
id | 305967 |
size | 16,692 |
Interval struct and collection for free intervals.
use subranges::FreeIntervals;
fn main() {
// new collection with free interval
let free = (0..100).into();
let mut collection = FreeIntervals::new(free);
// fill subrange of free interval
let first = collection.take_exact(32).unwrap();
println!("first: {first}"); // output: first: [0, 32)
// fill other subrange of free interval with alignment
let aligned = collection.take_exact_aligned(32, 10).unwrap();
println!("aligned: {aligned}"); // output: aligned: [40, 72)
// no free subrange with `length == 40`.
let none = collection.take_exact(40);
assert!(none.is_none());
// free `first` intervals with `length == 32`,
// it connects with padding with `length == 8` from aligned interval.
collection.insert(first);
// now we have subrange with `length == 40`.
let some = collection.take_exact(40).unwrap();
println!("some: {some}"); // output: some: [0, 40)
}