Struct rust_lapper::Lapper[][src]

pub struct Lapper<I, T> where
    I: PrimInt + Unsigned + Ord + Clone + Send + Sync,
    T: Eq + Clone + Send + Sync
{ pub intervals: Vec<Interval<I, T>>, pub overlaps_merged: bool, // some fields omitted }
Expand description

Primary object of the library. The public intervals holds all the intervals and can be used for iterating / pulling values out of the tree.

Fields

intervals: Vec<Interval<I, T>>

List of intervals

overlaps_merged: bool

Whether or not overlaps have been merged

Implementations

impl<I, T> Lapper<I, T> where
    I: PrimInt + Unsigned + Ord + Clone + Send + Sync,
    T: Eq + Clone + Send + Sync
[src]

pub fn new(intervals: Vec<Interval<I, T>>) -> Self[src]

Create a new instance of Lapper by passing in a vector of Intervals. This vector will immediately be sorted by start order.

use rust_lapper::{Lapper, Interval};
let data = (0..20).step_by(5)
                  .map(|x| Interval{start: x, stop: x + 10, val: true})
                  .collect::<Vec<Interval<usize, bool>>>();
let lapper = Lapper::new(data);

pub fn len(&self) -> usize[src]

Get the number over intervals in Lapper

use rust_lapper::{Lapper, Interval};
let data = (0..20).step_by(5)
                  .map(|x| Interval{start: x, stop: x + 10, val: true})
                  .collect::<Vec<Interval<usize, bool>>>();
let lapper = Lapper::new(data);
assert_eq!(lapper.len(), 4);

pub fn is_empty(&self) -> bool[src]

Check if lapper is empty

use rust_lapper::{Lapper, Interval};
let data: Vec<Interval<usize, bool>> = vec![];
let lapper = Lapper::new(data);
assert_eq!(lapper.is_empty(), true);

pub fn cov(&self) -> I[src]

Get the number of positions covered by the intervals in Lapper. This provides immutable access if it has already been set, or on the fly calculation.

use rust_lapper::{Lapper, Interval};
let data = (0..20).step_by(5)
                  .map(|x| Interval{start: x, stop: x + 10, val: true})
                  .collect::<Vec<Interval<usize, bool>>>();
let lapper = Lapper::new(data);
assert_eq!(lapper.cov(), 25);

pub fn set_cov(&mut self) -> I[src]

Get the number fo positions covered by the intervals in Lapper and store it. If you are going to be using the coverage, you should set it to avoid calculating it over and over.

pub fn iter(&self) -> IterLapper<'_, I, T>

Notable traits for IterLapper<'a, I, T>

impl<'a, I, T> Iterator for IterLapper<'a, I, T> where
    T: Eq + Clone + Send + Sync + 'a,
    I: PrimInt + Unsigned + Ord + Clone + Send + Sync
type Item = &'a Interval<I, T>;
[src]

Return an iterator over the intervals in Lapper

pub fn merge_overlaps(&mut self)[src]

Merge any intervals that overlap with eachother within the Lapper. This is an easy way to speed up queries.

pub fn lower_bound(start: I, intervals: &[Interval<I, T>]) -> usize[src]

Determine the first index that we should start checking for overlaps for via a binary search. Assumes that the maximum interval length in intervals has been subtracted from start, otherwise the result is undefined

pub fn bsearch_seq(key: I, elems: &[I]) -> usize[src]

pub fn union_and_intersect(&self, other: &Self) -> (I, I)[src]

Find the union and the intersect of two lapper objects. Union: The set of positions found in both lappers Intersect: The number of positions where both lappers intersect. Note that a position only counts one time, multiple Intervals covering the same position don’t add up.

use rust_lapper::{Lapper, Interval};
type Iv = Interval<u32, u32>;
let data1: Vec<Iv> = vec![
    Iv{start: 70, stop: 120, val: 0}, // max_len = 50
    Iv{start: 10, stop: 15, val: 0}, // exact overlap
    Iv{start: 12, stop: 15, val: 0}, // inner overlap
    Iv{start: 14, stop: 16, val: 0}, // overlap end
    Iv{start: 68, stop: 71, val: 0}, // overlap start
];
let data2: Vec<Iv> = vec![

    Iv{start: 10, stop: 15, val: 0},
    Iv{start: 40, stop: 45, val: 0},
    Iv{start: 50, stop: 55, val: 0},
    Iv{start: 60, stop: 65, val: 0},
    Iv{start: 70, stop: 75, val: 0},
];

let (mut lapper1, mut lapper2) = (Lapper::new(data1), Lapper::new(data2)) ;
// Should be the same either way it's calculated
let (union, intersect) = lapper1.union_and_intersect(&lapper2);
assert_eq!(intersect, 10);
assert_eq!(union, 73);
let (union, intersect) = lapper2.union_and_intersect(&lapper1);
assert_eq!(intersect, 10);
assert_eq!(union, 73);
lapper1.merge_overlaps();
lapper1.set_cov();
lapper2.merge_overlaps();
lapper2.set_cov();

// Should be the same either way it's calculated
let (union, intersect) = lapper1.union_and_intersect(&lapper2);
assert_eq!(intersect, 10);
assert_eq!(union, 73);
let (union, intersect) = lapper2.union_and_intersect(&lapper1);
assert_eq!(intersect, 10);
assert_eq!(union, 73);

pub fn intersect(&self, other: &Self) -> I[src]

Find the intersect of two lapper objects. Intersect: The number of positions where both lappers intersect. Note that a position only counts one time, multiple Intervals covering the same position don’t add up

pub fn union(&self, other: &Self) -> I[src]

Find the union of two lapper objects.

pub fn depth(&self) -> IterDepth<'_, I, T>

Notable traits for IterDepth<'a, I, T>

impl<'a, I, T> Iterator for IterDepth<'a, I, T> where
    T: Eq + Clone + Send + Sync + 'a,
    I: PrimInt + Unsigned + Ord + Clone + Send + Sync
type Item = Interval<I, I>;
[src]

Return the contiguous intervals of coverage, val represents the number of intervals covering the returned interval.

Examples

use rust_lapper::{Lapper, Interval};
let data = (0..20).step_by(5)
                  .map(|x| Interval{start: x, stop: x + 10, val: true})
                  .collect::<Vec<Interval<usize, bool>>>();
let lapper = Lapper::new(data);
assert_eq!(lapper.depth().collect::<Vec<Interval<usize, usize>>>(), vec![
            Interval { start: 0, stop: 5, val: 1 },
            Interval { start: 5, stop: 20, val: 2 },
            Interval { start: 20, stop: 25, val: 1 }]);

pub fn count(&self, start: I, stop: I) -> usize[src]

Count all intervals that overlap start .. stop. This performs two binary search in order to find all the excluded elements, and then deduces the intersection from there. See BITS for more details.

use rust_lapper::{Lapper, Interval};
let lapper = Lapper::new((0..100).step_by(5)
                                .map(|x| Interval{start: x, stop: x+2 , val: true})
                                .collect::<Vec<Interval<usize, bool>>>());
assert_eq!(lapper.count(5, 11), 2);

pub fn find(&self, start: I, stop: I) -> IterFind<'_, I, T>

Notable traits for IterFind<'a, I, T>

impl<'a, I, T> Iterator for IterFind<'a, I, T> where
    T: Eq + Clone + Send + Sync + 'a,
    I: PrimInt + Unsigned + Ord + Clone + Send + Sync
type Item = &'a Interval<I, T>;
[src]

Find all intervals that overlap start .. stop

use rust_lapper::{Lapper, Interval};
let lapper = Lapper::new((0..100).step_by(5)
                                .map(|x| Interval{start: x, stop: x+2 , val: true})
                                .collect::<Vec<Interval<usize, bool>>>());
assert_eq!(lapper.find(5, 11).count(), 2);

pub fn seek<'a>(
    &'a self,
    start: I,
    stop: I,
    cursor: &mut usize
) -> IterFind<'a, I, T>

