Page 1 of 1

Ruby array queue ?

Posted: Fri May 08, 2020 12:32 pm
by kortezzzz
Hi,
I've tried using the green queue primitive for a sensitive project that needs a decent accuracy but couldn't perform a full control on it. So wondered maybe Ruby can be the answer. The Ruby module should actually do a very simple task:
Receive a given array and push each of the indexes forward whenever it gets triggered. For instance, if the array is

4
5
7
9
13

It will output the integer 4 on the first trigger, then output the integer 5 on the second trigger, then 7 and so on until the array ends. Array's end should cause it stop pushing anything until a "reset" trigger received.

Any ideas?

Re: Ruby array queue ?

Posted: Fri May 08, 2020 11:41 pm
by tektoog
Hey,
This does, I think, what you're asking for ;)

TekTooG - Triggered values in queue.fsm
(1.51 KiB) Downloaded 911 times


No Ruby there though... :o :oops:

Re: Ruby array queue ?

Posted: Fri May 08, 2020 11:41 pm
by tiffy
Here is a better version in Green Primitives than the first one I uploaded.

Re: Ruby array queue ?

Posted: Sat May 09, 2020 1:28 am
by tulamide
kortezzzz wrote:Hi,
I've tried using the green queue primitive for a sensitive project that needs a decent accuracy but couldn't perform a full control on it. So wondered maybe Ruby can be the answer. The Ruby module should actually do a very simple task:
Receive a given array and push each of the indexes forward whenever it gets triggered. For instance, if the array is

4
5
7
9
13

It will output the integer 4 on the first trigger, then output the integer 5 on the second trigger, then 7 and so on until the array ends. Array's end should cause it stop pushing anything until a "reset" trigger received.

Any ideas?
That's called 'fifo' and describes a buffer that holds a certain number of data and spits out the oldest first ( "First In First Out" )

Here's an example in Ruby.

Re: Ruby array queue ?

Posted: Sat May 09, 2020 10:06 am
by kortezzzz
Guys, Thanks you so much for the beautiful examples 8-) This is classic "straight to toolbox" must have module.
Although tula's ruby one is the most elegant solution and probably the most CPU saver, I really loved the functionality of tiffy's and tektoog's green solution. So I made another progress and added to tektoog's one's trog's ruby counter which allows up\down option. Hope you like it :)

Re: Ruby array queue ?

Posted: Sat May 09, 2020 12:44 pm
by tektoog
Hey,
Good add ;)
I think it can still be optimized a bit ;)
check this one, notes are in there :) ;)



Take care,
TekTooG

Re: Ruby array queue ?

Posted: Sat May 09, 2020 2:37 pm
by kortezzzz
tektoog wrote:I think it can still be optimized a bit ;)
check this one, notes are in there :)


Thanks Tektoog :)