Tree

Struct Tree 

Source
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, EdgeData contains parent info)

Implementations§

Source§

impl Tree

Source

pub fn with_capacity(capacity: usize) -> Self

Creates a new tree with pre-allocated capacity for the given number of requirements.

Source

pub fn insert(&mut self, requirement: Requirement)

Inserts a requirement into the tree.

§Panics

Panics if a requirement with the same UUID already exists.

Source

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.

Source

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.

Source

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.

Source

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).

Source

pub fn iter(&self) -> impl Iterator<Item = RequirementView<'_>> + '_

Returns an iterator over all requirements in the tree as borrowed views.

Source

pub fn find_by_hrid(&self, hrid: &Hrid) -> Option<RequirementView<'_>>

Finds a requirement by its human-readable identifier.

Link two requirements identified by their HRIDs.

§Errors

Returns LoadError::NotFound when either HRID does not exist in the tree.

Source

pub fn children(&self, uuid: Uuid) -> Vec<Uuid>

Get all children of a requirement.

Source

pub fn parents(&self, uuid: Uuid) -> Vec<(Uuid, String)>

Get all parents of a requirement with their fingerprints.

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.

Source

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.

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.

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.

Update all suspect fingerprints in the tree.

Trait Implementations§

Source§

impl Debug for Tree

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Default for Tree

Source§

fn default() -> Self

Returns the “default value” for a type. Read more

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> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts 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 more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts 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
Source§

impl<T> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more