Struct NodePool

Source
pub struct NodePool {
    pub inner: Arc<NodePoolInner>,
}
Expand description

线程安全的节点池封装

使用 Arc 实现快速克隆,内部使用不可变数据结构保证线程安全

Fields§

§inner: Arc<NodePoolInner>

Implementations§

Source§

impl NodePool

Source

pub fn size(&self) -> usize

获取节点池中节点总数

Source

pub fn from(nodes: Vec<Node>, root_id: NodeId) -> Self

从节点列表构建节点池

§参数
  • nodes - 初始节点列表
  • root_id - 指定根节点ID
§注意

会自动构建父子关系映射表

Source

pub fn get_node(&self, id: &NodeId) -> Option<&Arc<Node>>

根据ID获取节点(immutable)

Source

pub fn contains_node(&self, id: &NodeId) -> bool

检查节点是否存在

Source

pub fn children(&self, parent_id: &NodeId) -> Option<&Vector<NodeId>>

获取直接子节点列表

Source

pub fn descendants(&self, parent_id: &NodeId) -> Vec<&Node>

递归获取所有子节点(深度优先)

Source

pub fn parent_id(&self, child_id: &NodeId) -> Option<&NodeId>

获取父节点ID

Source

pub fn ancestors(&self, child_id: &NodeId) -> Vec<&Arc<Node>>

获取完整祖先链

Source

pub fn validate_hierarchy(&self) -> Result<(), PoolError>

验证父子关系一致性

Source

pub fn filter_nodes<P>(&self, predicate: P) -> Vec<&Arc<Node>>
where P: Fn(&Node) -> bool,

根据类型筛选节点

Source

pub fn find_node<P>(&self, predicate: P) -> Option<&Arc<Node>>
where P: Fn(&Node) -> bool,

查找第一个匹配节点

Source

pub fn get_node_depth(&self, node_id: &NodeId) -> Option<usize>

获取节点在树中的深度

§参数
  • node_id - 目标节点ID
§返回值

返回节点的深度,根节点深度为0

Source

pub fn get_node_path(&self, node_id: &NodeId) -> Vec<NodeId>

获取从根节点到目标节点的完整路径

§参数
  • node_id - 目标节点ID
§返回值

返回从根节点到目标节点的节点ID路径

Source

pub fn is_leaf(&self, node_id: &NodeId) -> bool

检查节点是否为叶子节点

§参数
  • node_id - 目标节点ID
§返回值

如果节点不存在或没有子节点则返回 true

Source

pub fn get_siblings(&self, node_id: &NodeId) -> Vec<NodeId>

获取节点的同级节点(具有相同父节点的节点)

§参数
  • node_id - 目标节点ID
§返回值

返回同级节点的ID列表

Source

pub fn get_all_siblings(&self, node_id: &NodeId) -> Vec<NodeId>

获取节点的所有兄弟节点(包括自身)

§参数
  • node_id - 目标节点ID
§返回值

返回所有兄弟节点的ID列表(包括自身)

Source

pub fn get_subtree_size(&self, node_id: &NodeId) -> usize

获取节点的子树大小(包括自身和所有子节点)

§参数
  • node_id - 目标节点ID
§返回值

返回子树中的节点总数

Source

pub fn is_ancestor(&self, ancestor_id: &NodeId, descendant_id: &NodeId) -> bool

检查一个节点是否是另一个节点的祖先

§参数
  • ancestor_id - 可能的祖先节点ID
  • descendant_id - 可能的后代节点ID
§返回值

如果 ancestor_id 是 descendant_id 的祖先则返回 true

Source

pub fn get_lowest_common_ancestor( &self, node1_id: &NodeId, node2_id: &NodeId, ) -> Option<NodeId>

获取两个节点的最近公共祖先

§参数
  • node1_id - 第一个节点ID
  • node2_id - 第二个节点ID
§返回值

返回两个节点的最近公共祖先ID

Trait Implementations§

Source§

impl Clone for NodePool

Source§

fn clone(&self) -> NodePool

Returns a copy 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 Debug for NodePool

Source§

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

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

impl<'de> Deserialize<'de> for NodePool

Source§

fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>
where __D: Deserializer<'de>,

Deserialize this value from the given Serde deserializer. Read more
Source§

impl PartialEq for NodePool

Source§

fn eq(&self, other: &NodePool) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl Serialize for NodePool

Source§

fn serialize<__S>(&self, __serializer: __S) -> Result<__S::Ok, __S::Error>
where __S: Serializer,

Serialize this value into the given Serde serializer. Read more
Source§

impl Send for NodePool

Source§

impl StructuralPartialEq for NodePool

Source§

impl Sync for NodePool

Auto Trait Implementations§

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> 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> Same for T

Source§

type Output = T

Should always be Self
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<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
Source§

impl<T> DeserializeOwned for T
where T: for<'de> Deserialize<'de>,