Skip to content

Commit

Permalink
Drop superfluous struct
Browse files Browse the repository at this point in the history
This isn't Java, we don't need static functions to be part of a
class. If anything, this should have been a module.
  • Loading branch information
mmarx committed Sep 9, 2024
1 parent 450f47a commit d03d32d
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 32 deletions.
8 changes: 4 additions & 4 deletions nemo-physical/src/dictionary/bytes_dictionary.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ use hashbrown::HashMap;
use super::bytes_buffer::{BytesRef, GlobalBytesBuffer};
use super::{AddResult, KNOWN_ID_MARK};
use crate::dictionary::datavalue_dictionary::{SMALL_KNOWN_ID_MARK, SMALL_KNOWN_ID_MARK_AS_USIZE};
use crate::management::bytesized::{ByteSizeHelpers, ByteSized};
use crate::management::bytesized::{size_inner_hashmap_flat, size_inner_vec_flat, ByteSized};

pub(crate) struct IdUtils {}

Expand Down Expand Up @@ -187,9 +187,9 @@ impl<B: GlobalBytesBuffer> Drop for BytesDictionary<B> {
impl<B: GlobalBytesBuffer> ByteSized for BytesDictionary<B> {
fn size_bytes(&self) -> u64 {
size_of::<Self>() as u64
+ ByteSizeHelpers::size_inner_vec_flat(&self.store)
+ ByteSizeHelpers::size_inner_hashmap_flat(&self.map_short)
+ ByteSizeHelpers::size_inner_hashmap_flat(&self.map_long)
+ size_inner_vec_flat(&self.store)
+ size_inner_hashmap_flat(&self.map_short)
+ size_inner_hashmap_flat(&self.map_long)
+ B::buffer_size_bytes(self.buffer_id)
}
}
Expand Down
10 changes: 5 additions & 5 deletions nemo-physical/src/dictionary/meta_dv_dict.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
use crate::datavalues::ValueDomain;
use crate::datavalues::{AnyDataValue, DataValue};
use crate::dictionary::NONEXISTING_ID_MARK;
use crate::management::bytesized::{ByteSizeHelpers, ByteSized};
use crate::management::bytesized::{size_inner_vec_flat, ByteSized};

use super::DvDict;
use super::IriDvDictionary;
Expand Down Expand Up @@ -541,13 +541,13 @@ impl DvDict for MetaDvDictionary {
impl ByteSized for MetaDvDictionary {
fn size_bytes(&self) -> u64 {
size_of::<Self>() as u64
+ ByteSizeHelpers::size_inner_vec_flat(&self.dictblocks)
+ ByteSizeHelpers::size_inner_vec_flat(&self.dicts)
+ ByteSizeHelpers::size_inner_vec_flat(&self.generic_dicts)
+ size_inner_vec_flat(&self.dictblocks)
+ size_inner_vec_flat(&self.dicts)
+ size_inner_vec_flat(&self.generic_dicts)
+ self
.dicts
.iter()
.map(|dr| dr.dict.size_bytes() + ByteSizeHelpers::size_inner_vec_flat(&dr.gblocks))
.map(|dr| dr.dict.size_bytes() + size_inner_vec_flat(&dr.gblocks))
.sum::<u64>()
}
}
Expand Down
35 changes: 12 additions & 23 deletions nemo-physical/src/management/bytesized.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,28 +10,17 @@ pub trait ByteSized {
fn size_bytes(&self) -> u64;
}

/// Collection of some simple helper methods for estimating sizes.
pub(crate) struct ByteSizeHelpers;

impl ByteSizeHelpers {
/// Estimates the memory required for managing the content of a Hashbrown hashmap using only
/// the direct size of keys and values, without taking into accont any data they might point to.
///
/// The computation is approximate since the hashmap does not provide access to its current bucket
/// structure and control byte overhead, so we merely consider the reported capacity.
pub(crate) fn size_inner_hashmap_flat<K, V>(object: &hashbrown::HashMap<K, V>) -> u64
where
Self: Sized,
{
object.capacity() as u64 * size_of::<(K, V)>() as u64
}
/// Estimates the memory required for managing the content of a Hashbrown hashmap using only
/// the direct size of keys and values, without taking into accont any data they might point to.
///
/// The computation is approximate since the hashmap does not provide access to its current bucket
/// structure and control byte overhead, so we merely consider the reported capacity.
pub(crate) fn size_inner_hashmap_flat<K, V>(object: &hashbrown::HashMap<K, V>) -> u64 {
object.capacity() as u64 * size_of::<(K, V)>() as u64
}

/// Computes the memory required for managing the content of a vector using only
/// the direct size of content objects, without taking into accont any data they might point to.
pub(crate) fn size_inner_vec_flat<T>(object: &Vec<T>) -> u64
where
Self: Sized,
{
object.capacity() as u64 * size_of::<T>() as u64
}
/// Computes the memory required for managing the content of a vector using only
/// the direct size of content objects, without taking into accont any data they might point to.
pub(crate) fn size_inner_vec_flat<T>(object: &Vec<T>) -> u64 {
object.capacity() as u64 * size_of::<T>() as u64
}

0 comments on commit d03d32d

Please sign in to comment.