Skip to main content

RecordTree

Struct RecordTree 

Source
pub struct RecordTree<R> { /* private fields */ }
Expand description

Generic tree structure for Altium records.

Provides efficient navigation of parent-child relationships that are encoded via OWNERINDEX in the original flat record list.

Implementations§

Source§

impl<R: TreeRecord> RecordTree<R>

Source

pub fn from_records(records: Vec<R>) -> Self

Build a tree from a flat list of records using OWNERINDEX relationships.

Records with OWNERINDEX < 0 or >= len are treated as roots.

Source

pub fn len(&self) -> usize

Get the number of records in the tree.

Source

pub fn is_empty(&self) -> bool

Check if the tree is empty.

Source

pub fn get(&self, id: RecordId) -> Option<&R>

Get a record by ID.

Source

pub fn get_mut(&mut self, id: RecordId) -> Option<&mut R>

Get a mutable record by ID.

Source

pub fn get_by_index(&self, index: usize) -> Option<&R>

Get the record at a specific index.

Source

pub fn iter(&self) -> impl Iterator<Item = (RecordId, &R)>

Iterate over all records with their IDs.

Source

pub fn iter_mut(&mut self) -> impl Iterator<Item = (RecordId, &mut R)>

Iterate over all records mutably with their IDs.

Source

pub fn roots(&self) -> impl Iterator<Item = (RecordId, &R)>

Get root records (records with no valid parent).

Source

pub fn root_count(&self) -> usize

Get the number of root records.

Source

pub fn is_root(&self, id: RecordId) -> bool

Check if a record is a root.

Source

pub fn parent(&self, id: RecordId) -> Option<(RecordId, &R)>

Get the parent of a record.

Source

pub fn parent_id(&self, id: RecordId) -> Option<RecordId>

Get the parent ID of a record (without the record itself).

Source

pub fn children(&self, id: RecordId) -> impl Iterator<Item = (RecordId, &R)>

Get children of a record.

Source

pub fn child_count(&self, id: RecordId) -> usize

Get the number of children for a record.

Source

pub fn has_children(&self, id: RecordId) -> bool

Check if a record has children.

Source

pub fn ancestors(&self, id: RecordId) -> impl Iterator<Item = (RecordId, &R)>

Get all ancestors of a record (parent, grandparent, etc.).

Source

pub fn descendants(&self, id: RecordId) -> impl Iterator<Item = (RecordId, &R)>

Get all descendants of a record (children, grandchildren, etc.).

Source

pub fn depth(&self, id: RecordId) -> usize

Get the depth of a record (0 for roots).

Source

pub fn walk_depth_first(&self) -> TreeWalker<'_, R>

Walk the tree depth-first starting from roots.

Source

pub fn walk_from(&self, id: RecordId) -> TreeWalker<'_, R>

Walk the tree depth-first starting from a specific node.

Source

pub fn find<F>(&self, predicate: F) -> impl Iterator<Item = (RecordId, &R)>
where F: Fn(&R) -> bool,

Find records matching a predicate.

Source

pub fn find_first<F>(&self, predicate: F) -> Option<(RecordId, &R)>
where F: Fn(&R) -> bool,

Find the first record matching a predicate.

Source

pub fn path_to_root(&self, id: RecordId) -> Vec<RecordId>

Get the path from a record to the root (inclusive).

Source

pub fn into_records(self) -> Vec<R>

Consume the tree and return the underlying records.

Source

pub fn as_slice(&self) -> &[R]

Get a reference to the underlying records slice.

Source

pub fn add(&mut self, record: R) -> RecordId

Add a record to the tree.

Returns the ID of the newly added record.

Source

pub fn remove(&mut self, id: RecordId) -> Option<R>

Remove a record from the tree by ID.

Note: This invalidates all RecordIds after the removed record. Consider using a different approach for frequent removals.

Source

pub fn reparent(&mut self, id: RecordId, new_parent: Option<RecordId>)

Move a record to a new parent.

Trait Implementations§

Source§

impl<R: Clone> Clone for RecordTree<R>

Source§

fn clone(&self) -> RecordTree<R>

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl<R: Debug> Debug for RecordTree<R>

Source§

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

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

impl<R> Default for RecordTree<R>

Source§

fn default() -> Self

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

Auto Trait Implementations§

§

impl<R> Freeze for RecordTree<R>

§

impl<R> RefUnwindSafe for RecordTree<R>
where R: RefUnwindSafe,

§

impl<R> Send for RecordTree<R>
where R: Send,

§

impl<R> Sync for RecordTree<R>
where R: Sync,

§

impl<R> Unpin for RecordTree<R>
where R: Unpin,

§

impl<R> UnwindSafe for RecordTree<R>
where R: UnwindSafe,

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> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

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> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
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<G1, G2> Within<G2> for G1
where G2: Contains<G1>,

Source§

fn is_within(&self, b: &G2) -> bool