Better bias selection for hints that prefix the type

Co-Authored-By: Antonio Scandurra <antonio@zed.dev>
This commit is contained in:
Kirill Bulatov 2023-06-12 11:32:41 +03:00
parent 2b1b1225f5
commit 63074c5cd8
4 changed files with 79 additions and 42 deletions

View file

@ -95,35 +95,13 @@ impl<D> fmt::Debug for End<D> {
}
}
#[derive(Copy, Clone, Eq, PartialEq, Debug, Hash)]
#[derive(Copy, Clone, Eq, PartialEq, PartialOrd, Ord, Debug, Hash, Default)]
pub enum Bias {
#[default]
Left,
Right,
}
impl Default for Bias {
fn default() -> Self {
Bias::Left
}
}
impl PartialOrd for Bias {
fn partial_cmp(&self, other: &Self) -> Option<Ordering> {
Some(self.cmp(other))
}
}
impl Ord for Bias {
fn cmp(&self, other: &Self) -> Ordering {
match (self, other) {
(Self::Left, Self::Left) => Ordering::Equal,
(Self::Left, Self::Right) => Ordering::Less,
(Self::Right, Self::Right) => Ordering::Equal,
(Self::Right, Self::Left) => Ordering::Greater,
}
}
}
#[derive(Debug, Clone)]
pub struct SumTree<T: Item>(Arc<Node<T>>);