Skip to content
Merged
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
8 changes: 8 additions & 0 deletions src/hll/array4.rs
Original file line number Diff line number Diff line change
Expand Up @@ -257,6 +257,14 @@ impl Array4 {
use crate::hll::serialization::*;
use crate::hll::{get_slot, get_value};

if bytes.len() < HLL_PREAMBLE_SIZE {
return Err(SerdeError::InsufficientData(format!(
"expected at least {}, got {}",
HLL_PREAMBLE_SIZE,
bytes.len()
)));
}

let num_bytes = 1 << (lg_config_k - 1); // k/2 bytes for 4-bit packing

// Read cur_min from header
Expand Down
4 changes: 2 additions & 2 deletions src/hll/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -69,8 +69,8 @@ mod list;
mod serialization;
mod sketch;

pub use estimator::NumStdDev;
pub use sketch::HllSketch;
pub use self::estimator::NumStdDev;
pub use self::sketch::HllSketch;
Comment on lines +72 to +73
Copy link
Contributor

Choose a reason for hiding this comment

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

What's the idea behind this? Do we have tools to enforce this style repo-wide?

Copy link
Member Author

Choose a reason for hiding this comment

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

I found it when a mod name sometimes conflicts with a dependency name. Using self::sketch::HllSketch always unambiguously refers to the proper symbol.

Do we have tools to enforce this style repo-wide?

Not quite easy. One can define a custom clippy rule or work with ast-grep. But this rule depends on whether the (pub use) symbol is within this crate/module.


/// Target HLL type.
///
Expand Down
4 changes: 2 additions & 2 deletions src/hll/serialization.rs
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@ pub const DOUBLE_SIZE_BYTES: usize = 8;
/// Size of an int (u32) in bytes
pub const INT_SIZE_BYTES: usize = 4;

/// Read a u32 value from bytes at the given offset (little-endian)
/// Read an u32 value from bytes at the given offset (little-endian)
#[inline]
pub fn read_u32_le(bytes: &[u8], offset: usize) -> u32 {
u32::from_le_bytes([
Expand All @@ -181,7 +181,7 @@ pub fn read_f64_le(bytes: &[u8], offset: usize) -> f64 {
])
}

/// Write a u32 value to bytes at the given offset (little-endian)
/// Write an u32 value to bytes at the given offset (little-endian)
#[inline]
pub fn write_u32_le(bytes: &mut [u8], offset: usize, value: u32) {
bytes[offset..offset + INT_SIZE_BYTES].copy_from_slice(&value.to_le_bytes());
Expand Down