Is there a built-in datatype that I can use for a FIFO queue in Elixir?
I have looked at list, but it seems like it is not efficient to get the list tail? Maybe I am wrong about this?
My queue needs to hold a 100,000 or more elements. My need is that I am generating 44100 tuples a second of the form {t, y} for audio. I am trying to implement a delay, so I need to queue up a couple of seconds (maybe 10 at max?) of audio before sending it down the processing pipeline.
I'm not sure about the performance on 100,000 or more elements but it looks like you're looking for Queue. It's a FIFO Queue provided by the Erlang/OTP.
Example:
iex(39)> queue = :queue.new
{[], []}
iex(40)> queue = :queue.in(1, queue)
{[1], []}
iex(41)> queue = :queue.in(2, queue)
{[2], [1]}
iex(42)> queue = :queue.in(3, queue)
{[3, 2], [1]}
iex(43)> :queue.out(queue)
{{:value, 1}, {[3], [2]}}
iex(44)> {{:value, head}, queue} = :queue.out(queue)
{{:value, 1}, {[3], [2]}}
iex(45)> head
1
iex(46)> {{:value, head}, queue} = :queue.out(queue)
{{:value, 2}, {[], [3]}}
iex(47)> head
2
iex(48)> {{:value, head}, queue} = :queue.out(queue)
{{:value, 3}, {[], []}}
iex(49)> head
3
iex(51)> :queue.out(queue)
{:empty, {[], []}}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With