use std::fmt;
use super::csr_shared::VertexBookkeeping;
use super::{ColdStamps, HotNbr, Nbr, Timestamp};
use live_set::LiveSetStorage;
pub(crate) mod compaction;
pub(crate) mod core;
pub mod iter;
pub(crate) mod live_set;
pub mod overflow;
pub(crate) mod persistence;
pub(crate) mod read;
pub(crate) mod row;
pub mod serialization;
pub(crate) mod stats;
pub(crate) mod trait_impl;
pub(crate) mod write;
pub use iter::{MutableCsrIterator, VertexEdgesIter};
pub use overflow::{OverflowChunk, OverflowStorage};
pub use write::EdgePosition;
pub(crate) use row::PACKED_CSR_DENSITY;
pub struct MutableCsr {
hot_list: Vec<HotNbr>,
cold_list: Vec<ColdStamps>,
rows: VertexBookkeeping,
overflow_chunks: OverflowStorage,
overflow_chunk_edges: usize,
live_sets: LiveSetStorage,
tombstone_reuse_cutoff: Timestamp,
reuse_hint: Vec<u32>,
live_counts: Vec<u32>,
tombstone_counts: Vec<u32>,
primary_sorted: Vec<bool>,
edge_count: u64,
total_edge_capacity: usize,
overflow_chunk_allocs: u64,
primary_block_allocs: u64,
repack_count: u64,
tombstone_reuse_count: u64,
live_set_rebuild_count: u64,
tombstone_reuse_hint_hits: u64,
tombstone_reuse_hint_misses: u64,
}
impl MutableCsr {
#[inline]
pub(crate) fn slot_at(&self, idx: usize) -> Option<Nbr> {
Some(Nbr::from_parts(
*self.hot_list.get(idx)?,
*self.cold_list.get(idx)?,
))
}
#[inline]
pub(crate) fn set_slot(&mut self, idx: usize, nbr: Nbr) {
self.hot_list[idx] = nbr.hot();
self.cold_list[idx] = nbr.cold();
debug_assert_eq!(self.hot_list.len(), self.cold_list.len());
}
#[inline]
pub(crate) fn cold_at(&self, idx: usize) -> Option<ColdStamps> {
self.cold_list.get(idx).copied()
}
}
impl Clone for MutableCsr {
fn clone(&self) -> Self {
Self {
hot_list: self.hot_list.clone(),
cold_list: self.cold_list.clone(),
rows: self.rows.clone(),
overflow_chunks: self.overflow_chunks.clone(),
overflow_chunk_edges: self.overflow_chunk_edges,
live_sets: self.live_sets.clone(),
tombstone_reuse_cutoff: self.tombstone_reuse_cutoff,
reuse_hint: self.reuse_hint.clone(),
live_counts: self.live_counts.clone(),
tombstone_counts: self.tombstone_counts.clone(),
primary_sorted: self.primary_sorted.clone(),
edge_count: self.edge_count,
total_edge_capacity: self.total_edge_capacity,
overflow_chunk_allocs: self.overflow_chunk_allocs,
primary_block_allocs: self.primary_block_allocs,
repack_count: self.repack_count,
tombstone_reuse_count: self.tombstone_reuse_count,
live_set_rebuild_count: self.live_set_rebuild_count,
tombstone_reuse_hint_hits: self.tombstone_reuse_hint_hits,
tombstone_reuse_hint_misses: self.tombstone_reuse_hint_misses,
}
}
}
impl fmt::Debug for MutableCsr {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
f.debug_struct("MutableCsr")
.field("vertex_capacity", &self.vertex_capacity())
.field("total_edge_capacity", &self.total_edge_capacity)
.field("edge_count", &self.edge_count)
.finish_non_exhaustive()
}
}
#[cfg(test)]
mod tests;