51 lines
1.1 KiB
Rust
51 lines
1.1 KiB
Rust
use std::cmp::Ordering;
|
|
|
|
pub struct Result {
|
|
pub word: usize,
|
|
pub distance: usize,
|
|
}
|
|
|
|
impl PartialOrd for Result {
|
|
fn partial_cmp(&self, other: &Self) -> Option<Ordering> {
|
|
Some(self.distance.cmp(&other.distance))
|
|
.filter(|it| it != &Ordering::Equal)
|
|
.or_else(|| Some(self.word.cmp(&other.word)))
|
|
}
|
|
}
|
|
|
|
impl PartialEq for Result {
|
|
fn eq(&self, other: &Self) -> bool {
|
|
self.distance == other.distance && self.word == other.word
|
|
}
|
|
}
|
|
|
|
impl Eq for Result {}
|
|
|
|
impl Ord for Result {
|
|
fn cmp(&self, other: &Self) -> std::cmp::Ordering {
|
|
match self.distance.cmp(&other.distance) {
|
|
std::cmp::Ordering::Equal => self.word.cmp(&other.word),
|
|
std::cmp::Ordering::Greater => std::cmp::Ordering::Greater,
|
|
std::cmp::Ordering::Less => std::cmp::Ordering::Less,
|
|
}
|
|
}
|
|
}
|
|
|
|
//struct Standing {
|
|
// size: usize,
|
|
// results: Vec<Result>,
|
|
//}
|
|
//
|
|
//impl Standing {
|
|
// pub fn new(size: usize) -> Standing {
|
|
// Standing {
|
|
// size,
|
|
// results: BTreeSet::new(),
|
|
// }
|
|
// }
|
|
//
|
|
// pub fn addResult(&mut self, res: Result) {
|
|
// self.results.push(res)
|
|
// }
|
|
//}
|