|
|
|
|
|
|
|
|
|
|
|
|
Smart Queues
|
|
|
Smart Queue is a sequence / deque / vector of homogeneous elements. Smart queues can be used to model a last in, first out buffer or first in, first out buffer. This supports insertion and deletion of elements from random locations using an index. As with an associative array, the size of the queue can grow or shrink dynamically as elements are pushed or popped. |
|
|
|
|
|
Initialization of smart queues is supported for data types of integer, reg, bit, string, event and enumerated types. Elements of uninitialized Smart Queues are assigned the default value of the data type (for example, X for integer). |
|
|
|
|
|
|
|
|
|
|
|
Example : Smart Queues
|
|
|
|
|
|
1 program smart_queue {
2 integer smart [$]; // $ makes it smart queue
3 integer i = 0;
4 // Push 4 elements to end of queue
5 smart.push_back(random());
6 smart.push_back(random());
7 smart.push_back(random());
8 smart.push_back(random());
9 // Get value from front of queue
10 printf("value at front : %x\n",smart.pop_front());
11 printf("value at front : %x\n",smart.pop_front());
12 printf("value at front : %x\n",smart.pop_front());
13 printf("value at front : %x\n",smart.pop_front());
14 // Check if it not empty before you pop
15 if (smart.size() ! = 0) {
16 printf("value at front : %x\n",smart.pop_front());
17 }
18 smart.push_back(random());
19 smart.push_back(random());
20 // Just loop over all the values
21 foreach (smart, i) {
22 printf("value at %0d : %x\n",i, smart[i]);
23 }
24
25 }
26
You could download file smart_queue.vr here
|
|
|
|
|
|
Simulation : Smart Queues
|
|
|
|
|
|
value at front : 2fd9a2ac
value at front : 7377581d
value at front : 0ba1adbf
value at front : 131ab2c9
value at 0 : 3aae165d
value at 1 : 05e1726a
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Copyright © 1998-2014 |
Deepak Kumar Tala - All rights reserved |
Do you have any Comment? mail me at:deepak@asic-world.com
|
|