Struct NodePool

Source
pub struct NodePool { /* private fields */ }
Expand description

线程安全的节点池封装

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

Implementations§

Source§

impl NodePool

Source

pub fn new(inner: Arc<Tree>) -> Arc<NodePool>

Source

pub fn key(&self) -> &str

获取节点池的唯一标识符

Source

pub fn size(&self) -> usize

获取节点池中节点总数

Source

pub fn root(&self) -> Arc<Node>

Source

pub fn root_id(&self) -> &String

Source

pub fn get_inner(&self) -> &Arc<Tree>

Source

pub fn from(nodes: NodeEnum) -> Arc<NodePool>

从节点列表构建节点池

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

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

Source

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

根据ID获取节点(immutable)

Source

pub fn get_parent_node(&self, id: &String) -> Option<Arc<Node>>

Source

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

检查节点是否存在

Source

pub fn children( &self, parent_id: &String, ) -> Option<GenericVector<String, ArcK>>

获取直接子节点列表

Source

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

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

Source

pub fn for_each<F>(&self, id: &String, f: F)
where F: Fn(&Arc<Node>),

Source

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

获取父节点ID

Source

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

获取完整祖先链

Source

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

验证父子关系一致性

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: &String) -> Option<usize>

获取节点在树中的深度

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

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

Source

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

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

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

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

Source

pub fn resolve(&self, node_id: &String) -> Vec<Arc<Node>>

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

Source

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

检查节点是否为叶子节点

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

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

Source

pub fn get_left_siblings(&self, node_id: &String) -> Vec<String>

获取左边的所有节点 根据下标

Source

pub fn get_right_siblings(&self, node_id: &String) -> Vec<String>

获取右边边的所有节点 根据下标

Source

pub fn get_left_nodes(&self, node_id: &String) -> Vec<Arc<Node>>

获取左边的所有节点

Source

pub fn get_right_nodes(&self, node_id: &String) -> Vec<Arc<Node>>

获取右边的所有节点

Source

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

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

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

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

Source

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

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

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

返回子树中的节点总数

Source

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

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

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

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

Source

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

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

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

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

Source

pub fn parallel_query<P>(&self, predicate: P) -> Vec<Arc<Node>>
where P: Fn(&Node) -> bool + Send + Sync,

并行查询节点

§参数
  • predicate - 查询条件函数
§返回值

返回所有满足条件的节点

Source

pub fn parallel_batch_query<'a, P>( &'a self, batch_size: usize, predicate: P, ) -> Vec<Arc<Node>>
where P: Fn(&[Arc<Node>]) -> Vec<Arc<Node>> + Send + Sync,

并行批量查询节点

§参数
  • batch_size - 批处理大小
  • predicate - 查询条件函数
§返回值

返回所有满足条件的节点

Source

pub fn parallel_query_map<'a, P, T, F>( &'a self, predicate: P, transform: F, ) -> Vec<T>
where P: Fn(&Node) -> bool + Send + Sync, F: Fn(&Arc<Node>) -> T + Send + Sync, T: Send,

并行查询并转换结果

§参数
  • predicate - 查询条件函数
  • transform - 结果转换函数
§返回值

返回转换后的结果列表

Source

pub fn parallel_query_reduce<P, T, F>( &self, predicate: P, init: T, fold: F, ) -> T
where P: Fn(&Node) -> bool + Send + Sync, F: Fn(T, &Arc<Node>) -> T + Send + Sync, T: Send + Sync + Clone,

并行查询并聚合结果

§参数
  • predicate - 查询条件函数
  • init - 初始值
  • fold - 聚合函数
§返回值

返回聚合后的结果

Source§

impl NodePool

Source

pub fn query(&self) -> QueryEngine<'_>

创建查询引擎实例

Source§

impl NodePool

Source

pub fn optimized_query(&self, config: QueryCacheConfig) -> OptimizedQueryEngine

创建优化查询引擎(带缓存)

Source§

impl NodePool

Source

pub fn lazy_query(&self, config: LazyQueryConfig) -> LazyQueryEngine

创建懒加载查询引擎

Trait Implementations§

Source§

impl Clone for NodePool

Source§

fn clone(&self) -> NodePool

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 Debug for NodePool

Source§

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

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

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

Source§

fn deserialize<__D>( __deserializer: __D, ) -> Result<NodePool, <__D as Deserializer<'de>>::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 as Serializer>::Ok, <__S as Serializer>::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> 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> 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>,