Code Monkey home page Code Monkey logo

Comments (4)

starius avatar starius commented on June 15, 2024

I see the following problems:

  • nil can not be a key of a table, so heap.reverse wont work
  • nil is returned from methods like pop and peek when no value exists. If we allow nil as a valid payload, then this behaviour is to be changed
  • using nil as a valid valud is not Lua-ish

👎

from binaryheap.lua.

Tieske avatar Tieske commented on June 15, 2024

The idea was to use the same implementation for a heap with payload as one without a payload (in the latter case payload == nil)

nil can not be a key of a table, so heap.reverse wont work

if you test for nil first... just return nil

using nil as a valid valud is not Lua-ish

it is for omitting parameters

but as noted in my initial posting, it does have some issues... don't know the performance impact of those

from binaryheap.lua.

starius avatar starius commented on June 15, 2024

The idea was to use the same implementation for a heap with payload as one without a payload (in the latter case payload == nil)

I think, type of a heap should be determined when a heap is created. Otherwise, how to deal with same heap being used as both plain heap and unique heap?

from binaryheap.lua.

Tieske avatar Tieske commented on June 15, 2024

@starius re reading this, I think it is indeed not a good idea. Closing.

from binaryheap.lua.

Related Issues (11)

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.