use linkrs_core::types::Timestamp;
use linkrs_core::Value;
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
pub struct VertexCacheKey {
pub label_id: u32,
pub internal_id: u32,
}
impl VertexCacheKey {
pub fn new(label_id: u32, internal_id: u32) -> Self {
Self {
label_id,
internal_id,
}
}
}
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
pub struct IdIndexCacheKey {
pub label_id: u32,
pub external_id: String,
}
impl IdIndexCacheKey {
pub fn new(label_id: u32, external_id: String) -> Self {
Self {
label_id,
external_id,
}
}
}
#[derive(Debug, Clone)]
pub struct CachedVertex {
pub internal_id: u32,
pub external_id: String,
pub properties: Vec<(std::sync::Arc<str>, Value)>,
pub cached_at_ts: Timestamp,
pub create_ts: Timestamp,
pub column_starts: Vec<Timestamp>,
pub generation: u32,
}
#[derive(Debug, Clone, Copy)]
pub struct IdIndexCacheValue {
pub internal_id: u32,
pub cached_at_ts: Timestamp,
pub generation: u32,
}
impl CachedVertex {
pub fn estimated_size(&self) -> u32 {
let mut size = std::mem::size_of::<Self>();
size += self.external_id.len();
size += self
.column_starts
.capacity()
.saturating_mul(std::mem::size_of::<Timestamp>());
size += self
.properties
.capacity()
.saturating_mul(std::mem::size_of::<(String, Value)>());
for (name, value) in &self.properties {
size += name.len();
size += value.estimated_size();
}
size as u32
}
}