I would like to move contents of one queue to another.
When I do it the following way, it does not work
module x;
integer Q1[$] = { 1,2, 3, 5, 6, 7, 8, 9, 10};
integer Q2[$];
initial begin
for (int idx = 0; idx < Q1.size(); idx++) begin
Q2.push_back(Q1.pop_front());
end
for (int idx = 0; idx < Q2.size(); idx++) begin
$display ("Q2 ... %d", Q2[idx]);
end
end
endmodule
The issue with this code is obvious.
I am popping out the contents of Q1 in a loop which progressively reduces the loop size and loop exit condition depends on the queue size.
To handle this, do I need to do this in 2 steps
first transfer contents of Q1 to Q2 without popping the contents
iterate through Q1 and delete the Q1 contents
Any other efficient method?
PS: I see that queue does not support deleting the entire queue…
In reply to dave_59:
Q2 may have data already. So Q2 = Q1 will overwrite existing entries.
Anyway to append other than doing it procedurally in a loop?