tieske / binaryheap.lua Goto Github PK
View Code? Open in Web Editor NEWBinary heap implementation in Lua
Home Page: http://tieske.github.io/binaryheap.lua/
License: MIT License
Binary heap implementation in Lua
Home Page: http://tieske.github.io/binaryheap.lua/
License: MIT License
requires additional tests, and no length checking on the payload
table as it is no longer a valid list/array
using 1 table with a table of value and payload for each element, is probably less efficient than using two tables, one for values, the other for payloads.
see #1 (comment)
The documentation mentions field "reverse", which does not exist. There are fields "value" and "reverse". I think, they should be renamed to "values" and "reverse".
Method remove
behaves in different way in plain heap and in unique heap. I think it should be replaced with two methods:
removePos(pos)
removePayload(payload)
These two methods are better than ambigous remove
method.
Same considerations for update
method.
Can not find it on http://tieske.github.io/binaryheap.lua/index.html
It is actually a plain heap with map from values to positions. This if often needed.
-- Note: this function returns `payload` as the first result to prevent
-- extra locals when retrieving the `payload`.
-- @return value, payload at the top, or `nil` if there is none
function popU(self)
if self.values[1] then
local payload = self.payloads[1]
local value = remove(self, 1)
return value, payload
end
end
The comment+docs say that payload
is returned first; yet the code returns value
. Which is it meant to be?
It fails even on Travis CI configured for your project: https://travis-ci.com/Tieske/binaryheap.lua/jobs/177798107.
Method remove
returns (payload, value).
Method pop
returns (payload, value).
Method peek
returns (value, payload).
I think, all these methods should return (value, payload), because all heaps have values, but some heaps do not have payloads.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.