use std::fmt::Display;
use std::fmt::Formatter;
use vortex_array::ArrayRef;
use vortex_array::TypedArrayRef;
use vortex_array::array_slots;
use vortex_array::dtype::PType;
use vortex_array::scalar::Scalar;
use vortex_error::VortexResult;
use vortex_error::vortex_ensure;
pub mod for_compress;
pub mod for_decompress;
#[array_slots(crate::FoR)]
pub struct FoRSlots {
pub encoded: ArrayRef,
}
#[derive(Clone, Debug)]
pub struct FoRData {
pub(super) reference: Scalar,
}
pub trait FoRArrayExt: FoRArraySlotsExt {
fn reference_scalar(&self) -> &Scalar {
&self.reference
}
}
impl<T: TypedArrayRef<crate::FoR>> FoRArrayExt for T {}
impl Display for FoRData {
fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
write!(f, "reference: {}", self.reference)
}
}
impl FoRData {
pub(crate) fn try_new(reference: Scalar) -> VortexResult<Self> {
vortex_ensure!(!reference.is_null(), "Reference value cannot be null");
vortex_ensure!(
reference.dtype().is_int(),
"FoR requires an integer reference dtype, got {}",
reference.dtype()
);
Ok(Self { reference })
}
#[inline]
pub fn ptype(&self) -> PType {
self.reference.dtype().as_ptype()
}
}