linkrs_query/executor/traversal/
config.rs1use crate::parser::ast::pattern::PathSemantic;
2use linkrs_core::EdgeDirection;
3
4#[derive(Debug, Clone, Copy, PartialEq, Eq)]
5pub enum TraversalKind {
6 Expand,
7 Traverse,
8 ShortestPath,
9 AllPaths,
10 Subgraph,
11}
12
13#[derive(Debug, Clone, Copy, PartialEq, Eq)]
14pub enum TraversalOrder {
15 Bfs,
16 Dfs,
17}
18
19#[derive(Debug, Clone, Copy, PartialEq, Eq)]
20pub enum VisitedPolicy {
21 Global,
22 PerSeed,
23 None,
24}
25
26#[derive(Debug, Clone, Copy, PartialEq, Eq)]
27pub enum PathPolicy {
28 VertexOnly,
29 EdgeAndVertex,
30 FullPath,
31}
32
33#[derive(Debug, Clone, Copy, PartialEq, Eq)]
34pub enum EmitPolicy {
35 EveryDepth,
36 LeafOnly,
37 DestinationOnly,
38}
39
40#[derive(Debug, Clone)]
41pub struct TraversalConfig {
42 pub kind: TraversalKind,
43 pub direction: EdgeDirection,
44 pub edge_types: Vec<String>,
45 pub min_depth: u32,
46 pub max_depth: u32,
47 pub limit: usize,
48 pub order: TraversalOrder,
49 pub visited_policy: VisitedPolicy,
50 pub path_policy: PathPolicy,
51 pub emit_policy: EmitPolicy,
52 pub space_name: String,
53 pub vertex_tag: String,
55 pub path_semantic: Option<PathSemantic>,
57}
58
59impl TraversalConfig {
60 pub fn expand(space_name: String, direction: EdgeDirection, edge_types: Vec<String>) -> Self {
61 Self {
62 kind: TraversalKind::Expand,
63 direction,
64 edge_types,
65 min_depth: 1,
66 max_depth: 1,
67 limit: usize::MAX,
68 order: TraversalOrder::Bfs,
69 visited_policy: VisitedPolicy::None,
70 path_policy: PathPolicy::EdgeAndVertex,
71 emit_policy: EmitPolicy::EveryDepth,
72 space_name,
73 vertex_tag: String::new(),
74 path_semantic: None,
75 }
76 }
77
78 pub fn traverse(
79 space_name: String,
80 direction: EdgeDirection,
81 min_depth: u32,
82 max_depth: u32,
83 edge_types: Vec<String>,
84 ) -> Self {
85 Self {
86 kind: TraversalKind::Traverse,
87 direction,
88 edge_types,
89 min_depth,
90 max_depth,
91 limit: usize::MAX,
92 order: TraversalOrder::Dfs,
93 visited_policy: VisitedPolicy::Global,
94 path_policy: PathPolicy::VertexOnly,
95 emit_policy: EmitPolicy::EveryDepth,
96 space_name,
97 vertex_tag: String::new(),
98 path_semantic: None,
99 }
100 }
101}