diff --git a/crates/brk_computer/src/stateful/mod.rs b/crates/brk_computer/src/stateful/mod.rs index 3ae01ea2a..9d6c06068 100644 --- a/crates/brk_computer/src/stateful/mod.rs +++ b/crates/brk_computer/src/stateful/mod.rs @@ -55,7 +55,7 @@ use range_map::*; use r#trait::*; pub use withaddressdatasource::WithAddressDataSource; -const VERSION: Version = Version::new(19); +const VERSION: Version = Version::new(21); #[derive(Clone)] pub struct Vecs { diff --git a/crates/brk_vec/src/variants/compressed.rs b/crates/brk_vec/src/variants/compressed.rs index 716d23598..040ac68d7 100644 --- a/crates/brk_vec/src/variants/compressed.rs +++ b/crates/brk_vec/src/variants/compressed.rs @@ -59,8 +59,6 @@ where #[allow(unreachable_code, unused_variables)] pub fn import(parent: &Path, name: &str, version: Version) -> Result { - panic!("Compressed vecs are a work in progress right now, please use raw vecs instead"); - let mut inner = RawVec::import(parent, name, version)?; let pages_meta = { @@ -222,6 +220,22 @@ where self.inner.path() } + fn delete(&mut self, _: I) { + panic!("unsupported") + } + + fn unchecked_delete(&mut self, _: I) { + panic!("unsupported") + } + + fn fill_first_hole_or_push(&mut self, _: T) -> Result { + panic!("unsupported") + } + + fn update(&mut self, _: I, _: T) -> Result<()> { + panic!("unsupported") + } + fn flush(&mut self) -> Result<()> { let file_opt = self.inner.write_header_if_needed()?; diff --git a/crates/brk_vec/src/variants/raw.rs b/crates/brk_vec/src/variants/raw.rs index 8217fdefa..ae0cc39cb 100644 --- a/crates/brk_vec/src/variants/raw.rs +++ b/crates/brk_vec/src/variants/raw.rs @@ -56,6 +56,10 @@ where | Err(Error::DifferentVersion { .. }) => { let path = Self::path_(parent, name); fs::remove_file(path)?; + let holes_path = Self::holes_path_(parent, name); + if fs::exists(&holes_path)? { + fs::remove_file(holes_path)?; + } Self::import(parent, name, version) } _ => res, @@ -97,19 +101,18 @@ where 0 }; - let mut has_stored_holes = false; let holes_path = Self::holes_path_(parent, name); let holes = if fs::exists(&holes_path)? { - has_stored_holes = true; - let bytes = fs::read(&holes_path)?; - bytes - .chunks(size_of::()) - .map(|b| -> Result { - Ok(usize::from_ne_bytes(brk_core::copy_first_8bytes(b)?)) - }) - .collect::>>()? + Some( + fs::read(&holes_path)? + .chunks(size_of::()) + .map(|b| -> Result { + Ok(usize::from_ne_bytes(brk_core::copy_first_8bytes(b)?)) + }) + .collect::>>()?, + ) } else { - BTreeSet::new() + None }; Ok(Self { @@ -117,8 +120,8 @@ where name: Box::leak(Box::new(name.to_string())), parent: parent.to_owned(), pushed: vec![], - has_stored_holes, - holes, + has_stored_holes: holes.is_some(), + holes: holes.unwrap_or_default(), updated: BTreeMap::new(), local_stored_len: Some(stored_len), shared_stored_len: Arc::new(AtomicUsize::new(stored_len)), @@ -278,6 +281,7 @@ where if has_holes || had_holes { let holes_path = self.holes_path(); if has_holes { + self.has_stored_holes = true; fs::write( &holes_path, self.holes @@ -286,6 +290,7 @@ where .collect::>(), )?; } else if had_holes { + self.has_stored_holes = false; let _ = fs::remove_file(&holes_path); } }