|
| 1 | +import { GraphExpander, type Neighbor } from '../interfaces/graph-expander'; |
1 | 2 | import { PriorityQueue } from './priority-queue'; |
2 | 3 |
|
3 | | -/** |
4 | | - * Neighbor relationship returned by GraphExpander. |
5 | | - */ |
6 | | -export interface Neighbor { |
7 | | - targetId: string; |
8 | | - relationshipType: string; |
9 | | -} |
10 | | - |
11 | | -/** |
12 | | - * Interface for dynamic neighbor discovery during graph traversal. |
13 | | - * Allows BFS to work with any data source (API, database, file system, etc.). |
14 | | - * |
15 | | - * @template T - Type of node data |
16 | | - */ |
17 | | -export interface GraphExpander<T> { |
18 | | - /** |
19 | | - * Get neighbors of a node, potentially fetching from external source. |
20 | | - * |
21 | | - * @param nodeId - Node whose neighbors to fetch |
22 | | - * @returns Array of neighbor relationships |
23 | | - */ |
24 | | - getNeighbors(nodeId: string): Promise<Neighbor[]>; |
25 | | - |
26 | | - /** |
27 | | - * Get node degree for priority computation. |
28 | | - * Used to prioritize low-degree (specific) nodes over high-degree (generic) nodes. |
29 | | - * |
30 | | - * @param nodeId - Node to get degree for |
31 | | - * @returns Number of relationships (higher = lower priority) |
32 | | - */ |
33 | | - getDegree(nodeId: string): number; |
34 | | - |
35 | | - /** |
36 | | - * Get node data (may fetch from cache/API). |
37 | | - * |
38 | | - * @param nodeId - Node to retrieve |
39 | | - * @returns Node data or null if not found |
40 | | - */ |
41 | | - getNode(nodeId: string): Promise<T | null>; |
42 | | - |
43 | | - /** |
44 | | - * Add an edge to the final graph output. |
45 | | - * Called during node expansion to track discovered relationships. |
46 | | - * |
47 | | - * @param source - Source node ID |
48 | | - * @param target - Target node ID |
49 | | - * @param relationshipType - Type of relationship |
50 | | - */ |
51 | | - addEdge(source: string, target: string, relationshipType: string): void; |
52 | | -} |
53 | | - |
54 | 4 | /** |
55 | 5 | * Configuration options for bidirectional BFS. |
56 | 6 | */ |
|
0 commit comments