Notable traits for IterFind<'a, I, T>

impl<'a, I, T> Iterator for IterFind<'a, I, T> where
    T: Eq + Clone + Send + Sync + 'a,
    I: PrimInt + Unsigned + Ord + Clone + Send + Sync
type Item = &'a Interval<I, T>;
[src]

Find all intevals that overlap start .. stop. This method will work when queries to this lapper are in sorted (start) order. It uses a linear search from the last query instead of a binary search. A reference to a cursor must be passed in. This reference will be modified and should be reused in the next query. This allows seek to not need to make the lapper object mutable, and thus use the same lapper accross threads.

use rust_lapper::{Lapper, Interval};
let lapper = Lapper::new((0..100).step_by(5)
                                .map(|x| Interval{start: x, stop: x+2 , val: true})
                                .collect::<Vec<Interval<usize, bool>>>());
let mut cursor = 0;
for i in lapper.iter() {
   assert_eq!(lapper.seek(i.start, i.stop, &mut cursor).count(), 1);
}

Trait Implementations

impl<I: Clone, T: Clone> Clone for Lapper<I, T> where
    I: PrimInt + Unsigned + Ord + Clone + Send + Sync,
    T: Eq + Clone + Send + Sync
[src]

fn clone(&self) -> Lapper<I, T>[src]

