Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- use std::collections::BTreeMap;
- use std::cmp::Ordering;
- use std::ops::Bound::{Included, Excluded};
- #[derive( Debug)]
- struct FloatWrapper(f32);
- impl Eq for FloatWrapper { }
- impl PartialEq for FloatWrapper {
- fn eq(&self, other: &Self) -> bool {
- (self.0 - other.0).abs() < 1.17549435e-36f32
- }
- }
- impl Ord for FloatWrapper {
- fn cmp(&self, other: &Self) -> Ordering {
- if (self.0 - other.0).abs() < 1.17549435e-36f32 {
- Ordering::Equal
- } else if self.0 - other.0 > 0.0 {
- Ordering::Greater
- } else if self.0 - other.0 < 0.0 {
- Ordering::Less
- } else {
- Ordering::Equal
- }
- }
- }
- impl PartialOrd for FloatWrapper {
- fn partial_cmp(&self, other: &Self) -> Option<Ordering> {
- Some(self.cmp(other))
- }
- }
- fn main() {
- let mut ww = BTreeMap::new();
- ww.insert(FloatWrapper(1.0), "one");
- ww.insert(FloatWrapper(2.0), "two");
- ww.insert(FloatWrapper(3.0), "three");
- ww.insert(FloatWrapper(4.0), "three");
- let rez : Vec<&str> = ww.range((Included(&FloatWrapper(1.5)),(Excluded(&FloatWrapper(5.0)) )))
- .take(1)
- .map(|(_,&v)|v)
- .collect();
- println!("{:?}",rez)
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement