Skip to content

Commit

Permalink
tile-clusterer: more aggressively drop non-canonical groups
Browse files Browse the repository at this point in the history
  • Loading branch information
ahicks92 committed Oct 5, 2024
1 parent ff72a49 commit e884fd3
Showing 1 changed file with 4 additions and 5 deletions.
9 changes: 4 additions & 5 deletions scripts/ds/tile-clusterer.lua
Original file line number Diff line number Diff line change
Expand Up @@ -124,11 +124,12 @@ end

---@param group_number number
---@return number
function TileClusterer:walk_canonical_list(group_number)
function TileClusterer:walk_canonical_list(group_number, safe_to_drop)
local old_group_number = group_number
while group_number do
old_group_number = group_number
group_number = self.canonical_linked_list[group_number]
if safe_to_drop and group_number then self.groups[old_group_number] = nil end
end

return old_group_number
Expand Down Expand Up @@ -322,10 +323,8 @@ function TileClusterer:get_groups(callback)
local seen = {}

for num_old in pairs(self.groups) do
num = self:walk_canonical_list(num_old)
-- Very quick cleanup: nothing consults non-canonical groups and this is
-- free.
if num < num_old then self.groups[num_old] = nil end
num = self:walk_canonical_list(num_old, true)

local candidate = self.groups[num]
if not seen[candidate] then
seen[candidate] = true
Expand Down

0 comments on commit e884fd3

Please sign in to comment.