Returns a copy of the value. Read more

fn clone_from(&mut self, source: &Self)1.0.0[src]

Performs copy-assignment from source. Read more

impl<I: Debug, T: Debug> Debug for Lapper<I, T> where
    I: PrimInt + Unsigned + Ord + Clone + Send + Sync,
    T: Eq + Clone + Send + Sync
[src]

fn fmt(&self, f: &mut Formatter<'_>) -> Result[src]

Formats the value using the given formatter. Read more

impl<I, T> IntoIterator for Lapper<I, T> where
    T: Eq + Clone + Send + Sync,
    I: PrimInt + Unsigned + Ord + Clone + Send + Sync
[src]

type Item = Interval<I, T>

The type of the elements being iterated over.

type IntoIter = IntoIter<Self::Item>

Which kind of iterator are we turning this into?

fn into_iter(self) -> Self::IntoIter[src]

Creates an iterator from a value. Read more

impl<'a, I, T> IntoIterator for &'a Lapper<I, T> where
    T: Eq + Clone + Send + Sync + 'a,
    I: PrimInt + Unsigned + Ord + Clone + Send + Sync
[src]

type Item = &'a Interval<I, T>

The type of the elements being iterated over.

type IntoIter = Iter<'a, Interval<I, T>>

Which kind of iterator are we turning this into?

fn into_iter(self) -> Iter<'a, Interval<I, T>>[src]

Creates an iterator from a value. Read more

impl<'a, I, T> IntoIterator for &'a mut Lapper<I, T> where
    T: Eq + Clone + Send + Sync + 'a,
    I: PrimInt + Unsigned + Ord + Clone + Send + Sync
[src]

type Item = &'a mut Interval<I, T>

The type of the elements being iterated over.

type IntoIter = IterMut<'a, Interval<I, T>>

Which kind of iterator are we turning this into?

fn into_iter(self) -> IterMut<'a, Interval<I, T>>[src]

Creates an iterator from a value. Read more

Auto Trait Implementations

impl<I, T> RefUnwindSafe for Lapper<I, T> where
    I: RefUnwindSafe,
    T: RefUnwindSafe

impl<I, T> Send for Lapper<I, T>

impl<I, T> Sync for Lapper<I, T>

impl<I, T> Unpin for Lapper<I, T> where
    I: Unpin,
    T: Unpin

impl<I, T> UnwindSafe for Lapper<I, T> where
    I: UnwindSafe,
    T: UnwindSafe

Blanket Implementations

impl<T> Any for T where
    T: 'static + ?Sized
[src]

pub fn type_id(&self) -> TypeId[src]

Gets the TypeId of self. Read more

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

pub fn borrow(&self) -> &T[src]

Immutably borrows from an owned value. Read more

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

pub fn borrow_mut(&mut self) -> &mut T[src]

Mutably borrows from an owned value. Read more

impl<T> From<T> for T[src]

pub fn from(t: T) -> T[src]

Performs the conversion.

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

pub fn into(self) -> U[src]

Performs the conversion.

impl<T> ToOwned for T where
    T: Clone
[src]

type Owned = T

The resulting type after obtaining ownership.

pub fn to_owned(&self) -> T[src]

Creates owned data from borrowed data, usually by cloning. Read more

pub fn clone_into(&self, target: &mut T)[src]

🔬 This is a nightly-only experimental API. (toowned_clone_into)

recently added

Uses borrowed data to replace owned data, usually by cloning. Read more

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

pub fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>[src]

Performs the conversion.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.

pub fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>[src]

Performs the conversion.