oxgraph_hyper_bcsr/id.rs
1//! Local identifier newtypes and role enum for bipartite-CSR hypergraph
2//! views.
3
4use oxgraph_layout_util::{HyperedgeAxis, IncidenceAxis, LocalId, VertexAxis};
5
6/// Side of a directed hyperedge an incidence belongs to.
7///
8/// `oxgraph-hyper` keeps the participation role as an associated type rather
9/// than a concrete enum so views can pick whatever vocabulary fits their
10/// storage. `BcsrRole` is the role chosen for [`BcsrHypergraph`](crate::BcsrHypergraph):
11/// each participant is either on the head side or the tail side of a directed
12/// hyperedge. Role bytes are not stored — the role is recovered from which
13/// section the participant lives in.
14///
15/// # Performance
16///
17/// Copying, comparing, ordering, hashing, and debug-formatting are `O(1)`.
18#[derive(Clone, Copy, Debug, Eq, Hash, Ord, PartialEq, PartialOrd)]
19pub enum BcsrRole {
20 /// The vertex participates on the source (head) side of a directed hyperedge.
21 Head,
22 /// The vertex participates on the target (tail) side of a directed hyperedge.
23 Tail,
24}
25
26/// Local vertex ID for [`BcsrHypergraph`](crate::BcsrHypergraph).
27///
28/// Values are dense handles in `0..vertex_count` for one validated
29/// view. They are layout-local IDs and are not stable across rebuilding or
30/// compaction unless a higher layer defines that contract. This is an alias of
31/// the shared [`LocalId`](oxgraph_layout_util::LocalId) branded by the vertex
32/// axis, so a built hypergraph and its borrowed view yield the same handle
33/// type.
34///
35/// # Performance
36///
37/// Copying, comparing, ordering, hashing, and debug-formatting are `O(1)`.
38pub type BcsrVertexId<VertexIndex> = LocalId<VertexAxis, VertexIndex>;
39
40/// Local hyperedge ID for [`BcsrHypergraph`](crate::BcsrHypergraph).
41///
42/// Values are dense handles in `0..hyperedge_count` for one validated
43/// view. They are layout-local IDs and are not stable across rebuilding or
44/// compaction unless a higher layer defines that contract. This is an alias of
45/// the shared [`LocalId`](oxgraph_layout_util::LocalId) branded by the
46/// hyperedge axis.
47///
48/// # Performance
49///
50/// Copying, comparing, ordering, hashing, and debug-formatting are `O(1)`.
51pub type BcsrHyperedgeId<RelationIndex> = LocalId<HyperedgeAxis, RelationIndex>;
52
53/// Local participant (incidence) ID for [`BcsrHypergraph`](crate::BcsrHypergraph).
54///
55/// Participant IDs span a single dense `u32` index space anchored on the
56/// hyperedge-major arrays:
57///
58/// - `[0, P_head)` are head incidences; the value indexes `head_participants`.
59/// - `[P_head, P_head + P_tail)` are tail incidences; subtracting `P_head` yields a position in
60/// `tail_participants`.
61///
62/// They are layout-local IDs and are not stable across rebuilding or
63/// compaction unless a higher layer defines that contract. This is an alias of
64/// the shared [`LocalId`](oxgraph_layout_util::LocalId) branded by the
65/// incidence axis.
66///
67/// # Performance
68///
69/// Copying, comparing, ordering, hashing, and debug-formatting are `O(1)`.
70pub type BcsrParticipantId<IncidenceIndex> = LocalId<IncidenceAxis, IncidenceIndex>;