use crate::encoding::EncodingType;
use linkrs_core::{DataType, Value};
use std::sync::Arc;
pub const DEFAULT_VERSION_CHAIN_CAP: usize = 64;
#[derive(Debug, Clone)]
pub struct PropertySchema {
pub name: Arc<str>,
pub prop_id: i32,
pub data_type: DataType,
pub nullable: bool,
pub encoding_type: EncodingType,
pub default_value: Option<Value>,
}
impl PropertySchema {
pub fn new(name: impl Into<Arc<str>>, prop_id: i32, data_type: DataType) -> Self {
Self {
name: name.into(),
prop_id,
data_type,
nullable: false,
encoding_type: EncodingType::None,
default_value: None,
}
}
pub fn nullable(mut self, nullable: bool) -> Self {
self.nullable = nullable;
self
}
pub fn with_encoding(mut self, encoding_type: EncodingType) -> Self {
self.encoding_type = encoding_type;
self
}
pub fn with_default_value(mut self, default_value: Option<Value>) -> Self {
self.default_value = default_value;
self
}
}
#[derive(Debug, Clone, Default)]
pub struct PropertyCompactionStats {
pub tombstone_count: usize,
pub total_records: usize,
pub live_records: usize,
pub reclaimable_bytes: usize,
}
impl PropertyCompactionStats {
pub fn fragmentation_ratio(&self) -> f64 {
if self.total_records == 0 {
0.0
} else {
self.tombstone_count as f64 / self.total_records as f64
}
}
}