use std::collections::hash_map::RandomState;
use super::{JpegCachedPlan, JpegPlanCacheError};
mod diagnostics;
mod resolve;
mod state;
pub use diagnostics::JpegPlanCacheDiagnostics;
#[cfg(test)]
pub(super) use state::metadata_entry_size_for_test;
pub(super) use state::PlanCache;
pub const DEFAULT_JPEG_PLAN_CACHE_ENTRIES: usize = 8;
pub const DEFAULT_JPEG_PLAN_CACHE_HOST_BYTES: usize = 64 * 1024 * 1024;
#[derive(Clone, Copy, Debug, Eq, PartialEq)]
#[doc(hidden)]
pub enum JpegPlanCacheInsert {
Cached,
SkippedDisabled,
SkippedOversized,
}
#[doc(hidden)]
pub struct JpegPlanCache {
inner: PlanCache<RandomState>,
}
impl JpegPlanCache {
#[must_use]
pub fn new() -> Self {
Self::with_limits(
DEFAULT_JPEG_PLAN_CACHE_ENTRIES,
DEFAULT_JPEG_PLAN_CACHE_HOST_BYTES,
)
}
#[must_use]
pub fn with_limits(entry_limit: usize, host_byte_limit: usize) -> Self {
Self {
inner: PlanCache::with_limits_and_digest_builder(
entry_limit,
host_byte_limit,
RandomState::new(),
),
}
}
pub fn get(&mut self, input: &[u8]) -> Option<JpegCachedPlan> {
self.inner.get(input)
}
pub fn insert(
&mut self,
plan: JpegCachedPlan,
) -> Result<JpegPlanCacheInsert, JpegPlanCacheError> {
self.inner.insert(plan)
}
#[must_use]
pub const fn diagnostics(&self) -> JpegPlanCacheDiagnostics {
self.inner.diagnostics()
}
}
impl Default for JpegPlanCache {
fn default() -> Self {
Self::new()
}
}