Skip to content

Commit d0b9a0f

Browse files
authored
feat: dfs supports undirected graph data (#66)
1 parent edcb0e3 commit d0b9a0f

File tree

3 files changed

+19
-8
lines changed

3 files changed

+19
-8
lines changed

CHANGELOG.md

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,25 @@
11
# ChangeLog
2+
3+
#### 0.1.26
4+
5+
- feat: dfs supports undirected graph data;
6+
27
#### 0.1.25
38

49
- feat: Optimized data preprocessing coding - when the feature values are all numerical, use the original values (plus normalization), and do not use one-hot coding
10+
511
#### 0.1.24
612

7-
- fix: i-louvain without cluster problem;
13+
- fix: i-louvain without cluster problem;
14+
815
#### 0.1.23
916

1017
- perf: k-means algorithm: set K to minimum
18+
1119
#### 0.1.22
1220

1321
- fix: k-means algorithm, perf: louvain -- support specified parameters such as propertyKey,involvedKeys and uninvolvedKeys
22+
1423
#### 0.1.21
1524

1625
- perf: k-means algorithm -- Optimize parameters and return

packages/graph/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@antv/algorithm",
3-
"version": "0.1.25",
3+
"version": "0.1.26",
44
"description": "graph algorithm",
55
"keywords": [
66
"graph",

packages/graph/src/dfs.ts

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
import { IAlgorithmCallbacks, GraphData } from './types'
2-
import { getNeighbors } from './util'
1+
import { IAlgorithmCallbacks, GraphData } from './types';
2+
import { getNeighbors } from './util';
33

44
function initCallbacks(callbacks: IAlgorithmCallbacks = {} as IAlgorithmCallbacks) {
55
const initiatedCallback = callbacks;
@@ -35,23 +35,24 @@ function depthFirstSearchRecursive(
3535
currentNode: string,
3636
previousNode: string,
3737
callbacks: IAlgorithmCallbacks,
38+
directed: boolean = true,
3839
) {
3940
callbacks.enter({
4041
current: currentNode,
4142
previous: previousNode,
4243
});
4344

44-
const { edges = [] } = graphData
45+
const { edges = [] } = graphData;
4546

46-
getNeighbors(currentNode, edges, 'target').forEach((nextNode) => {
47+
getNeighbors(currentNode, edges, directed ? 'target' : undefined).forEach((nextNode) => {
4748
if (
4849
callbacks.allowTraversal({
4950
previous: previousNode,
5051
current: currentNode,
5152
next: nextNode,
5253
})
5354
) {
54-
depthFirstSearchRecursive(graphData, nextNode, currentNode, callbacks);
55+
depthFirstSearchRecursive(graphData, nextNode, currentNode, callbacks, directed);
5556
}
5657
});
5758

@@ -71,6 +72,7 @@ export default function depthFirstSearch(
7172
graphData: GraphData,
7273
startNodeId: string,
7374
callbacks?: IAlgorithmCallbacks,
75+
directed: boolean = true,
7476
) {
75-
depthFirstSearchRecursive(graphData, startNodeId, '', initCallbacks(callbacks));
77+
depthFirstSearchRecursive(graphData, startNodeId, '', initCallbacks(callbacks), directed);
7678
}

0 commit comments

Comments
 (0)