Giter VIP home page Giter VIP logo

lua-heaps's Introduction

lua-heaps

Build Status

This started as a benchmark for binary and skew heaps in Lua. It compares them to sorting a table, which doesn't fare well.

Now it's a reasonably good implementation of both kinds of heaps, probably a little better for binary heaps than skew heaps because I use binary heaps.

The binary heap implementation tries to keep garbage creation to a minimum, which seems to help speed things up.

Usage is:

local heap = require"binary_heap" -- or "skew_heap"
local H = heap:new()

H:insert(2, "world")
H:insert(1, "hello")

local k1, w1 = H:pop()
local k2, w2 = H:pop()

print(k1, k2)  -- prints "hello world"

Keys and values are kept separate because it can, in some cases (like my common one) reduce garbage creation.

You can provide a comparison function to heap:new, which will be passed the keys (but not values) of the two items to compare.

The heaps tested against Lua 5.1-5.3 and LuaJIT.

lua-heaps's People

Contributors

geoffleyland avatar

Stargazers

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

Watchers

 avatar  avatar  avatar

lua-heaps's Issues

Max-heap howto?

Hi, I noticed that the current implementation creates a min-heap (root is min value in heap). How can I construct a max-heap, where max value will take the root position? I know that it is basically switching the <> operators but I'd rather ask here in case it is something more than just operator change.

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.