MCPcopy Create free account
hub / github.com/GraphLite-AI/GraphLite / expand_element_n_times

Method expand_element_n_times

graphlite/src/exec/executor.rs:6568–6662  ·  view source on GitHub ↗

Expand an element exactly n times

(
        &self,
        start_path: &[String],
        element: &PathElement,
        path_type: &PathType,
        graph: &Arc<GraphCache>,
        visited_nodes: &mut std::collections::HashSet<Stri

Source from the content-addressed store, hash-verified

6566
6567 /// Expand an element exactly n times
6568 fn expand_element_n_times(
6569 &self,
6570 start_path: &[String],
6571 element: &PathElement,
6572 path_type: &PathType,
6573 graph: &Arc<GraphCache>,
6574 visited_nodes: &mut std::collections::HashSet<String>,
6575 visited_edges: &mut std::collections::HashSet<String>,
6576 n: u32,
6577 ) -> Result<Vec<Vec<String>>, ExecutionError> {
6578 if n == 0 {
6579 return Ok(vec![start_path.to_vec()]);
6580 }
6581
6582 let mut current_paths = vec![start_path.to_vec()];
6583
6584 for _ in 0..n {
6585 let mut new_paths = Vec::new();
6586
6587 for path in current_paths {
6588 let current_node_id = path.last().unwrap();
6589
6590 // Get edges based on direction
6591 let edges = match element.direction {
6592 EdgeDirection::Outgoing => graph.get_outgoing_edges(current_node_id),
6593 EdgeDirection::Incoming => graph.get_incoming_edges(current_node_id),
6594 EdgeDirection::Both | EdgeDirection::Undirected => {
6595 graph.get_connected_edges(current_node_id)
6596 }
6597 };
6598
6599 // Filter edges by label if specified
6600 let filtered_edges: Vec<_> = if element.edge_labels.is_empty() {
6601 edges
6602 } else {
6603 edges
6604 .into_iter()
6605 .filter(|e| element.edge_labels.contains(&e.label))
6606 .collect()
6607 };
6608
6609 // Check each edge for path type constraints
6610 for edge in filtered_edges {
6611 let next_node_id = match element.direction {
6612 EdgeDirection::Outgoing => &edge.to_node,
6613 EdgeDirection::Incoming => &edge.from_node,
6614 EdgeDirection::Both | EdgeDirection::Undirected => {
6615 if edge.from_node == *current_node_id {
6616 &edge.to_node
6617 } else {
6618 &edge.from_node
6619 }
6620 }
6621 };
6622
6623 // Check path type constraints
6624 let is_valid = match path_type {
6625 PathType::Walk => true, // No constraints

Callers 1

expand_single_elementMethod · 0.80

Calls 8

unwrapMethod · 0.80
get_outgoing_edgesMethod · 0.80
get_incoming_edgesMethod · 0.80
get_connected_edgesMethod · 0.80
containsMethod · 0.80
cloneMethod · 0.80
is_emptyMethod · 0.45
insertMethod · 0.45

Tested by

no test coverage detected