Skip to content
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions datasketches/src/cpc/pair_table.rs
Original file line number Diff line number Diff line change
Expand Up @@ -246,4 +246,9 @@ impl PairTable {
}
}
}

/// Returns the estimated size of the heap allocations in bytes
pub fn estimated_size(&self) -> usize {
self.slots.capacity() * std::mem::size_of::<u32>()
}
}
12 changes: 12 additions & 0 deletions datasketches/src/cpc/sketch.rs
Original file line number Diff line number Diff line change
Expand Up @@ -450,6 +450,18 @@ impl CpcSketch {

matrix
}

/// Returns the estimated size of the sketch in bytes
pub fn estimated_size(&self) -> usize {
let heap_size = self.sliding_window.capacity()
+ self
.surprising_value_table
.as_ref()
.map(|t| t.estimated_size())
.unwrap_or(0);

std::mem::size_of::<Self>() + heap_size
}
Comment thread
tisonkun marked this conversation as resolved.
}

impl CpcSketch {
Expand Down
10 changes: 10 additions & 0 deletions datasketches/src/hll/array4.rs
Original file line number Diff line number Diff line change
Expand Up @@ -425,6 +425,16 @@ impl Array4 {

bytes.into_bytes()
}

/// Returns the estimated size of the heap allocations in bytes
pub fn estimated_size(&self) -> usize {
self.bytes.len()
+ self
.aux_map
.as_ref()
.map(|a| a.estimated_size())
.unwrap_or(0)
}
Comment on lines +429 to +437

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: can add but not necessay

}

#[cfg(test)]
Expand Down
5 changes: 5 additions & 0 deletions datasketches/src/hll/array6.rs
Original file line number Diff line number Diff line change
Expand Up @@ -272,6 +272,11 @@ impl Array6 {

bytes.into_bytes()
}

/// Returns the estimated size of the heap allocations in bytes
pub fn estimated_size(&self) -> usize {
self.bytes.len()
}
}

/// Calculate number of bytes needed for k slots with 6 bits each
Expand Down
5 changes: 5 additions & 0 deletions datasketches/src/hll/array8.rs
Original file line number Diff line number Diff line change
Expand Up @@ -344,6 +344,11 @@ impl Array8 {

bytes.into_bytes()
}

/// Returns the estimated size of the heap allocations in bytes
pub fn estimated_size(&self) -> usize {
self.bytes.len()
}
}

#[cfg(test)]
Expand Down
5 changes: 5 additions & 0 deletions datasketches/src/hll/aux_map.rs
Original file line number Diff line number Diff line change
Expand Up @@ -226,6 +226,11 @@ impl AuxMap {
}
})
}

/// Returns the estimated size of the heap allocations in bytes
pub fn estimated_size(&self) -> usize {
self.entries.len() * std::mem::size_of::<Coupon>()
}
}

/// Iterator over AuxMap entries
Expand Down
5 changes: 5 additions & 0 deletions datasketches/src/hll/container.rs
Original file line number Diff line number Diff line change
Expand Up @@ -135,4 +135,9 @@ impl Container {
pub fn iter(&self) -> impl Iterator<Item = Coupon> + '_ {
self.coupons.iter().filter(|&&c| !c.is_empty()).copied()
}

/// Returns the estimated size of the heap allocations in bytes
pub fn estimated_size(&self) -> usize {
self.coupons.len() * std::mem::size_of::<Coupon>()
}
}
13 changes: 13 additions & 0 deletions datasketches/src/hll/sketch.rs
Original file line number Diff line number Diff line change
Expand Up @@ -423,6 +423,19 @@ impl HllSketch {
Mode::Array8(arr) => arr.serialize(self.lg_config_k),
}
}

/// Returns the estimated size of the sketch in bytes
pub fn estimated_size(&self) -> usize {
let heap_size = match &self.mode {
Mode::List { list, .. } => list.container().estimated_size(),
Mode::Set { set, .. } => set.container().estimated_size(),
Mode::Array4(arr) => arr.estimated_size(),
Mode::Array6(arr) => arr.estimated_size(),
Mode::Array8(arr) => arr.estimated_size(),
};

std::mem::size_of::<Self>() + heap_size
}
Comment thread
tisonkun marked this conversation as resolved.
}

fn promote_container_to_set(container: &Container, hll_type: HllType) -> Mode {
Expand Down