<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>庆亮的博客-webgame架构 &#187; HashTable</title>
	<atom:link href="http://www.qingliangcn.com/tag/hashtable/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.qingliangcn.com</link>
	<description>关注LAMP&#124;PHP源代码分析&#124;web架构&#124;PHP扩展&#124;Erlang&#124;服务端架构</description>
	<lastBuildDate>Fri, 10 Jun 2011 04:10:10 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
		<item>
		<title>PHP源代码分析之HashTable</title>
		<link>http://www.qingliangcn.com/2009/07/php%e6%ba%90%e4%bb%a3%e7%a0%81%e5%88%86%e6%9e%90%e4%b9%8bhashtable/</link>
		<comments>http://www.qingliangcn.com/2009/07/php%e6%ba%90%e4%bb%a3%e7%a0%81%e5%88%86%e6%9e%90%e4%b9%8bhashtable/#comments</comments>
		<pubDate>Sun, 26 Jul 2009 12:34:22 +0000</pubDate>
		<dc:creator>庆亮</dc:creator>
				<category><![CDATA[PHP内核与扩展]]></category>
		<category><![CDATA[HashTable]]></category>
		<category><![CDATA[php]]></category>

		<guid isPermaLink="false">http://www.nd21.com/?p=180</guid>
		<description><![CDATA[从PHP的zval结构体可以看出PHP使用HashTable来保存数组信息，PHP的HashTable使用了一些技巧，这些技巧是PHP高效数组操作的直接原因，源代码在PHP源代码目录的Zend/zend_hash.h&#160;&#160;Zend/zend_hash.c&#160;中。先来看看Zend&#160;HashTable的定义： 参数解释： nTableSize&#160;&#160;哈希表的大小 nTableMask&#160;&#160;数值上等于nTableSize&#160;-1&#160; nNumOfElements&#160;记录了当前HashTable中保存的记录数 nNextFreeElement&#160;&#160;指向下一个空闲的Bucket（之后有解释） pInternalPointer&#160; pListHead&#160;&#160;指向Bucket列表头部 pListTail&#160;&#160;&#160;&#160;指向Bucket列表尾部 arBuckets pDestructor&#160;&#160;&#160;一个函数指针，在HashTable发生增、删、改时自动调用，以完成某些清理工作。 persistent&#160;&#160;&#160;是否是持久 nApplyCount aApplyProtection 这两个参数用于放置在遍历时发生无限递归 &#160; &#160; 可以看到Bucket是一个双向链表，参数解释： h&#160;&#160;当元素使用数字索引时使用 nKeyLength&#160;&#160;当使用字符串索引时，该选项表示字符串索引的长度，而字符串则保存在Bucket结构体的最后一个元素arKey中。尽管arKey被声明为一个只有一个元素的数组，但是这并不妨碍我们在其中保存字符串，因为数组名可以看做指针，将arKey作为结构体的最后一个元素则Bucket结构体就成了变长结构体，而该变长结构体的长度则需要nKeyLength的辅助才能确定，这是C语言中的常见技巧。 pNext指向具有相同hash值的下一个bucket元素，无论HashTable设计的如何完美，冲突都是难免的。当采用字符串索引时，h成员变量存放的就是字符串索引的hash值。 pData指向保存的数据，如果数据本身又为指针，则用pDataPtr来保存对应的指针，而辞此时pData则指向自身结构体的pDataPtr。 接着看Zend&#160;HashTable的一些相关函数: #define&#160;HASH_PROTECT_RECURSION(ht) \ if&#160;((ht)-&#62;bApplyProtection)&#160;{ \ if&#160;((ht)-&#62;nApplyCount++&#160;&#62;=&#160;3)&#160;{ \ zend_error(E_ERROR,&#160;&#34;Nesting&#160;level&#160;too&#160;deep&#160;-&#160;recursive&#160;dependency?&#34;); \ } \ } 这个宏用于防止循环引用。 #define&#160;ZEND_HASH_IF_FULL_DO_RESIZE(ht) \ if&#160;((ht)-&#62;nNumOfElements&#160;&#62;&#160;(ht)-&#62;nTableSize)&#160;{ \ zend_hash_do_resize(ht); \ } 该宏用于判断HashTable中的元素是否超过了HashTable表的大小，如果超过则扩展HashTable的大小，查看zend_hash_do_resize的代码可以看到每次扩展大小都是成倍的。 看看Zend&#160;HashTable是如何初始化的 ZEND_API&#160;int&#160;_zend_hash_init(HashTable&#160;*ht,&#160;uint&#160;nSize,&#160;hash_func_t&#160;pHashFunction,&#160;dtor_func_t&#160;pDestructor,&#160;zend_bool&#160;persistent&#160;ZEND_FILE_LINE_DC) { uint&#160;i&#160;=&#160;3;&#160;//这里可以看出数组默认的初始化为8 Bucket&#160;**tmp; SET_INCONSISTENT(HT_OK);&#160;&#160;&#160;//&#160;用于调试&#160; if&#160;(nSize&#160;&#62;=&#160;0&#215;80000000)&#160;{ /*&#160;prevent&#160;overflow&#160;*/ ht-&#62;nTableSize&#160;=&#160;0&#215;80000000; }&#160;else&#160;{ while&#160;((1U&#160;&#60;&#60;&#160;i)&#160;&#60;&#160;nSize)&#160;{ i++; [...]]]></description>
			<content:encoded><![CDATA[<p class="p0" style="margin-top: 5pt; margin-bottom: 5pt"><span style="font-family: '宋体'; font-size: 10pt; mso-spacerun: 'yes'">从<font face="Times New Roman">PHP</font><font face="宋体">的</font><font face="Times New Roman">zval</font><font face="宋体">结构体可以看出</font></span><span style="font-family: 'Times New Roman'; font-size: 10pt; mso-spacerun: 'yes'">PHP使用HashTable来保存数组信息，PHP的HashTable使用了一些技巧，这些技巧是PHP高效数组操作的直接原因，源代码在PHP源代码目录的Zend/zend_hash.h&nbsp;&nbsp;Zend/zend_hash.c&nbsp;中。先来看看Zend&nbsp;HashTable的定义：</span></p>
<p class="p0" style="margin-top: 5pt; margin-bottom: 5pt"><span style="font-family: 'Times New Roman'; font-size: 10pt; mso-spacerun: 'yes'"><img width="536" height="257" alt="" src="http://www.nd21.com/blog2/blog2/uploads/php_lift_cycle_1 (6).png" /></span></p>
<p class="p0" style="margin-top: 5pt; margin-bottom: 5pt"><span style="font-family: 'Times New Roman'; font-size: 10pt; mso-spacerun: 'yes'"><span id="more-180"></span></span></p>
<p><span style="font-family: 'Times New Roman'; font-size: 10pt; mso-spacerun: 'yes'"></p>
<p class="p0" style="margin-top: 5pt; margin-bottom: 5pt"><span style="font-family: '宋体'; font-size: 10pt; mso-spacerun: 'yes'">参数解释：</span><span style="font-family: '宋体'; font-size: 10pt; mso-spacerun: 'yes'"><o:p></o:p></span></p>
<p class="p0" style="margin-top: 5pt; margin-bottom: 5pt"><span style="font-family: '宋体'; font-size: 10pt; mso-spacerun: 'yes'">nTableSize&nbsp;&nbsp;<font face="宋体">哈希表的大小</font></span><span style="font-family: '宋体'; font-size: 10pt; mso-spacerun: 'yes'"><o:p></o:p></span></p>
<p class="p0" style="margin-top: 5pt; margin-bottom: 5pt"><span style="font-family: '宋体'; font-size: 10pt; mso-spacerun: 'yes'">nTableMask&nbsp;&nbsp;<font face="宋体">数值上等于</font><font face="Times New Roman">nTableSize&nbsp;-1&nbsp;</font></span><span style="font-family: '宋体'; font-size: 10pt; mso-spacerun: 'yes'"><o:p></o:p></span></p>
<p class="p0" style="margin-top: 5pt; margin-bottom: 5pt"><span style="font-family: '宋体'; font-size: 10pt; mso-spacerun: 'yes'">nNumOfElements&nbsp;<font face="宋体">记录了当前</font><font face="Times New Roman">HashTable</font><font face="宋体">中保存的记录数</font></span><span style="font-family: '宋体'; font-size: 10pt; mso-spacerun: 'yes'"><o:p></o:p></span></p>
<p class="p0" style="margin-top: 5pt; margin-bottom: 5pt"><span style="font-family: '宋体'; font-size: 10pt; mso-spacerun: 'yes'">nNextFreeElement&nbsp;&nbsp;<font face="宋体">指向下一个空闲的</font><font face="Times New Roman">Bucket</font><font face="宋体">（之后有解释）</font></span><span style="font-family: '宋体'; font-size: 10pt; mso-spacerun: 'yes'"><o:p></o:p></span></p>
<p class="p0" style="margin-top: 5pt; margin-bottom: 5pt"><span style="font-family: '宋体'; font-size: 10pt; mso-spacerun: 'yes'">pInternalPointer&nbsp;</span><span style="font-family: '宋体'; font-size: 10pt; mso-spacerun: 'yes'"><o:p></o:p></span></p>
<p class="p0" style="margin-top: 5pt; margin-bottom: 5pt"><span style="font-family: '宋体'; font-size: 10pt; mso-spacerun: 'yes'">pListHead&nbsp;&nbsp;<font face="宋体">指向</font><font face="Times New Roman">Bucket</font><font face="宋体">列表头部</font></span><span style="font-family: '宋体'; font-size: 10pt; mso-spacerun: 'yes'"><o:p></o:p></span></p>
<p class="p0" style="margin-top: 5pt; margin-bottom: 5pt"><span style="font-family: '宋体'; font-size: 10pt; mso-spacerun: 'yes'">pListTail&nbsp;&nbsp;&nbsp;&nbsp;<font face="宋体">指向</font><font face="Times New Roman">Bucket</font><font face="宋体">列表尾部</font></span><span style="font-family: '宋体'; font-size: 10pt; mso-spacerun: 'yes'"><o:p></o:p></span></p>
<p class="p0" style="margin-top: 5pt; margin-bottom: 5pt"><span style="font-family: '宋体'; font-size: 10pt; mso-spacerun: 'yes'">arBuckets</span><span style="font-family: '宋体'; font-size: 10pt; mso-spacerun: 'yes'"><o:p></o:p></span></p>
<p class="p0" style="margin-top: 5pt; margin-bottom: 5pt"><span style="font-family: '宋体'; font-size: 10pt; mso-spacerun: 'yes'">pDestructor&nbsp;&nbsp;&nbsp;<font face="宋体">一个函数指针，在</font><font face="Times New Roman">HashTable</font><font face="宋体">发生增、删、改时自动调用，以完成某些清理工作。</font></span><span style="font-family: '宋体'; font-size: 10pt; mso-spacerun: 'yes'"><o:p></o:p></span></p>
<p class="p0" style="margin-top: 5pt; margin-bottom: 5pt"><span style="font-family: '宋体'; font-size: 10pt; mso-spacerun: 'yes'">persistent&nbsp;&nbsp;&nbsp;<font face="宋体">是否是持久</font></span><span style="font-family: '宋体'; font-size: 10pt; mso-spacerun: 'yes'"><o:p></o:p></span></p>
<p class="p0" style="margin-top: 5pt; margin-bottom: 5pt"><span style="font-family: '宋体'; font-size: 10pt; mso-spacerun: 'yes'">nApplyCount</span><span style="font-family: '宋体'; font-size: 10pt; mso-spacerun: 'yes'"><o:p></o:p></span></p>
<p class="p0" style="margin-top: 5pt; margin-bottom: 5pt"><span style="font-family: '宋体'; font-size: 10pt; mso-spacerun: 'yes'">aApplyProtection 这两个参数用于放置在遍历时发生无限递归</span></p>
<p class="p0" style="margin-top: 5pt; margin-bottom: 5pt">&nbsp;</p>
<p class="p0" style="margin-top: 5pt; margin-bottom: 5pt"><span style="font-family: '宋体'; font-size: 10pt; mso-spacerun: 'yes'"><img alt="" src="http://www.nd21.com/blog2/blog2/uploads/php_lift_cycle_1 (7).png" /></span></p>
<p class="p0" style="margin-top: 5pt; margin-bottom: 5pt">&nbsp;</p>
<p><span style="font-family: '宋体'; font-size: 10pt; mso-spacerun: 'yes'"></p>
<p class="p0" style="margin-top: 5pt; margin-bottom: 5pt"><span style="font-family: '宋体'; font-size: 10pt; mso-spacerun: 'yes'">可以看到<font face="Times New Roman">Bucket</font><font face="宋体">是一个双向链表，参数解释：</font></span><span style="font-family: '宋体'; font-size: 10pt; mso-spacerun: 'yes'"><o:p></o:p></span></p>
<p class="p0" style="margin-top: 5pt; margin-bottom: 5pt"><span style="font-family: '宋体'; font-size: 10pt; mso-spacerun: 'yes'">h&nbsp;&nbsp;<font face="宋体">当元素使用数字索引时使用</font></span><span style="font-family: '宋体'; font-size: 10pt; mso-spacerun: 'yes'"><o:p></o:p></span></p>
<p class="p0" style="margin-top: 5pt; margin-bottom: 5pt"><span style="font-family: '宋体'; font-size: 10pt; mso-spacerun: 'yes'">nKeyLength&nbsp;&nbsp;<font face="宋体">当使用字符串索引时，该选项表示字符串索引的长度，而字符串则保存在</font><font face="Times New Roman">Bucket</font><font face="宋体">结构体的最后一个元素</font><font face="Times New Roman">arKey</font><font face="宋体">中。尽管</font><font face="Times New Roman">arKey</font><font face="宋体">被声明为一个只有一个元素的数组，但是这并不妨碍我们在其中保存字符串，因为数组名可以看做指针，将</font><font face="Times New Roman">arKey</font><font face="宋体">作为结构体的最后一个元素则</font><font face="Times New Roman">Bucket</font><font face="宋体">结构体就成了变长结构体，而该变长结构体的长度则需要</font><font face="Times New Roman">nKeyLength</font><font face="宋体">的辅助才能确定，这是</font><font face="Times New Roman">C</font><font face="宋体">语言中的常见技巧。</font></span><span style="font-family: '宋体'; font-size: 10pt; mso-spacerun: 'yes'"><o:p></o:p></span></p>
<p class="p0" style="margin-top: 5pt; margin-bottom: 5pt"><span style="font-family: '宋体'; font-size: 10pt; mso-spacerun: 'yes'">pNext<font face="宋体">指向具有相同</font><font face="Times New Roman">hash</font><font face="宋体">值的下一个</font><font face="Times New Roman">bucket</font><font face="宋体">元素，无论</font><font face="Times New Roman">HashTable</font><font face="宋体">设计的如何完美，冲突都是难免的。当采用字符串索引时，</font><font face="Times New Roman">h</font><font face="宋体">成员变量存放的就是字符串索引的</font><font face="Times New Roman">hash</font><font face="宋体">值。</font></span><span style="font-family: '宋体'; font-size: 10pt; mso-spacerun: 'yes'"><o:p></o:p></span></p>
<p class="p0" style="margin-top: 5pt; margin-bottom: 5pt"><span style="font-family: '宋体'; font-size: 10pt; mso-spacerun: 'yes'">pData<font face="宋体">指向保存的数据，如果数据本身又为指针，则用</font><font face="Times New Roman">pDataPtr</font><font face="宋体">来保存对应的指针，而辞此时</font><font face="Times New Roman">pData</font><font face="宋体">则指向自身结构体的</font><font face="Times New Roman">pDataPtr</font><font face="宋体">。</font></span><span style="font-family: '宋体'; font-size: 10pt; mso-spacerun: 'yes'"><o:p></o:p></span></p>
<p class="p0" style="margin-top: 5pt; margin-bottom: 5pt"><span style="font-family: '宋体'; font-size: 10pt; mso-spacerun: 'yes'">接着看<font face="Times New Roman">Zend&nbsp;HashTable</font><font face="宋体">的一些相关函数</font><font face="Times New Roman">:</font></span><span style="font-family: '宋体'; font-size: 10pt; mso-spacerun: 'yes'"><o:p></o:p></span></p>
<p class="p0" style="margin-top: 5pt; margin-bottom: 5pt"><span style="font-family: '宋体'; font-size: 10pt; mso-spacerun: 'yes'"><o:p></o:p></span></p>
<p class="p0" style="margin-top: 0pt; margin-bottom: 0pt"><span style="font-family: 'Times New Roman'; color: rgb(0,0,255); font-size: 9pt; mso-spacerun: 'yes'">#define</span><span style="font-family: 'Times New Roman'; font-size: 9pt; mso-spacerun: 'yes'">&nbsp;HASH_PROTECT_RECURSION(ht)</span><span style="font-family: 'Times New Roman'; font-size: 9pt; mso-spacerun: 'yes'"> </span><span style="font-family: 'Times New Roman'; font-size: 9pt; mso-spacerun: 'yes'">\</span><span style="font-family: 'Times New Roman'; font-size: 9pt; mso-spacerun: 'yes'"><o:p></o:p></span></p>
<p class="p0" style="margin-top: 0pt; margin-bottom: 0pt"><span style="font-family: 'Times New Roman'; color: rgb(0,0,255); font-size: 9pt; mso-spacerun: 'yes'">if</span><span style="font-family: 'Times New Roman'; font-size: 9pt; mso-spacerun: 'yes'">&nbsp;((ht)-&gt;bApplyProtection)&nbsp;{</span><span style="font-family: 'Times New Roman'; font-size: 9pt; mso-spacerun: 'yes'"> </span><span style="font-family: 'Times New Roman'; font-size: 9pt; mso-spacerun: 'yes'">\</span><span style="font-family: 'Times New Roman'; font-size: 9pt; mso-spacerun: 'yes'"><o:p></o:p></span></p>
<p class="p0" style="margin-top: 0pt; margin-bottom: 0pt"><span style="font-family: 'Times New Roman'; color: rgb(0,0,255); font-size: 9pt; mso-spacerun: 'yes'">if</span><span style="font-family: 'Times New Roman'; font-size: 9pt; mso-spacerun: 'yes'">&nbsp;((ht)-&gt;nApplyCount++&nbsp;&gt;=&nbsp;3)&nbsp;{</span><span style="font-family: 'Times New Roman'; font-size: 9pt; mso-spacerun: 'yes'"> </span><span style="font-family: 'Times New Roman'; font-size: 9pt; mso-spacerun: 'yes'">\</span><span style="font-family: 'Times New Roman'; font-size: 9pt; mso-spacerun: 'yes'"><o:p></o:p></span></p>
<p class="p0" style="margin-top: 0pt; margin-bottom: 0pt"><span style="font-family: 'Times New Roman'; font-size: 9pt; mso-spacerun: 'yes'">zend_error(E_ERROR,&nbsp;</span><span style="font-family: 'Times New Roman'; color: rgb(163,21,21); font-size: 9pt; mso-spacerun: 'yes'">&quot;Nesting&nbsp;level&nbsp;too&nbsp;deep&nbsp;-&nbsp;recursive&nbsp;dependency?&quot;</span><span style="font-family: 'Times New Roman'; font-size: 9pt; mso-spacerun: 'yes'">);</span><span style="font-family: 'Times New Roman'; font-size: 9pt; mso-spacerun: 'yes'"> </span><span style="font-family: 'Times New Roman'; font-size: 9pt; mso-spacerun: 'yes'">\</span><span style="font-family: 'Times New Roman'; font-size: 9pt; mso-spacerun: 'yes'"><o:p></o:p></span></p>
<p class="p0" style="margin-top: 0pt; margin-bottom: 0pt"><span style="font-family: 'Times New Roman'; font-size: 9pt; mso-spacerun: 'yes'">}</span><span style="font-family: 'Times New Roman'; font-size: 9pt; mso-spacerun: 'yes'"> </span><span style="font-family: 'Times New Roman'; font-size: 9pt; mso-spacerun: 'yes'">\</span><span style="font-family: 'Times New Roman'; font-size: 9pt; mso-spacerun: 'yes'"><o:p></o:p></span></p>
<p class="p0" style="margin-top: 5pt; margin-bottom: 5pt"><span style="font-family: 'Times New Roman'; font-size: 9pt; mso-spacerun: 'yes'">}</span><span style="font-family: 'Times New Roman'; font-size: 9pt; mso-spacerun: 'yes'"><o:p></o:p></span></p>
<p class="p0" style="margin-top: 5pt; margin-bottom: 5pt"><span style="font-family: '宋体'; font-size: 9pt; mso-spacerun: 'yes'">这个宏用于防止循环引用。</span><span style="font-family: '宋体'; font-size: 9pt; mso-spacerun: 'yes'"><o:p></o:p></span></p>
<p class="p0" style="margin-top: 5pt; margin-bottom: 5pt"><span style="font-family: '宋体'; font-size: 9pt; mso-spacerun: 'yes'"><o:p></o:p></span></p>
<p class="p0" style="margin-top: 0pt; margin-bottom: 0pt"><span style="font-family: 'Times New Roman'; color: rgb(0,0,255); font-size: 9pt; mso-spacerun: 'yes'">#define</span><span style="font-family: 'Times New Roman'; font-size: 9pt; mso-spacerun: 'yes'">&nbsp;ZEND_HASH_IF_FULL_DO_RESIZE(ht)</span><span style="font-family: 'Times New Roman'; font-size: 9pt; mso-spacerun: 'yes'"> </span><span style="font-family: 'Times New Roman'; font-size: 9pt; mso-spacerun: 'yes'">\</span><span style="font-family: 'Times New Roman'; font-size: 9pt; mso-spacerun: 'yes'"><o:p></o:p></span></p>
<p class="p0" style="margin-top: 0pt; margin-bottom: 0pt"><span style="font-family: 'Times New Roman'; color: rgb(0,0,255); font-size: 9pt; mso-spacerun: 'yes'">if</span><span style="font-family: 'Times New Roman'; font-size: 9pt; mso-spacerun: 'yes'">&nbsp;((ht)-&gt;nNumOfElements&nbsp;&gt;&nbsp;(ht)-&gt;nTableSize)&nbsp;{</span><span style="font-family: 'Times New Roman'; font-size: 9pt; mso-spacerun: 'yes'"> </span><span style="font-family: 'Times New Roman'; font-size: 9pt; mso-spacerun: 'yes'">\</span><span style="font-family: 'Times New Roman'; font-size: 9pt; mso-spacerun: 'yes'"><o:p></o:p></span></p>
<p class="p0" style="margin-top: 0pt; margin-bottom: 0pt"><span style="font-family: 'Times New Roman'; font-size: 9pt; mso-spacerun: 'yes'">zend_hash_do_resize(ht);</span><span style="font-family: 'Times New Roman'; font-size: 9pt; mso-spacerun: 'yes'"> </span><span style="font-family: 'Times New Roman'; font-size: 9pt; mso-spacerun: 'yes'">\</span><span style="font-family: 'Times New Roman'; font-size: 9pt; mso-spacerun: 'yes'"><o:p></o:p></span></p>
<p class="p0" style="margin-top: 5pt; margin-bottom: 5pt"><span style="font-family: 'Times New Roman'; font-size: 9pt; mso-spacerun: 'yes'">}</span><span style="font-family: 'Times New Roman'; font-size: 9pt; mso-spacerun: 'yes'"><o:p></o:p></span></p>
<p class="p0" style="margin-top: 5pt; margin-bottom: 5pt"><span style="font-family: '宋体'; font-size: 9pt; mso-spacerun: 'yes'">该宏用于判断<font face="Times New Roman">HashTable</font><font face="宋体">中的元素是否超过了</font><font face="Times New Roman">HashTable</font><font face="宋体">表的大小，如果超过则扩展</font><font face="Times New Roman">HashTable</font><font face="宋体">的大小，查看</font></span><span style="font-family: 'Times New Roman'; font-size: 9pt; mso-spacerun: 'yes'">zend_hash_do_resize</span><span style="font-family: '宋体'; font-size: 9pt; mso-spacerun: 'yes'">的代码可以看到每次扩展大小都是成倍的。</span><span style="font-family: '宋体'; font-size: 9pt; mso-spacerun: 'yes'"><o:p></o:p></span></p>
<p class="p0" style="margin-top: 5pt; margin-bottom: 5pt"><span style="font-family: '宋体'; font-size: 9pt; mso-spacerun: 'yes'">看看<font face="Times New Roman">Zend&nbsp;HashTable</font><font face="宋体">是如何初始化的</font></span><span style="font-family: '宋体'; font-size: 9pt; mso-spacerun: 'yes'"><o:p></o:p></span></p>
<p class="p0" style="margin-top: 0pt; margin-bottom: 0pt"><span style="font-family: 'Times New Roman'; font-size: 9pt; mso-spacerun: 'yes'">ZEND_API&nbsp;</span><span style="font-family: 'Times New Roman'; color: rgb(0,0,255); font-size: 9pt; mso-spacerun: 'yes'">int</span><span style="font-family: 'Times New Roman'; font-size: 9pt; mso-spacerun: 'yes'">&nbsp;_zend_hash_init(HashTable&nbsp;*ht,&nbsp;uint&nbsp;nSize,&nbsp;hash_func_t&nbsp;pHashFunction,&nbsp;dtor_func_t&nbsp;pDestructor,&nbsp;zend_bool&nbsp;persistent&nbsp;ZEND_FILE_LINE_DC)</span><span style="font-family: 'Times New Roman'; font-size: 9pt; mso-spacerun: 'yes'"><o:p></o:p></span></p>
<p class="p0" style="margin-top: 0pt; margin-bottom: 0pt"><span style="font-family: 'Times New Roman'; font-size: 9pt; mso-spacerun: 'yes'">{</span><span style="font-family: 'Times New Roman'; font-size: 9pt; mso-spacerun: 'yes'"><o:p></o:p></span></p>
<p class="p0" style="margin-top: 0pt; margin-bottom: 0pt"><span style="font-family: 'Times New Roman'; font-size: 9pt; mso-spacerun: 'yes'">uint&nbsp;i&nbsp;=&nbsp;3;</span><span style="font-family: '宋体'; font-size: 9pt; mso-spacerun: 'yes'">&nbsp;//<font face="宋体">这里可以看出数组默认的初始化为</font><font face="Times New Roman">8</font></span><span style="font-family: 'Times New Roman'; font-size: 9pt; mso-spacerun: 'yes'"><o:p></o:p></span></p>
<p class="p0" style="margin-top: 0pt; margin-bottom: 0pt"><span style="font-family: 'Times New Roman'; font-size: 9pt; mso-spacerun: 'yes'">Bucket&nbsp;**tmp;</span><span style="font-family: 'Times New Roman'; font-size: 9pt; mso-spacerun: 'yes'"><o:p></o:p></span></p>
<p class="p0" style="margin-top: 0pt; margin-bottom: 0pt"><span style="font-family: 'Times New Roman'; font-size: 9pt; mso-spacerun: 'yes'"><o:p></o:p></span></p>
<p class="p0" style="margin-top: 0pt; margin-bottom: 0pt"><span style="font-family: 'Times New Roman'; font-size: 9pt; mso-spacerun: 'yes'">SET_INCONSISTENT(HT_OK);</span><span style="font-family: '宋体'; font-size: 9pt; mso-spacerun: 'yes'">&nbsp;&nbsp;&nbsp;//&nbsp;<font face="宋体">用于调试&nbsp;</font></span><span style="font-family: 'Times New Roman'; font-size: 9pt; mso-spacerun: 'yes'"><o:p></o:p></span></p>
<p class="p0" style="margin-top: 0pt; margin-bottom: 0pt"><span style="font-family: 'Times New Roman'; font-size: 9pt; mso-spacerun: 'yes'"><o:p></o:p></span></p>
<p class="p0" style="margin-top: 0pt; margin-bottom: 0pt"><span style="font-family: 'Times New Roman'; color: rgb(0,0,255); font-size: 9pt; mso-spacerun: 'yes'">if</span><span style="font-family: 'Times New Roman'; font-size: 9pt; mso-spacerun: 'yes'">&nbsp;(nSize&nbsp;&gt;=&nbsp;0&#215;80000000)&nbsp;{</span><span style="font-family: 'Times New Roman'; font-size: 9pt; mso-spacerun: 'yes'"><o:p></o:p></span></p>
<p class="p0" style="margin-top: 0pt; margin-bottom: 0pt"><span style="font-family: 'Times New Roman'; color: rgb(0,128,0); font-size: 9pt; mso-spacerun: 'yes'">/*&nbsp;prevent&nbsp;overflow&nbsp;*/</span><span style="font-family: 'Times New Roman'; color: rgb(0,128,0); font-size: 9pt; mso-spacerun: 'yes'"><o:p></o:p></span></p>
<p class="p0" style="margin-top: 0pt; margin-bottom: 0pt"><span style="font-family: 'Times New Roman'; font-size: 9pt; mso-spacerun: 'yes'">ht-&gt;nTableSize&nbsp;=&nbsp;0&#215;80000000;</span><span style="font-family: 'Times New Roman'; font-size: 9pt; mso-spacerun: 'yes'"><o:p></o:p></span></p>
<p class="p0" style="margin-top: 0pt; margin-bottom: 0pt"><span style="font-family: 'Times New Roman'; font-size: 9pt; mso-spacerun: 'yes'">}&nbsp;</span><span style="font-family: 'Times New Roman'; color: rgb(0,0,255); font-size: 9pt; mso-spacerun: 'yes'">else</span><span style="font-family: 'Times New Roman'; font-size: 9pt; mso-spacerun: 'yes'">&nbsp;{</span><span style="font-family: 'Times New Roman'; font-size: 9pt; mso-spacerun: 'yes'"><o:p></o:p></span></p>
<p class="p0" style="margin-top: 0pt; margin-bottom: 0pt"><span style="font-family: 'Times New Roman'; color: rgb(0,0,255); font-size: 9pt; mso-spacerun: 'yes'">while</span><span style="font-family: 'Times New Roman'; font-size: 9pt; mso-spacerun: 'yes'">&nbsp;((1U&nbsp;&lt;&lt;&nbsp;i)&nbsp;&lt;&nbsp;nSize)&nbsp;{</span><span style="font-family: 'Times New Roman'; font-size: 9pt; mso-spacerun: 'yes'"><o:p></o:p></span></p>
<p class="p0" style="margin-top: 0pt; margin-bottom: 0pt"><span style="font-family: 'Times New Roman'; font-size: 9pt; mso-spacerun: 'yes'">i++;</span><span style="font-family: 'Times New Roman'; font-size: 9pt; mso-spacerun: 'yes'"><o:p></o:p></span></p>
<p class="p0" style="margin-top: 0pt; margin-bottom: 0pt"><span style="font-family: 'Times New Roman'; font-size: 9pt; mso-spacerun: 'yes'">}</span><span style="font-family: 'Times New Roman'; font-size: 9pt; mso-spacerun: 'yes'"><o:p></o:p></span></p>
<p class="p0" style="margin-top: 0pt; margin-bottom: 0pt"><span style="font-family: 'Times New Roman'; font-size: 9pt; mso-spacerun: 'yes'">ht-&gt;nTableSize&nbsp;=&nbsp;1&nbsp;&lt;&lt;&nbsp;i;</span><span style="font-family: 'Times New Roman'; font-size: 9pt; mso-spacerun: 'yes'"><o:p></o:p></span></p>
<p class="p0" style="margin-top: 0pt; margin-bottom: 0pt"><span style="font-family: 'Times New Roman'; font-size: 9pt; mso-spacerun: 'yes'">}</span><span style="font-family: 'Times New Roman'; font-size: 9pt; mso-spacerun: 'yes'"><o:p></o:p></span></p>
<p class="p0" style="margin-top: 0pt; margin-bottom: 0pt"><span style="font-family: 'Times New Roman'; font-size: 9pt; mso-spacerun: 'yes'"><o:p></o:p></span></p>
<p class="p0" style="margin-top: 0pt; margin-bottom: 0pt"><span style="font-family: 'Times New Roman'; font-size: 9pt; mso-spacerun: 'yes'">ht-&gt;nTableMask&nbsp;=&nbsp;ht-&gt;nTableSize&nbsp;-&nbsp;1;</span><span style="font-family: 'Times New Roman'; font-size: 9pt; mso-spacerun: 'yes'"><o:p></o:p></span></p>
<p class="p0" style="margin-top: 0pt; margin-bottom: 0pt"><span style="font-family: 'Times New Roman'; font-size: 9pt; mso-spacerun: 'yes'">ht-&gt;pDestructor&nbsp;=&nbsp;pDestructor;</span><span style="font-family: 'Times New Roman'; font-size: 9pt; mso-spacerun: 'yes'"><o:p></o:p></span></p>
<p class="p0" style="margin-top: 0pt; margin-bottom: 0pt"><span style="font-family: 'Times New Roman'; font-size: 9pt; mso-spacerun: 'yes'">ht-&gt;arBuckets&nbsp;=&nbsp;NULL;</span><span style="font-family: 'Times New Roman'; font-size: 9pt; mso-spacerun: 'yes'"><o:p></o:p></span></p>
<p class="p0" style="margin-top: 0pt; margin-bottom: 0pt"><span style="font-family: 'Times New Roman'; font-size: 9pt; mso-spacerun: 'yes'">ht-&gt;pListHead&nbsp;=&nbsp;NULL;</span><span style="font-family: 'Times New Roman'; font-size: 9pt; mso-spacerun: 'yes'"><o:p></o:p></span></p>
<p class="p0" style="margin-top: 0pt; margin-bottom: 0pt"><span style="font-family: 'Times New Roman'; font-size: 9pt; mso-spacerun: 'yes'">ht-&gt;pListTail&nbsp;=&nbsp;NULL;</span><span style="font-family: 'Times New Roman'; font-size: 9pt; mso-spacerun: 'yes'"><o:p></o:p></span></p>
<p class="p0" style="margin-top: 0pt; margin-bottom: 0pt"><span style="font-family: 'Times New Roman'; font-size: 9pt; mso-spacerun: 'yes'">ht-&gt;nNumOfElements&nbsp;=&nbsp;0;</span><span style="font-family: 'Times New Roman'; font-size: 9pt; mso-spacerun: 'yes'"><o:p></o:p></span></p>
<p class="p0" style="margin-top: 0pt; margin-bottom: 0pt"><span style="font-family: 'Times New Roman'; font-size: 9pt; mso-spacerun: 'yes'">ht-&gt;nNextFreeElement&nbsp;=&nbsp;0;</span><span style="font-family: 'Times New Roman'; font-size: 9pt; mso-spacerun: 'yes'"><o:p></o:p></span></p>
<p class="p0" style="margin-top: 0pt; margin-bottom: 0pt"><span style="font-family: 'Times New Roman'; font-size: 9pt; mso-spacerun: 'yes'">ht-&gt;pInternalPointer&nbsp;=&nbsp;NULL;</span><span style="font-family: 'Times New Roman'; font-size: 9pt; mso-spacerun: 'yes'"><o:p></o:p></span></p>
<p class="p0" style="margin-top: 0pt; margin-bottom: 0pt"><span style="font-family: 'Times New Roman'; font-size: 9pt; mso-spacerun: 'yes'">ht-&gt;persistent&nbsp;=&nbsp;persistent;</span><span style="font-family: 'Times New Roman'; font-size: 9pt; mso-spacerun: 'yes'"><o:p></o:p></span></p>
<p class="p0" style="margin-top: 0pt; margin-bottom: 0pt"><span style="font-family: 'Times New Roman'; font-size: 9pt; mso-spacerun: 'yes'">ht-&gt;nApplyCount&nbsp;=&nbsp;0;</span><span style="font-family: 'Times New Roman'; font-size: 9pt; mso-spacerun: 'yes'"><o:p></o:p></span></p>
<p class="p0" style="margin-top: 0pt; margin-bottom: 0pt"><span style="font-family: 'Times New Roman'; font-size: 9pt; mso-spacerun: 'yes'">ht-&gt;bApplyProtection&nbsp;=&nbsp;1;</span><span style="font-family: 'Times New Roman'; font-size: 9pt; mso-spacerun: 'yes'"><o:p></o:p></span></p>
<p class="p0" style="margin-top: 0pt; margin-bottom: 0pt"><span style="font-family: 'Times New Roman'; font-size: 9pt; mso-spacerun: 'yes'"><o:p></o:p></span></p>
<p class="p0" style="margin-top: 0pt; margin-bottom: 0pt"><span style="font-family: 'Times New Roman'; color: rgb(0,128,0); font-size: 9pt; mso-spacerun: 'yes'">/*&nbsp;Uses&nbsp;ecalloc()&nbsp;so&nbsp;that&nbsp;Bucket*&nbsp;==&nbsp;NULL&nbsp;*/</span><span style="font-family: 'Times New Roman'; color: rgb(0,128,0); font-size: 9pt; mso-spacerun: 'yes'"><o:p></o:p></span></p>
<p class="p0" style="margin-top: 0pt; margin-bottom: 0pt"><span style="font-family: 'Times New Roman'; color: rgb(0,0,255); font-size: 9pt; mso-spacerun: 'yes'">if</span><span style="font-family: 'Times New Roman'; font-size: 9pt; mso-spacerun: 'yes'">&nbsp;(persistent)&nbsp;{</span><span style="font-family: 'Times New Roman'; font-size: 9pt; mso-spacerun: 'yes'"><o:p></o:p></span></p>
<p class="p0" style="margin-top: 0pt; margin-bottom: 0pt"><span style="font-family: 'Times New Roman'; font-size: 9pt; mso-spacerun: 'yes'">tmp&nbsp;=&nbsp;(Bucket&nbsp;**)&nbsp;calloc(ht-&gt;nTableSize,&nbsp;</span><span style="font-family: 'Times New Roman'; color: rgb(0,0,255); font-size: 9pt; mso-spacerun: 'yes'">sizeof</span><span style="font-family: 'Times New Roman'; font-size: 9pt; mso-spacerun: 'yes'">(Bucket&nbsp;*));</span><span style="font-family: 'Times New Roman'; font-size: 9pt; mso-spacerun: 'yes'"><o:p></o:p></span></p>
<p class="p0" style="margin-top: 0pt; margin-bottom: 0pt"><span style="font-family: 'Times New Roman'; color: rgb(0,0,255); font-size: 9pt; mso-spacerun: 'yes'">if</span><span style="font-family: 'Times New Roman'; font-size: 9pt; mso-spacerun: 'yes'">&nbsp;(!tmp)&nbsp;{</span><span style="font-family: 'Times New Roman'; font-size: 9pt; mso-spacerun: 'yes'"><o:p></o:p></span></p>
<p class="p0" style="margin-top: 0pt; margin-bottom: 0pt"><span style="font-family: 'Times New Roman'; color: rgb(0,0,255); font-size: 9pt; mso-spacerun: 'yes'">return</span><span style="font-family: 'Times New Roman'; font-size: 9pt; mso-spacerun: 'yes'">&nbsp;FAILURE;</span><span style="font-family: 'Times New Roman'; font-size: 9pt; mso-spacerun: 'yes'"><o:p></o:p></span></p>
<p class="p0" style="margin-top: 0pt; margin-bottom: 0pt"><span style="font-family: 'Times New Roman'; font-size: 9pt; mso-spacerun: 'yes'">}</span><span style="font-family: 'Times New Roman'; font-size: 9pt; mso-spacerun: 'yes'"><o:p></o:p></span></p>
<p class="p0" style="margin-top: 0pt; margin-bottom: 0pt"><span style="font-family: 'Times New Roman'; font-size: 9pt; mso-spacerun: 'yes'">ht-&gt;arBuckets&nbsp;=&nbsp;tmp;</span><span style="font-family: 'Times New Roman'; font-size: 9pt; mso-spacerun: 'yes'"><o:p></o:p></span></p>
<p class="p0" style="margin-top: 0pt; margin-bottom: 0pt"><span style="font-family: 'Times New Roman'; font-size: 9pt; mso-spacerun: 'yes'">}&nbsp;</span><span style="font-family: 'Times New Roman'; color: rgb(0,0,255); font-size: 9pt; mso-spacerun: 'yes'">else</span><span style="font-family: 'Times New Roman'; font-size: 9pt; mso-spacerun: 'yes'">&nbsp;{</span><span style="font-family: 'Times New Roman'; font-size: 9pt; mso-spacerun: 'yes'"><o:p></o:p></span></p>
<p class="p0" style="margin-top: 0pt; margin-bottom: 0pt"><span style="font-family: 'Times New Roman'; font-size: 9pt; mso-spacerun: 'yes'">tmp&nbsp;=&nbsp;(Bucket&nbsp;**)&nbsp;ecalloc_rel(ht-&gt;nTableSize,&nbsp;</span><span style="font-family: 'Times New Roman'; color: rgb(0,0,255); font-size: 9pt; mso-spacerun: 'yes'">sizeof</span><span style="font-family: 'Times New Roman'; font-size: 9pt; mso-spacerun: 'yes'">(Bucket&nbsp;*));</span><span style="font-family: 'Times New Roman'; font-size: 9pt; mso-spacerun: 'yes'"><o:p></o:p></span></p>
<p class="p0" style="margin-top: 0pt; margin-bottom: 0pt"><span style="font-family: 'Times New Roman'; color: rgb(0,0,255); font-size: 9pt; mso-spacerun: 'yes'">if</span><span style="font-family: 'Times New Roman'; font-size: 9pt; mso-spacerun: 'yes'">&nbsp;(tmp)&nbsp;{</span><span style="font-family: 'Times New Roman'; font-size: 9pt; mso-spacerun: 'yes'"><o:p></o:p></span></p>
<p class="p0" style="margin-top: 0pt; margin-bottom: 0pt"><span style="font-family: 'Times New Roman'; font-size: 9pt; mso-spacerun: 'yes'">ht-&gt;arBuckets&nbsp;=&nbsp;tmp;</span><span style="font-family: 'Times New Roman'; font-size: 9pt; mso-spacerun: 'yes'"><o:p></o:p></span></p>
<p class="p0" style="margin-top: 0pt; margin-bottom: 0pt"><span style="font-family: 'Times New Roman'; font-size: 9pt; mso-spacerun: 'yes'">}</span><span style="font-family: 'Times New Roman'; font-size: 9pt; mso-spacerun: 'yes'"><o:p></o:p></span></p>
<p class="p0" style="margin-top: 0pt; margin-bottom: 0pt"><span style="font-family: 'Times New Roman'; font-size: 9pt; mso-spacerun: 'yes'">}</span><span style="font-family: 'Times New Roman'; font-size: 9pt; mso-spacerun: 'yes'"><o:p></o:p></span></p>
<p class="p0" style="margin-top: 0pt; margin-bottom: 0pt"><span style="font-family: 'Times New Roman'; font-size: 9pt; mso-spacerun: 'yes'"><o:p></o:p></span></p>
<p class="p0" style="margin-top: 0pt; margin-bottom: 0pt"><span style="font-family: 'Times New Roman'; color: rgb(0,0,255); font-size: 9pt; mso-spacerun: 'yes'">return</span><span style="font-family: 'Times New Roman'; font-size: 9pt; mso-spacerun: 'yes'">&nbsp;SUCCESS;</span><span style="font-family: 'Times New Roman'; font-size: 9pt; mso-spacerun: 'yes'"><o:p></o:p></span></p>
<p class="p0" style="margin-top: 5pt; margin-bottom: 5pt"><span style="font-family: 'Times New Roman'; font-size: 9pt; mso-spacerun: 'yes'">}</span><span style="font-family: 'Times New Roman'; font-size: 9pt; mso-spacerun: 'yes'"><o:p></o:p></span></p>
<p class="p0" style="margin-top: 5pt; margin-bottom: 5pt"><span style="font-family: 'Times New Roman'; font-size: 9pt; mso-spacerun: 'yes'"><o:p></o:p></span></p>
<p class="p0" style="margin-top: 5pt; margin-bottom: 5pt"><span style="font-family: '宋体'; font-size: 9pt; mso-spacerun: 'yes'">可以看到<font face="Times New Roman">HashTable</font><font face="宋体">的大小被自动的初始化为</font><font face="Times New Roman">2</font><font face="宋体">的</font><font face="Times New Roman">n</font><font face="宋体">次方，</font></span><span style="font-family: 'Times New Roman'; font-size: 9pt; mso-spacerun: 'yes'">persistent</span><span style="font-family: '宋体'; font-size: 9pt; mso-spacerun: 'yes'">参数用于指示是否是&ldquo;永久&rdquo;方式分配内存，如果是则采用系统分配内存方法，否则采用<font face="Times New Roman">ZendMM</font><font face="宋体">的内存分配方式，关于</font><font face="Times New Roman">ZendMM</font><font face="宋体">请搜索</font></span><span style="font-family: '宋体'; color: rgb(0,0,255); font-size: 9pt; font-weight: bold; mso-spacerun: 'yes'">PHP<font face="宋体">内存管理</font></span><span style="font-family: '宋体'; font-size: 9pt; mso-spacerun: 'yes'">的相关内容。</span><span style="font-family: '宋体'; font-size: 9pt; mso-spacerun: 'yes'"><o:p></o:p></span></p>
<p class="p0" style="margin-top: 5pt; margin-bottom: 5pt"><span style="font-family: '宋体'; font-size: 9pt; mso-spacerun: 'yes'">申请得到的<font face="Times New Roman">bucket</font><font face="宋体">指针内存块都放在</font><font face="Times New Roman">HashTable</font><font face="宋体">的</font><font face="Times New Roman">arBucket</font><font face="宋体">中，可以把这段内存块看成一个数组，数组中的每个元素都指向一个实际的</font><font face="Times New Roman">bucket</font><font face="宋体">。</font></span><span style="font-family: '宋体'; font-size: 9pt; mso-spacerun: 'yes'"><o:p></o:p></span></p>
<p class="p0" style="margin-top: 5pt; margin-bottom: 5pt"><span style="font-family: '宋体'; font-size: 9pt; mso-spacerun: 'yes'"><o:p></o:p></span></p>
<p class="p0" style="margin-top: 0pt; margin-bottom: 0pt"><span style="font-family: 'Times New Roman'; font-size: 9pt; mso-spacerun: 'yes'">ZEND_API&nbsp;</span><span style="font-family: 'Times New Roman'; color: rgb(0,0,255); font-size: 9pt; mso-spacerun: 'yes'">int</span><span style="font-family: 'Times New Roman'; font-size: 9pt; mso-spacerun: 'yes'">&nbsp;_zend_hash_add_or_update(HashTable&nbsp;*ht,&nbsp;</span><span style="font-family: 'Times New Roman'; color: rgb(0,0,255); font-size: 9pt; mso-spacerun: 'yes'">char</span><span style="font-family: 'Times New Roman'; font-size: 9pt; mso-spacerun: 'yes'">&nbsp;*arKey,&nbsp;uint&nbsp;nKeyLength,&nbsp;</span><span style="font-family: 'Times New Roman'; color: rgb(0,0,255); font-size: 9pt; mso-spacerun: 'yes'">void</span><span style="font-family: 'Times New Roman'; font-size: 9pt; mso-spacerun: 'yes'">&nbsp;*pData,&nbsp;uint&nbsp;nDataSize,&nbsp;</span><span style="font-family: 'Times New Roman'; color: rgb(0,0,255); font-size: 9pt; mso-spacerun: 'yes'">void</span><span style="font-family: 'Times New Roman'; font-size: 9pt; mso-spacerun: 'yes'">&nbsp;**pDest,&nbsp;</span><span style="font-family: 'Times New Roman'; color: rgb(0,0,255); font-size: 9pt; mso-spacerun: 'yes'">int</span><span style="font-family: 'Times New Roman'; font-size: 9pt; mso-spacerun: 'yes'">&nbsp;flag&nbsp;ZEND_FILE_LINE_DC)</span><span style="font-family: 'Times New Roman'; font-size: 9pt; mso-spacerun: 'yes'"><o:p></o:p></span></p>
<p class="p0" style="margin-top: 0pt; margin-bottom: 0pt"><span style="font-family: 'Times New Roman'; font-size: 9pt; mso-spacerun: 'yes'">{</span><span style="font-family: 'Times New Roman'; font-size: 9pt; mso-spacerun: 'yes'"><o:p></o:p></span></p>
<p class="p0" style="margin-top: 0pt; margin-bottom: 0pt"><span style="font-family: 'Times New Roman'; font-size: 9pt; mso-spacerun: 'yes'">ulong&nbsp;h;</span><span style="font-family: 'Times New Roman'; font-size: 9pt; mso-spacerun: 'yes'"><o:p></o:p></span></p>
<p class="p0" style="margin-top: 0pt; margin-bottom: 0pt"><span style="font-family: 'Times New Roman'; font-size: 9pt; mso-spacerun: 'yes'">uint&nbsp;nIndex;</span><span style="font-family: 'Times New Roman'; font-size: 9pt; mso-spacerun: 'yes'"><o:p></o:p></span></p>
<p class="p0" style="margin-top: 0pt; margin-bottom: 0pt"><span style="font-family: 'Times New Roman'; font-size: 9pt; mso-spacerun: 'yes'">Bucket&nbsp;*p;</span><span style="font-family: 'Times New Roman'; font-size: 9pt; mso-spacerun: 'yes'"><o:p></o:p></span></p>
<p class="p0" style="margin-top: 0pt; margin-bottom: 0pt"><span style="font-family: 'Times New Roman'; font-size: 9pt; mso-spacerun: 'yes'"><o:p></o:p></span></p>
<p class="p0" style="margin-top: 0pt; margin-bottom: 0pt"><span style="font-family: 'Times New Roman'; font-size: 9pt; mso-spacerun: 'yes'">IS_CONSISTENT(ht);</span><span style="font-family: 'Times New Roman'; font-size: 9pt; mso-spacerun: 'yes'"><o:p></o:p></span></p>
<p class="p0" style="margin-top: 0pt; margin-bottom: 0pt"><span style="font-family: 'Times New Roman'; font-size: 9pt; mso-spacerun: 'yes'"><o:p></o:p></span></p>
<p class="p0" style="margin-top: 0pt; margin-bottom: 0pt"><span style="font-family: 'Times New Roman'; color: rgb(0,0,255); font-size: 9pt; mso-spacerun: 'yes'">if</span><span style="font-family: 'Times New Roman'; font-size: 9pt; mso-spacerun: 'yes'">&nbsp;(nKeyLength&nbsp;&lt;=&nbsp;0)&nbsp;{</span><span style="font-family: 'Times New Roman'; font-size: 9pt; mso-spacerun: 'yes'"><o:p></o:p></span></p>
<p class="p0" style="margin-top: 0pt; margin-bottom: 0pt"><span style="font-family: 'Times New Roman'; color: rgb(0,0,255); font-size: 9pt; mso-spacerun: 'yes'">#if</span><span style="font-family: 'Times New Roman'; font-size: 9pt; mso-spacerun: 'yes'">&nbsp;ZEND_DEBUG</span><span style="font-family: 'Times New Roman'; font-size: 9pt; mso-spacerun: 'yes'"><o:p></o:p></span></p>
<p class="p0" style="margin-top: 0pt; margin-bottom: 0pt"><span style="font-family: 'Times New Roman'; font-size: 9pt; mso-spacerun: 'yes'">ZEND_PUTS(</span><span style="font-family: 'Times New Roman'; color: rgb(163,21,21); font-size: 9pt; mso-spacerun: 'yes'">&quot;zend_hash_update:&nbsp;Can&#8217;t&nbsp;put&nbsp;in&nbsp;empty&nbsp;key\n&quot;</span><span style="font-family: 'Times New Roman'; font-size: 9pt; mso-spacerun: 'yes'">);</span><span style="font-family: 'Times New Roman'; font-size: 9pt; mso-spacerun: 'yes'"><o:p></o:p></span></p>
<p class="p0" style="margin-top: 0pt; margin-bottom: 0pt"><span style="font-family: 'Times New Roman'; color: rgb(0,0,255); font-size: 9pt; mso-spacerun: 'yes'">#endif</span><span style="font-family: 'Times New Roman'; color: rgb(0,0,255); font-size: 9pt; mso-spacerun: 'yes'"><o:p></o:p></span></p>
<p class="p0" style="margin-top: 0pt; margin-bottom: 0pt"><span style="font-family: 'Times New Roman'; color: rgb(0,0,255); font-size: 9pt; mso-spacerun: 'yes'">return</span><span style="font-family: 'Times New Roman'; font-size: 9pt; mso-spacerun: 'yes'">&nbsp;FAILURE;</span><span style="font-family: 'Times New Roman'; font-size: 9pt; mso-spacerun: 'yes'"><o:p></o:p></span></p>
<p class="p0" style="margin-top: 0pt; margin-bottom: 0pt"><span style="font-family: 'Times New Roman'; font-size: 9pt; mso-spacerun: 'yes'">}</span><span style="font-family: 'Times New Roman'; font-size: 9pt; mso-spacerun: 'yes'"><o:p></o:p></span></p>
<p class="p0" style="margin-top: 0pt; margin-bottom: 0pt"><span style="font-family: 'Times New Roman'; font-size: 9pt; mso-spacerun: 'yes'"><o:p></o:p></span></p>
<p class="p0" style="margin-top: 0pt; margin-bottom: 0pt"><span style="font-family: 'Times New Roman'; color: rgb(0,128,0); font-size: 9pt; mso-spacerun: 'yes'">//根据索引值和索引长度生成hash值</span><span style="font-family: 'Times New Roman'; color: rgb(0,128,0); font-size: 9pt; mso-spacerun: 'yes'"><o:p></o:p></span></p>
<p class="p0" style="margin-top: 0pt; margin-bottom: 0pt"><span style="font-family: 'Times New Roman'; font-size: 9pt; mso-spacerun: 'yes'">h&nbsp;=&nbsp;zend_inline_hash_func(arKey,&nbsp;nKeyLength);</span><span style="font-family: 'Times New Roman'; font-size: 9pt; mso-spacerun: 'yes'"><o:p></o:p></span></p>
<p class="p0" style="margin-top: 0pt; margin-bottom: 0pt"><span style="font-family: 'Times New Roman'; color: rgb(0,128,0); font-size: 9pt; mso-spacerun: 'yes'">//用hash值和nTableMask进行按位于运算，用于索引的快速定位</span><span style="font-family: 'Times New Roman'; color: rgb(0,128,0); font-size: 9pt; mso-spacerun: 'yes'"><o:p></o:p></span></p>
<p class="p0" style="margin-top: 0pt; margin-bottom: 0pt"><span style="font-family: 'Times New Roman'; color: rgb(0,128,0); font-size: 9pt; mso-spacerun: 'yes'">//按位于后的结果不可能大于nTableMask的值</span><span style="font-family: 'Times New Roman'; color: rgb(0,128,0); font-size: 9pt; mso-spacerun: 'yes'"><o:p></o:p></span></p>
<p class="p0" style="margin-top: 0pt; margin-bottom: 0pt"><span style="font-family: 'Times New Roman'; color: rgb(0,128,0); font-size: 9pt; mso-spacerun: 'yes'">//结合下面的代码，可以看出这段代码的巧妙</span><span style="font-family: 'Times New Roman'; color: rgb(0,128,0); font-size: 9pt; mso-spacerun: 'yes'"><o:p></o:p></span></p>
<p class="p0" style="margin-top: 0pt; margin-bottom: 0pt"><span style="font-family: 'Times New Roman'; font-size: 9pt; mso-spacerun: 'yes'">nIndex&nbsp;=&nbsp;h&nbsp;&amp;&nbsp;ht-&gt;nTableMask;</span><span style="font-family: 'Times New Roman'; font-size: 9pt; mso-spacerun: 'yes'"><o:p></o:p></span></p>
<p class="p0" style="margin-top: 0pt; margin-bottom: 0pt"><span style="font-family: 'Times New Roman'; font-size: 9pt; mso-spacerun: 'yes'">p&nbsp;=&nbsp;ht-&gt;arBuckets[nIndex];</span><span style="font-family: 'Times New Roman'; font-size: 9pt; mso-spacerun: 'yes'"><o:p></o:p></span></p>
<p class="p0" style="margin-top: 0pt; margin-bottom: 0pt"><span style="font-family: 'Times New Roman'; color: rgb(0,128,0); font-size: 9pt; mso-spacerun: 'yes'">//如果p不为NULL，则产生了hash冲突</span><span style="font-family: 'Times New Roman'; color: rgb(0,128,0); font-size: 9pt; mso-spacerun: 'yes'"><o:p></o:p></span></p>
<p class="p0" style="margin-top: 0pt; margin-bottom: 0pt"><span style="font-family: 'Times New Roman'; color: rgb(0,0,255); font-size: 9pt; mso-spacerun: 'yes'">while</span><span style="font-family: 'Times New Roman'; font-size: 9pt; mso-spacerun: 'yes'">&nbsp;(p&nbsp;!=&nbsp;NULL)&nbsp;{</span><span style="font-family: 'Times New Roman'; font-size: 9pt; mso-spacerun: 'yes'"><o:p></o:p></span></p>
<p class="p0" style="margin-top: 0pt; margin-bottom: 0pt"><span style="font-family: 'Times New Roman'; color: rgb(0,0,255); font-size: 9pt; mso-spacerun: 'yes'">if</span><span style="font-family: 'Times New Roman'; font-size: 9pt; mso-spacerun: 'yes'">&nbsp;((p-&gt;h&nbsp;==&nbsp;h)&nbsp;&amp;&amp;&nbsp;(p-&gt;nKeyLength&nbsp;==&nbsp;nKeyLength))&nbsp;{</span><span style="font-family: 'Times New Roman'; font-size: 9pt; mso-spacerun: 'yes'"><o:p></o:p></span></p>
<p class="p0" style="margin-top: 0pt; margin-bottom: 0pt"><span style="font-family: 'Times New Roman'; color: rgb(0,0,255); font-size: 9pt; mso-spacerun: 'yes'">if</span><span style="font-family: 'Times New Roman'; font-size: 9pt; mso-spacerun: 'yes'">&nbsp;(!memcmp(p-&gt;arKey,&nbsp;arKey,&nbsp;nKeyLength))&nbsp;{</span><span style="font-family: 'Times New Roman'; font-size: 9pt; mso-spacerun: 'yes'"><o:p></o:p></span></p>
<p class="p0" style="margin-top: 0pt; margin-bottom: 0pt"><span style="font-family: 'Times New Roman'; color: rgb(0,0,255); font-size: 9pt; mso-spacerun: 'yes'">if</span><span style="font-family: 'Times New Roman'; font-size: 9pt; mso-spacerun: 'yes'">&nbsp;(flag&nbsp;&amp;&nbsp;HASH_ADD)&nbsp;{</span><span style="font-family: 'Times New Roman'; font-size: 9pt; mso-spacerun: 'yes'"><o:p></o:p></span></p>
<p class="p0" style="margin-top: 0pt; margin-bottom: 0pt"><span style="font-family: 'Times New Roman'; color: rgb(0,0,255); font-size: 9pt; mso-spacerun: 'yes'">return</span><span style="font-family: 'Times New Roman'; font-size: 9pt; mso-spacerun: 'yes'">&nbsp;FAILURE;</span><span style="font-family: 'Times New Roman'; font-size: 9pt; mso-spacerun: 'yes'"><o:p></o:p></span></p>
<p class="p0" style="margin-top: 0pt; margin-bottom: 0pt"><span style="font-family: 'Times New Roman'; font-size: 9pt; mso-spacerun: 'yes'">}</span><span style="font-family: 'Times New Roman'; font-size: 9pt; mso-spacerun: 'yes'"><o:p></o:p></span></p>
<p class="p0" style="margin-top: 0pt; margin-bottom: 0pt"><span style="font-family: 'Times New Roman'; font-size: 9pt; mso-spacerun: 'yes'">HANDLE_BLOCK_INTERRUPTIONS();</span><span style="font-family: 'Times New Roman'; font-size: 9pt; mso-spacerun: 'yes'"><o:p></o:p></span></p>
<p class="p0" style="margin-top: 0pt; margin-bottom: 0pt"><span style="font-family: 'Times New Roman'; color: rgb(0,0,255); font-size: 9pt; mso-spacerun: 'yes'">#if</span><span style="font-family: 'Times New Roman'; font-size: 9pt; mso-spacerun: 'yes'">&nbsp;ZEND_DEBUG</span><span style="font-family: 'Times New Roman'; font-size: 9pt; mso-spacerun: 'yes'"><o:p></o:p></span></p>
<p class="p0" style="margin-top: 0pt; margin-bottom: 0pt"><span style="font-family: 'Times New Roman'; color: rgb(0,0,255); font-size: 9pt; mso-spacerun: 'yes'">if</span><span style="font-family: 'Times New Roman'; font-size: 9pt; mso-spacerun: 'yes'">&nbsp;(p-&gt;pData&nbsp;==&nbsp;pData)&nbsp;{</span><span style="font-family: 'Times New Roman'; font-size: 9pt; mso-spacerun: 'yes'"><o:p></o:p></span></p>
<p class="p0" style="margin-top: 0pt; margin-bottom: 0pt"><span style="font-family: 'Times New Roman'; font-size: 9pt; mso-spacerun: 'yes'">ZEND_PUTS(</span><span style="font-family: 'Times New Roman'; color: rgb(163,21,21); font-size: 9pt; mso-spacerun: 'yes'">&quot;Fatal&nbsp;error&nbsp;in&nbsp;zend_hash_update:&nbsp;p-&gt;pData&nbsp;==&nbsp;pData\n&quot;</span><span style="font-family: 'Times New Roman'; font-size: 9pt; mso-spacerun: 'yes'">);</span><span style="font-family: 'Times New Roman'; font-size: 9pt; mso-spacerun: 'yes'"><o:p></o:p></span></p>
<p class="p0" style="margin-top: 0pt; margin-bottom: 0pt"><span style="font-family: 'Times New Roman'; font-size: 9pt; mso-spacerun: 'yes'">HANDLE_UNBLOCK_INTERRUPTIONS();</span><span style="font-family: 'Times New Roman'; font-size: 9pt; mso-spacerun: 'yes'"><o:p></o:p></span></p>
<p class="p0" style="margin-top: 0pt; margin-bottom: 0pt"><span style="font-family: 'Times New Roman'; color: rgb(0,0,255); font-size: 9pt; mso-spacerun: 'yes'">return</span><span style="font-family: 'Times New Roman'; font-size: 9pt; mso-spacerun: 'yes'">&nbsp;FAILURE;</span><span style="font-family: 'Times New Roman'; font-size: 9pt; mso-spacerun: 'yes'"><o:p></o:p></span></p>
<p class="p0" style="margin-top: 0pt; margin-bottom: 0pt"><span style="font-family: 'Times New Roman'; font-size: 9pt; mso-spacerun: 'yes'">}</span><span style="font-family: 'Times New Roman'; font-size: 9pt; mso-spacerun: 'yes'"><o:p></o:p></span></p>
<p class="p0" style="margin-top: 0pt; margin-bottom: 0pt"><span style="font-family: 'Times New Roman'; color: rgb(0,0,255); font-size: 9pt; mso-spacerun: 'yes'">#endif</span><span style="font-family: 'Times New Roman'; color: rgb(0,0,255); font-size: 9pt; mso-spacerun: 'yes'"><o:p></o:p></span></p>
<p class="p0" style="margin-top: 0pt; margin-bottom: 0pt"><span style="font-family: 'Times New Roman'; color: rgb(0,128,0); font-size: 9pt; mso-spacerun: 'yes'">//到了这里就说明是更新操作</span><span style="font-family: 'Times New Roman'; color: rgb(0,128,0); font-size: 9pt; mso-spacerun: 'yes'"><o:p></o:p></span></p>
<p class="p0" style="margin-top: 0pt; margin-bottom: 0pt"><span style="font-family: 'Times New Roman'; color: rgb(0,128,0); font-size: 9pt; mso-spacerun: 'yes'">//先调用原来的析构函数执行清理</span><span style="font-family: 'Times New Roman'; color: rgb(0,128,0); font-size: 9pt; mso-spacerun: 'yes'"><o:p></o:p></span></p>
<p class="p0" style="margin-top: 0pt; margin-bottom: 0pt"><span style="font-family: 'Times New Roman'; color: rgb(0,0,255); font-size: 9pt; mso-spacerun: 'yes'">if</span><span style="font-family: 'Times New Roman'; font-size: 9pt; mso-spacerun: 'yes'">&nbsp;(ht-&gt;pDestructor)&nbsp;{</span><span style="font-family: 'Times New Roman'; font-size: 9pt; mso-spacerun: 'yes'"><o:p></o:p></span></p>
<p class="p0" style="margin-top: 0pt; margin-bottom: 0pt"><span style="font-family: 'Times New Roman'; font-size: 9pt; mso-spacerun: 'yes'">ht-&gt;pDestructor(p-&gt;pData);</span><span style="font-family: 'Times New Roman'; font-size: 9pt; mso-spacerun: 'yes'"><o:p></o:p></span></p>
<p class="p0" style="margin-top: 0pt; margin-bottom: 0pt"><span style="font-family: 'Times New Roman'; font-size: 9pt; mso-spacerun: 'yes'">}</span><span style="font-family: 'Times New Roman'; font-size: 9pt; mso-spacerun: 'yes'"><o:p></o:p></span></p>
<p class="p0" style="margin-top: 0pt; margin-bottom: 0pt"><span style="font-family: 'Times New Roman'; font-size: 9pt; mso-spacerun: 'yes'">UPDATE_DATA(ht,&nbsp;p,&nbsp;pData,&nbsp;nDataSize);</span><span style="font-family: 'Times New Roman'; font-size: 9pt; mso-spacerun: 'yes'"><o:p></o:p></span></p>
<p class="p0" style="margin-top: 0pt; margin-bottom: 0pt"><span style="font-family: 'Times New Roman'; color: rgb(0,0,255); font-size: 9pt; mso-spacerun: 'yes'">if</span><span style="font-family: 'Times New Roman'; font-size: 9pt; mso-spacerun: 'yes'">&nbsp;(pDest)&nbsp;{</span><span style="font-family: 'Times New Roman'; font-size: 9pt; mso-spacerun: 'yes'"><o:p></o:p></span></p>
<p class="p0" style="margin-top: 0pt; margin-bottom: 0pt"><span style="font-family: 'Times New Roman'; font-size: 9pt; mso-spacerun: 'yes'">*pDest&nbsp;=&nbsp;p-&gt;pData;</span><span style="font-family: 'Times New Roman'; font-size: 9pt; mso-spacerun: 'yes'"><o:p></o:p></span></p>
<p class="p0" style="margin-top: 0pt; margin-bottom: 0pt"><span style="font-family: 'Times New Roman'; font-size: 9pt; mso-spacerun: 'yes'">}</span><span style="font-family: 'Times New Roman'; font-size: 9pt; mso-spacerun: 'yes'"><o:p></o:p></span></p>
<p class="p0" style="margin-top: 0pt; margin-bottom: 0pt"><span style="font-family: 'Times New Roman'; font-size: 9pt; mso-spacerun: 'yes'">HANDLE_UNBLOCK_INTERRUPTIONS();</span><span style="font-family: 'Times New Roman'; font-size: 9pt; mso-spacerun: 'yes'"><o:p></o:p></span></p>
<p class="p0" style="margin-top: 0pt; margin-bottom: 0pt"><span style="font-family: 'Times New Roman'; color: rgb(0,0,255); font-size: 9pt; mso-spacerun: 'yes'">return</span><span style="font-family: 'Times New Roman'; font-size: 9pt; mso-spacerun: 'yes'">&nbsp;SUCCESS;</span><span style="font-family: 'Times New Roman'; font-size: 9pt; mso-spacerun: 'yes'"><o:p></o:p></span></p>
<p class="p0" style="margin-top: 0pt; margin-bottom: 0pt"><span style="font-family: 'Times New Roman'; font-size: 9pt; mso-spacerun: 'yes'">}</span><span style="font-family: 'Times New Roman'; font-size: 9pt; mso-spacerun: 'yes'"><o:p></o:p></span></p>
<p class="p0" style="margin-top: 0pt; margin-bottom: 0pt"><span style="font-family: 'Times New Roman'; font-size: 9pt; mso-spacerun: 'yes'">}</span><span style="font-family: 'Times New Roman'; font-size: 9pt; mso-spacerun: 'yes'"><o:p></o:p></span></p>
<p class="p0" style="margin-top: 0pt; margin-bottom: 0pt"><span style="font-family: 'Times New Roman'; font-size: 9pt; mso-spacerun: 'yes'">p&nbsp;=&nbsp;p-&gt;pNext;</span><span style="font-family: 'Times New Roman'; font-size: 9pt; mso-spacerun: 'yes'"><o:p></o:p></span></p>
<p class="p0" style="margin-top: 0pt; margin-bottom: 0pt"><span style="font-family: 'Times New Roman'; font-size: 9pt; mso-spacerun: 'yes'">}</span><span style="font-family: 'Times New Roman'; font-size: 9pt; mso-spacerun: 'yes'"><o:p></o:p></span></p>
<p class="p0" style="margin-top: 0pt; margin-bottom: 0pt"><span style="font-family: 'Times New Roman'; color: rgb(0,128,0); font-size: 9pt; mso-spacerun: 'yes'">//来到这里说明是增加元素操作</span><span style="font-family: 'Times New Roman'; color: rgb(0,128,0); font-size: 9pt; mso-spacerun: 'yes'"><o:p></o:p></span></p>
<p class="p0" style="margin-top: 0pt; margin-bottom: 0pt"><span style="font-family: 'Times New Roman'; font-size: 9pt; mso-spacerun: 'yes'">p&nbsp;=&nbsp;(Bucket&nbsp;*)&nbsp;pemalloc(</span><span style="font-family: 'Times New Roman'; color: rgb(0,0,255); font-size: 9pt; mso-spacerun: 'yes'">sizeof</span><span style="font-family: 'Times New Roman'; font-size: 9pt; mso-spacerun: 'yes'">(Bucket)&nbsp;-&nbsp;1&nbsp;+&nbsp;nKeyLength,&nbsp;ht-&gt;persistent);</span><span style="font-family: 'Times New Roman'; font-size: 9pt; mso-spacerun: 'yes'"><o:p></o:p></span></p>
<p class="p0" style="margin-top: 0pt; margin-bottom: 0pt"><span style="font-family: 'Times New Roman'; color: rgb(0,0,255); font-size: 9pt; mso-spacerun: 'yes'">if</span><span style="font-family: 'Times New Roman'; font-size: 9pt; mso-spacerun: 'yes'">&nbsp;(!p)&nbsp;{</span><span style="font-family: 'Times New Roman'; font-size: 9pt; mso-spacerun: 'yes'"><o:p></o:p></span></p>
<p class="p0" style="margin-top: 0pt; margin-bottom: 0pt"><span style="font-family: 'Times New Roman'; color: rgb(0,0,255); font-size: 9pt; mso-spacerun: 'yes'">return</span><span style="font-family: 'Times New Roman'; font-size: 9pt; mso-spacerun: 'yes'">&nbsp;FAILURE;</span><span style="font-family: 'Times New Roman'; font-size: 9pt; mso-spacerun: 'yes'"><o:p></o:p></span></p>
<p class="p0" style="margin-top: 0pt; margin-bottom: 0pt"><span style="font-family: 'Times New Roman'; font-size: 9pt; mso-spacerun: 'yes'">}</span><span style="font-family: 'Times New Roman'; font-size: 9pt; mso-spacerun: 'yes'"><o:p></o:p></span></p>
<p class="p0" style="margin-top: 0pt; margin-bottom: 0pt"><span style="font-family: 'Times New Roman'; font-size: 9pt; mso-spacerun: 'yes'">memcpy(p-&gt;arKey,&nbsp;arKey,&nbsp;nKeyLength);</span><span style="font-family: 'Times New Roman'; font-size: 9pt; mso-spacerun: 'yes'"><o:p></o:p></span></p>
<p class="p0" style="margin-top: 0pt; margin-bottom: 0pt"><span style="font-family: 'Times New Roman'; font-size: 9pt; mso-spacerun: 'yes'">p-&gt;nKeyLength&nbsp;=&nbsp;nKeyLength;</span><span style="font-family: 'Times New Roman'; font-size: 9pt; mso-spacerun: 'yes'"><o:p></o:p></span></p>
<p class="p0" style="margin-top: 0pt; margin-bottom: 0pt"><span style="font-family: 'Times New Roman'; font-size: 9pt; mso-spacerun: 'yes'">INIT_DATA(ht,&nbsp;p,&nbsp;pData,&nbsp;nDataSize);</span><span style="font-family: 'Times New Roman'; font-size: 9pt; mso-spacerun: 'yes'"><o:p></o:p></span></p>
<p class="p0" style="margin-top: 0pt; margin-bottom: 0pt"><span style="font-family: 'Times New Roman'; font-size: 9pt; mso-spacerun: 'yes'">p-&gt;h&nbsp;=&nbsp;h;</span><span style="font-family: 'Times New Roman'; font-size: 9pt; mso-spacerun: 'yes'"><o:p></o:p></span></p>
<p class="p0" style="margin-top: 0pt; margin-bottom: 0pt"><span style="font-family: 'Times New Roman'; font-size: 9pt; mso-spacerun: 'yes'">CONNECT_TO_BUCKET_DLLIST(p,&nbsp;ht-&gt;arBuckets[nIndex]);</span><span style="font-family: 'Times New Roman'; font-size: 9pt; mso-spacerun: 'yes'"><o:p></o:p></span></p>
<p class="p0" style="margin-top: 0pt; margin-bottom: 0pt"><span style="font-family: 'Times New Roman'; color: rgb(0,0,255); font-size: 9pt; mso-spacerun: 'yes'">if</span><span style="font-family: 'Times New Roman'; font-size: 9pt; mso-spacerun: 'yes'">&nbsp;(pDest)&nbsp;{</span><span style="font-family: 'Times New Roman'; font-size: 9pt; mso-spacerun: 'yes'"><o:p></o:p></span></p>
<p class="p0" style="margin-top: 0pt; margin-bottom: 0pt"><span style="font-family: 'Times New Roman'; font-size: 9pt; mso-spacerun: 'yes'">*pDest&nbsp;=&nbsp;p-&gt;pData;</span><span style="font-family: 'Times New Roman'; font-size: 9pt; mso-spacerun: 'yes'"><o:p></o:p></span></p>
<p class="p0" style="margin-top: 0pt; margin-bottom: 0pt"><span style="font-family: 'Times New Roman'; font-size: 9pt; mso-spacerun: 'yes'">}</span><span style="font-family: 'Times New Roman'; font-size: 9pt; mso-spacerun: 'yes'"><o:p></o:p></span></p>
<p class="p0" style="margin-top: 0pt; margin-bottom: 0pt"><span style="font-family: 'Times New Roman'; font-size: 9pt; mso-spacerun: 'yes'"><o:p></o:p></span></p>
<p class="p0" style="margin-top: 0pt; margin-bottom: 0pt"><span style="font-family: 'Times New Roman'; font-size: 9pt; mso-spacerun: 'yes'">HANDLE_BLOCK_INTERRUPTIONS();</span><span style="font-family: 'Times New Roman'; font-size: 9pt; mso-spacerun: 'yes'"><o:p></o:p></span></p>
<p class="p0" style="margin-top: 0pt; margin-bottom: 0pt"><span style="font-family: 'Times New Roman'; font-size: 9pt; mso-spacerun: 'yes'">CONNECT_TO_GLOBAL_DLLIST(p,&nbsp;ht);</span><span style="font-family: 'Times New Roman'; font-size: 9pt; mso-spacerun: 'yes'"><o:p></o:p></span></p>
<p class="p0" style="margin-top: 0pt; margin-bottom: 0pt"><span style="font-family: 'Times New Roman'; font-size: 9pt; mso-spacerun: 'yes'">ht-&gt;arBuckets[nIndex]&nbsp;=&nbsp;p;</span><span style="font-family: 'Times New Roman'; font-size: 9pt; mso-spacerun: 'yes'"><o:p></o:p></span></p>
<p class="p0" style="margin-top: 0pt; margin-bottom: 0pt"><span style="font-family: 'Times New Roman'; font-size: 9pt; mso-spacerun: 'yes'">HANDLE_UNBLOCK_INTERRUPTIONS();</span><span style="font-family: 'Times New Roman'; font-size: 9pt; mso-spacerun: 'yes'"><o:p></o:p></span></p>
<p class="p0" style="margin-top: 0pt; margin-bottom: 0pt"><span style="font-family: 'Times New Roman'; font-size: 9pt; mso-spacerun: 'yes'"><o:p></o:p></span></p>
<p class="p0" style="margin-top: 0pt; margin-bottom: 0pt"><span style="font-family: 'Times New Roman'; font-size: 9pt; mso-spacerun: 'yes'">ht-&gt;nNumOfElements++;</span><span style="font-family: 'Times New Roman'; font-size: 9pt; mso-spacerun: 'yes'"><o:p></o:p></span></p>
<p class="p0" style="margin-top: 0pt; margin-bottom: 0pt"><span style="font-family: 'Times New Roman'; font-size: 9pt; mso-spacerun: 'yes'">ZEND_HASH_IF_FULL_DO_RESIZE(ht);</span><span style="font-family: 'Times New Roman'; font-size: 9pt; mso-spacerun: 'yes'"> </span><span style="font-family: 'Times New Roman'; color: rgb(0,128,0); font-size: 9pt; mso-spacerun: 'yes'">/*&nbsp;If&nbsp;the&nbsp;Hash&nbsp;table&nbsp;is&nbsp;full,&nbsp;resize&nbsp;it&nbsp;*/</span><span style="font-family: 'Times New Roman'; color: rgb(0,128,0); font-size: 9pt; mso-spacerun: 'yes'"><o:p></o:p></span></p>
<p class="p0" style="margin-top: 0pt; margin-bottom: 0pt"><span style="font-family: 'Times New Roman'; color: rgb(0,0,255); font-size: 9pt; mso-spacerun: 'yes'">return</span><span style="font-family: 'Times New Roman'; font-size: 9pt; mso-spacerun: 'yes'">&nbsp;SUCCESS;</span><span style="font-family: 'Times New Roman'; font-size: 9pt; mso-spacerun: 'yes'"><o:p></o:p></span></p>
<p class="p0" style="margin-top: 5pt; margin-bottom: 5pt"><span style="font-family: 'Times New Roman'; font-size: 9pt; mso-spacerun: 'yes'">}</span><span style="font-family: 'Times New Roman'; font-size: 9pt; mso-spacerun: 'yes'"><o:p></o:p></span></p>
<p class="p0" style="margin-top: 5pt; margin-bottom: 5pt"><span style="font-family: '宋体'; font-size: 9pt; mso-spacerun: 'yes'">看到这里就可以发现多数代码都是类似的了，</span><span style="font-family: '宋体'; font-size: 9pt; mso-spacerun: 'yes'"><o:p></o:p></span></p>
<p class="p0" style="margin-top: 0pt; margin-bottom: 0pt"><span style="font-family: 'Times New Roman'; color: rgb(0,0,255); font-size: 9pt; mso-spacerun: 'yes'">#define</span><span style="font-family: 'Times New Roman'; font-size: 9pt; mso-spacerun: 'yes'">&nbsp;CONNECT_TO_BUCKET_DLLIST(element,&nbsp;list_head)</span><span style="font-family: 'Times New Roman'; font-size: 9pt; mso-spacerun: 'yes'"> </span><span style="font-family: 'Times New Roman'; font-size: 9pt; mso-spacerun: 'yes'">\</span><span style="font-family: 'Times New Roman'; font-size: 9pt; mso-spacerun: 'yes'"><o:p></o:p></span></p>
<p class="p0" style="margin-top: 0pt; margin-bottom: 0pt"><span style="font-family: 'Times New Roman'; font-size: 9pt; mso-spacerun: 'yes'">(element)-&gt;pNext&nbsp;=&nbsp;(list_head);</span><span style="font-family: 'Times New Roman'; font-size: 9pt; mso-spacerun: 'yes'"> </span><span style="font-family: 'Times New Roman'; font-size: 9pt; mso-spacerun: 'yes'">\</span><span style="font-family: 'Times New Roman'; font-size: 9pt; mso-spacerun: 'yes'"><o:p></o:p></span></p>
<p class="p0" style="margin-top: 0pt; margin-bottom: 0pt"><span style="font-family: 'Times New Roman'; font-size: 9pt; mso-spacerun: 'yes'">(element)-&gt;pLast&nbsp;=&nbsp;NULL;</span><span style="font-family: 'Times New Roman'; font-size: 9pt; mso-spacerun: 'yes'"> </span><span style="font-family: 'Times New Roman'; font-size: 9pt; mso-spacerun: 'yes'">\</span><span style="font-family: 'Times New Roman'; font-size: 9pt; mso-spacerun: 'yes'"><o:p></o:p></span></p>
<p class="p0" style="margin-top: 0pt; margin-bottom: 0pt"><span style="font-family: 'Times New Roman'; color: rgb(0,0,255); font-size: 9pt; mso-spacerun: 'yes'">if</span><span style="font-family: 'Times New Roman'; font-size: 9pt; mso-spacerun: 'yes'">&nbsp;((element)-&gt;pNext)&nbsp;{</span><span style="font-family: 'Times New Roman'; font-size: 9pt; mso-spacerun: 'yes'"> </span><span style="font-family: 'Times New Roman'; font-size: 9pt; mso-spacerun: 'yes'">\</span><span style="font-family: 'Times New Roman'; font-size: 9pt; mso-spacerun: 'yes'"><o:p></o:p></span></p>
<p class="p0" style="margin-top: 0pt; margin-bottom: 0pt"><span style="font-family: 'Times New Roman'; font-size: 9pt; mso-spacerun: 'yes'">(element)-&gt;pNext-&gt;pLast&nbsp;=&nbsp;(element);</span><span style="font-family: 'Times New Roman'; font-size: 9pt; mso-spacerun: 'yes'"> </span><span style="font-family: 'Times New Roman'; font-size: 9pt; mso-spacerun: 'yes'">\</span><span style="font-family: 'Times New Roman'; font-size: 9pt; mso-spacerun: 'yes'"><o:p></o:p></span></p>
<p class="p0" style="margin-top: 0pt; margin-bottom: 0pt"><span style="font-family: 'Times New Roman'; font-size: 9pt; mso-spacerun: 'yes'">}</span><span style="font-family: 'Times New Roman'; font-size: 9pt; mso-spacerun: 'yes'"><o:p></o:p></span></p>
<p class="p0" style="margin-top: 0pt; margin-bottom: 0pt"><span style="font-family: 'Times New Roman'; font-size: 9pt; mso-spacerun: 'yes'"><o:p></o:p></span></p>
<p class="p0" style="margin-top: 0pt; margin-bottom: 0pt"><span style="font-family: '宋体'; font-size: 9pt; mso-spacerun: 'yes'">这个宏用于将一个<font face="Times New Roman">bucket</font><font face="宋体">加入到</font><font face="Times New Roman">bucket</font><font face="宋体">链表中</font></span><span style="font-family: '宋体'; font-size: 9pt; mso-spacerun: 'yes'"><o:p></o:p></span></p>
<p class="p0" style="margin-top: 0pt; margin-bottom: 0pt"><span style="font-family: 'Times New Roman'; font-size: 9pt; mso-spacerun: 'yes'"><o:p></o:p></span></p>
<p class="p0" style="margin-top: 0pt; margin-bottom: 0pt"><span style="font-family: 'Times New Roman'; color: rgb(0,0,255); font-size: 9pt; mso-spacerun: 'yes'">#define</span><span style="font-family: 'Times New Roman'; font-size: 9pt; mso-spacerun: 'yes'">&nbsp;CONNECT_TO_GLOBAL_DLLIST(element,&nbsp;ht)</span><span style="font-family: 'Times New Roman'; font-size: 9pt; mso-spacerun: 'yes'"> </span><span style="font-family: 'Times New Roman'; font-size: 9pt; mso-spacerun: 'yes'">\</span><span style="font-family: 'Times New Roman'; font-size: 9pt; mso-spacerun: 'yes'"><o:p></o:p></span></p>
<p class="p0" style="margin-top: 0pt; margin-bottom: 0pt"><span style="font-family: 'Times New Roman'; font-size: 9pt; mso-spacerun: 'yes'">(element)-&gt;pListLast&nbsp;=&nbsp;(ht)-&gt;pListTail;</span><span style="font-family: 'Times New Roman'; font-size: 9pt; mso-spacerun: 'yes'"> </span><span style="font-family: 'Times New Roman'; font-size: 9pt; mso-spacerun: 'yes'">\</span><span style="font-family: 'Times New Roman'; font-size: 9pt; mso-spacerun: 'yes'"><o:p></o:p></span></p>
<p class="p0" style="margin-top: 0pt; margin-bottom: 0pt"><span style="font-family: 'Times New Roman'; font-size: 9pt; mso-spacerun: 'yes'">(ht)-&gt;pListTail&nbsp;=&nbsp;(element);</span><span style="font-family: 'Times New Roman'; font-size: 9pt; mso-spacerun: 'yes'"> </span><span style="font-family: 'Times New Roman'; font-size: 9pt; mso-spacerun: 'yes'">\</span><span style="font-family: 'Times New Roman'; font-size: 9pt; mso-spacerun: 'yes'"><o:p></o:p></span></p>
<p class="p0" style="margin-top: 0pt; margin-bottom: 0pt"><span style="font-family: 'Times New Roman'; font-size: 9pt; mso-spacerun: 'yes'">(element)-&gt;pListNext&nbsp;=&nbsp;NULL;</span><span style="font-family: 'Times New Roman'; font-size: 9pt; mso-spacerun: 'yes'"> </span><span style="font-family: 'Times New Roman'; font-size: 9pt; mso-spacerun: 'yes'">\</span><span style="font-family: 'Times New Roman'; font-size: 9pt; mso-spacerun: 'yes'"><o:p></o:p></span></p>
<p class="p0" style="margin-top: 0pt; margin-bottom: 0pt"><span style="font-family: 'Times New Roman'; color: rgb(0,0,255); font-size: 9pt; mso-spacerun: 'yes'">if</span><span style="font-family: 'Times New Roman'; font-size: 9pt; mso-spacerun: 'yes'">&nbsp;((element)-&gt;pListLast&nbsp;!=&nbsp;NULL)&nbsp;{</span><span style="font-family: 'Times New Roman'; font-size: 9pt; mso-spacerun: 'yes'"> </span><span style="font-family: 'Times New Roman'; font-size: 9pt; mso-spacerun: 'yes'">\</span><span style="font-family: 'Times New Roman'; font-size: 9pt; mso-spacerun: 'yes'"><o:p></o:p></span></p>
<p class="p0" style="margin-top: 0pt; margin-bottom: 0pt"><span style="font-family: 'Times New Roman'; font-size: 9pt; mso-spacerun: 'yes'">(element)-&gt;pListLast-&gt;pListNext&nbsp;=&nbsp;(element);</span><span style="font-family: 'Times New Roman'; font-size: 9pt; mso-spacerun: 'yes'"> </span><span style="font-family: 'Times New Roman'; font-size: 9pt; mso-spacerun: 'yes'">\</span><span style="font-family: 'Times New Roman'; font-size: 9pt; mso-spacerun: 'yes'"><o:p></o:p></span></p>
<p class="p0" style="margin-top: 0pt; margin-bottom: 0pt"><span style="font-family: 'Times New Roman'; font-size: 9pt; mso-spacerun: 'yes'">}</span><span style="font-family: 'Times New Roman'; font-size: 9pt; mso-spacerun: 'yes'"> </span><span style="font-family: 'Times New Roman'; font-size: 9pt; mso-spacerun: 'yes'">\</span><span style="font-family: 'Times New Roman'; font-size: 9pt; mso-spacerun: 'yes'"><o:p></o:p></span></p>
<p class="p0" style="margin-top: 0pt; margin-bottom: 0pt"><span style="font-family: 'Times New Roman'; color: rgb(0,0,255); font-size: 9pt; mso-spacerun: 'yes'">if</span><span style="font-family: 'Times New Roman'; font-size: 9pt; mso-spacerun: 'yes'">&nbsp;(!(ht)-&gt;pListHead)&nbsp;{</span><span style="font-family: 'Times New Roman'; font-size: 9pt; mso-spacerun: 'yes'"> </span><span style="font-family: 'Times New Roman'; font-size: 9pt; mso-spacerun: 'yes'">\</span><span style="font-family: 'Times New Roman'; font-size: 9pt; mso-spacerun: 'yes'"><o:p></o:p></span></p>
<p class="p0" style="margin-top: 0pt; margin-bottom: 0pt"><span style="font-family: 'Times New Roman'; font-size: 9pt; mso-spacerun: 'yes'">(ht)-&gt;pListHead&nbsp;=&nbsp;(element);</span><span style="font-family: 'Times New Roman'; font-size: 9pt; mso-spacerun: 'yes'"> </span><span style="font-family: 'Times New Roman'; font-size: 9pt; mso-spacerun: 'yes'">\</span><span style="font-family: 'Times New Roman'; font-size: 9pt; mso-spacerun: 'yes'"><o:p></o:p></span></p>
<p class="p0" style="margin-top: 0pt; margin-bottom: 0pt"><span style="font-family: 'Times New Roman'; font-size: 9pt; mso-spacerun: 'yes'">}</span><span style="font-family: 'Times New Roman'; font-size: 9pt; mso-spacerun: 'yes'"> </span><span style="font-family: 'Times New Roman'; font-size: 9pt; mso-spacerun: 'yes'">\</span><span style="font-family: 'Times New Roman'; font-size: 9pt; mso-spacerun: 'yes'"><o:p></o:p></span></p>
<p class="p0" style="margin-top: 0pt; margin-bottom: 0pt"><span style="font-family: 'Times New Roman'; color: rgb(0,0,255); font-size: 9pt; mso-spacerun: 'yes'">if</span><span style="font-family: 'Times New Roman'; font-size: 9pt; mso-spacerun: 'yes'">&nbsp;((ht)-&gt;pInternalPointer&nbsp;==&nbsp;NULL)&nbsp;{</span><span style="font-family: 'Times New Roman'; font-size: 9pt; mso-spacerun: 'yes'"> </span><span style="font-family: 'Times New Roman'; font-size: 9pt; mso-spacerun: 'yes'">\</span><span style="font-family: 'Times New Roman'; font-size: 9pt; mso-spacerun: 'yes'"><o:p></o:p></span></p>
<p class="p0" style="margin-top: 0pt; margin-bottom: 0pt"><span style="font-family: 'Times New Roman'; font-size: 9pt; mso-spacerun: 'yes'">(ht)-&gt;pInternalPointer&nbsp;=&nbsp;(element);</span><span style="font-family: 'Times New Roman'; font-size: 9pt; mso-spacerun: 'yes'"> </span><span style="font-family: 'Times New Roman'; font-size: 9pt; mso-spacerun: 'yes'">\</span><span style="font-family: 'Times New Roman'; font-size: 9pt; mso-spacerun: 'yes'"><o:p></o:p></span></p>
<p class="p0" style="margin-top: 5pt; margin-bottom: 5pt"><span style="font-family: 'Times New Roman'; font-size: 9pt; mso-spacerun: 'yes'">}</span><span style="font-family: 'Times New Roman'; font-size: 9pt; mso-spacerun: 'yes'"><o:p></o:p></span></p>
<p class="p0" style="margin-top: 5pt; margin-bottom: 5pt"><span style="font-family: '宋体'; font-size: 9pt; mso-spacerun: 'yes'">该宏用于将一个<font face="Times New Roman">bucket</font><font face="宋体">加入到</font><font face="Times New Roman">HashTable</font><font face="宋体">的链表中</font></span></p>
<p class="p0" style="margin-top: 5pt; margin-bottom: 5pt">&nbsp;</p>
<p><span style="font-family: '宋体'; font-size: 9pt; mso-spacerun: 'yes'"><font face="宋体"></p>
<p class="p0" style="margin-top: 5pt; margin-bottom: 5pt"><span style="font-family: '宋体'; font-size: 9pt; mso-spacerun: 'yes'">下面列出<font face="Times New Roman">zend&nbsp;</font><font face="宋体">封装好的函数或者宏：</font></span><span style="font-family: '宋体'; font-size: 9pt; mso-spacerun: 'yes'"><o:p></o:p></span></p>
<p class="p0" style="margin-top: 5pt; margin-bottom: 5pt"><span style="font-family: 'Times New Roman'; font-size: 9pt; mso-spacerun: 'yes'">zend_hash_add_empty_element</span><span style="font-family: '宋体'; font-size: 9pt; mso-spacerun: 'yes'">&nbsp;&nbsp;&nbsp;给数组增加一个空元素</span><span style="font-family: '宋体'; font-size: 9pt; mso-spacerun: 'yes'"><o:p></o:p></span></p>
<p class="p0" style="margin-top: 5pt; margin-bottom: 5pt"><span style="font-family: 'Times New Roman'; font-size: 9pt; mso-spacerun: 'yes'">zend_hash_do_resize</span><span style="font-family: '宋体'; font-size: 9pt; mso-spacerun: 'yes'">&nbsp;&nbsp;扩大哈希表的大小</span><span style="font-family: '宋体'; font-size: 9pt; mso-spacerun: 'yes'"><o:p></o:p></span></p>
<p class="p0" style="margin-top: 5pt; margin-bottom: 5pt"><span style="font-family: 'Times New Roman'; font-size: 9pt; mso-spacerun: 'yes'">_zend_hash_index_update_or_next_insert</span><span style="font-family: '宋体'; font-size: 9pt; mso-spacerun: 'yes'">&nbsp;插入或者更新指定数字索引的元素</span><span style="font-family: '宋体'; font-size: 9pt; mso-spacerun: 'yes'"><o:p></o:p></span></p>
<p class="p0" style="margin-top: 5pt; margin-bottom: 5pt"><span style="font-family: 'Times New Roman'; font-size: 9pt; mso-spacerun: 'yes'">zend_hash_del_key_or_index</span><span style="font-family: '宋体'; font-size: 9pt; mso-spacerun: 'yes'">&nbsp;&nbsp;根据索引删除<font face="Times New Roman">HashTable</font><font face="宋体">中的元素</font></span><span style="font-family: '宋体'; font-size: 9pt; mso-spacerun: 'yes'"><o:p></o:p></span></p>
<p class="p0" style="margin-top: 5pt; margin-bottom: 5pt"><span style="font-family: 'Times New Roman'; font-size: 9pt; mso-spacerun: 'yes'">zend_hash_apply</span><span style="font-family: '宋体'; font-size: 9pt; mso-spacerun: 'yes'">&nbsp;&nbsp;&nbsp;遍历<font face="Times New Roman">HashTable</font><font face="宋体">，注意当中使用了两个宏</font></span><span style="font-family: 'Times New Roman'; font-size: 9pt; mso-spacerun: 'yes'">HASH_PROTECT_RECURSION</span><span style="font-family: '宋体'; font-size: 9pt; mso-spacerun: 'yes'">&nbsp;和&nbsp;</span><span style="font-family: 'Times New Roman'; font-size: 9pt; mso-spacerun: 'yes'">HASH_UNPROTECT_RECURSION</span><span style="font-family: '宋体'; font-size: 9pt; mso-spacerun: 'yes'">来防止遍历陷入死循环。</span><span style="font-family: '宋体'; font-size: 9pt; mso-spacerun: 'yes'"><o:p></o:p></span></p>
<p class="p0" style="margin-top: 0pt; margin-bottom: 0pt"><span style="font-family: 'Times New Roman'; color: rgb(0,0,255); font-size: 9pt; mso-spacerun: 'yes'">#define</span><span style="font-family: 'Times New Roman'; font-size: 9pt; mso-spacerun: 'yes'">&nbsp;HASH_PROTECT_RECURSION(ht)</span><span style="font-family: 'Times New Roman'; font-size: 9pt; mso-spacerun: 'yes'"> </span><span style="font-family: 'Times New Roman'; font-size: 9pt; mso-spacerun: 'yes'">\</span><span style="font-family: 'Times New Roman'; font-size: 9pt; mso-spacerun: 'yes'"><o:p></o:p></span></p>
<p class="p0" style="margin-top: 0pt; margin-bottom: 0pt"><span style="font-family: 'Times New Roman'; color: rgb(0,0,255); font-size: 9pt; mso-spacerun: 'yes'">if</span><span style="font-family: 'Times New Roman'; font-size: 9pt; mso-spacerun: 'yes'">&nbsp;((ht)-&gt;bApplyProtection)&nbsp;{</span><span style="font-family: 'Times New Roman'; font-size: 9pt; mso-spacerun: 'yes'"> </span><span style="font-family: 'Times New Roman'; font-size: 9pt; mso-spacerun: 'yes'">\</span><span style="font-family: 'Times New Roman'; font-size: 9pt; mso-spacerun: 'yes'"><o:p></o:p></span></p>
<p class="p0" style="margin-top: 0pt; margin-bottom: 0pt"><span style="font-family: 'Times New Roman'; color: rgb(0,0,255); font-size: 9pt; mso-spacerun: 'yes'">if</span><span style="font-family: 'Times New Roman'; font-size: 9pt; mso-spacerun: 'yes'">&nbsp;((ht)-&gt;nApplyCount++&nbsp;&gt;=&nbsp;3)&nbsp;{</span><span style="font-family: 'Times New Roman'; font-size: 9pt; mso-spacerun: 'yes'"> </span><span style="font-family: 'Times New Roman'; font-size: 9pt; mso-spacerun: 'yes'">\</span><span style="font-family: 'Times New Roman'; font-size: 9pt; mso-spacerun: 'yes'"><o:p></o:p></span></p>
<p class="p0" style="margin-top: 0pt; margin-bottom: 0pt"><span style="font-family: 'Times New Roman'; font-size: 9pt; mso-spacerun: 'yes'">zend_error(E_ERROR,&nbsp;</span><span style="font-family: 'Times New Roman'; color: rgb(163,21,21); font-size: 9pt; mso-spacerun: 'yes'">&quot;Nesting&nbsp;level&nbsp;too&nbsp;deep&nbsp;-&nbsp;recursive&nbsp;dependency?&quot;</span><span style="font-family: 'Times New Roman'; font-size: 9pt; mso-spacerun: 'yes'">);</span><span style="font-family: 'Times New Roman'; font-size: 9pt; mso-spacerun: 'yes'"> </span><span style="font-family: 'Times New Roman'; font-size: 9pt; mso-spacerun: 'yes'">\</span><span style="font-family: 'Times New Roman'; font-size: 9pt; mso-spacerun: 'yes'"><o:p></o:p></span></p>
<p class="p0" style="margin-top: 0pt; margin-bottom: 0pt"><span style="font-family: 'Times New Roman'; font-size: 9pt; mso-spacerun: 'yes'">}</span><span style="font-family: 'Times New Roman'; font-size: 9pt; mso-spacerun: 'yes'"> </span><span style="font-family: 'Times New Roman'; font-size: 9pt; mso-spacerun: 'yes'">\</span><span style="font-family: 'Times New Roman'; font-size: 9pt; mso-spacerun: 'yes'"><o:p></o:p></span></p>
<p class="p0" style="margin-top: 0pt; margin-bottom: 0pt"><span style="font-family: 'Times New Roman'; font-size: 9pt; mso-spacerun: 'yes'">}</span><span style="font-family: 'Times New Roman'; font-size: 9pt; mso-spacerun: 'yes'"><o:p></o:p></span></p>
<p class="p0" style="margin-top: 0pt; margin-bottom: 0pt"><span style="font-family: 'Times New Roman'; font-size: 9pt; mso-spacerun: 'yes'"><o:p></o:p></span></p>
<p class="p0" style="margin-top: 0pt; margin-bottom: 0pt"><span style="font-family: 'Times New Roman'; font-size: 9pt; mso-spacerun: 'yes'"><o:p></o:p></span></p>
<p class="p0" style="margin-top: 0pt; margin-bottom: 0pt"><span style="font-family: 'Times New Roman'; color: rgb(0,0,255); font-size: 9pt; mso-spacerun: 'yes'">#define</span><span style="font-family: 'Times New Roman'; font-size: 9pt; mso-spacerun: 'yes'">&nbsp;HASH_UNPROTECT_RECURSION(ht)</span><span style="font-family: 'Times New Roman'; font-size: 9pt; mso-spacerun: 'yes'"> </span><span style="font-family: 'Times New Roman'; font-size: 9pt; mso-spacerun: 'yes'">\</span><span style="font-family: 'Times New Roman'; font-size: 9pt; mso-spacerun: 'yes'"><o:p></o:p></span></p>
<p class="p0" style="margin-top: 0pt; margin-bottom: 0pt"><span style="font-family: 'Times New Roman'; color: rgb(0,0,255); font-size: 9pt; mso-spacerun: 'yes'">if</span><span style="font-family: 'Times New Roman'; font-size: 9pt; mso-spacerun: 'yes'">&nbsp;((ht)-&gt;bApplyProtection)&nbsp;{</span><span style="font-family: 'Times New Roman'; font-size: 9pt; mso-spacerun: 'yes'"> </span><span style="font-family: 'Times New Roman'; font-size: 9pt; mso-spacerun: 'yes'">\</span><span style="font-family: 'Times New Roman'; font-size: 9pt; mso-spacerun: 'yes'"><o:p></o:p></span></p>
<p class="p0" style="margin-top: 0pt; margin-bottom: 0pt"><span style="font-family: 'Times New Roman'; font-size: 9pt; mso-spacerun: 'yes'">(ht)-&gt;nApplyCount&#8211;;</span><span style="font-family: 'Times New Roman'; font-size: 9pt; mso-spacerun: 'yes'"> </span><span style="font-family: 'Times New Roman'; font-size: 9pt; mso-spacerun: 'yes'">\</span><span style="font-family: 'Times New Roman'; font-size: 9pt; mso-spacerun: 'yes'"><o:p></o:p></span></p>
<p class="p0" style="margin-top: 0pt; margin-bottom: 0pt"><span style="font-family: 'Times New Roman'; font-size: 9pt; mso-spacerun: 'yes'">}</span><span style="font-family: 'Times New Roman'; font-size: 9pt; mso-spacerun: 'yes'"><o:p></o:p></span></p>
<p class="p0" style="margin-top: 5pt; margin-bottom: 5pt"><span style="font-family: '宋体'; font-size: 9pt; mso-spacerun: 'yes'"><o:p></o:p></span></p>
<p class="p0" style="margin-top: 5pt; margin-bottom: 5pt"><span style="font-family: 'Times New Roman'; font-size: 9pt; mso-spacerun: 'yes'">zend_hash_reverse_apply</span><span style="font-family: '宋体'; font-size: 9pt; mso-spacerun: 'yes'">&nbsp;&nbsp;反向遍历<font face="Times New Roman">HashTable</font></span><span style="font-family: '宋体'; font-size: 9pt; mso-spacerun: 'yes'"><o:p></o:p></span></p>
<p class="p0" style="margin-top: 5pt; margin-bottom: 5pt"><span style="font-family: 'Times New Roman'; font-size: 9pt; mso-spacerun: 'yes'">zend_hash_copy</span><span style="font-family: '宋体'; font-size: 9pt; mso-spacerun: 'yes'">&nbsp;&nbsp;拷贝</span><span style="font-family: '宋体'; font-size: 9pt; mso-spacerun: 'yes'"><o:p></o:p></span></p>
<p class="p0" style="margin-top: 5pt; margin-bottom: 5pt"><span style="font-family: 'Times New Roman'; font-size: 9pt; mso-spacerun: 'yes'">_zend_hash_merge</span><span style="font-family: '宋体'; font-size: 9pt; mso-spacerun: 'yes'">&nbsp;&nbsp;合并</span><span style="font-family: '宋体'; font-size: 9pt; mso-spacerun: 'yes'"><o:p></o:p></span></p>
<p class="p0" style="margin-top: 5pt; margin-bottom: 5pt"><span style="font-family: 'Times New Roman'; font-size: 9pt; mso-spacerun: 'yes'">zend_hash_find</span><span style="font-family: '宋体'; font-size: 9pt; mso-spacerun: 'yes'">&nbsp;&nbsp;字符串索引方式查找</span><span style="font-family: '宋体'; font-size: 9pt; mso-spacerun: 'yes'"><o:p></o:p></span></p>
<p class="p0" style="margin-top: 5pt; margin-bottom: 5pt"><span style="font-family: 'Times New Roman'; font-size: 9pt; mso-spacerun: 'yes'">zend_hash_index_find</span><span style="font-family: '宋体'; font-size: 9pt; mso-spacerun: 'yes'">&nbsp;&nbsp;数值索引方法查找</span><span style="font-family: '宋体'; font-size: 9pt; mso-spacerun: 'yes'"><o:p></o:p></span></p>
<p class="p0" style="margin-top: 5pt; margin-bottom: 5pt"><span style="font-family: 'Times New Roman'; font-size: 9pt; mso-spacerun: 'yes'">zend_hash_quick_find</span><span style="font-family: '宋体'; font-size: 9pt; mso-spacerun: 'yes'">&nbsp;&nbsp;&nbsp;上面两个函数的封装</span><span style="font-family: '宋体'; font-size: 9pt; mso-spacerun: 'yes'"><o:p></o:p></span></p>
<p class="p0" style="margin-top: 5pt; margin-bottom: 5pt"><span style="font-family: 'Times New Roman'; font-size: 9pt; mso-spacerun: 'yes'">zend_hash_exists</span><span style="font-family: '宋体'; font-size: 9pt; mso-spacerun: 'yes'">&nbsp;&nbsp;是否存在索引</span><span style="font-family: '宋体'; font-size: 9pt; mso-spacerun: 'yes'"><o:p></o:p></span></p>
<p class="p0" style="margin-top: 5pt; margin-bottom: 5pt"><span style="font-family: 'Times New Roman'; font-size: 9pt; mso-spacerun: 'yes'">zend_hash_index_exists</span><span style="font-family: '宋体'; font-size: 9pt; mso-spacerun: 'yes'">&nbsp;是否存在索引</span><span style="font-family: '宋体'; font-size: 9pt; mso-spacerun: 'yes'"><o:p></o:p></span></p>
<p class="p0" style="margin-top: 5pt; margin-bottom: 5pt"><span style="font-family: 'Times New Roman'; font-size: 9pt; mso-spacerun: 'yes'">zend_hash_quick_exists</span><span style="font-family: '宋体'; font-size: 9pt; mso-spacerun: 'yes'">&nbsp;&nbsp;上面两个方法的封装</span><span style="font-family: '宋体'; font-size: 9pt; mso-spacerun: 'yes'"><o:p></o:p></span></p>
<p class="p0" style="margin-top: 0pt; margin-bottom: 0pt"><span style="font-family: 'Times New Roman'; font-size: 9pt; mso-spacerun: 'yes'">ZEND_API&nbsp;</span><span style="font-family: 'Times New Roman'; color: rgb(0,0,255); font-size: 9pt; mso-spacerun: 'yes'">int</span><span style="font-family: 'Times New Roman'; font-size: 9pt; mso-spacerun: 'yes'">&nbsp;zend_hash_num_elements(HashTable&nbsp;*ht)</span><span style="font-family: 'Times New Roman'; font-size: 9pt; mso-spacerun: 'yes'"><o:p></o:p></span></p>
<p class="p0" style="margin-top: 0pt; margin-bottom: 0pt"><span style="font-family: 'Times New Roman'; font-size: 9pt; mso-spacerun: 'yes'">{</span><span style="font-family: 'Times New Roman'; font-size: 9pt; mso-spacerun: 'yes'"><o:p></o:p></span></p>
<p class="p0" style="margin-top: 0pt; margin-bottom: 0pt"><span style="font-family: 'Times New Roman'; font-size: 9pt; mso-spacerun: 'yes'">IS_CONSISTENT(ht);</span><span style="font-family: 'Times New Roman'; font-size: 9pt; mso-spacerun: 'yes'"><o:p></o:p></span></p>
<p class="p0" style="margin-top: 0pt; margin-bottom: 0pt"><span style="font-family: 'Times New Roman'; font-size: 9pt; mso-spacerun: 'yes'"><o:p></o:p></span></p>
<p class="p0" style="margin-top: 0pt; margin-bottom: 0pt"><span style="font-family: 'Times New Roman'; color: rgb(0,0,255); font-size: 9pt; mso-spacerun: 'yes'">return</span><span style="font-family: 'Times New Roman'; font-size: 9pt; mso-spacerun: 'yes'">&nbsp;ht-&gt;nNumOfElements;</span><span style="font-family: 'Times New Roman'; font-size: 9pt; mso-spacerun: 'yes'"><o:p></o:p></span></p>
<p class="p0" style="margin-top: 5pt; margin-bottom: 5pt"><span style="font-family: 'Times New Roman'; font-size: 9pt; mso-spacerun: 'yes'">}</span><span style="font-family: 'Times New Roman'; font-size: 9pt; mso-spacerun: 'yes'"><o:p></o:p></span></p>
<p class="p0" style="margin-top: 0pt; margin-bottom: 0pt"><span style="font-family: '宋体'; font-size: 9pt; mso-spacerun: 'yes'">获得数组大小</span></p>
<p class="p0" style="margin-top: 0pt; margin-bottom: 0pt">&nbsp;</p>
<p class="p0" style="margin-top: 0pt; margin-bottom: 0pt"><span style="font-family: '宋体'; font-size: 9pt; mso-spacerun: 'yes'">为了更加方便的操作HashTable，Zend将上面的宏做了进一步的封装。</span></p>
<p class="p0" style="margin-top: 0pt; margin-bottom: 0pt"><span style="font-family: '宋体'; font-size: 9pt; mso-spacerun: 'yes'"><img width="577" height="468" alt="" src="http://www.nd21.com/blog2/blog2/uploads/php_hash_table_hong.png" /></span></p>
<p class="p0" style="margin-top: 0pt; margin-bottom: 0pt"><span style="font-family: '宋体'; font-size: 9pt; mso-spacerun: 'yes'">（上述内容截自 <a href="http://devzone.zend.com/node/view/id/1022#Heading5">http://devzone.zend.com/node/view/id/1022#Heading5</a>）</span></p>
<p class="p0" style="margin-top: 0pt; margin-bottom: 0pt">&nbsp;</p>
<p class="p0" style="margin-top: 0pt; margin-bottom: 0pt"><span style="font-family: '宋体'; font-size: 9pt; mso-spacerun: 'yes'">呵呵，非常方便的操作数组的方式。</span></p>
<p><!--EndFragment--></font></span><!--EndFragment--></span><!--EndFragment--></span><!--EndFragment--></p>
]]></content:encoded>
			<wfw:commentRss>http://www.qingliangcn.com/2009/07/php%e6%ba%90%e4%bb%a3%e7%a0%81%e5%88%86%e6%9e%90%e4%b9%8bhashtable/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>


