Struct subranges::FreeIntervals
source · pub struct FreeIntervals { /* private fields */ }
Expand description
Collection of free intervals. You can take parts of the free intervals and add new free intervals.
Implementations§
source§impl FreeIntervals
impl FreeIntervals
sourcepub fn new(free_interval: Interval) -> Self
pub fn new(free_interval: Interval) -> Self
Initialize collection with free interval.
Examples found in repository?
3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27
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)
}
sourcepub fn take_enough(&mut self, length: u64) -> Option<Interval>
pub fn take_enough(&mut self, length: u64) -> Option<Interval>
Take the minimal interval larger then length
.
If collection doesn’t contain such free interval, None
will be returned.
sourcepub fn take_enough_aligned(
&mut self,
length: u64,
align: u64
) -> Option<Interval>
pub fn take_enough_aligned( &mut self, length: u64, align: u64 ) -> Option<Interval>
Take the minimal interval larger then length
.
Add paddintg to the interval start, to align it.
The align padding will be added to collection as a new free interval.
If collection doesn’t contain such free interval, None
will be returned.
sourcepub fn take_exact(&mut self, length: u64) -> Option<Interval>
pub fn take_exact(&mut self, length: u64) -> Option<Interval>
Take the minimal interval larger then length
and split it into [length, extra]
parts.
Add extra
part as new free interval.
If collection doesn’t contain such free interval, None
will be returned.
Examples found in repository?
3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27
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)
}
sourcepub fn take_exact_aligned(
&mut self,
length: u64,
align: u64
) -> Option<Interval>
pub fn take_exact_aligned( &mut self, length: u64, align: u64 ) -> Option<Interval>
Take the minimal interval larger then length
and split it into [length, extra]
parts.
Add extra
part as new free interval.
Add paddintg to the interval start, to align it.
The align padding will be added to collection as a new free interval.
If collection doesn’t contain such free interval, None
will be returned.
Examples found in repository?
3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27
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)
}
sourcepub fn insert(&mut self, interval: Interval)
pub fn insert(&mut self, interval: Interval)
Insert free interval
to collection.
Connects it with any near free interval in the collection.
Examples found in repository?
3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27
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)
}