MCPcopy Create free account
hub / github.com/KentBeck/BPlusTree3 / compact

Method compact

rust/src/compact_arena.rs:213–242  ·  view source on GitHub ↗

Compact the arena by removing gaps (expensive operation)

(&mut self)

Source from the content-addressed store, hash-verified

211
212 /// Compact the arena by removing gaps (expensive operation)
213 pub fn compact(&mut self)
214 where
215 T: Clone,
216 {
217 let mut new_storage = Vec::with_capacity(self.storage.len());
218 let mut new_allocated_mask = Vec::with_capacity(self.allocated_mask.len());
219 let mut index_mapping = vec![NULL_NODE; self.storage.len()];
220
221 // Copy allocated items to new storage
222 for (old_index, (item, &allocated)) in self
223 .storage
224 .iter()
225 .zip(self.allocated_mask.iter())
226 .enumerate()
227 {
228 if allocated {
229 let new_index = new_storage.len();
230 new_storage.push(item.clone());
231 new_allocated_mask.push(true);
232 index_mapping[old_index] = new_index as NodeId;
233 }
234 }
235
236 self.storage = new_storage;
237 self.allocated_mask = new_allocated_mask;
238 self.free_list.clear();
239
240 // Note: This breaks existing NodeIds!
241 // In a real implementation, you'd need to update all references
242 }
243
244 /// Get the number of allocated items
245 pub fn len(&self) -> usize {

Callers

nothing calls this directly

Calls 3

cloneMethod · 0.80
lenMethod · 0.45
clearMethod · 0.45

Tested by

no test coverage detected