Code Monkey home page Code Monkey logo

binaryheap.lua's People

Contributors

fperrad avatar starius avatar tieske avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar

binaryheap.lua's Issues

Allow nil for payloads

requires additional tests, and no length checking on the payload table as it is no longer a valid list/array

field "reverse"

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".

how to remove by pos in unique heap?

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.

unique:pop() return value

-- 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?

remove, pop and peek results order

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.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.