Computer science in Lua

classic Classic list List threaded Threaded
9 messages Options
Reply | Threaded
Open this post in threaded view
|

Computer science in Lua

Evandro Leopoldino Gonçalves
Hi guys!

I'm implementing some classical algorithms and data structures in Lua. Maybe it can be useful for someone :D

https://github.com/EvandroLG/computer_science_in_lua

My best,
Evandro
Reply | Threaded
Open this post in threaded view
|

Re: Computer science in Lua

Luiz Henrique de Figueiredo
> I'm implementing some classical algorithms and data structures in Lua.
> Maybe it can be useful for someone :D
>
> https://github.com/EvandroLG/computer_science_in_lua

See also

Lua Implementations of Common Data Structures,
by Matthew M. Burke,
Chapter 18, Lua Programming Gems
http://www.lua.org/gems/

Unfortunately, the link to the code there leads nowhere at the moment.
Perhaps Matthew can fix this?

Reply | Threaded
Open this post in threaded view
|

Re: Computer science in Lua

David Favro
In reply to this post by Evandro Leopoldino Gonçalves
On 12/17/2015 02:31 PM, Evandro Leopoldino Gonçalves wrote:
> I'm implementing some classical algorithms and data structures in Lua.
>

Interesting and maybe useful if someone couldn't use any C, only Lua.

Your OO is broken however, at least for binary heap all instances share
a common data array (although not size).  This is one reason why I
dislike "template" style OO, very prone to this kind of error.

local BinaryHeap = require("evandro-lg-binary-heap");

local heap1 = BinaryHeap:new();
local heap2 = BinaryHeap:new();

heap1:add(4);
heap1:add(8);
io.write( "heap1 size: ", heap1:size(),
     "\theap2 size: ", heap2:size(),
     "\theap1 minimum: ", heap1:get_minimum(), "\n" );

heap2:add(1);
io.write( "heap1 size: ", heap1:size(),
     "\theap2 size: ", heap2:size(),
     "\theap1 minimum: ", heap1:get_minimum(), "\n" );

Output, see the second "heap1 minimum" which reflects the number
ostensibly inserted into heap2:

heap1 size: 2    heap2 size: 0    heap1 minimum: 4
heap1 size: 2    heap2 size: 1    heap1 minimum: 1

-- David

P.S., what's the license?


Reply | Threaded
Open this post in threaded view
|

Re: Computer science in Lua

Joseph Manning
In reply to this post by Evandro Leopoldino Gonçalves
On Thu, December 17, 2015 19:31, Evandro Leopoldino Gonçalves wrote:

>> I'm implementing some classical algorithms and data structures in Lua.
>> Maybe it can be useful for someone :D
>>
>> https://github.com/EvandroLG/computer_science_in_lua

Evandro,

   There is no need to write a 'swap' function in Lua;
   you can just write
      a, b = b, a
   to swap the values in variables 'a' and 'b'.
   This may simplify your code a little.

Joseph

------------------------------------------------------------------------
Joseph Manning / Computer Science / UCC Cork Ireland / [hidden email]
------------------------------------------------------------------------



Reply | Threaded
Open this post in threaded view
|

Re: Computer science in Lua

Nagaev Boris
In reply to this post by Evandro Leopoldino Gonçalves
On Thu, Dec 17, 2015 at 10:31 PM, Evandro Leopoldino Gonçalves
<[hidden email]> wrote:
> Hi guys!
>
> I'm implementing some classical algorithms and data structures in Lua. Maybe
> it can be useful for someone :D
>
> https://github.com/EvandroLG/computer_science_in_lua
>
> My best,
> Evandro

We have binary heap and LRU cache implemented in pure Lua:
https://github.com/Tieske/binaryheap.lua
https://github.com/starius/lua-lru


--


Best regards,
Boris Nagaev

Reply | Threaded
Open this post in threaded view
|

Re: Computer science in Lua

Hisham
In reply to this post by Evandro Leopoldino Gonçalves
On 17 December 2015 at 17:31, Evandro Leopoldino Gonçalves
<[hidden email]> wrote:
> Hi guys!
>
> I'm implementing some classical algorithms and data structures in Lua. Maybe
> it can be useful for someone :D
>
> https://github.com/EvandroLG/computer_science_in_lua

See also this collection by Roland Yonaba:

https://github.com/Yonaba/Algorithm-Implementations

Enjoy! :)

-- Hisham

Reply | Threaded
Open this post in threaded view
|

Re: Computer science in Lua

Ignacio Burgueño-2

Also these are well documented

http://sano.luaforge.net

Reply | Threaded
Open this post in threaded view
|

Re: Computer science in Lua

Evandro Leopoldino Gonçalves
Thank you guys for tips and materials! :D

2015-12-19 12:44 GMT-02:00 Ignacio Burgueño <[hidden email]>:

Also these are well documented

http://sano.luaforge.net




--
Att,
Evandro
Reply | Threaded
Open this post in threaded view
|

RE: Computer science in Lua

Thijs Schreijer
In reply to this post by Ignacio Burgueño-2

and a few more; http://lua-users.org/lists/lua-l/2015-04/msg00341.html

 


From: [hidden email] [[hidden email]] on behalf of Ignacio Burgueño [[hidden email]]
Sent: 19 December 2015 15:44
To: Lua list
Subject: Re: Computer science in Lua

Also these are well documented

http://sano.luaforge.net