PageRenderTime 47ms CodeModel.GetById 20ms RepoModel.GetById 0ms app.codeStats 0ms

/php/quickhashstringinthash.loadfromfile.html

https://bitbucket.org/stillzhl/manuals
HTML | 195 lines | 162 code | 33 blank | 0 comment | 0 complexity | dab86a62830ad6d3cc06756a4363d83f MD5 | raw file
  1. <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
  2. <html>
  3. <head>
  4. <meta http-equiv="content-type" content="text/html; charset=UTF-8">
  5. <title>This factory method creates a hash from a file</title>
  6. </head>
  7. <body><div class="manualnavbar" style="text-align: center;">
  8. <div class="prev" style="text-align: left; float: left;"><a href="quickhashstringinthash.getsize.html">QuickHashStringIntHash::getSize</a></div>
  9. <div class="next" style="text-align: right; float: right;"><a href="quickhashstringinthash.loadfromstring.html">QuickHashStringIntHash::loadFromString</a></div>
  10. <div class="up"><a href="class.quickhashstringinthash.html">QuickHashStringIntHash</a></div>
  11. <div class="home"><a href="index.html">PHP Manual</a></div>
  12. </div><hr /><div id="quickhashstringinthash.loadfromfile" class="refentry">
  13. <div class="refnamediv">
  14. <h1 class="refname">QuickHashStringIntHash::loadFromFile</h1>
  15. <p class="verinfo">(No version information available, might only be in SVN)</p><p class="refpurpose"><span class="refname">QuickHashStringIntHash::loadFromFile</span> &mdash; <span class="dc-title">This factory method creates a hash from a file</span></p>
  16. </div>
  17. <div class="refsect1 description" id="refsect1-quickhashstringinthash.loadfromfile-description">
  18. <h3 class="title">说明</h3>
  19. <div class="methodsynopsis dc-description">
  20. <span class="modifier">public</span> <span class="modifier">static</span> <span class="type"><a href="class.quickhashstringinthash.html" class="type QuickHashStringIntHash">QuickHashStringIntHash</a></span> <span class="methodname"><strong>QuickHashStringIntHash::loadFromFile</strong></span>
  21. ( <span class="methodparam"><span class="type">string</span> <code class="parameter">$filename</code></span>
  22. [, <span class="methodparam"><span class="type">int</span> <code class="parameter">$size</code><span class="initializer"> = 0</span></span>
  23. [, <span class="methodparam"><span class="type">int</span> <code class="parameter">$options</code><span class="initializer"> = 0</span></span>
  24. ]] )</div>
  25. <p class="para rdfs-comment">
  26. This factory method creates a new hash from a definition file on disk. The
  27. file format consists of a signature &#039;QH\0x21\0&#039;, the number of elements as
  28. a 32 bit signed integer in system Endianness, an unsigned 32 bit integer
  29. containing the number of element data to follow in characters. This element
  30. data contains all the strings. The follows another signed 32 bit integer
  31. containing the number of bucket lists. After the header and the strings,
  32. the elements follow. They are ordered by bucket list so that the keys don&#039;t
  33. have to be hashed in order to restore the hash. For each bucket list, the
  34. following information is stored (all as 32 bit integers): the bucket list
  35. index, the number of elements in that list, and then in pairs of two
  36. unsigned 32 bit integers the elements, where the first one is the index
  37. into the string list containing the keys, and the second one the value. An
  38. example could be:
  39. </p>
  40. <p class="para">
  41. <div class="example" id="example-4915">
  42. <p><strong>Example #1 QuickHash StringIntHash file format</strong></p>
  43. <div class="example-contents screen"><div class="descriptioncode"><pre class="descriptioncode">00000000 51 48 21 00 02 00 00 00 09 00 00 00 40 00 00 00 |QH!.........@...|
  44. 00000010 4f 4e 45 00 4e 49 4e 45 00 07 00 00 00 01 00 00 |ONE.NINE........|
  45. 00000020 00 00 00 00 00 01 00 00 00 2f 00 00 00 01 00 00 |........./......|
  46. 00000030 00 04 00 00 00 03 00 00 00 |.........|
  47. 00000039</pre>
  48. </div></div>
  49. </div>
  50. </p>
  51. <p class="para">
  52. <div class="example" id="example-4916">
  53. <p><strong>Example #2 QuickHash IntHash file format</strong></p>
  54. <div class="example-contents screen"><div class="descriptioncode"><pre class="descriptioncode">header signature (&#039;QH&#039;; key type: 2; value type: 1; filler: \0x00)
  55. 00000000 51 48 21 00
  56. number of elements:
  57. 00000004 02 00 00 00
  58. length of string values (9 characters):
  59. 00000008 09 00 00 00
  60. number of hash bucket lists (this is configured for hashes as argument to the
  61. constructor normally, 64 in this case):
  62. 0000000C 40 00 00 00
  63. string values:
  64. 00000010 4f 4e 45 00 4e 49 4e 45 00
  65. bucket lists:
  66. bucket list 1 (with key 7, and 1 element):
  67. header:
  68. 07 00 00 00 01 00 00 00
  69. elements (key index: 0 (&#039;ONE&#039;), value = 0):
  70. 00 00 00 00 01 00 00 00
  71. bucket list 2 (with key 0x2f, and 1 element):
  72. header:
  73. 2f 00 00 00 01 00 00 00
  74. elements (key index: 4 (&#039;NINE&#039;), value = 3):
  75. 04 00 00 00 03 00 00 00</pre>
  76. </div></div>
  77. </div>
  78. </p>
  79. </div>
  80. <div class="refsect1 parameters" id="refsect1-quickhashstringinthash.loadfromfile-parameters">
  81. <h3 class="title">参数</h3>
  82. <p class="para">
  83. <dl>
  84. <dt>
  85. <span class="term"><em><code class="parameter">filename</code></em></span>
  86. <dd>
  87. <p class="para">
  88. The filename of the file to read the hash from.
  89. </p>
  90. </dd>
  91. </dt>
  92. <dt>
  93. <span class="term"><em><code class="parameter">size</code></em></span>
  94. <dd>
  95. <p class="para">
  96. The amount of bucket lists to configure. The number you pass in will be
  97. automatically rounded up to the next power of two. It is also
  98. automatically limited from 4 to 4194304.
  99. </p>
  100. </dd>
  101. </dt>
  102. <dt>
  103. <span class="term"><em><code class="parameter">options</code></em></span>
  104. <dd>
  105. <p class="para">
  106. The same options that the class&#039; constructor takes; except that the size
  107. option is ignored. It is read from the file format (unlike the
  108. QuickHashIntHash and QuickHashIntStringHash classes, where it is
  109. automatically calculated from the number of entries in the hash.)
  110. </p>
  111. </dd>
  112. </dt>
  113. </dl>
  114. </p>
  115. </div>
  116. <div class="refsect1 returnvalues" id="refsect1-quickhashstringinthash.loadfromfile-returnvalues">
  117. <h3 class="title">返回值</h3>
  118. <p class="para">
  119. Returns a new QuickHashStringIntHash.
  120. </p>
  121. </div>
  122. <div class="refsect1 examples" id="refsect1-quickhashstringinthash.loadfromfile-examples">
  123. <h3 class="title">范例</h3>
  124. <p class="para">
  125. <div class="example" id="example-4917">
  126. <p><strong>Example #3 <span class="function"><strong>QuickHashStringIntHash::loadFromFile()</strong></span> example</strong></p>
  127. <div class="example-contents">
  128. <div class="phpcode"><code><span style="color: #000000">
  129. <span style="color: #0000BB">&lt;?php<br />$file&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #0000BB">dirname</span><span style="color: #007700">(&nbsp;</span><span style="color: #0000BB">__FILE__&nbsp;</span><span style="color: #007700">)&nbsp;.&nbsp;</span><span style="color: #DD0000">"/simple.hash.string"</span><span style="color: #007700">;<br /></span><span style="color: #0000BB">$hash&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #0000BB">QuickHashStringIntHash</span><span style="color: #007700">::</span><span style="color: #0000BB">loadFromFile</span><span style="color: #007700">(<br />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000BB">$file</span><span style="color: #007700">,<br />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000BB">QuickHashStringIntHash</span><span style="color: #007700">::</span><span style="color: #0000BB">DO_NOT_USE_ZEND_ALLOC<br /></span><span style="color: #007700">);<br />foreach(&nbsp;</span><span style="color: #0000BB">range</span><span style="color: #007700">(&nbsp;</span><span style="color: #0000BB">0</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">0x0f&nbsp;</span><span style="color: #007700">)&nbsp;as&nbsp;</span><span style="color: #0000BB">$key&nbsp;</span><span style="color: #007700">)<br />{<br />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000BB">$i&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #0000BB">48712&nbsp;</span><span style="color: #007700">+&nbsp;</span><span style="color: #0000BB">$key&nbsp;</span><span style="color: #007700">*&nbsp;</span><span style="color: #0000BB">1631</span><span style="color: #007700">;<br />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000BB">$k&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #0000BB">base_convert</span><span style="color: #007700">(&nbsp;</span><span style="color: #0000BB">$i</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">10</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">36&nbsp;</span><span style="color: #007700">);<br />&nbsp;&nbsp;&nbsp;&nbsp;echo&nbsp;</span><span style="color: #0000BB">$k</span><span style="color: #007700">,&nbsp;</span><span style="color: #DD0000">'&nbsp;=&gt;&nbsp;'</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">$hash</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">get</span><span style="color: #007700">(&nbsp;</span><span style="color: #0000BB">$k&nbsp;</span><span style="color: #007700">),&nbsp;</span><span style="color: #DD0000">"\n"</span><span style="color: #007700">;<br />}<br /></span><span style="color: #0000BB">?&gt;</span>
  130. </span>
  131. </code></div>
  132. </div>
  133. <div class="example-contents"><p>以上例程的输出类似于</p></div>
  134. <div class="example-contents screen">
  135. <div class="cdata"><pre>
  136. 11l4 =&gt; 48712
  137. 12uf =&gt; 50343
  138. 143q =&gt; 51974
  139. 15d1 =&gt; 53605
  140. 16mc =&gt; 55236
  141. 17vn =&gt; 56867
  142. 194y =&gt; 58498
  143. 1ae9 =&gt; 60129
  144. 1bnk =&gt; 61760
  145. 1cwv =&gt; 63391
  146. 1e66 =&gt; 65022
  147. 1ffh =&gt; 66653
  148. 1gos =&gt; 68284
  149. 1hy3 =&gt; 69915
  150. 1j7e =&gt; 71546
  151. 1kgp =&gt; 73177
  152. </pre></div>
  153. </div>
  154. </div>
  155. </p>
  156. </div>
  157. </div><hr /><div class="manualnavbar" style="text-align: center;">
  158. <div class="prev" style="text-align: left; float: left;"><a href="quickhashstringinthash.getsize.html">QuickHashStringIntHash::getSize</a></div>
  159. <div class="next" style="text-align: right; float: right;"><a href="quickhashstringinthash.loadfromstring.html">QuickHashStringIntHash::loadFromString</a></div>
  160. <div class="up"><a href="class.quickhashstringinthash.html">QuickHashStringIntHash</a></div>
  161. <div class="home"><a href="index.html">PHP Manual</a></div>
  162. </div></body></html>