队列的0代表第一个元素 $代表最后一个元素。队列是1D unpacked的数组,可以被用作LIFO和FIFO buffer。

module dq;// A queue of 8-bit bytes – unbounded queuebit[7:0] dq1[$];// A queue of strings – unbounded queuestring mname[$] = { "Bob" };// An initialized queue – unbounded queuebit[15:0] dq2[$] = { 3, 2, 7, 1 };// A bounded queue – size = 256. Maximum index @255.bit q2[$:255];//bit q2[255:$]; // Compile ERROR – invalid syntaxint dq2_size;
initial begindq1[0] = 'hff;dq1[1] = 'h00;dq1[$] = 'h01; //last entry - will override dq1[1]='h00$display($stime,,,"dq1=",dq1);dq1[1] = 'h02;$display($stime,,,"dq1=", dq1);mname[1] = "mike"; //push-in - grow the queue$display($stime,,, "mname=", mname);//displays initialized 4 entries$display($stime,,,"dq2=", dq2);dq2[4] = {16'h 1111};$display($stime,,,"dq2=", dq2);q2[0] = 1;q2[1] = 0;$display($stime,,, "q2=",q2);q2[3] = 1; //skipped entry '2' - so no 3rd entry$display($stime,,, "q2=",q2);dq2_size = dq2.size( );
$display($stime,,,"dq2 size = %0d",dq2_size);for (int i = 0; i < dq2_size; i++) //read the entire queue$display($stime,,,"dq2[%0d] = %0h", i, dq2[i]);//insert a value at index 256 which is out of bound dq2.insert(256,1); You get a run-time Errorendendmodule

0 dq1='{'hff, 'h1}

0 dq1='{'hff, 'h2}

0 mname='{"Bob", "mike"}

0 dq2='{'h3, 'h2, 'h7, 'h1}

0 dq2='{'h3, 'h2, 'h7, 'h1, 'h1111}

0 q2='{'h1, 'h0} 0 q2='{'h1, 'h0}

0 dq2 size = 5 0 dq2[0] = 3

0 dq2[1] = 2 0 dq2[2] = 7

0 dq2[3] = 1 0 dq2[4] = 1111

V C S S i m u l a t i o n R e p o r t

bit q2[$:255] 是一个bounded的队列,限制了最大值为255,所以一共能存256个元素。如果超过了255th,比如256th,就会丢失256th 数据。

bit[7:0] dq1[$] 是一个unbounded队列,存储的8bit 数据。

string mname[$] = {"Bob"}; 中的第一个元素被声明了。

3.1 队列方法

对FIFO来说,最重要的是pop_front和push_back。

module dq;bit[7:0] dq1[$]; // A unbounded queue of unsigned 8-bitint q3[$:5] = {0,1,2,3,4,5}; //bounded queueint a;initial begina = dq1.size( ); //empty queue$display ($stime,,, "empty dq1 size = %0d",a);dq1[0] = 0; dq1[1] = 1; dq1[2] = 2;$display ($stime,,, "dq1 SIZE = %0d",dq1.size( ));$display ($stime,,, "dq1=",dq1);dq1.insert (3,3); //index, value$display($stime,,, "After Insert dq1 SIZE = %0d",dq1.size( ));$display ($stime,,, "dq1=",dq1);dq1.delete (3); //index$display ($stime,,, "After delete dq1 SIZE = %0d",dq1.size( ));$display ($stime,,, "dq1=",dq1);a = dq1.pop_front( ); //pop frst entry of the queue$display ($stime,,, "dq1 pop front = %0d ",a);$display ($stime,,, "dq1=",dq1);a = dq1.pop_back( ); //pop last entry of the queue$display ($stime,,, "dq1 pop back = %0d ",a);$display ($stime,,, "dq1=",dq1);//push the frst entry of the queue with '4'dq1.push_front(4);$display ($stime,,, "push front dq1=",dq1);//push the last entry of the queue with '5'dq1.push_back(5);$display ($stime,,, "push back dq1=",dq1);q3_size = q3.size + 5; //size > q3 size underfow : pop from index 6,7,8,9,10 – run time Warningfor (int i = 0; i < q3_size; i++)$display($stime,,,"q3[%0d] = %0d", i, q3.pop_front( ) );end//Solution for underfow - check for size before popwhile (q3.size( ) > 0)$display($stime,,,"q3 = %0d", q3.pop_front ( ));//overfow : push over the bound limit – run time Warningfor (int i = 0; i < q3_size; i++) beginq3.push_front( i );$display($stime,,,"q3[%0d] :: q3 = %p", i , q3);end
endmodule

