pub struct CrossShardEdgeManager { /* private fields */ }Expand description
Manages edges that cross shard boundaries.
When a local node has an edge to a node on another shard, this manager:
- Tracks the pending cross-shard edges
- Coordinates resolution of ghost nodes
- Handles edge decay synchronization across shards
§Thread Safety
This type is not thread-safe. Wrap in a mutex if concurrent access is needed.
Implementations§
Source§impl CrossShardEdgeManager
impl CrossShardEdgeManager
Sourcepub fn with_capacity(capacity: usize) -> Self
pub fn with_capacity(capacity: usize) -> Self
Create a new manager with pre-allocated capacity.
§Arguments
capacity- Initial capacity for edge maps
Sourcepub fn add_outgoing_edge(&mut self, edge: CrossShardEdge)
pub fn add_outgoing_edge(&mut self, edge: CrossShardEdge)
Register an outgoing cross-shard edge.
The edge is added to both the outgoing edges map and the pending
resolution queue. Call clear_pending() after resolving ghost nodes.
§Arguments
edge- The cross-shard edge to register
§Example
let edge = CrossShardEdge {
from_node: local_id,
to_node: remote_id,
to_shard: ShardId::new(1),
weight: 0.5,
};
manager.add_outgoing_edge(edge);Sourcepub fn add_outgoing_edges(
&mut self,
edges: impl IntoIterator<Item = CrossShardEdge>,
)
pub fn add_outgoing_edges( &mut self, edges: impl IntoIterator<Item = CrossShardEdge>, )
Register multiple outgoing edges at once.
More efficient than calling add_outgoing_edge in a loop.
§Arguments
edges- Iterator of edges to register
Sourcepub fn add_incoming_edge(&mut self, edge: CrossShardEdge)
pub fn add_incoming_edge(&mut self, edge: CrossShardEdge)
Register an incoming cross-shard edge.
Incoming edges are from nodes on other shards that point to a node we own locally.
§Arguments
edge- The cross-shard edge to register
Sourcepub fn pending_edges(&self) -> &[CrossShardEdge]
pub fn pending_edges(&self) -> &[CrossShardEdge]
Get all pending edges that need ghost node resolution.
These are edges that have been registered but whose target nodes have not yet been fetched from their remote shards.
§Returns
A slice of pending cross-shard edges.
Sourcepub fn pending_count(&self) -> usize
pub fn pending_count(&self) -> usize
Get the number of pending edges.
Sourcepub fn has_pending(&self) -> bool
pub fn has_pending(&self) -> bool
Check if there are pending edges.
Sourcepub fn clear_pending(&mut self)
pub fn clear_pending(&mut self)
Clear pending edges after resolution.
Call this after successfully fetching ghost node data for all pending edges.
Sourcepub fn take_pending(&mut self) -> Vec<CrossShardEdge>
pub fn take_pending(&mut self) -> Vec<CrossShardEdge>
Take ownership of pending edges and clear the queue.
This is useful when you need to process the edges and don’t want to clone them.
§Returns
The vector of pending edges.
Sourcepub fn get_outgoing(&self, node_id: &NodeId) -> Option<&Vec<CrossShardEdge>>
pub fn get_outgoing(&self, node_id: &NodeId) -> Option<&Vec<CrossShardEdge>>
Sourcepub fn get_incoming(&self, node_id: &NodeId) -> Option<&Vec<CrossShardEdge>>
pub fn get_incoming(&self, node_id: &NodeId) -> Option<&Vec<CrossShardEdge>>
Sourcepub fn has_outgoing(&self, node_id: &NodeId) -> bool
pub fn has_outgoing(&self, node_id: &NodeId) -> bool
Check if a node has outgoing cross-shard edges.
Sourcepub fn has_incoming(&self, node_id: &NodeId) -> bool
pub fn has_incoming(&self, node_id: &NodeId) -> bool
Check if a node has incoming cross-shard edges.
Sourcepub fn remove_shard_edges(&mut self, shard_id: ShardId) -> usize
pub fn remove_shard_edges(&mut self, shard_id: ShardId) -> usize
Sourcepub fn remove_node_edges(&mut self, node_id: &NodeId) -> (usize, usize)
pub fn remove_node_edges(&mut self, node_id: &NodeId) -> (usize, usize)
Sourcepub fn decay_edges(&mut self, rate: f64, threshold: f64) -> Vec<CrossShardEdge>
pub fn decay_edges(&mut self, rate: f64, threshold: f64) -> Vec<CrossShardEdge>
Decay cross-shard edge weights.
Applies exponential decay to all edge weights and removes edges that fall below the threshold.
§Arguments
rate- Decay rate (0.0 to 1.0), e.g., 0.1 means 10% decaythreshold- Minimum weight threshold; edges below this are pruned
§Returns
Vector of edges that were pruned due to low weight.
Sourcepub fn strengthen_edge(
&mut self,
from_node: &NodeId,
to_node: &NodeId,
amount: f64,
) -> Option<f64>
pub fn strengthen_edge( &mut self, from_node: &NodeId, to_node: &NodeId, amount: f64, ) -> Option<f64>
Sourcepub fn connected_shards(&self) -> Vec<ShardId>
pub fn connected_shards(&self) -> Vec<ShardId>
Sourcepub fn edges_by_shard(&self) -> HashMap<ShardId, Vec<&CrossShardEdge>>
pub fn edges_by_shard(&self) -> HashMap<ShardId, Vec<&CrossShardEdge>>
Get edges grouped by target shard.
Useful for batching requests to remote shards.
§Returns
A map of shard ID to edges targeting that shard.
Sourcepub fn pending_by_shard(&self) -> HashMap<ShardId, Vec<&CrossShardEdge>>
pub fn pending_by_shard(&self) -> HashMap<ShardId, Vec<&CrossShardEdge>>
Get pending edges grouped by target shard.
Useful for batching ghost node resolution requests.
Sourcepub fn edge_count(&self) -> usize
pub fn edge_count(&self) -> usize
Total number of cross-shard edges (outgoing + incoming).
Sourcepub fn outgoing_count(&self) -> usize
pub fn outgoing_count(&self) -> usize
Number of outgoing cross-shard edges.
Sourcepub fn incoming_count(&self) -> usize
pub fn incoming_count(&self) -> usize
Number of incoming cross-shard edges.
Sourcepub fn nodes_with_outgoing(&self) -> usize
pub fn nodes_with_outgoing(&self) -> usize
Number of unique local nodes with outgoing edges.
Sourcepub fn nodes_with_incoming(&self) -> usize
pub fn nodes_with_incoming(&self) -> usize
Number of unique local nodes with incoming edges.
Sourcepub fn stats(&self) -> CrossShardEdgeStats
pub fn stats(&self) -> CrossShardEdgeStats
Get statistics about cross-shard edges.