diff options
author | number Zero <silverunicorn2011@yandex.ru> | 2018-01-28 02:19:24 +0300 |
---|---|---|
committer | number Zero <silverunicorn2011@yandex.ru> | 2018-01-28 02:19:24 +0300 |
commit | 2cd2093b337250de8f8ece1bbebe1dbd78f95e5d (patch) | |
tree | 77909fa65d22c893074c9bb1176f9058eb1c5ee7 | |
parent | 054494abb6446d9eaf98c2cab3611c22e2b16952 (diff) |
Reduce queue size
-rw-r--r-- | technic/machines/switching_station.lua | 10 |
1 files changed, 7 insertions, 3 deletions
diff --git a/technic/machines/switching_station.lua b/technic/machines/switching_station.lua index 3ef9268..21d394b 100644 --- a/technic/machines/switching_station.lua +++ b/technic/machines/switching_station.lua @@ -190,9 +190,13 @@ local get_network = function(sw_pos, pos1, tier) local all_nodes = {} local queue = {} add_cable_node(all_nodes, pos1, network_id, queue) - for _, pos in ipairs(queue) do - traverse_network(PR_nodes, RE_nodes, BA_nodes, SP_nodes, all_nodes, - pos, technic.machines[tier], tier, sw_pos, network_id, queue) + while next(queue) do + local to_visit = {} + for _, pos in ipairs(queue) do + traverse_network(PR_nodes, RE_nodes, BA_nodes, SP_nodes, all_nodes, + pos, technic.machines[tier], tier, sw_pos, network_id, to_visit) + end + queue = to_visit end PR_nodes = flatten(PR_nodes) BA_nodes = flatten(BA_nodes) |