Simulation log:

0 empty dq1 size = 0                                 //empty queue size

0 dq1 SIZE = 3                                         //size after providing values to frst three elements

0 dq1='{'h0, 'h1, 'h2}                                 //assigned frst three elements

0 After Insert dq1 SIZE = 4                               //Insert value 3 at index 3.

0 dq1='{'h0, 'h1, 'h2, 'h3}                                 //shows inserted value

0 After delete dq1 SIZE = 3                              //delete value at index 3

0 dq1='{'h0, 'h1, 'h2}                                         //shows dq1 after deletion

0 dq1 pop front = 0                                         //pop the front index of the queue

0 dq1='{'h1, 'h2}                                              //dq1 after element at index

0 is gone (popped) 0 dq1 pop back = 2       //pop the back (last) index of the queue

0 dq1='{'h1}                                                 //the last index/value is gone

0 push front dq1='{'h4, 'h1}                         //push at the front of the queue (value 4)

0 push back dq1='{'h4, 'h1, 'h5}                 //push at the end of the queue (value 5)

3.2 一些队列的方法

module dq;// int queue initializedint queue1 [$] = { 100,200,300,400,500 };int queue2 [$]; // int queueint tmp;
initial begin// Get frst item of queue1 (index 0) and store in tmptmp = queue1 [0];$display("queue1[0] = ",tmp);// Get last item of queue1 (index 4) and store in tmptmp = queue1 [$];$display("queue1[$] = ",tmp);// Copy all elements in queue1 into queue2queue2 = queue1;$display("queue2 = ",queue2);// Empty the queue1 (delete all items)queue1 = { };//OR you can also do 'queue1.delete( );'$display("queue1 = ",queue1);// Replace element at index 2 with 150queue2[2] = 150;$display("queue2 = ",queue2);// Inserts value 250 to index# 2queue2.insert (2, 250);$display("queue2 = ",queue2);queue2 = { queue2, 220 }; // Append 220 to queue2$display("queue2 = ",queue2);// Put 199 as the frst element of queue2queue2 = { 199, queue2 };$display("queue2 = ",queue2);// shift out 0th index (effectively 0th index deleted)queue2 = queue2 [1:$];$display("queue2 = ",queue2);// shift out last index (effectively last index deleted)queue2 = queue2 [0:$-1];$display("queue2 = ",queue2);// shift out frst and last itemqueue2 = queue2 [1:$-1];$display("queue2 = ",queue2);end
endmodule

Simulation log: queue1[0] = 100 //frst item of queue1 (index 0)

queue1[$] = 500 //last item of queue1 (index 4)

queue2 = '{100, 200, 300, 400, 500} //queue2 after queue2=queue1

queue1 = '{} //queue1 after emptying the queue

queue2 = '{100, 200, 150, 400, 500} //after changing queue2[2]=150

queue2 = '{100, 200, 250, 150, 400, 500} //after inserting '250' at index 2

queue2 = '{100, 200, 250, 150, 400, 500, 220} //appending queue2 with value 220

queue2 = '{199, 100, 200, 250, 150, 400, 500, 220} //putting 199 as the frst element

queue2 = '{100, 200, 250, 150, 400, 500, 220} //deleting/shifting frst element (i.e. '199')

queue2 = '{100, 200, 250, 150, 400, 500} //deleting/shifting last element (i.e. '220')

queue2 = '{200, 250, 150, 400} //delete/shift frst and last element

V C S S i m u l a t i o n R e p o r t

