mirror of
https://github.com/appgurueu/modlib.git
synced 2024-11-21 14:53:44 +01:00
Heap: Localize math.floor & table.insert
This commit is contained in:
parent
5d3c011f79
commit
86033f0470
6
heap.lua
6
heap.lua
@ -1,5 +1,5 @@
|
||||
-- Localize globals
|
||||
local math, setmetatable, table = math, setmetatable, table
|
||||
local math_floor, setmetatable, table_insert = math.floor, setmetatable, table.insert
|
||||
|
||||
-- Set environment
|
||||
local _ENV = {}
|
||||
@ -15,12 +15,12 @@ function new(less_than)
|
||||
end
|
||||
|
||||
function push(self, value)
|
||||
table.insert(self, value)
|
||||
table_insert(self, value)
|
||||
local function heapify(index)
|
||||
if index == 1 then
|
||||
return
|
||||
end
|
||||
local parent = math.floor(index / 2)
|
||||
local parent = math_floor(index / 2)
|
||||
if self.less_than(self[index], self[parent]) then
|
||||
self[parent], self[index] = self[index], self[parent]
|
||||
heapify(parent)
|
||||
|
Loading…
Reference in New Issue
Block a user