⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 00518.html

📁 这是一本关于verilog编程语言的教程,对学习verilog语言有帮助
💻 HTML
字号:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Frameset//EN">
<html>
<head>
<title>4.15.1 数组定位符方法</title>
    <meta http-equiv="Content-Type" content="text/html; charset=GB2312" />
    <meta name="generator" content="Doc-O-Matic" />
    <meta http-equiv="Content-Style-Type" content="text/css" />
    <link rel="STYLESHEET" href="default.css" type="text/css" />

<script type="text/javascript" src="scripts.js"></script>
</head>
<body class="Element700" onload="onBodyLoadEx('systemverilog31a.html', 'topic', '00518.html');" onmousedown="onBodyMouseDown();">

<!-- Begin Popups -->
<div class="Element801" id="popup00098">
<div class="Element800">
<div class="Element14">
链接</div>
<div class="Element11">
<div class="Element10">
<a href="00517.html" target="topic">4.15 数组处理方法</a></div>
</div>
</div>
</div>

<!-- End Popups -->

<!-- Begin Page Header -->
<div class="Element710" id="areafixed">
<div class="Element92">
<table width="100%" cellspacing="0" cellpadding="0">
<tr><td width="33%">
<div class="Element1">
<a href="#" onmousedown="showPopup(this, 'popup00098');"><img src="seealsolink.png" border="0" alt="" title=""></a> SystemVerilog 3.1a语言参考手册</div>
</td><td width="34%">
<div class="Element2">
</div>
</td><td width="33%">
<div class="Element90">
<a href="00517.html" target="topic"><img src="btn_prev_lightblue.gif" border="0" alt="Previous" title="Previous" onmouseover="switchImage(this, 'btn_prev_lightblue_hover.gif');" onmouseout="switchImage(this, 'btn_prev_lightblue.gif');"></a><a href="00517.html" target="topic"><img src="btn_up_lightblue.gif" border="0" alt="Up" title="Up" onmouseover="switchImage(this, 'btn_up_lightblue_hover.gif');" onmouseout="switchImage(this, 'btn_up_lightblue.gif');"></a><a href="00519.html" target="topic"><img src="btn_next_lightblue.gif" border="0" alt="Next" title="Next" onmouseover="switchImage(this, 'btn_next_lightblue_hover.gif');" onmouseout="switchImage(this, 'btn_next_lightblue.gif');"></a></div>
</td></tr></table><div class="Element5">
4.15.1 数组定位符方法</div>
</div>
</div>

<!-- End Page Header -->

<!-- Begin Client Area -->
<div class="Element720" id="areascroll">
<div class="Element721">

