pub struct Link { /* private fields */ }Expand description
A relationship’s child to parent map.
Implementations§
Source§impl Link
impl Link
Sourcepub fn build(parents_of: &[Rid], parents: u64) -> Result<Self>
pub fn build(parents_of: &[Rid], parents: u64) -> Result<Self>
Builds a link from one parent rid per child, with NO_PARENT for the unmatched.
The form is chosen here and not by the caller: monotone when every child has a parent and
the rids are non-decreasing, packed otherwise. That decision is a pass over the slice the
caller already produced, so it costs a comparison per child on top of a build that was
already linear.
§Errors
If a parent rid is not NO_PARENT and is not below parents, which means the link and
the key map it was built against disagree about how many rows the parent table has. That is
a bug rather than a data condition, and a link built past the end of its parent resolves to
a row that is not there, which is the one failure in this layer that is a wrong answer.
Sourcepub fn forward(&self, child: Rid) -> Option<Rid>
pub fn forward(&self, child: Rid) -> Option<Rid>
The parent of a child row, or None if it has none or the child is past the end.
Sourcepub fn forward_run(&self, first: Rid, out: &mut [Rid]) -> Result<()>
pub fn forward_run(&self, first: Rid, out: &mut [Rid]) -> Result<()>
The parents of a run of consecutive children, with NO_PARENT for the ones that have none.
This is Link::forward over a range, and what it adds is the monotone form. Answering one
child there is a select1, which is a search, and walking a run of them one search at a time
is paying for random access on a read that is sequential. So the run is found once and then
read off the bitmap in order: a one bit is a child of the current parent and a zero bit moves
on to the next parent, which is a load per sixty four bits and a count of zeros per word.
§Errors
If the run goes past the last child.
Sourcepub fn backward(&self, parent: Rid) -> Option<Range<Rid>>
pub fn backward(&self, parent: Rid) -> Option<Range<Rid>>
The children of a parent row, as a half open range of child rids.
None for the packed form, which does not answer this direction, and for a parent past the
end. An empty range is a parent with no children and is not the same answer.
Sourcepub fn part_bounds(&self, part: usize) -> Option<Bounds>
pub fn part_bounds(&self, part: usize) -> Option<Bounds>
The minimum and maximum parent rid over one part of the child table, for section 5.5.
None for a part past the end of the table; Some(None) for a part in which no child has a
parent, which is a part a reduction skips.
Sourcepub fn read(bytes: &[u8]) -> Result<Self>
pub fn read(bytes: &[u8]) -> Result<Self>
Reads a link from exactly the bytes Link::write produced.
§Errors
If the payload is shorter than its header, names a form or a layout this build does not know, or holds a body that is not the size its header implies. Every one of those is a section to drop rather than a query to fail, by section 3.1.