3. 队列 quene相关推荐

  1. 数据结构与算法——队列( Quene )

    队列( Quene ) 队列是一个有序列表,可以用数组或是链表来实现 遵循先入先出的原则.即:先存入队列的数据,要先取出.后存入的要后取出 1 数组模拟队列 队列本身是有序列表 因为队列的输出.输入是 ...

  2. Python多线程结合队列下载百度音乐的方法

    本文实例讲述了Python多线程结合队列下载百度音乐的方法.分享给大家供大家参考.具体如下: 一直想做个下载音乐的脚本,后来决定就拿百度音乐开刀,经过多次分析,终于制作了一个下载百度音乐的脚本,目前只 ...

  3. 数据结构:队列queue的实现及功能

    数据结构:队列quene的实现及功能 队列是数据结构的一种,数据存储方式为先进先出. 什么是队列:队列是一种特殊的线性表,特殊之处在于它只允许在表的前端(front)进行删除操作,而在表的后端(rea ...

  4. 线程进程,信号量,event事件,定时器,RLock,quene.Quene

    cpu进程,核线程,都是并发几个 全局解释锁,多核cpu优势削弱 RLock用法与Lock一致,但是可以允许开启多个锁,但是也要关闭后,别的进程才能打开 信号量也是锁但是是一次可以进去几个. Seam ...

  5. 三十二、图的创建深度优先遍历(DFS)广度优先遍历(BFS)

    一.图的基本介绍 为什么要有图 前面我们学了线性表和树 线性表局限于一个直接前驱和一个直接后继的关系 树也只能有一个直接前驱也就是父节点 当我们需要表示多对多的关系时, 这里我们就用到了图. 图的举例 ...

  6. java -jar 默认参数_JAVA入门学习指南,建议收藏

    如果你不懂Java 并且想认真学习接触了解一下Java的语法,建议把这篇文章收藏了,多看几遍,应该可以初步掌握Java 大部分基础的语法 . 让我们出发吧!ps:本文有点长,耐心阅读 . 〇,编程环境 ...

  7. Python爬虫案例演示:Python多线程、多进程、协程

    很多时候我们写了一个爬虫,实现了需求后会发现了很多值得改进的地方,其中很重要的一点就是爬取速度.本文 就通过代码讲解如何使用 多进程.多线程.协程 来提升爬取速度.注意:我们不深入介绍理论和原理,一切 ...

  8. 被迫毕业,面试 30 家公司,终于上岸了!

    大家好,我是君哥.今天分享一个老弟,被"毕业"后的求职经历. 在老东家干了 6 年,发展一般,很想出去,但是一直没有合适的机会,只好一边准备面试一边学习.让我没有想到的是,突然收到 ...

  9. NoSqlRedis

    文章目录 1 什么是NoSql 1.1 NoSql分类 2 Redis 2.1 Redis的认识 2.2 Redis特点(优势) 2.3 redis和memcache之间区别--面试题 2.4 red ...

最新文章

  1. Redux 入门教程(三):React-Redux 的用法
  2. WebClient.UploadValues Post中文乱码的解决方法
  3. cordova使用cordova-plugin-baidumaplocation插件获取定位
  4. Win32汇编基本编程框架
  5. OA中SSH+JBPM项目整合
  6. 【HNOI2019】部分题简要题解
  7. Golang 规则引擎原理及实战
  8. Ofbiz 电子商务平台
  9. internetreadfile读取数据长度为0_【完结】TensorFlow2.0 快速上手手册
  10. Git入门及上传项目到github中
  11. SpringMVC学习总结(三)——Controller接口详解(1)
  12. 【问题记录】python 函数 传入一个对象返回一个对象值得注意
  13. (转载)C/C++:sizeof('a')的值为什么不一样?
  14. GMS 地下水数值模拟
  15. 利用PDM实现机械制造业的信息集成
  16. 看中国魅力女强人 访格力电器总裁董明珠
  17. 调侃《HeadFirst设计模式》之装饰者模式
  18. python视频补帧_我花了三天写了手机补帧神器
  19. uni-app活动倒计时功能
  20. 智能驾驶仿真场景构建技术

热门文章

  1. 淘系高级技术专家的十年 | 既往不恋,纵情向前!
  2. .3dl.look.cube文件格式预设怎么使用?.3dl.look.cube文件怎么安装?
  3. c++语言编译器哪个好,C/C++语言编译器哪个好?几款好用的编译器推荐给你
  4. Pytorch学习-训练模型的3种方法
  5. 树梅派上搭建tensorflow+opencv+pi camera的物体识别
  6. 做社群运营,你复盘了吗?
  7. Tushare原学习文档(七 龙虎榜数据)
  8. 3、OmniGraffle系列-泳道图
  9. Linux环境配置编译orange,orangepi zero2编译环境搭建及传感器测试
  10. 产品开发专用的GPS超小型模块