mirror of
https://github.com/appgurueu/modlib.git
synced 2024-11-21 23:03: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
|
-- Localize globals
|
||||||
local math, setmetatable, table = math, setmetatable, table
|
local math_floor, setmetatable, table_insert = math.floor, setmetatable, table.insert
|
||||||
|
|
||||||
-- Set environment
|
-- Set environment
|
||||||
local _ENV = {}
|
local _ENV = {}
|
||||||
@ -15,12 +15,12 @@ function new(less_than)
|
|||||||
end
|
end
|
||||||
|
|
||||||
function push(self, value)
|
function push(self, value)
|
||||||
table.insert(self, value)
|
table_insert(self, value)
|
||||||
local function heapify(index)
|
local function heapify(index)
|
||||||
if index == 1 then
|
if index == 1 then
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
local parent = math.floor(index / 2)
|
local parent = math_floor(index / 2)
|
||||||
if self.less_than(self[index], self[parent]) then
|
if self.less_than(self[index], self[parent]) then
|
||||||
self[parent], self[index] = self[index], self[parent]
|
self[parent], self[index] = self[index], self[parent]
|
||||||
heapify(parent)
|
heapify(parent)
|
||||||
|
Loading…
Reference in New Issue
Block a user