pub struct Adjacency { /* private fields */ }Expand description
A relationship’s parent to children map.
Implementations§
Source§impl Adjacency
impl Adjacency
Sourcepub fn build(parents_of: &[Rid], parents: u64) -> Result<Self>
pub fn build(parents_of: &[Rid], parents: u64) -> Result<Self>
Builds the adjacency from one parent rid per child, with NO_PARENT for the unmatched.
Two passes over the slice, one to count each parent’s children and one to place them, which is a counting sort. The children arrive in row order, so each list comes out ascending.
§Errors
If a parent rid is not NO_PARENT and is not below parents, for the reason
crate::Link::build refuses the same thing.
Sourcepub fn children_of(&self, parent: Rid, out: &mut Vec<Rid>) -> Result<()>
pub fn children_of(&self, parent: Rid, out: &mut Vec<Rid>) -> Result<()>
The child rows that point at parent, ascending, appended to out.
§Errors
If parent is past the end, or the packed rows are shorter than the lists say.
Sourcepub fn reached(&self, held: &Rids) -> u64
pub fn reached(&self, held: &Rids) -> u64
How many children the parents of held have between them, without reading a child row.
Two selects a member, for a caller deciding whether Self::push is worth its gathers.
Sourcepub fn push(&self, held: &Rids) -> Result<Rids>
pub fn push(&self, held: &Rids) -> Result<Rids>
The child rows that point into held, which is a set over the parent table.
The lists of the members, set as bits of one bitmap over the children, which the set then
settles into whichever form its size calls for. A bit a child costs no comparison, where
sorting the lists together cost a log a child, and the result is the exact set a forward
push of held through the link would give.
§Errors
If held is not a set over the parent table.
Sourcepub fn write(&self, out: &mut Vec<u8>) -> Result<()>
pub fn write(&self, out: &mut Vec<u8>) -> Result<()>
Appends the header and the body.
§Errors
If the width does not fit the byte the layout gives it, which no width a u64 takes can.
Sourcepub fn read(bytes: &[u8]) -> Result<Self>
pub fn read(bytes: &[u8]) -> Result<Self>
Reads an adjacency from exactly the bytes Adjacency::write produced.
§Errors
If the payload is shorter than its header, names a layout this build does not know, or holds a body that is not the size its header implies.
Sourcepub fn read_from(payload: Vec<u8>, at: usize) -> Result<Self>
pub fn read_from(payload: Vec<u8>, at: usize) -> Result<Self>
Adjacency::read of the bytes of payload from at on, keeping payload for the child
rows rather than copying them out of it. See Tail for why.
§Errors
As Adjacency::read, or if at is past the end of payload.