pub struct DisjointIntervals<T> { /* private fields */ }Expand description
互いに素な区間を管理するデータ構造
Implementations§
Source§impl<T> DisjointIntervals<T>
impl<T> DisjointIntervals<T>
pub fn new() -> Self
pub fn len(&self) -> usize
pub fn is_empty(&self) -> bool
pub fn iter(&self) -> impl Iterator<Item = Range<T>>
Sourcepub fn insert<U, F>(&mut self, interval: Range<T>, init: U, f: F) -> Uwhere
F: FnMut(U, InsertItem<T>) -> U,
pub fn insert<U, F>(&mut self, interval: Range<T>, init: U, f: F) -> Uwhere
F: FnMut(U, InsertItem<T>) -> U,
区間を追加する
初期値 init, 関数 f による畳み込み結果を返す
§Examples
use disjoint_intervals::{DisjointIntervals, InsertItem};
let mut intervals = DisjointIntervals::<i32>::new();
intervals.insert(-10..5, (), |_, _| ());
let overlapped = intervals.insert(0..10, 0, |acc, item| {
if let InsertItem::Overlap(item) = item {
acc + (item.end - item.start)
} else {
acc
}
});
assert_eq!(overlapped, 5);
assert_eq!(intervals.iter().collect::<Vec<_>>(), vec![-10..10]);Sourcepub fn remove<U, F>(&mut self, interval: Range<T>, init: U, f: F) -> Uwhere
F: FnMut(U, RemoveItem<T>) -> U,
pub fn remove<U, F>(&mut self, interval: Range<T>, init: U, f: F) -> Uwhere
F: FnMut(U, RemoveItem<T>) -> U,
区間を削除する
初期値 init, 関数 f による畳み込み結果を返す
§Examples
use disjoint_intervals::{DisjointIntervals, RemoveItem};
let mut intervals = DisjointIntervals::<i32>::new();
intervals.insert(-10..5, (), |_, _| ());
let removed = intervals.remove(-5..10, 0, |acc, item| {
if let RemoveItem::Remove(item) = item {
acc + (item.end - item.start)
} else {
acc
}
});
assert_eq!(removed, 10);
assert_eq!(intervals.iter().collect::<Vec<_>>(), vec![-10..-5]);Sourcepub fn ge(&self, x: T) -> Option<Range<T>>
pub fn ge(&self, x: T) -> Option<Range<T>>
x 以上の開始点を持つ最初の区間を返す
§Examples
use disjoint_intervals::DisjointIntervals;
let mut intervals = DisjointIntervals::<i32>::new();
intervals.insert(0..5, (), |_, _| ());
intervals.insert(10..15, (), |_, _| ());
assert_eq!(intervals.ge(0), Some(0..5));
assert_eq!(intervals.ge(3), Some(10..15));
assert_eq!(intervals.ge(15), None);Sourcepub fn le(&self, x: T) -> Option<Range<T>>
pub fn le(&self, x: T) -> Option<Range<T>>
x 以下の開始点を持つ最後の区間を返す
§Examples
use disjoint_intervals::DisjointIntervals;
let mut intervals = DisjointIntervals::<i32>::new();
intervals.insert(0..5, (), |_, _| ());
intervals.insert(10..15, (), |_, _| ());
assert_eq!(intervals.le(12), Some(10..15));
assert_eq!(intervals.le(10), Some(10..15));
assert_eq!(intervals.le(5), Some(0..5));
assert_eq!(intervals.le(-1), None);Trait Implementations§
Source§impl<T: Clone> Clone for DisjointIntervals<T>
impl<T: Clone> Clone for DisjointIntervals<T>
Source§fn clone(&self) -> DisjointIntervals<T>
fn clone(&self) -> DisjointIntervals<T>
Returns a duplicate of the value. Read more
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source. Read moreSource§impl<T> Debug for DisjointIntervals<T>where
T: Debug,
impl<T> Debug for DisjointIntervals<T>where
T: Debug,
Source§impl<T> Default for DisjointIntervals<T>
impl<T> Default for DisjointIntervals<T>
Source§impl<T: PartialEq> PartialEq for DisjointIntervals<T>
impl<T: PartialEq> PartialEq for DisjointIntervals<T>
impl<T: Eq> Eq for DisjointIntervals<T>
impl<T> StructuralPartialEq for DisjointIntervals<T>
Auto Trait Implementations§
impl<T> Freeze for DisjointIntervals<T>
impl<T> RefUnwindSafe for DisjointIntervals<T>where
T: RefUnwindSafe,
impl<T> Send for DisjointIntervals<T>where
T: Send,
impl<T> Sync for DisjointIntervals<T>where
T: Sync,
impl<T> Unpin for DisjointIntervals<T>
impl<T> UnsafeUnpin for DisjointIntervals<T>
impl<T> UnwindSafe for DisjointIntervals<T>where
T: RefUnwindSafe,
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more