Skip to content

Commit

Permalink
slight error handling cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
zkxs committed Aug 25, 2024
1 parent 2bb8722 commit 3cc415f
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 3 deletions.
5 changes: 3 additions & 2 deletions line_cardinality/src/count_unique_impl/hyperloglog.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ use super::{init_hasher_state, RandomState};
type Hash = u64;

const DEFAULT_SIZE: usize = 65536;
static DEFAULT_SIZE_ERROR_MESSAGE: &str = "expected DEFAULT_SIZE to be a valid size";

/// Estimates the unique count and holds necessary state. The estimate is performed using
/// [HyperLogLog](https://en.wikipedia.org/wiki/HyperLogLog), a state-of-the art cardinality
Expand Down Expand Up @@ -68,7 +69,7 @@ impl Default for HyperLogLog<()> {
impl HyperLogLog<()> {
/// Creates a new [`HyperLogLog`] with 65536 bytes of memory used to store state.
pub fn new() -> Self {
Self::with_capacity(DEFAULT_SIZE).unwrap()
Self::with_capacity(DEFAULT_SIZE).expect(DEFAULT_SIZE_ERROR_MESSAGE)
}

/// Creates a new [`HyperLogLog`] with `size` bytes of memory used to store state.
Expand All @@ -95,7 +96,7 @@ where
/// Creates a new [`HyperLogLog`] with 65536 bytes of memory used to store state and a custom
/// `line_mapper` function which will be applied to each read line before counting.
pub fn with_line_mapper(line_mapper: M) -> Self {
Self::with_line_mapper_and_capacity(line_mapper, DEFAULT_SIZE).unwrap()
Self::with_line_mapper_and_capacity(line_mapper, DEFAULT_SIZE).expect(DEFAULT_SIZE_ERROR_MESSAGE)
}

/// Creates a new [`HyperLogLog`] with `size` bytes of memory used to store state and a custom
Expand Down
2 changes: 1 addition & 1 deletion line_cardinality/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ pub trait CountUnique: Sized {
self.count_line(&bytes[start..]);
}
} else {
self.count_unique_in_read(bytes).unwrap()
self.count_unique_in_read(bytes).expect("somehow failed to BufRead bytes from memory!?")
}
}
}
Expand Down

0 comments on commit 3cc415f

Please sign in to comment.