pub struct Tree {
pub root_id: NodeId,
pub nodes: Vector<HashMap<NodeId, Arc<Node>>>,
pub parent_map: HashMap<NodeId, NodeId>,
/* private fields */
}Fields§
§root_id: NodeId§nodes: Vector<HashMap<NodeId, Arc<Node>>>§parent_map: HashMap<NodeId, NodeId>Implementations§
Source§impl Tree
impl Tree
Sourcepub fn get_shard_index(&self, id: &NodeId) -> usize
pub fn get_shard_index(&self, id: &NodeId) -> usize
Sourcepub fn get_shard_indices(&self, ids: &[&NodeId]) -> Vec<usize>
pub fn get_shard_indices(&self, ids: &[&NodeId]) -> Vec<usize>
Sourcepub fn get_shard_index_batch<'a>(
&self,
ids: &'a [&'a NodeId],
) -> Vec<(usize, &'a NodeId)>
pub fn get_shard_index_batch<'a>( &self, ids: &'a [&'a NodeId], ) -> Vec<(usize, &'a NodeId)>
批量获取分片索引和ID对 (优化版本)
§性能优化
旧实现: 两次锁操作 (读锁检查 + 写锁更新) 新实现: 零全局锁,DashMap 分片并发
100个ID的性能对比:
- 旧实现: ~50µs (锁竞争)
- 新实现: ~5µs (无锁)
Sourcepub fn clear_shard_cache()
pub fn clear_shard_cache()
Sourcepub fn shard_cache_stats() -> (usize, usize)
pub fn shard_cache_stats() -> (usize, usize)
获取缓存统计信息
pub fn contains_node(&self, id: &NodeId) -> bool
pub fn get_node(&self, id: &NodeId) -> Option<Arc<Node>>
pub fn get_parent_node(&self, id: &NodeId) -> Option<Arc<Node>>
pub fn from(nodes: NodeTree) -> Self
pub fn new(root: Node) -> Self
pub fn update_attr( &mut self, id: &NodeId, new_values: HashMap<String, Value>, ) -> PoolResult<()>
pub fn update_node(&mut self, node: Node) -> PoolResult<()>
pub fn add_at_index( &mut self, parent_id: &NodeId, index: usize, node: &Node, ) -> PoolResult<()>
pub fn add_node( &mut self, parent_id: &NodeId, nodes: &Vec<Node>, ) -> PoolResult<()>
pub fn node(&mut self, key: &str) -> NodeRef<'_>
pub fn mark(&mut self, key: &str) -> MarkRef<'_>
pub fn attrs(&mut self, key: &str) -> AttrsRef<'_>
pub fn children(&self, parent_id: &NodeId) -> Option<Vector<NodeId>>
pub fn children_node(&self, parent_id: &NodeId) -> Option<Vector<Arc<Node>>>
pub fn all_children( &self, parent_id: &NodeId, filter: Option<&dyn Fn(&Node) -> bool>, ) -> Option<NodeTree>
pub fn children_count(&self, parent_id: &NodeId) -> usize
pub fn remove_mark_by_name( &mut self, id: &NodeId, mark_name: &str, ) -> PoolResult<()>
pub fn get_marks(&self, id: &NodeId) -> Option<Vector<Mark>>
pub fn remove_mark( &mut self, id: &NodeId, mark_types: &[String], ) -> PoolResult<()>
pub fn add_mark(&mut self, id: &NodeId, marks: &[Mark]) -> PoolResult<()>
pub fn move_node( &mut self, source_parent_id: &NodeId, target_parent_id: &NodeId, node_id: &NodeId, position: Option<usize>, ) -> PoolResult<()>
pub fn remove_node( &mut self, parent_id: &NodeId, nodes: Vec<NodeId>, ) -> PoolResult<()>
pub fn remove_node_by_id(&mut self, node_id: &NodeId) -> PoolResult<()>
Sourcepub fn remove_node_by_index(
&mut self,
parent_id: &NodeId,
index: usize,
) -> PoolResult<()>
pub fn remove_node_by_index( &mut self, parent_id: &NodeId, index: usize, ) -> PoolResult<()>
根据下标删除
Trait Implementations§
Source§impl<'de> Deserialize<'de> for Tree
impl<'de> Deserialize<'de> for Tree
Source§fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
Deserialize this value from the given Serde deserializer. Read more
impl StructuralPartialEq for Tree
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
Mutably borrows from an owned value. Read more
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
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>
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 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>
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