@@ -33,30 +33,28 @@ topo_sort = function(nodes) {
3333 nodes = copy(nodes ) # copy ref to be sure
3434 n = nrow(nodes )
3535 # sort nodes with few parent to start
36- nodes = nodes [order(lengths(parents ), decreasing = FALSE )]
36+ nodes = nodes [order(lengths(get( " parents" ) ), decreasing = FALSE )]
3737
3838 nodes [, `:=`(topo = NA_integer_ , depth = NA_integer_ )] # cols for topo-index and depth layer in sort
3939 j = 1L
4040 topo_count = 1L
4141 depth_count = 0L
42- topo = depth = parents = id = NULL
43- . = NULL # nolint
4442 while (topo_count < = n ) {
4543 # if element is not sorted and has no deps (anymore), we sort it in
4644 if (is.na(nodes $ topo [j ]) && length(nodes $ parents [[j ]]) == 0L ) {
47- nodes [j , topo : = topo_count ]
45+ nodes [j , " topo" : = topo_count ]
4846 topo_count = topo_count + 1L
49- nodes [j , depth : = depth_count ]
47+ nodes [j , " depth" : = depth_count ]
5048 }
5149 j = (j %% n ) + 1L # inc j, but wrap around end
5250 if (j == 1L ) { # we wrapped, lets remove nodes of current layer from deps
53- layer = nodes [. (depth_count ), id , on = " depth" , nomatch = NULL ]
51+ layer = nodes [list (depth_count ), " id " , on = " depth" , nomatch = NULL ][[ 1L ] ]
5452 if (length(layer ) == 0L ) {
5553 stop(" Cycle detected, this is not a DAG!" )
5654 }
57- nodes [, parents : = map(parents , function (x ) setdiff(x , layer ))]
55+ nodes [, " parents" : = map(get( " parents" ) , function (x ) setdiff(x , layer ))]
5856 depth_count = depth_count + 1L
5957 }
6058 }
61- nodes [order(topo ), c(" id" , " depth" )] # sort by topo, and then remove topo-col
59+ nodes [order(get( " topo" ) ), c(" id" , " depth" )] # sort by topo, and then remove topo-col
6260}
0 commit comments