Skip to content

Commit

Permalink
rename kv_heap_size to heap_size
Browse files Browse the repository at this point in the history
Signed-off-by: Richard Chien <[email protected]>
  • Loading branch information
stdrc committed Mar 22, 2024
1 parent 439649d commit d22e427
Showing 1 changed file with 7 additions and 7 deletions.
14 changes: 7 additions & 7 deletions src/common/estimate_size/src/collections/hashset.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,14 +21,14 @@ use crate::{EstimateSize, KvSize};
#[derive(Default)]
pub struct EstimatedHashSet<T: EstimateSize> {
inner: HashSet<T>,
kv_heap_size: KvSize,
heap_size: KvSize,
}

impl<T: EstimateSize> EstimateSize for EstimatedHashSet<T> {
fn estimated_heap_size(&self) -> usize {
// TODO: Add hashset internal size.
// https://github.com/risingwavelabs/risingwave/issues/9713
self.kv_heap_size.size()
self.heap_size.size()
}
}

Expand All @@ -38,10 +38,10 @@ where
{
/// Insert into the cache.
pub fn insert(&mut self, value: T) -> bool {
let kv_heap_size = self.kv_heap_size.add_val(&value);
let heap_size = self.heap_size.add_val(&value);
let inserted = self.inner.insert(value);
if inserted {
self.kv_heap_size.set(kv_heap_size);
self.heap_size.set(heap_size);
}
inserted
}
Expand All @@ -50,18 +50,18 @@ where
pub fn remove(&mut self, value: &T) -> bool {
let removed = self.inner.remove(value);
if removed {
self.kv_heap_size.sub_val(value);
self.heap_size.sub_val(value);
}
removed
}

/// Convert an [`EstimatedVec`] to a [`EstimatedHashSet`]. Do not need to recalculate the
/// heap size.
pub fn from_vec(v: EstimatedVec<T>) -> Self {
let kv_heap_size = v.estimated_heap_size();
let heap_size = v.estimated_heap_size();
Self {
inner: HashSet::from_iter(v),
kv_heap_size: KvSize::with_size(kv_heap_size),
heap_size: KvSize::with_size(heap_size),
}
}
}
Expand Down

0 comments on commit d22e427

Please sign in to comment.