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

📄 6.6.3c.htm

📁 建立《编译原理网络课程》的目的不仅使学生掌握构造编译程序的原理和技术
💻 HTM
字号:
<html>

<head>
<title>编译原理</title>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<link type="text/css" rel="stylesheet" href="../css/specification.css">
</head>

<body>

<table align=right width=300>
<tr>
<td><img src="../images/previous.gif" onmouseover="javascript:style.cursor='hand'" onclick="vbscript:window.location.href='6.6.3b.htm'"></td>
<td><img src="../images/next.gif" onmouseover="javascript:style.cursor='hand'" onclick="vbscript:window.location.href='6.6.4.htm'"></img></td>
</tr>
</table>
<br><br>

<table><tr><td>&nbsp&nbsp&nbsp&nbsp</td>
<td class="content">
<P>
下面要介绍的是P.J.Weinberger的C编译程序中实际用到的散列函数hashpjw,如图6.29所示。 
</p>
</td></tr></table>
    
<table><tr><td>&nbsp&nbsp&nbsp&nbsp</td>
<td class="content">
<P>
(1) <font color="#0000FF">#define</font> PRIME 211 <br>     
        &nbsp;&nbsp;&nbsp;  (2) <font color="#0000FF">#define</font> EOS '\0'<br>    
        &nbsp;&nbsp;&nbsp;  (3) <font color="#0000FF"> int</font> hashpjw(s) <br>     
        &nbsp;&nbsp;&nbsp;  (4) <font color="#0000FF"> char</font> *s; <br>     
        &nbsp;&nbsp;&nbsp;  (5){ <br>     
        &nbsp;&nbsp;&nbsp;  (6) &nbsp;&nbsp;&nbsp;<font color="#0000FF">char</font> *p; <br>     
        &nbsp;&nbsp;&nbsp;  (7) &nbsp;&nbsp;&nbsp;<font color="#0000FF">unsigned</font> h=0,g; <br>     
        &nbsp;&nbsp;&nbsp;  (8) &nbsp;&nbsp;&nbsp;<font color="#0000FF">for</font>(p=s;*p!=EOS;p=p+1){ <br>    
        &nbsp;&nbsp;&nbsp;  (9) &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;h=(h<<4)+(*p); <br>     
        &nbsp;&nbsp;&nbsp;  (10)&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <font color="#0000FF">if</font>(g=h&0xf0000000){     
        <br>    
        &nbsp;&nbsp;&nbsp;  (11)&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;  h= h^(g>>24); <br>     
        &nbsp;&nbsp;&nbsp;  (12) &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;h=h^g;      
        <br>    
        &nbsp;&nbsp;&nbsp;  (13)&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;} <br>     
        &nbsp;&nbsp;&nbsp;  (14)&nbsp;&nbsp;&nbsp;} <br>     
        &nbsp;&nbsp;&nbsp;  (15) &nbsp;&nbsp;<font color="#0000FF">return</font> h%PRIME; <br>     
        &nbsp;&nbsp;&nbsp;&nbsp; (16) } </p>     
      <p> &nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp; 
      <b>图6.29</b> 散列函数hashpjw </p>    
</td></tr></table>

<table><tr><td>&nbsp&nbsp&nbsp&nbsp</td>
<td class="content">
<P>
函数hashpjw是从h=0开始计算的。对每一个字符c,将h左移4位,并加上c,得到新的h。如果在32位的h的四位高序位(最左边的四位)中有1存在的话,那么把这四位提取出来并右移24位,把它与h进行模2相加,然后将四位高序位中曾是1的那些位置为0。经试验证明散列函数hashpiw对于用它建立的各种长度不同的符号表都取得了很好的效果。即在这样的符号表中字符串能均匀的落人到各个链表中去。不但如此,haShpjw本身的计算既快速又简洁。
</p>
</td></tr></table>


<br>
<table align=right width=300>
<tr>
<td><img src="../images/previous.gif" onmouseover="javascript:style.cursor='hand'" onclick="vbscript:window.location.href='6.6.3b.htm'"></td>
<td><img src="../images/next.gif" onmouseover="javascript:style.cursor='hand'" onclick="vbscript:window.location.href='6.6.4.htm'"></img></td>
</tr>
</table>

</BODY>

<html><script language="JavaScript">

⌨️ 快捷键说明

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