summaryrefslogtreecommitdiffstats
path: root/src/tree_build/bid.rs
blob: e1ebd9884e63523c74b1355bc7ba4f8aa87e7a51 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
use {
    id_arena::Id,
    super::{
        bline::BLine,
    },
    std::{
        cmp::{self, Ordering},
    },
};

pub type BId = Id<BLine>;

// a structure making it possible to keep bline references
//  sorted in a binary heap with the line with the smallest
//  score at the top
pub struct SortableBId {
    pub id: BId,
    pub score: i32,
}
impl Eq for SortableBId {}
impl PartialEq for SortableBId {
    fn eq(&self, other: &SortableBId) -> bool {
        self.score == other.score // unused but required by spec of Ord
    }
}
impl Ord for SortableBId {
    fn cmp(&self, other: &SortableBId) -> Ordering {
        if self.score == other.score {
            Ordering::Equal
        } else if self.score < other.score {
            Ordering::Greater
        } else {
            Ordering::Less
        }
    }
}
impl PartialOrd for SortableBId {
    fn partial_cmp(&self, other: &SortableBId) -> Option<cmp::Ordering> {
        Some(self.cmp(other))
    }
}