mirror of
https://github.com/hl-archive-node/nanoreth.git
synced 2025-12-06 10:59:55 +00:00
chore: remove PerfectHasingFunction Filters (#10627)
Co-authored-by: joshieDo <93316087+joshieDo@users.noreply.github.com>
This commit is contained in:
@ -1,38 +0,0 @@
|
||||
use strum::AsRefStr;
|
||||
|
||||
#[derive(Debug, Copy, Clone)]
|
||||
/// Static File filters.
|
||||
pub enum Filters {
|
||||
/// Static File uses filters with [`InclusionFilter`] and [`PerfectHashingFunction`].
|
||||
WithFilters(InclusionFilter, PerfectHashingFunction),
|
||||
/// Static File doesn't use any filters.
|
||||
WithoutFilters,
|
||||
}
|
||||
|
||||
impl Filters {
|
||||
/// Returns `true` if static file uses filters.
|
||||
pub const fn has_filters(&self) -> bool {
|
||||
matches!(self, Self::WithFilters(_, _))
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Debug, Copy, Clone, AsRefStr)]
|
||||
#[cfg_attr(feature = "clap", derive(clap::ValueEnum))]
|
||||
/// Static File inclusion filter. Also see [Filters].
|
||||
pub enum InclusionFilter {
|
||||
#[strum(serialize = "cuckoo")]
|
||||
/// Cuckoo filter
|
||||
Cuckoo,
|
||||
}
|
||||
|
||||
#[derive(Debug, Copy, Clone, AsRefStr)]
|
||||
#[cfg_attr(feature = "clap", derive(clap::ValueEnum))]
|
||||
/// Static File perfect hashing function. Also see [Filters].
|
||||
pub enum PerfectHashingFunction {
|
||||
#[strum(serialize = "fmph")]
|
||||
/// Fingerprint-Based Minimal Perfect Hash Function
|
||||
Fmph,
|
||||
#[strum(serialize = "gofmph")]
|
||||
/// Fingerprint-Based Minimal Perfect Hash Function with Group Optimization
|
||||
GoFmph,
|
||||
}
|
||||
@ -9,12 +9,10 @@
|
||||
#![cfg_attr(docsrs, feature(doc_cfg, doc_auto_cfg))]
|
||||
|
||||
mod compression;
|
||||
mod filters;
|
||||
mod segment;
|
||||
|
||||
use alloy_primitives::BlockNumber;
|
||||
pub use compression::Compression;
|
||||
pub use filters::{Filters, InclusionFilter, PerfectHashingFunction};
|
||||
pub use segment::{SegmentConfig, SegmentHeader, SegmentRangeInclusive, StaticFileSegment};
|
||||
|
||||
/// Default static file block count.
|
||||
|
||||
@ -1,4 +1,4 @@
|
||||
use crate::{BlockNumber, Compression, Filters, InclusionFilter};
|
||||
use crate::{BlockNumber, Compression};
|
||||
use alloy_primitives::TxNumber;
|
||||
use derive_more::Display;
|
||||
use serde::{Deserialize, Serialize};
|
||||
@ -48,17 +48,7 @@ impl StaticFileSegment {
|
||||
|
||||
/// Returns the default configuration of the segment.
|
||||
pub const fn config(&self) -> SegmentConfig {
|
||||
let default_config = SegmentConfig {
|
||||
filters: Filters::WithFilters(
|
||||
InclusionFilter::Cuckoo,
|
||||
super::PerfectHashingFunction::Fmph,
|
||||
),
|
||||
compression: Compression::Lz4,
|
||||
};
|
||||
|
||||
match self {
|
||||
Self::Headers | Self::Transactions | Self::Receipts => default_config,
|
||||
}
|
||||
SegmentConfig { compression: Compression::Lz4 }
|
||||
}
|
||||
|
||||
/// Returns the number of columns for the segment
|
||||
@ -79,18 +69,12 @@ impl StaticFileSegment {
|
||||
/// Returns file name for the provided segment and range, alongside filters, compression.
|
||||
pub fn filename_with_configuration(
|
||||
&self,
|
||||
filters: Filters,
|
||||
compression: Compression,
|
||||
block_range: &SegmentRangeInclusive,
|
||||
) -> String {
|
||||
let prefix = self.filename(block_range);
|
||||
|
||||
let filters_name = match filters {
|
||||
Filters::WithFilters(inclusion_filter, phf) => {
|
||||
format!("{}-{}", inclusion_filter.as_ref(), phf.as_ref())
|
||||
}
|
||||
Filters::WithoutFilters => "none".to_string(),
|
||||
};
|
||||
let filters_name = "none".to_string();
|
||||
|
||||
// ATTENTION: if changing the name format, be sure to reflect those changes in
|
||||
// [`Self::parse_filename`.]
|
||||
@ -306,8 +290,6 @@ impl SegmentHeader {
|
||||
/// Configuration used on the segment.
|
||||
#[derive(Debug, Clone, Copy)]
|
||||
pub struct SegmentConfig {
|
||||
/// Inclusion filters used on the segment
|
||||
pub filters: Filters,
|
||||
/// Compression used on the segment
|
||||
pub compression: Compression,
|
||||
}
|
||||
@ -380,46 +362,28 @@ mod tests {
|
||||
(
|
||||
StaticFileSegment::Headers,
|
||||
2..=30,
|
||||
"static_file_headers_2_30_cuckoo-fmph_lz4",
|
||||
Some((
|
||||
Compression::Lz4,
|
||||
Filters::WithFilters(
|
||||
InclusionFilter::Cuckoo,
|
||||
crate::PerfectHashingFunction::Fmph,
|
||||
),
|
||||
)),
|
||||
"static_file_headers_2_30_none_lz4",
|
||||
Some(Compression::Lz4),
|
||||
),
|
||||
(
|
||||
StaticFileSegment::Headers,
|
||||
2..=30,
|
||||
"static_file_headers_2_30_cuckoo-fmph_zstd",
|
||||
Some((
|
||||
Compression::Zstd,
|
||||
Filters::WithFilters(
|
||||
InclusionFilter::Cuckoo,
|
||||
crate::PerfectHashingFunction::Fmph,
|
||||
),
|
||||
)),
|
||||
"static_file_headers_2_30_none_zstd",
|
||||
Some(Compression::Zstd),
|
||||
),
|
||||
(
|
||||
StaticFileSegment::Headers,
|
||||
2..=30,
|
||||
"static_file_headers_2_30_cuckoo-fmph_zstd-dict",
|
||||
Some((
|
||||
Compression::ZstdWithDictionary,
|
||||
Filters::WithFilters(
|
||||
InclusionFilter::Cuckoo,
|
||||
crate::PerfectHashingFunction::Fmph,
|
||||
),
|
||||
)),
|
||||
"static_file_headers_2_30_none_zstd-dict",
|
||||
Some(Compression::ZstdWithDictionary),
|
||||
),
|
||||
];
|
||||
|
||||
for (segment, block_range, filename, configuration) in test_vectors {
|
||||
for (segment, block_range, filename, compression) in test_vectors {
|
||||
let block_range: SegmentRangeInclusive = block_range.into();
|
||||
if let Some((compression, filters)) = configuration {
|
||||
if let Some(compression) = compression {
|
||||
assert_eq!(
|
||||
segment.filename_with_configuration(filters, compression, &block_range,),
|
||||
segment.filename_with_configuration(compression, &block_range),
|
||||
filename
|
||||
);
|
||||
} else {
|
||||
|
||||
Reference in New Issue
Block a user