-
Notifications
You must be signed in to change notification settings - Fork 235
Expand file tree
/
Copy pathall_paths.h
More file actions
67 lines (58 loc) · 2.67 KB
/
Copy pathall_paths.h
File metadata and controls
67 lines (58 loc) · 2.67 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
/*
* Copyright 2018-2021 Redis Labs Ltd. and Contributors
*
* This file is available under the Redis Labs Source Available License Agreement
*/
/*
* Finds all paths starting at given source node
* We're computing one path at a time, this is done
* to take advantage of scenarios where a query specifies LIMIT.
* To implement this kind of iterative path fiding using DFS
* we're keeping track after:
* 1. the last path computed, which we'll try to expand
* 2. neighboring nodes discovered, each placed within a "level"
* array containing all nodes discovered at a specific level.
* */
#pragma once
#include "../datatypes/path/path.h"
#include "../graph/graph.h"
#include "../graph/entities/node.h"
#include "../filter_tree/filter_tree.h"
typedef struct {
Node node;
Edge edge;
} LevelConnection;
typedef struct {
LevelConnection **levels; // Nodes reached at depth i, and edges leading to them.
Path *path; // Current path.
Graph *g; // Graph to traverse.
Edge *neighbors; // Reusable buffer of edges along the current path.
int *relationIDs; // edge type(s) to traverse.
int relationCount; // length of relationIDs.
GRAPH_EDGE_DIR dir; // traverse direction.
uint minLen; // Path minimum length.
uint maxLen; // Path max length.
Node *dst; // Destination node, defaults to NULL in case of general all paths execution.
Record r; // Record the traversal is being performed upon, only used for edge filtering.
FT_FilterNode *ft; // FilterTree of predicates to be applied to traversed edges.
uint edge_idx; // Record index of the edge alias, only used for edge filtering.
} AllPathsCtx;
// Create a new All paths context object.
AllPathsCtx *AllPathsCtx_New(
Node *src, // Source node to traverse.
Node *dst, // Destination node of the paths
Graph *g, // Graph to traverse.
int *relationIDs, // Edge type(s) on which we'll traverse.
int relationCount, // Length of relationIDs.
GRAPH_EDGE_DIR dir, // Traversal direction.
uint minLen, // Path length must contain be at least minLen + 1 nodes.
uint maxLen, // Path length must not exceed maxLen + 1 nodes.
Record r, // Record the traversal is being performed upon.
FT_FilterNode *ft, // FilterTree of predicates to be applied to traversed edges.
uint edge_idx // Record index of the edge alias.
);
// Tries to produce a new path from given context
// If no additional path can be computed return NULL.
Path *AllPathsCtx_NextPath(AllPathsCtx *ctx);
// Free context object.
void AllPathsCtx_Free(AllPathsCtx *ctx);