-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
better traits for convenience constructors
- Loading branch information
Robert Durfee
committed
Aug 13, 2020
1 parent
6ca6179
commit 11c81d7
Showing
7 changed files
with
224 additions
and
62 deletions.
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 |
---|---|---|
@@ -1,14 +1,13 @@ | ||
[package] | ||
name = "segment-map" | ||
version = "0.1.0" | ||
version = "0.1.1" | ||
authors = ["Robert Durfee <rbd@mit.edu>"] | ||
description = "A self-balancing binary search tree for mapping discrete, disjoint segments to values." | ||
license-file = "LICENSE" | ||
repository = "https://github.com/RobertDurfee/SegmentMap" | ||
license = "MIT" | ||
repository = "https://github.com/RobertDurfee/SegmentMap/tree/v0.1.1" | ||
readme = "README.md" | ||
keywords = ["segment-map", "interval-map", "segment", "interval", "map"] | ||
categories = ["data-structures"] | ||
edition = "2018" | ||
|
||
[dependencies] | ||
num = "0.3" |
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,79 @@ | ||
use std::{ | ||
usize, | ||
u8, | ||
u16, | ||
u32, | ||
u64, | ||
u128, | ||
isize, | ||
i8, | ||
i16, | ||
i32, | ||
i64, | ||
i128 | ||
}; | ||
|
||
pub trait Bounded { | ||
fn min() -> Self; | ||
fn max() -> Self; | ||
} | ||
|
||
impl Bounded for usize { | ||
fn min() -> usize { usize::MIN } | ||
fn max() -> usize { usize::MAX } | ||
} | ||
|
||
impl Bounded for u8 { | ||
fn min() -> u8 { u8::MIN } | ||
fn max() -> u8 { u8::MAX } | ||
} | ||
|
||
impl Bounded for u16 { | ||
fn min() -> u16 { u16::MIN } | ||
fn max() -> u16 { u16::MAX } | ||
} | ||
|
||
impl Bounded for u32 { | ||
fn min() -> u32 { u32::MIN } | ||
fn max() -> u32 { u32::MAX } | ||
} | ||
|
||
impl Bounded for u64 { | ||
fn min() -> u64 { u64::MIN } | ||
fn max() -> u64 { u64::MAX } | ||
} | ||
|
||
impl Bounded for u128 { | ||
fn min() -> u128 { u128::MIN } | ||
fn max() -> u128 { u128::MAX } | ||
} | ||
|
||
impl Bounded for isize { | ||
fn min() -> isize { isize::MIN } | ||
fn max() -> isize { isize::MAX } | ||
} | ||
|
||
impl Bounded for i8 { | ||
fn min() -> i8 { i8::MIN } | ||
fn max() -> i8 { i8::MAX } | ||
} | ||
|
||
impl Bounded for i16 { | ||
fn min() -> i16 { i16::MIN } | ||
fn max() -> i16 { i16::MAX } | ||
} | ||
|
||
impl Bounded for i32 { | ||
fn min() -> i32 { i32::MIN } | ||
fn max() -> i32 { i32::MAX } | ||
} | ||
|
||
impl Bounded for i64 { | ||
fn min() -> i64 { i64::MIN } | ||
fn max() -> i64 { i64::MAX } | ||
} | ||
|
||
impl Bounded for i128 { | ||
fn min() -> i128 { i128::MIN } | ||
fn max() -> i128 { i128::MAX } | ||
} |
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 |
---|---|---|
@@ -1,6 +1,10 @@ | ||
mod segment; | ||
mod segment_map_node; | ||
mod segment_map; | ||
mod bounded; | ||
mod next; | ||
|
||
pub use crate::segment_map::SegmentMap; | ||
pub use crate::segment::Segment; | ||
pub use crate::bounded::Bounded; | ||
pub use crate::next::Next; |
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,51 @@ | ||
pub trait Next: Clone + PartialOrd { | ||
fn next(&self) -> Self; | ||
} | ||
|
||
impl Next for usize { | ||
fn next(&self) -> usize { self.checked_add(1).expect("integer overflow") } | ||
} | ||
|
||
impl Next for u8 { | ||
fn next(&self) -> u8 { self.checked_add(1).expect("integer overflow") } | ||
} | ||
|
||
impl Next for u16 { | ||
fn next(&self) -> u16 { self.checked_add(1).expect("integer overflow") } | ||
} | ||
|
||
impl Next for u32 { | ||
fn next(&self) -> u32 { self.checked_add(1).expect("integer overflow") } | ||
} | ||
|
||
impl Next for u64 { | ||
fn next(&self) -> u64 { self.checked_add(1).expect("integer overflow") } | ||
} | ||
|
||
impl Next for u128 { | ||
fn next(&self) -> u128 { self.checked_add(1).expect("integer overflow") } | ||
} | ||
|
||
impl Next for isize { | ||
fn next(&self) -> isize { self.checked_add(1).expect("integer overflow") } | ||
} | ||
|
||
impl Next for i8 { | ||
fn next(&self) -> i8 { self.checked_add(1).expect("integer overflow") } | ||
} | ||
|
||
impl Next for i16 { | ||
fn next(&self) -> i16 { self.checked_add(1).expect("integer overflow") } | ||
} | ||
|
||
impl Next for i32 { | ||
fn next(&self) -> i32 { self.checked_add(1).expect("integer overflow") } | ||
} | ||
|
||
impl Next for i64 { | ||
fn next(&self) -> i64 { self.checked_add(1).expect("integer overflow") } | ||
} | ||
|
||
impl Next for i128 { | ||
fn next(&self) -> i128 { self.checked_add(1).expect("integer overflow") } | ||
} |
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
Oops, something went wrong.