Adjacency
Adjacency
is a structure used to specify how many objects of a particular kind can be accepted within a relation. It is a fundamental unit within the adjacency specification.
Representation
The Adjacency
structure is defined as follows:
#![allow(unused)] fn main() { pub struct Adjacency { kind: u64, deg_min: u32, deg_max: u32, } }
Field Descriptions
Field | Type | Description |
---|---|---|
kind | u64 | The ID of the kind of objects that can be accepted. |
deg_min | u32 | The minimum number (inclusive) of objects of that kind. |
deg_max | u32 | The maximum number (inclusive) of objects of that kind. |
Encoding
A single Adjacency
structure can be encoded into a u128
for compact representation:
#![allow(unused)] fn main() { let encoded = (u128(adjacency.kind) << 64) | (u128(adjacency.deg_min) << 32) | u128(adjacency.deg_max); }
Adjacency Specification
An adjacency specification defines the set of adjacencies that a relation supports.
Ascending Order
Adjacencies must be listed in ascending order based on the kind
field.
Special Kind Values
Two special kind
values have particular meanings:
u64::MIN
(0): Represents "any," meaning any kind not explicitly mentioned.u64::MAX
(2^64 - 1): Represents "total," indicating the total number of objects that can be accepted in the relation.
The "any" kind must always be listed first, and the "total" kind must be last, if present.
Encoding
An adjacency specification can be encoded into a series of Bytes32
values.
Each Bytes32
can hold two Adjacency
structures. If the number of adjacencies is odd, the remaining space in the final Bytes32
is padded with zeros.