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

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

  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} 


  • 8
    点赞
  • 23
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值