Hi All
I want to make two dimensional queue in the SV and I need to push and pop more than one element at the same time.
I don’t know how to do that, would you give me some suggestions?
Thanks
In reply to peter:
Here’s an example which pushes elements in 2D queue first then pops values back
int q[$][$] ;
int val ;
initial begin
for ( int i = 0 ; i < 2 ; i ++ )
begin
for ( int j = 0 ; j < 2 ; j ++ )
begin
q[i].push_back(i+j*10); // Pushes elements in 2D queue .
$display("q[%0d] is %0p",i,q[i]);
end
end
for ( int i = 0 ; i < 2 ; i ++ )
begin
for ( int j = 0 ; j < 2 ; j ++ )
begin
val = q[i].pop_back();
$display("val is %0d",val);
end
end
end
// Note that :: q[i][j].push_back( .. ) would be Error as q[i][j] is leaf element ( packed element ) !!
In reply to ABD_91:
thanks for reply
How to pop more than one element at the same time?
In reply to peter:
At a time you can pop only 1 element . So if you want 2 elements you should call pop twice
In reply to peter:
Queues are most efficient for pushing/popping one element at a time from the front or back of the queue. You can also use array concatenation and the streaming operators for all kinds of array manipulation. It would help if you could explain more what you are looking to accomplish, especially where you want to put the multiple elements you want to pop off. It might be more useful to use dynamic arrays instead of queues.