use std::cmp::Ordering;
use std::collections::BinaryHeap;
use std::time::SystemTime;
#[derive(Clone, Eq, PartialEq)]
pub struct CrawlerScheduler {
pub host: String,
pub next_crawl_time: SystemTime,
}
impl Ord for CrawlerScheduler {
fn cmp(&self, other: &CrawlerScheduler) -> Ordering {
other
.next_crawl_time
.cmp(&self.next_crawl_time)
.then_with(|| other.host.cmp(&self.host))
}
}
impl PartialOrd for CrawlerScheduler {
fn partial_cmp(&self, other: &CrawlerScheduler) -> Option<Ordering> {
Some(self.cmp(other))
}
}
pub type HostPriorityQueue = BinaryHeap<CrawlerScheduler>;