Binary v0.0.5 Binary.Queue View Source
Queue for binary data.
It resembles a pipeline: data is pushed on one end and pulled from the other. The order by which bytes are pushed in is the same by which they are pulled out.
Internally, this queue implementation optimizes on the amount of copying of binary data in memory. Copying possibly occurs when binary data is pulled from the queue.
Examples
iex> Binary.Queue.new() |> Binary.Queue.push(<<5, 208, 224, 23, 85>>) %Binary.Queue{data: {[<<5, 208, 224, 23, 85>>],[]}, size: 5}
iex> Binary.Queue.new() |> Binary.Queue.push(<<5, 208, 224, 23, 85>>) |> Binary.Queue.pull(4) {<<5, 208, 224, 23>> , %Binary.Queue{data: {[],[“U”]}, size: 1}}
iex> Binary.Queue.new() |> Binary.Queue.push(<<5, 208, 224, 23, 85>>) |> Binary.Queue.push(<<82, 203>>) %Binary.Queue{data: {[<<82, 203>>],[<<5, 208, 224, 23, 85>>]}, size: 7}
Link to this section Summary
Functions
Returns the amount of bytes on the queue
Returns the amount of bytes on the queue
Returns a new empty binary queue
Pulls a single byte from the queue. Returns a tuple of the first byte and the new queue without that first byte
Pulls a number of bytes from the queue. Returns a tuple of the first byte and the new queue without that first byte
Push binary data on the queue. Returns a new queue containing the pushed binary data
Link to this section Types
Link to this section Functions
Returns the amount of bytes on the queue
Examples
iex> q = Binary.Queue.new() %Binary.Queue{data: {[],[]}, size: 0} iex> Binary.Queue.is_empty(q) true iex> q = Binary.Queue.push(q, <<23, 75, 17>>) %Binary.Queue{data: {[<<23, 75, 17>>],[]}, size: 3} iex> Binary.Queue.is_empty(q) false
len(%Binary.Queue{data: term(), size: term()}) :: non_neg_integer()
Returns the amount of bytes on the queue
Examples
iex> q = Binary.Queue.push(Binary.Queue.new(), <<23, 75, 17>>) %Binary.Queue{data: {[<<23, 75, 17>>],[]}, size: 3} iex> Binary.Queue.len(q) 3
Returns a new empty binary queue.
Examples
iex> Binary.Queue.new() %Binary.Queue{data: {[],[]}, size: 0}
Pulls a single byte from the queue. Returns a tuple of the first byte and the new queue without that first byte.
Examples
iex> q = Binary.Queue.push(Binary.Queue.new(), <<23, 75>>) %Binary.Queue{data: {[<<23, 75>>],[]}, size: 2} iex> Binary.Queue.pull(q) {<<23>>, %Binary.Queue{data: {[], [“K”]}, size: 1}}
pull(t(), non_neg_integer()) :: {binary(), t()}
Pulls a number of bytes from the queue. Returns a tuple of the first byte and the new queue without that first byte.
Examples
iex> q = Binary.Queue.push(Binary.Queue.new(), <<23, 75, 17>>) %Binary.Queue{data: {[<<23, 75, 17>>],[]}, size: 3} iex> Binary.Queue.pull(q, 2) {<<23, 75>>, %Binary.Queue{data: {[], [<<17>>]}, size: 1}}