use crate::core::util::error::lucene_error::Result;
use crate::core::util::packed::abstract_paged_mutable::AbstractPagedMutableBase;
use crate::core::util::packed::mutable_enum::MutableEnum;
use crate::core::util::packed::{Format, FormatAndBits, PackedInts, fastest_format_and_bits};
#[derive(Default)]
pub struct PagedMutable {
format: Format,
bits_per_value: i32,
fill_pages: bool,
}
impl PagedMutable {
pub fn with_overhead_ratio(
page_size: i32,
bits_per_value: i32,
acceptable_overhead_ratio: f32,
) -> Self {
let format_and_bits =
fastest_format_and_bits(page_size, bits_per_value, acceptable_overhead_ratio);
Self::with_format_and_bits(format_and_bits)
}
fn with_format_and_bits(format_and_bits: FormatAndBits) -> Self {
Self::with_bits_and_format(format_and_bits.bits_per_value, format_and_bits.format)
}
fn with_bits_and_format(bits_per_value: i32, format: Format) -> Self {
Self {
format,
bits_per_value,
fill_pages: true,
}
}
}
impl AbstractPagedMutableBase for PagedMutable {
fn new_mutable(&self, value_count: usize, bits_per_value: i32) -> Result<MutableEnum> {
debug_assert!(self.bits_per_value >= bits_per_value);
let sub_mutable = PackedInts::get_mutable_impl(value_count, self.bits_per_value, self.format)?;
Ok(MutableEnum::Packed(sub_mutable))
}
fn new_unfilled_copy(&self) -> Self {
PagedMutable {
format: self.format,
bits_per_value: self.bits_per_value,
fill_pages: false,
}
}
fn base_ram_bytes_used_base(&self) -> i64 {
0
}
fn fill_pages(&self) -> bool {
self.fill_pages
}
fn bits_per_value(&self) -> i32 {
self.bits_per_value
}
}
impl std::fmt::Display for PagedMutable {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
f.write_str("PagedMutable")
}
}