Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ name = "ex1"
[features]
default = []
with_serde = ["serde/derive"]
sort_unstable = []

[dependencies]
num-traits = "0.2.12"
Expand Down
35 changes: 31 additions & 4 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -194,11 +194,27 @@ where
/// let lapper = Lapper::new(data);
/// ```
pub fn new(mut intervals: Vec<Interval<I, T>>) -> Self {
#[cfg(feature = "sort_unstable")]
intervals.sort_unstable();

#[cfg(not(feature = "sort_unstable"))]
intervals.sort();

let (mut starts, mut stops): (Vec<_>, Vec<_>) =
intervals.iter().map(|x| (x.start, x.stop)).unzip();
starts.sort();
stops.sort();

#[cfg(feature = "sort_unstable")]
{
starts.sort_unstable();
stops.sort_unstable();
}

#[cfg(not(feature = "sort_unstable"))]
{
starts.sort();
stops.sort();
}

let mut max_len = zero::<I>();
for interval in intervals.iter() {
let i_len = interval
Expand Down Expand Up @@ -376,8 +392,19 @@ where
// Fix the starts and stops used by counts
let (mut starts, mut stops): (Vec<_>, Vec<_>) =
self.intervals.iter().map(|x| (x.start, x.stop)).unzip();
starts.sort();
stops.sort();

#[cfg(feature = "sort_unstable")]
{
starts.sort_unstable();
stops.sort_unstable();
}

#[cfg(not(feature = "sort_unstable"))]
{
starts.sort();
stops.sort();
}

self.starts = starts;
self.stops = stops;
self.max_len = self
Expand Down