<!-- Begin Page Content -->
<div class="Element58">
<a name="描述"></a><div class="Element11">
<div class="Element10">
<p class="Element10">
数组定位符方法可以对任意非压缩数组(包括队列)进行操作,但它们的返回值是一个队列。这些定位符方法能够在数组中搜索满足一个指定表示式的元素(或它们的索引)。数组定位符方法以未指定的顺序遍历数组。表达式选项不应具有任何边带效应,否则,会出现不可预料的结果。&nbsp;</p>
<p class="Element10">
&nbsp;</p>
<p class="Element10">
这些方法的原型如下: </p><div class="Element170">
<a href="#" onclick="CopyElementToClipboard('code00175');">Copy Code</a></div>
<div class="Element13"><div class="Element12" id="code00175"><pre class="Element12"><span style="color: #0000FF">function</span> array_type<span style="color: #800080">[</span><span style="color: #FF0000">$</span><span style="color: #800080">]</span> locator_method<span style="color: #800080">(</span>array_type iterator<span style="color: #800080">=</span>item<span style="color: #800080">);</span>
<span style="color: #008000">// 与数组相同的类型</span></pre></div></div>
<p class="Element10">
或者 </p><div class="Element170">
<a href="#" onclick="CopyElementToClipboard('code00176');">Copy Code</a></div>
<div class="Element13"><div class="Element12" id="code00176"><pre class="Element12"><span style="color: #0000FF">function</span> int_or_index_type[<span style="color: #FF0000">$</span>] index_locator_method<span style="color: #800080">(</span>array_type iterator<span style="color: #800080">=</span>item<span style="color: #800080">);</span>
<span style="color: #008000">// 索引类型</span></pre></div></div>
<p class="Element10">
索引定位符方法为除联合数组外的所有数组返回一个<span style="color: #0000FF">int</span>队列,而对联合数组的操作返回一个与联合数组索引类型具有相同类型的队列。&nbsp;</p>
<p class="Element10">
&nbsp;</p>
<p class="Element10">
如果没有元素满足指定的表达式或者数组是空数组(在队列或动态数组的情况下),那么返回一个空队列。否则,这些方法返回一个包含满足表达式的所有元素的队列。索引定位符方法返回一个满足表达式的所有元素的索引的队列。使用<span style="color: #0000FF">with</span>子句指定的可选表达式必须能够计算成一个布尔值。&nbsp;</p>
<p class="Element10">
&nbsp;</p>
<p class="Element10">
定位符方法在数组元素上迭代,接着它被用来计算<span style="color: #0000FF">with</span>子句指定的表达式。迭代器自变量可选地指定变量的名字,<span style="color: #0000FF">with</span>表达式使用这个变量在每一次迭代上指定数组的元素。如果没有指定,那么使用缺省的元素名字。迭代器名字的范围就是<span style="color: #0000FF">with</span>表达式。&nbsp;</p>
<p class="Element10">
&nbsp;</p>
<p class="Element10">
支持下列的定位符方法(<span style="color: #0000FF">with</span>子句是强制的):</p>
<ul class="Element630">
<li class="Element600"><span style="color: #0000FF">find</span><span style="color: #800080">()</span>返回满足指定表达式的所有元素。</li>
<li class="Element600"><span style="color: #0000FF">find_index</span><span style="color: #800080">()</span>返回满足指定表达式的所有元素的索引。</li>
<li class="Element600"><span style="color: #0000FF">find_first</span><span style="color: #800080">()</span>返回满足指定表达式的第一个元素。</li>
<li class="Element600"><span style="color: #0000FF">find_first_index</span><span style="color: #800080">()</span>返回满足指定表达式的第一个元素的索引。</li>
<li class="Element600"><span style="color: #0000FF">find_last</span><span style="color: #800080">()</span>返回满足指定表达式的最后一个元素。</li>
<li class="Element600"><span style="color: #0000FF">find_last_index</span><span style="color: #800080">()</span>返回满足指定表达式的最后一个元素的索引。</li>
</ul><p class="Element10">
对于下列的定位符方法,如果为指定数组的元素类型定义了关系操作符,那么<span style="color: #0000FF">with</span>子句(<span style="color: #800080">&lt;</span>,<span style="color: #800080">&gt;</span>,<span style="color: #800080">==</span>)(以及它的表达式)可以被忽略。如果指定了一个<span style="color: #0000FF">with</span>子句,表达式类型的关系操作符(<span style="color: #800080">&lt;</span>,<span style="color: #800080">&gt;</span>,<span style="color: #800080">==</span>)必须被定义。</p>
<ul class="Element630">
<li class="Element600"><span style="color: #0000FF">min</span><span style="color: #800080">()</span>返回具有最小值或者它的表达式可以被计算成最小的元素。</li>
<li class="Element600"><span style="color: #0000FF">max</span><span style="color: #800080">()</span>返回具有最大值或者它的表达式可以被计算成最大的元素。</li>
<li class="Element600"><span style="color: #0000FF">unique</span><span style="color: #800080">()</span>返回具有唯一值或者它的表达式是唯一的所有元素。</li>
<li class="Element600"><span style="color: #0000FF">unique_index</span><span style="color: #800080">()</span>返回具有唯一值或者它的表达式是唯一的所有元素的索引。</li>
</ul><p class="Element10">
例子: </p><div class="Element170">
<a href="#" onclick="CopyElementToClipboard('code00177');">Copy Code</a></div>
<div class="Element13"><div class="Element12" id="code00177"><pre class="Element12"><span style="color: #0000FF">string</span> SA<span style="color: #800080">[</span><span style="color: #FF0000">10</span><span style="color: #800080">],</span> qs<span style="color: #800080">[</span><span style="color: #FF0000">$</span><span style="color: #800080">];</span>
<span style="color: #0000FF">int</span> IA<span style="color: #800080">[</span><span style="color: #FF0000">*</span><span style="color: #800080">],</span> qi<span style="color: #800080">[</span><span style="color: #FF0000">$</span><span style="color: #800080">];</span>

<span style="color: #008000">// 找到大于5的所有元素</span>
qi <span style="color: #800080">=</span> IA<span style="color: #800080">.</span><span style="color: #0000FF">find</span><span style="color: #800080">(</span>x<span style="color: #800080">)</span> <span style="color: #0000FF">with</span> <span style="color: #800080">(</span>x<span style="color: #800080">&gt;</span><span style="color: #FF0000">5</span><span style="color: #800080">);</span>

<span style="color: #008000">// 找到等于3的所有元素的索引。</span>
qi <span style="color: #800080">=</span> IA<span style="color: #800080">.</span><span style="color: #0000FF">find_index</span> <span style="color: #0000FF">with</span> <span style="color: #800080">(</span><span style="color: #0000FF">item</span><span style="color: #800080">==</span><span style="color: #FF0000">3</span><span style="color: #800080">);</span>

<span style="color: #008000">// 找到等于Bob的第一个元素</span>
qs <span style="color: #800080">=</span> SA<span style="color: #800080">.</span><span style="color: #0000FF">find_first with</span><span style="color: #800080">(</span><span style="color: #0000FF">item</span><span style="color: #800080">==</span><span style="color: #575D94">&quot;Bob&quot;</span><span style="color: #800080">);</span>

