#![allow(unused_variables)] // TODO(you): remove this lint after implementing this mod #![allow(dead_code)] // TODO(you): remove this lint after implementing this mod use std::cmp::{self}; use std::collections::BinaryHeap; use anyhow::Result; use crate::key::KeySlice; use super::StorageIterator; struct HeapWrapper(pub usize, pub Box); impl PartialEq for HeapWrapper { fn eq(&self, other: &Self) -> bool { self.partial_cmp(other).unwrap() == cmp::Ordering::Equal } } impl Eq for HeapWrapper {} impl PartialOrd for HeapWrapper { #[allow(clippy::non_canonical_partial_ord_impl)] fn partial_cmp(&self, other: &Self) -> Option { match self.1.key().cmp(&other.1.key()) { cmp::Ordering::Greater => Some(cmp::Ordering::Greater), cmp::Ordering::Less => Some(cmp::Ordering::Less), cmp::Ordering::Equal => self.0.partial_cmp(&other.0), } .map(|x| x.reverse()) } } impl Ord for HeapWrapper { fn cmp(&self, other: &Self) -> cmp::Ordering { self.partial_cmp(other).unwrap() } } /// Merge multiple iterators of the same type. If the same key occurs multiple times in some /// iterators, perfer the one with smaller index. pub struct MergeIterator { iters: BinaryHeap>, current: Option>, } impl MergeIterator { pub fn create(iters: Vec>) -> Self { unimplemented!() } } impl StorageIterator = KeySlice<'a>>> StorageIterator for MergeIterator { type KeyType<'a> = KeySlice<'a>; fn key(&self) -> KeySlice { unimplemented!() } fn value(&self) -> &[u8] { unimplemented!() } fn is_valid(&self) -> bool { unimplemented!() } fn next(&mut self) -> Result<()> { unimplemented!() } }