diff --git a/src/lib.rs b/src/lib.rs index decd5c7..15a5cb2 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -16,7 +16,7 @@ pub struct EliasFano { impl EliasFano { /// Compress a unique, ordered set of elements. pub fn compress(elements: &[u32]) -> Self { - debug_assert!(elements.is_sorted()); + debug_assert!(elements.windows(2).all(|w| w[0] < w[1])); debug_assert!(elements.len() < u32::MAX as usize); if elements.is_empty() { return Self { @@ -246,6 +246,7 @@ fn read_compact_size(reader: &mut R) -> Result { #[derive(Debug)] pub struct Hintsfile { map: BTreeMap, + stop_height: u32, } impl Hintsfile { @@ -273,7 +274,7 @@ impl Hintsfile { let ef = EliasFano::from_reader(reader)?; map.insert(height, ef); } - Ok(Self { map }) + Ok(Self { map, stop_height }) } /// Get the unspent indices for a block height. Returns `None` if unavailable. @@ -289,7 +290,7 @@ impl Hintsfile { /// The last height this file encodes for. pub fn stop_height(&self) -> u32 { - self.map.keys().max().copied().unwrap_or_default() + self.stop_height } } @@ -331,10 +332,10 @@ mod sealed { pub trait Sealed {} } -impl sealed::Sealed for crate::StageNew {} -impl sealed::Sealed for crate::StageInProgress {} +impl sealed::Sealed for StageNew {} +impl sealed::Sealed for StageInProgress {} -/// Stage of hintsfile prgroess. +/// Stage of hintsfile progress. pub trait Stage: sealed::Sealed {} impl Stage for StageNew {}