Skip to content

Commit 7439c99

Browse files
authored
Merge pull request #6 from JoseSK999/fix-stop-height
fix: return a consistent `stop_height` value
2 parents 5a23aaf + 264cf95 commit 7439c99

1 file changed

Lines changed: 7 additions & 6 deletions

File tree

src/lib.rs

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ pub struct EliasFano {
1616
impl EliasFano {
1717
/// Compress a unique, ordered set of elements.
1818
pub fn compress(elements: &[u32]) -> Self {
19-
debug_assert!(elements.is_sorted());
19+
debug_assert!(elements.windows(2).all(|w| w[0] < w[1]));
2020
debug_assert!(elements.len() < u32::MAX as usize);
2121
if elements.is_empty() {
2222
return Self {
@@ -246,6 +246,7 @@ fn read_compact_size<R: Read>(reader: &mut R) -> Result<u32, std::io::Error> {
246246
#[derive(Debug)]
247247
pub struct Hintsfile {
248248
map: BTreeMap<u32, EliasFano>,
249+
stop_height: u32,
249250
}
250251

251252
impl Hintsfile {
@@ -273,7 +274,7 @@ impl Hintsfile {
273274
let ef = EliasFano::from_reader(reader)?;
274275
map.insert(height, ef);
275276
}
276-
Ok(Self { map })
277+
Ok(Self { map, stop_height })
277278
}
278279

279280
/// Get the unspent indices for a block height. Returns `None` if unavailable.
@@ -289,7 +290,7 @@ impl Hintsfile {
289290

290291
/// The last height this file encodes for.
291292
pub fn stop_height(&self) -> u32 {
292-
self.map.keys().max().copied().unwrap_or_default()
293+
self.stop_height
293294
}
294295
}
295296

@@ -331,10 +332,10 @@ mod sealed {
331332
pub trait Sealed {}
332333
}
333334

334-
impl sealed::Sealed for crate::StageNew {}
335-
impl sealed::Sealed for crate::StageInProgress {}
335+
impl sealed::Sealed for StageNew {}
336+
impl sealed::Sealed for StageInProgress {}
336337

337-
/// Stage of hintsfile prgroess.
338+
/// Stage of hintsfile progress.
338339
pub trait Stage: sealed::Sealed {}
339340

340341
impl Stage for StageNew {}

0 commit comments

Comments
 (0)