-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
data:
/intervals/
for structures for intervals
- Loading branch information
Showing
4 changed files
with
34 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
//! # Interval Tree | ||
//! Interval Tree implementation | ||
//! | ||
//! This just does a linear scan for stabbing queries. This is a great target for optimizing the compiler. | ||
use std::ops::Range; | ||
|
||
#[derive(Debug)] | ||
pub struct IntervalTree<T: Ord + Clone> { | ||
data: Vec<Range<T>>, | ||
} | ||
|
||
impl<T: Ord + Clone> IntervalTree<T> { | ||
pub fn new(mut ranges: Vec<Range<T>>) -> Self { | ||
Self { data: ranges } | ||
} | ||
|
||
pub fn stab(&self, point: T) -> Vec<Range<T>> { | ||
self.data | ||
.iter() | ||
.filter(|&range| range.contains(&point)) | ||
.cloned() | ||
.collect() | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
pub mod interval_tree; | ||
pub use interval_tree::IntervalTree; | ||
|
||
pub mod partition_map; | ||
pub use partition_map::PartitionMap; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,4 +4,4 @@ pub mod graphviz; | |
|
||
pub mod graph_like; | ||
|
||
pub mod partition_map; | ||
pub mod intervals; |