af_unix: Save O(n) setup of Tarjan's algo.
Before starting Tarjan's algorithm, we need to mark all vertices as unvisited. We can save this O(n) setup by reserving two special indices (0, 1) and using two variables. The first time we link a vertex to unix_unvisited_vertices, we set unix_vertex_unvisited_index to index. During DFS, we can see that the index of unvisited vertices is the same as unix_vertex_unvisited_index. When we finalise SCC later, we set unix_vertex_grouped_index to each vertex's index. Then, we can know (i) that the vertex is on the stack if the index of a visited vertex is >= 2 and (ii) that it is not on the stack and belongs to a different SCC if the index is unix_vertex_grouped_index. After the whole algorithm, all indices of vertices are set as unix_vertex_grouped_index. Next time we start DFS, we know that all unvisited vertices have unix_vertex_grouped_index, and we can use unix_vertex_unvisited_index as the not-on-stack marker. To use the same variable in __unix_walk_scc(), we can swap unix_vertex_(grouped|unvisited)_index at the end of Tarjan's algorithm. Signed-off-by:Kuniyuki Iwashima <kuniyu@amazon.com> Acked-by:
Paolo Abeni <pabeni@redhat.com> Link: https://lore.kernel.org/r/20240325202425.60930-10-kuniyu@amazon.com Signed-off-by:
Jakub Kicinski <kuba@kernel.org>
Loading
-
mentioned in commit ff7509d4
-
mentioned in commit ec1d33ce
-
mentioned in commit c42cc351
-
mentioned in commit 8ebc6cb2
-
mentioned in commit c585cdd3
-
mentioned in commit 495fc221
-
mentioned in commit ddf2f371
-
mentioned in commit a559b979
-
mentioned in commit 6490f5a7
-
mentioned in commit 0cf8f956
-
mentioned in commit 8e25e199
-
mentioned in commit 1b8bba59
-
mentioned in commit 30bd4038
-
mentioned in commit 5ed18832
-
mentioned in commit 2d1f9c4d
-
mentioned in commit 6941ff28
-
mentioned in commit 6321dcf6
-
mentioned in commit c44653bc
-
mentioned in commit 73e12f1e
-
mentioned in commit 9da88b73
-
mentioned in commit 58308eb6
-
mentioned in commit afa0900a
-
mentioned in commit 1f7634a4
-
mentioned in commit 250c362a
Please sign in to comment