Skip to content
Open
Show file tree
Hide file tree
Changes from all 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 size of the heap allocations in bytes
pub fn heap_size(&self) -> usize {
self.slots.len() * std::mem::size_of::<u32>()
}
Comment on lines +250 to +253
}
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 size of the sketch in bytes
pub fn size(&self) -> usize {
let heap_size = self.sliding_window.len()
+ self
.surprising_value_table
.as_ref()
.map(|t| t.heap_size())
.unwrap_or(0);
Comment on lines +456 to +461

std::mem::size_of::<Self>() + heap_size
}
}

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

bytes.into_bytes()
}

/// Returns the size of the heap allocations in bytes
pub fn heap_size(&self) -> usize {
self.bytes.len() + self.aux_map.as_ref().map(|a| a.heap_size()).unwrap_or(0)
}
}

#[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 size of the heap allocations in bytes
pub fn heap_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 size of the heap allocations in bytes
pub fn heap_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 size of the heap allocations in bytes
pub fn heap_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 size of the heap allocations in bytes
pub fn heap_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 size of the sketch in bytes
pub fn size(&self) -> usize {
let heap_size = match &self.mode {
Mode::List { list, .. } => list.container().heap_size(),
Mode::Set { set, .. } => set.container().heap_size(),
Mode::Array4(arr) => arr.heap_size(),
Mode::Array6(arr) => arr.heap_size(),
Mode::Array8(arr) => arr.heap_size(),
};

std::mem::size_of::<Self>() + heap_size
}
}

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