Skip to content

Commit 83a9fc3

Browse files
committed
Add take method to SegmentContainer
1 parent 64d11fb commit 83a9fc3

File tree

2 files changed

+21
-0
lines changed

2 files changed

+21
-0
lines changed

db4-storage/src/segments/graph/segment.rs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,18 @@ impl MemGraphSegment {
5151
&self.layers
5252
}
5353

54+
/// Replaces this segment with an empty instance, returning the old segment
55+
/// with its data.
56+
///
57+
/// The new segment will have the same number of layers as the original.
58+
pub fn take(&mut self) -> Self {
59+
let layers = self.layers.iter_mut().map(|layer| layer.take()).collect();
60+
61+
Self {
62+
layers,
63+
}
64+
}
65+
5466
pub fn add_properties(&mut self, t: TimeIndexEntry, props: impl IntoIterator<Item = (usize, Prop)>) {
5567
let layer = &mut self.layers[Self::LAYER];
5668

db4-storage/src/segments/mod.rs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -184,6 +184,15 @@ impl<T: HasRow> SegmentContainer<T> {
184184
}
185185
}
186186

187+
/// Replaces this container with an empty instance, returning the
188+
/// old container with its data.
189+
pub fn take(&mut self) -> Self {
190+
std::mem::replace(
191+
self,
192+
Self::new(self.segment_id, self.max_page_len, self.meta.clone()),
193+
)
194+
}
195+
187196
#[inline]
188197
pub fn est_size(&self) -> usize {
189198
// TODO: this is a rough estimate and should be improved

0 commit comments

Comments
 (0)