<span style="color: #008000">// 找到等于Henry的最后一个元素</span>
qs <span style="color: #800080">=</span> SA<span style="color: #800080">.</span><span style="color: #0000FF">find_last</span><span style="color: #800080">(</span>y<span style="color: #800080">)</span> <span style="color: #0000FF">with</span> <span style="color: #800080">(</span>y<span style="color: #800080">==</span><span style="color: #575D94">&quot;Henry&quot;</span><span style="color: #800080">);</span>

<span style="color: #008000">// 找到大于Z的最后一个元素的索引</span>
qi <span style="color: #800080">=</span> SA<span style="color: #800080">.</span><span style="color: #0000FF">find_last_index</span><span style="color: #800080">(</span>s<span style="color: #800080">)</span> <span style="color: #0000FF">with</span> <span style="color: #800080">(</span>s<span style="color: #800080">&gt;</span><span style="color: #575D94">&quot;Z&quot;</span><span style="color: #800080">);</span>

<span style="color: #008000">// 找到最小的元素</span>
qi <span style="color: #800080">=</span> IA<span style="color: #800080">.</span><span style="color: #0000FF">min</span><span style="color: #800080">;</span>

<span style="color: #008000">// 找到具有最大数值的字符串</span>
qs <span style="color: #800080">=</span> SA<span style="color: #800080">.</span><span style="color: #0000FF">max with</span><span style="color: #800080">(</span><span style="color: #0000FF">item</span><span style="color: #800080">.</span><span style="color: #0000FF">atoi</span><span style="color: #800080">);</span>

<span style="color: #008000">// 找到所有的唯一字符串元素</span>
qs <span style="color: #800080">=</span> SA<span style="color: #800080">.</span><span style="color: #0000FF">unique</span><span style="color: #800080">;</span>

<span style="color: #008000">// 找到以小写字母表示的所有唯一字符串</span>
qs <span style="color: #800080">=</span> SA.<span style="color: #0000FF">unique</span><span style="color: #800080">(</span>s<span style="color: #800080">)</span> <span style="color: #0000FF">with</span> <span style="color: #800080">(</span>s<span style="color: #800080">.</span><span style="color: #0000FF">tolower</span><span style="color: #800080">);</span></pre></div></div>
</div>
</div>
<a name="Group"></a><div class="Element14">
<a onclick="toggleVisibilityStored('Group');" class="a_Element14"><img src="sectionminus.png" border="0" alt="" title="" id="imgGroup">Group</a></div>
<div id="divGroup">
<div class="Element11">
<div class="Element10">
<p class="Element10">
<a href="00517.html" target="topic">4.15 数组处理方法</a></p></div>
</div>
</div>
<a name="Links"></a><div class="Element14">
<a onclick="toggleVisibilityStored('链接');" class="a_Element14"><img src="sectionminus.png" border="0" alt="" title="" id="img链接">链接</a></div>
<div id="div链接">
<div class="Element11">
<div class="Element10">
<a href="00517.html" target="topic">4.15 数组处理方法</a></div>
</div>
</div>
</div>
<!-- End Page Content -->

<!-- Begin Page Footer -->
<hr width="98%" align="center" size="1" color="#CCCCCC" />
<table align="center" cellpadding="0" cellspacing="0" border="0">
	<tbody>
		<tr height="10">
			<td></td>
		</tr>
		<tr align="center">
			<td>
<script type="text/javascript"><!--
google_ad_client = "pub-5266859600380184";
google_ad_width = 468;
google_ad_height = 60;
google_ad_format = "468x60_as";
google_ad_type = "text_image";
google_ad_channel ="";
google_page_url = document.location;
//--></script>
<script type="text/javascript"
  src="http://pagead2.googlesyndication.com/pagead/show_ads.js">
</script>
			</td>
		</tr>
		<tr height="15">
			<td></td>
		</tr>
		<tr align="center">
			<td>
				<font size=2>除非特别声明,原文版权归作者所有,如有转摘请注明原作者以及译者(<a href="http://www.fpgatech.net/"  target="_blank">FPGA技术网</a>)信息。<br />
如果您对本主题有何建议或意见,请登陆<a href="http://www.fpgatech.net/forum/forumdisplay.php?fid=18" target="_blank">FPGA开发者家园</a>提交,您的参与是我们前进的动力。</font>
<script language="javascript" type="text/javascript" src="http://js.users.51.la/195685.js"></script>
<noscript><a href="http://www.51.la/?195685" target="_blank"><img alt="&#x6211;&#x8981;&#x5566;&#x514D;&#x8D39;&#x7EDF;&#x8BA1;" src="http://img.users.51.la/195685.asp" style="border:none" /></a></noscript>
			</td>
		</tr>
	</tbody>
</table>

<!-- End Page Footer -->
</div>
</div>

<!-- End Client Area -->
</body></html>

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -