Queue

The Queue data structure, also known as First In, First Out (FIFO) queue, allows addition and deletion of items in opposite ends of the data structure. Insertion is performed in the back of the queue while deletion is performed in the front of the queue. In DataStructures.jl, the Queue type is a light-weight wrapper around the Deque type.

Queues are often used as a base for many different data structures, some of its variations implemented by DataStructures.jl include:

Constructors

DataStructures.QueueType
Queue{T}() where {T}
Queue{T}([blksize::Integer=1024])

Create a Queue object containing elements of type T for First In, First Out (FIFO) access.

Parameters

  • T::Type Queue element data type.
  • blksize::Integer=1024 Unrolled linked-list block size (in bytes). Default = 1024.

Examples

julia> q_int = Queue{Int64}() # create a queue with int elements
Queue{Int64}(Deque [Int64[]])

julia> q_float = Queue{Float64}() # create a queue with float elements
Queue{Float64}(Deque [Float64[]])
source

Usage

The Queue type implements the following methods:


Base.:==Method
==(x::Queue, y::Queue)

Verify if queues x and y are equivalent in their contents.

source
Base.eltypeMethod
eltype(::Type{Queue{T}}) where {T}

Return the type of the elements in the queue.

source
Base.lengthMethod
length(q::Queue)

Return the number of elements in queue q.

source
Base.popfirst!Method
popfirst!(q::Queue)

Removes an element from the front of the queue q and returns it.

source
Base.push!Method
push!(q::Queue, x)

Inserts the value x to the end of the queue q.

source