use core::marker::PhantomData;
use oxgraph_layout_util::SnapshotWidth;
pub use oxgraph_layout_util::{LayoutIndex, LayoutSnapshotWord, LayoutWord};
use crate::snapshot::{
SNAPSHOT_KIND_BCSR_HEAD_OFFSETS_BASE, SNAPSHOT_KIND_BCSR_HEAD_PARTICIPANTS_BASE,
SNAPSHOT_KIND_BCSR_TAIL_OFFSETS_BASE, SNAPSHOT_KIND_BCSR_TAIL_PARTICIPANTS_BASE,
SNAPSHOT_KIND_BCSR_VERTEX_INCOMING_HYPEREDGES_BASE,
SNAPSHOT_KIND_BCSR_VERTEX_INCOMING_OFFSETS_BASE,
SNAPSHOT_KIND_BCSR_VERTEX_OUTGOING_HYPEREDGES_BASE,
SNAPSHOT_KIND_BCSR_VERTEX_OUTGOING_OFFSETS_BASE,
};
pub const SNAPSHOT_BCSR_SECTION_VERSION: u32 = 1;
pub trait BcsrWords {
type VertexIndex: LayoutIndex;
type RelationIndex: LayoutIndex;
type IncidenceIndex: LayoutIndex;
type OffsetWord: LayoutWord<Index = Self::IncidenceIndex>;
type VertexWord: LayoutWord<Index = Self::VertexIndex>;
type RelationWord: LayoutWord<Index = Self::RelationIndex>;
}
type WordFamilyBrand<VertexIndex, RelationIndex, IncidenceIndex> =
PhantomData<fn() -> (VertexIndex, RelationIndex, IncidenceIndex)>;
pub struct NativeWords<VertexIndex, RelationIndex, IncidenceIndex> {
_family: WordFamilyBrand<VertexIndex, RelationIndex, IncidenceIndex>,
}
impl<VertexIndex, RelationIndex, IncidenceIndex> BcsrWords
for NativeWords<VertexIndex, RelationIndex, IncidenceIndex>
where
VertexIndex: LayoutIndex + LayoutWord<Index = VertexIndex>,
RelationIndex: LayoutIndex + LayoutWord<Index = RelationIndex>,
IncidenceIndex: LayoutIndex + LayoutWord<Index = IncidenceIndex>,
{
type IncidenceIndex = IncidenceIndex;
type OffsetWord = IncidenceIndex;
type RelationIndex = RelationIndex;
type RelationWord = RelationIndex;
type VertexIndex = VertexIndex;
type VertexWord = VertexIndex;
}
pub struct LeWords<VertexIndex, RelationIndex, IncidenceIndex> {
_family: WordFamilyBrand<VertexIndex, RelationIndex, IncidenceIndex>,
}
impl<VertexIndex, RelationIndex, IncidenceIndex> BcsrWords
for LeWords<VertexIndex, RelationIndex, IncidenceIndex>
where
VertexIndex: SnapshotWidth,
RelationIndex: SnapshotWidth,
IncidenceIndex: SnapshotWidth,
{
type IncidenceIndex = IncidenceIndex;
type OffsetWord = IncidenceIndex::LittleEndianWord;
type RelationIndex = RelationIndex;
type RelationWord = RelationIndex::LittleEndianWord;
type VertexIndex = VertexIndex;
type VertexWord = VertexIndex::LittleEndianWord;
}
pub trait BcsrSnapshotIndex: SnapshotWidth {
const HEAD_OFFSETS_KIND: u32 = SNAPSHOT_KIND_BCSR_HEAD_OFFSETS_BASE | Self::WIDTH_CODE;
const HEAD_PARTICIPANTS_KIND: u32 =
SNAPSHOT_KIND_BCSR_HEAD_PARTICIPANTS_BASE | Self::WIDTH_CODE;
const TAIL_OFFSETS_KIND: u32 = SNAPSHOT_KIND_BCSR_TAIL_OFFSETS_BASE | Self::WIDTH_CODE;
const TAIL_PARTICIPANTS_KIND: u32 =
SNAPSHOT_KIND_BCSR_TAIL_PARTICIPANTS_BASE | Self::WIDTH_CODE;
const VERTEX_OUTGOING_OFFSETS_KIND: u32 =
SNAPSHOT_KIND_BCSR_VERTEX_OUTGOING_OFFSETS_BASE | Self::WIDTH_CODE;
const VERTEX_OUTGOING_HYPEREDGES_KIND: u32 =
SNAPSHOT_KIND_BCSR_VERTEX_OUTGOING_HYPEREDGES_BASE | Self::WIDTH_CODE;
const VERTEX_INCOMING_OFFSETS_KIND: u32 =
SNAPSHOT_KIND_BCSR_VERTEX_INCOMING_OFFSETS_BASE | Self::WIDTH_CODE;
const VERTEX_INCOMING_HYPEREDGES_KIND: u32 =
SNAPSHOT_KIND_BCSR_VERTEX_INCOMING_HYPEREDGES_BASE | Self::WIDTH_CODE;
const SECTION_VERSION: u32 = SNAPSHOT_BCSR_SECTION_VERSION;
}
impl BcsrSnapshotIndex for u16 {}
impl BcsrSnapshotIndex for u32 {}
impl BcsrSnapshotIndex for u64 {}