#![forbid(unsafe_code)]
use crate::dsfb::features::Channel;
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub struct OptimizeOptions {
pub allow_exact_ref: bool,
pub allow_configurational: bool,
pub allow_byte_rans: bool,
pub allow_sequence_rans: bool,
pub allow_sequence_dict: bool,
pub allow_shared_dict: bool,
pub allow_bases: bool,
pub allow_temporal_bases: bool,
pub allow_universe: bool,
pub allow_dsfb_ranking: bool,
}
impl Default for OptimizeOptions {
fn default() -> Self {
Self {
allow_exact_ref: true,
allow_configurational: true,
allow_byte_rans: true,
allow_sequence_rans: true,
allow_sequence_dict: true,
allow_shared_dict: true,
allow_bases: true,
allow_temporal_bases: true,
allow_universe: true,
allow_dsfb_ranking: true,
}
}
}
impl OptimizeOptions {
pub const fn raw_only() -> Self {
Self {
allow_exact_ref: false,
allow_configurational: false,
allow_byte_rans: false,
allow_sequence_rans: false,
allow_sequence_dict: false,
allow_shared_dict: false,
allow_bases: false,
allow_temporal_bases: false,
allow_universe: false,
allow_dsfb_ranking: false,
}
}
pub const fn raw_rans() -> Self {
Self {
allow_exact_ref: false,
allow_configurational: false,
allow_byte_rans: true,
allow_sequence_rans: false,
allow_sequence_dict: false,
allow_shared_dict: false,
allow_bases: false,
allow_temporal_bases: false,
allow_universe: false,
allow_dsfb_ranking: false,
}
}
pub const fn raw_sequence() -> Self {
Self {
allow_exact_ref: false,
allow_configurational: false,
allow_byte_rans: false,
allow_sequence_rans: true,
allow_sequence_dict: false,
allow_shared_dict: false,
allow_bases: false,
allow_temporal_bases: false,
allow_universe: false,
allow_dsfb_ranking: false,
}
}
pub const fn channel_allowed(&self, channel: Channel) -> bool {
match channel {
Channel::SharedContent => self.allow_exact_ref,
Channel::PrevVersion => self.allow_bases,
Channel::Adjacent | Channel::PrevInFile | Channel::FamilyBase => {
self.allow_bases && self.allow_temporal_bases
}
Channel::Universe => self.allow_universe,
Channel::Rans => self.allow_byte_rans || self.allow_sequence_rans,
Channel::Raw => true,
Channel::SharedDict => self.allow_shared_dict,
}
}
pub const fn representation_allowed(
&self,
d: &crate::core::representation::Representation,
) -> bool {
use crate::core::representation::Representation;
match d {
Representation::Raw { .. } => true,
Representation::Rans { .. } => self.allow_byte_rans,
Representation::SequenceRans { .. } => self.allow_sequence_rans,
Representation::SequenceDict { .. } => self.allow_sequence_dict,
Representation::SequenceSharedDict { .. } => self.allow_shared_dict,
Representation::ExactRef { .. } => self.allow_exact_ref,
Representation::BaseResidual { .. } => self.allow_bases,
Representation::EntropyRef { .. } => self.allow_universe,
Representation::Zero { .. }
| Representation::Fill { .. }
| Representation::Inline { .. }
| Representation::Sparse { .. }
| Representation::Palette { .. }
| Representation::Periodic { .. }
| Representation::Permutation { .. }
| Representation::SparseBlock64 { .. } => self.allow_configurational,
}
}
pub fn ablation_modes() -> Vec<(&'static str, OptimizeOptions)> {
vec![
("full", OptimizeOptions::default()),
("raw", OptimizeOptions::raw_only()),
("raw-byte-rans", OptimizeOptions::raw_rans()),
(
"no-exact-ref",
OptimizeOptions {
allow_exact_ref: false,
..Default::default()
},
),
(
"no-base",
OptimizeOptions {
allow_bases: false,
allow_temporal_bases: false,
..Default::default()
},
),
(
"no-temporal",
OptimizeOptions {
allow_temporal_bases: false,
..Default::default()
},
),
(
"no-config",
OptimizeOptions {
allow_configurational: false,
..Default::default()
},
),
(
"no-rans",
OptimizeOptions {
allow_byte_rans: false,
allow_sequence_rans: false,
..Default::default()
},
),
(
"no-byte-rans",
OptimizeOptions {
allow_byte_rans: false,
..Default::default()
},
),
(
"no-sequence-rans",
OptimizeOptions {
allow_sequence_rans: false,
..Default::default()
},
),
(
"no-sequence-dict",
OptimizeOptions {
allow_sequence_dict: false,
..Default::default()
},
),
(
"no-shared-dict",
OptimizeOptions {
allow_shared_dict: false,
..Default::default()
},
),
(
"no-universe",
OptimizeOptions {
allow_universe: false,
..Default::default()
},
),
(
"no-dsfb",
OptimizeOptions {
allow_dsfb_ranking: false,
..Default::default()
},
),
]
}
pub fn cumulative_ladder_modes() -> Vec<(&'static str, OptimizeOptions, bool)> {
vec![
("A0-raw", OptimizeOptions::raw_only(), false),
("A1-byte-rans", OptimizeOptions::raw_rans(), false),
(
"A2-exact-ref",
OptimizeOptions {
allow_exact_ref: true,
allow_configurational: false,
allow_byte_rans: true,
allow_sequence_rans: false,
allow_sequence_dict: false,
allow_shared_dict: false,
allow_bases: false,
allow_temporal_bases: false,
allow_universe: false,
allow_dsfb_ranking: false,
},
false,
),
(
"A3-base-residual",
OptimizeOptions {
allow_exact_ref: true,
allow_configurational: false,
allow_byte_rans: true,
allow_sequence_rans: false,
allow_sequence_dict: false,
allow_shared_dict: false,
allow_bases: true,
allow_temporal_bases: false,
allow_universe: false,
allow_dsfb_ranking: false,
},
false,
),
(
"A4-config",
OptimizeOptions {
allow_exact_ref: true,
allow_configurational: true,
allow_byte_rans: true,
allow_sequence_rans: false,
allow_sequence_dict: false,
allow_shared_dict: false,
allow_bases: true,
allow_temporal_bases: false,
allow_universe: false,
allow_dsfb_ranking: false,
},
false,
),
(
"A5-temporal-bases",
OptimizeOptions {
allow_exact_ref: true,
allow_configurational: true,
allow_byte_rans: true,
allow_sequence_rans: false,
allow_sequence_dict: false,
allow_shared_dict: false,
allow_bases: true,
allow_temporal_bases: true,
allow_universe: false,
allow_dsfb_ranking: false,
},
false,
),
(
"A6-universe",
OptimizeOptions {
allow_exact_ref: true,
allow_configurational: true,
allow_byte_rans: true,
allow_sequence_rans: false,
allow_sequence_dict: false,
allow_shared_dict: false,
allow_bases: true,
allow_temporal_bases: true,
allow_universe: true,
allow_dsfb_ranking: false,
},
false,
),
(
"A7-dsfb",
OptimizeOptions {
allow_exact_ref: true,
allow_configurational: true,
allow_byte_rans: true,
allow_sequence_rans: false,
allow_sequence_dict: false,
allow_shared_dict: false,
allow_bases: true,
allow_temporal_bases: true,
allow_universe: true,
allow_dsfb_ranking: true,
},
false,
),
(
"A8-background",
OptimizeOptions {
allow_exact_ref: true,
allow_configurational: true,
allow_byte_rans: true,
allow_sequence_rans: false,
allow_sequence_dict: false,
allow_shared_dict: false,
allow_bases: true,
allow_temporal_bases: true,
allow_universe: true,
allow_dsfb_ranking: true,
},
true,
),
("E1-sequence-rans", OptimizeOptions::default(), true),
(
"E2-sequence-dict",
OptimizeOptions {
allow_shared_dict: false,
..Default::default()
},
true,
),
("E3-shared-dict", OptimizeOptions::default(), true),
]
}
}