use crate::{
error::BcsrError,
internal::validation::{BcsrValidation, DerivedCounts, validate_sections},
word::LayoutWord,
};
#[derive(Clone, Copy, Debug)]
pub struct BcsrSections<'view, OffsetWord, VertexWord, RelationWord>
where
OffsetWord: LayoutWord,
VertexWord: LayoutWord,
RelationWord: LayoutWord,
{
pub head_offsets: &'view [OffsetWord],
pub head_participants: &'view [VertexWord],
pub tail_offsets: &'view [OffsetWord],
pub tail_participants: &'view [VertexWord],
pub vertex_outgoing_offsets: &'view [OffsetWord],
pub vertex_outgoing_hyperedges: &'view [RelationWord],
pub vertex_incoming_offsets: &'view [OffsetWord],
pub vertex_incoming_hyperedges: &'view [RelationWord],
}
#[cfg(kani)]
impl<'view, OffsetWord, VertexWord, RelationWord>
BcsrSections<'view, OffsetWord, VertexWord, RelationWord>
where
OffsetWord: LayoutWord,
VertexWord: LayoutWord,
RelationWord: LayoutWord,
{
#[expect(
clippy::too_many_arguments,
reason = "eight slice arguments mirror the eight BcsrSections fields in the documented declaration order"
)]
pub(crate) fn for_kani(
head_offsets: &'view [OffsetWord],
head_participants: &'view [VertexWord],
tail_offsets: &'view [OffsetWord],
tail_participants: &'view [VertexWord],
vertex_outgoing_offsets: &'view [OffsetWord],
vertex_outgoing_hyperedges: &'view [RelationWord],
vertex_incoming_offsets: &'view [OffsetWord],
vertex_incoming_hyperedges: &'view [RelationWord],
) -> Self {
Self {
head_offsets,
head_participants,
tail_offsets,
tail_participants,
vertex_outgoing_offsets,
vertex_outgoing_hyperedges,
vertex_incoming_offsets,
vertex_incoming_hyperedges,
}
}
}
#[derive(Clone, Copy, Debug)]
pub struct BcsrHypergraph<
'view,
VertexIndex,
RelationIndex,
IncidenceIndex,
OffsetWord,
VertexWord,
RelationWord,
> where
OffsetWord: LayoutWord<Index = IncidenceIndex>,
VertexWord: LayoutWord<Index = VertexIndex>,
RelationWord: LayoutWord<Index = RelationIndex>,
VertexIndex: crate::word::LayoutIndex,
RelationIndex: crate::word::LayoutIndex,
IncidenceIndex: crate::word::LayoutIndex,
{
counts: DerivedCounts,
sections: BcsrSections<'view, OffsetWord, VertexWord, RelationWord>,
}
impl<'view, VertexIndex, RelationIndex, IncidenceIndex, OffsetWord, VertexWord, RelationWord>
BcsrHypergraph<
'view,
VertexIndex,
RelationIndex,
IncidenceIndex,
OffsetWord,
VertexWord,
RelationWord,
>
where
OffsetWord: LayoutWord<Index = IncidenceIndex>,
VertexWord: LayoutWord<Index = VertexIndex>,
RelationWord: LayoutWord<Index = RelationIndex>,
VertexIndex: crate::word::LayoutIndex,
RelationIndex: crate::word::LayoutIndex,
IncidenceIndex: crate::word::LayoutIndex,
{
pub fn open(
sections: BcsrSections<'view, OffsetWord, VertexWord, RelationWord>,
) -> Result<Self, BcsrError> {
Self::open_with(sections, BcsrValidation::Layout)
}
pub fn open_with(
sections: BcsrSections<'view, OffsetWord, VertexWord, RelationWord>,
level: BcsrValidation,
) -> Result<Self, BcsrError> {
let counts = validate_sections(§ions, level)?;
Ok(Self { counts, sections })
}
#[must_use]
pub const fn vertex_count(&self) -> usize {
self.counts.vertex_count
}
#[must_use]
pub const fn hyperedge_count(&self) -> usize {
self.counts.hyperedge_count
}
#[must_use]
pub const fn outgoing_incidence_count(&self) -> usize {
self.counts.p_outgoing
}
#[must_use]
pub const fn incoming_incidence_count(&self) -> usize {
self.counts.p_incoming
}
pub(in crate::internal) const fn counts(&self) -> DerivedCounts {
self.counts
}
pub(in crate::internal) const fn sections(
&self,
) -> &BcsrSections<'view, OffsetWord, VertexWord, RelationWord> {
&self.sections
}
}