use std::cmp::Ordering;
use crate::database::iterator::DatabaseIterator;
impl PartialEq for Box<dyn DatabaseIterator> {
fn eq(&self, other: &Self) -> bool {
self.peek() == other.peek()
}
}
impl Eq for Box<dyn DatabaseIterator> {}
impl PartialOrd for Box<dyn DatabaseIterator> {
fn partial_cmp(&self, other: &Self) -> Option<Ordering> {
Some(self.cmp(other))
}
}
impl Ord for Box<dyn DatabaseIterator> {
fn cmp(&self, other: &Self) -> Ordering {
match (self.peek(), other.peek()) {
(Some(a), Some(b)) => {
if a.get_key() < b.get_key() {
Ordering::Greater
} else if a.get_key() > b.get_key() {
Ordering::Less
}
else if a.get_seq_no() > b.get_seq_no() {
Ordering::Greater
} else {
Ordering::Less
}
} (Some(_), None) => Ordering::Less,
(None, Some(_)) => Ordering::Greater,
(None, None) => Ordering::Equal,
}
}
}