您的位置:首页 > 产品设计 > UI/UE

systemverilog queue 的使用,如何判断元素是否存在

2016-10-18 23:01 4251 查看
Queue:

    int queue[$] = {1,2,3}; 

    int queue[$:256]; //A queue whose maximum size is 256 bits

7.10.1 operator

    queue[0:$] //travel the queue

7.10.3 methods

    function int size();

    function void insert(input integer index, input element_t item);

    function void delete( [input integer index] ); // input index is optional, is index is not specified, then the delete() method deletes all the elements in the queue.

    function element_t pop_front();

    function element_t pop_back();

    function void push_front(input element_t item);

    function void push_back(input element_t item);

所以queue 在sv中是没有find/exists function的,但是可以使用array 中的find_xxx function 返回一个queue
4000

  function:

-find()
returns all the elements satisfying the given expression.
-find_index()
returns the indices of all the elements satisfying the given expression.
-find_first()
returns the first element satisfying the given expression.
-find_first_index()
returns the index of the first element satisfying the given expression


-find_last() returns the last element satisfying the given expression.

-find_last_index() returns the index of the last element satisfying the given expression.

program automatic queue_demo;

  int queue[$] = {1,2,3};

  initial begin
queue.push_back(4);
queue.push_back(3);
$display("queue:%p",queue);
queue=queue.find(x) with (x==3); //find() with(item !=3) delete the element"3"
$display("queue:%p",queue);
//foreach(queue[idx])
//  $display("queue:%d",queue[idx]);

  end

endprogram


结果:

queue:'{1, 2, 3, 4, 3} 

queue:'{3, 3} 
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  systemverilog queue