Implementation of Queue

22 views
Skip to first unread message

Dirk Laurie

unread,
Feb 15, 2013, 7:25:16 AM2/15/13
to lua-table...@googlegroups.com
2013/2/15 Axel Kittenberger <axk...@gmail.com>:
> If you take a look at my workarounds with "Array", "CountArray" and "Queue"
>
> https://github.com/axkibe/lsyncd/blob/master/lsyncd.lua
>

Your Queue does too much. It allows items to jump the queue.
That's where the problems start.

A Queue has only two functions, like a Stack has only two functions.
Both are special cases of a Deque, which has four functions,
as follows:

Queue.put, Queue.get = Deque.rightin, Deque.leftout
Stack.push, Stack.pop = Deque.rightin, Deque.rightout

Axel Kittenberger

unread,
Feb 15, 2013, 7:42:27 AM2/15/13
to lua-table...@googlegroups.com
Maybe "Queue" is a misnomer.
Maybe this class goes beyond generic routines.
So in cause of doubt ignore it.
I'd be already happy with "Array" and "CountArray".

However in my application "jumping" is needed.
In my opinion a wonderful example where nil holes can make sense.

The background: Lsyncd watches a file system through inotify.
When something happened it queues the events.
The order is important and chronological, therefore a queue.
It calls a rsync process to update a remote mirror.
Since a few versions ago it may run multiple rsync processes at the same time.
It includes logic which ones could intefer with each other.

When a rsync process finishes, the events that raised the process are dequeued.
This may not be the left or the right most.
Its a real life example that goes awry to theoretical principle of a queue.

Think of it in a real life queue in front of a counter
where, for the comfort of the customer,
to speed things up,
a second employee regulary goes up the line
and asks each person if he can help him already,
if what he needs is simple enough
so before he has to wait to reach the counter.
he is serverd.
Some people are helped that way
and can go home earlier.
That is removed right from within the queue.

- Axel
> --
> You received this message because you are subscribed to the Google Groups "lua table semantics" group.
> To unsubscribe from this group and stop receiving emails from it, send an email to lua-table-seman...@googlegroups.com.
> For more options, visit https://groups.google.com/groups/opt_out.
>
>
Reply all
Reply to author
Forward
0 new messages