pub struct Tree { /* private fields */ }Expand description
An in-memory representation of the set of requirements with decomposed storage.
Requirements are stored as separate components:
- Content data:
HashMap<Uuid, RequirementData> - HRIDs:
HashMap<Uuid, Hrid>(separate to allow O(1) lookup) - HRID lookup:
BTreeMap<Hrid, Uuid> - Relationships:
DiGraphMap<Uuid, EdgeData>(edges are child→parent,EdgeDatacontains parent info)
Implementations§
Source§impl Tree
impl Tree
Sourcepub fn with_capacity(capacity: usize) -> Self
pub fn with_capacity(capacity: usize) -> Self
Creates a new tree with pre-allocated capacity for the given number of requirements.
Sourcepub fn insert(&mut self, requirement: Requirement)
pub fn insert(&mut self, requirement: Requirement)
Inserts a requirement into the tree.
§Panics
Panics if a requirement with the same UUID already exists.
Sourcepub fn hrid(&self, uuid: Uuid) -> Option<&Hrid>
pub fn hrid(&self, uuid: Uuid) -> Option<&Hrid>
Retrieves just the HRID for a requirement by UUID.
This is more efficient than requirement() when only the HRID is
needed.
Sourcepub fn get_requirement(&self, uuid: Uuid) -> Option<Requirement>
pub fn get_requirement(&self, uuid: Uuid) -> Option<Requirement>
Retrieves a requirement by UUID as an owned Requirement.
This is more efficient than calling requirement().to_requirement()
when you need an owned Requirement, as it avoids creating the
intermediate view.
Sourcepub fn requirement(&self, uuid: Uuid) -> Option<RequirementView<'_>>
pub fn requirement(&self, uuid: Uuid) -> Option<RequirementView<'_>>
Retrieves a requirement by UUID as a borrowed view.
Note: Since UUID is passed by value, we need to find a way to get a
reference to it. The UUID is stored as a key in the requirements
HashMap.
Sourcepub fn next_index(&self, kind: &KindString) -> NonZeroUsize
pub fn next_index(&self, kind: &KindString) -> NonZeroUsize
Returns the next available index for a requirement of the given kind.
This method uses a range query on the hrid_to_uuid BTreeMap to find
the maximum ID for the given kind. Time complexity is O(log n) where n
is the total number of requirements.
The input kind will be normalized to uppercase.
§Panics
Panics if the provided kind is invalid (empty or contains non-alphabetic characters).
Sourcepub fn iter(&self) -> impl Iterator<Item = RequirementView<'_>> + '_
pub fn iter(&self) -> impl Iterator<Item = RequirementView<'_>> + '_
Returns an iterator over all requirements in the tree as borrowed views.
Sourcepub fn find_by_hrid(&self, hrid: &Hrid) -> Option<RequirementView<'_>>
pub fn find_by_hrid(&self, hrid: &Hrid) -> Option<RequirementView<'_>>
Finds a requirement by its human-readable identifier.
Sourcepub fn link_requirement(
&mut self,
child: &Hrid,
parent: &Hrid,
) -> Result<LinkOutcome, LoadError>
pub fn link_requirement( &mut self, child: &Hrid, parent: &Hrid, ) -> Result<LinkOutcome, LoadError>
Link two requirements identified by their HRIDs.
§Errors
Returns LoadError::NotFound when either HRID does not exist in the
tree.
Sourcepub fn parents(&self, uuid: Uuid) -> Vec<(Uuid, String)>
pub fn parents(&self, uuid: Uuid) -> Vec<(Uuid, String)>
Get all parents of a requirement with their fingerprints.
Sourcepub fn upsert_parent_link(
&mut self,
child_uuid: Uuid,
parent_uuid: Uuid,
fingerprint: String,
) -> bool
pub fn upsert_parent_link( &mut self, child_uuid: Uuid, parent_uuid: Uuid, fingerprint: String, ) -> bool
Insert or update a parent link for the given child UUID.
Returns true if an existing link was replaced, or false if a new
link was created.
§Panics
Panics if either the child or parent UUID does not exist in the tree.
Sourcepub fn update_hrids(&mut self) -> impl Iterator<Item = Uuid> + '_
pub fn update_hrids(&mut self) -> impl Iterator<Item = Uuid> + '_
Read all the requirements and update any incorrect parent HRIDs. Returns an iterator of UUIDs whose parents were updated.
§Panics
Panics if a requirement references a parent UUID that doesn’t exist in the tree, or if a requirement is its own parent.
Sourcepub fn suspect_links(&self) -> Vec<SuspectLink>
pub fn suspect_links(&self) -> Vec<SuspectLink>
Find all suspect links in the requirement graph.
A link is suspect when the fingerprint stored in the edge data does not match the current fingerprint of the parent requirement.
§Panics
Panics if a child UUID in the graph doesn’t have a corresponding HRID.
Sourcepub fn accept_suspect_link(
&mut self,
child_uuid: Uuid,
parent_uuid: Uuid,
) -> bool
pub fn accept_suspect_link( &mut self, child_uuid: Uuid, parent_uuid: Uuid, ) -> bool
Update the fingerprint for a specific parent link.
Returns true if the fingerprint was updated.
§Panics
Panics if the child or parent requirement is not found.
Sourcepub fn accept_all_suspect_links(&mut self) -> Vec<(Uuid, Uuid)>
pub fn accept_all_suspect_links(&mut self) -> Vec<(Uuid, Uuid)>
Update all suspect fingerprints in the tree.
Trait Implementations§
Auto Trait Implementations§
impl Freeze for Tree
impl RefUnwindSafe for Tree
impl Send for Tree
impl Sync for Tree
impl Unpin for Tree
impl UnwindSafe for Tree
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more