Introduction:
The queue is a special data type in System Verilog that works on the principle of FIFO (First in First Out). Thus, the element that is stored first in the queue is retrieved first, just as the case in the real-life queue.
What is Queue in System Verilog?
- Queues are based on the concept of a linked list in which the elements consist of 2 parts. 1st part is the value that needs to be stored, and the 2nd part is the address of the next element of the list. If the element is the last one, then the 2nd part is null otherwise it points to the next item.
- Queue in system Verilog, handles all the address-related operations internally which makes using queue a lot easier. Queue like an associative array has no specific size and the size grows and shrinks dynamically depending upon the number of elements stored. But in queues, the index is continuous in nature, unlike the associative arrays.
Concept of push and pop:-
- As discussed, queues work on the concept of FIFO, i.e., first in first out. This means that a new element can be added at the end of the queue. Also, the element which is first in queue means that it was inserted earlier than other elements and thus this element will be removed from the queue first.
- Push in queue means inserting a new element at the end of the queue.
- Pop in queue means getting the first element present in the queue and removing it from the queue.