1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162
|
<?xml version="1.0" encoding="utf-8"?>
<!-- $Revision$ -->
<refentry xml:id="quickhashinthash.loadfromfile" xmlns="http://docbook.org/ns/docbook" xmlns:xlink="http://www.w3.org/1999/xlink">
<refnamediv>
<refname>QuickHashIntHash::loadFromFile</refname>
<refpurpose>This factory method creates a hash from a file</refpurpose>
</refnamediv>
<refsect1 role="description">
&reftitle.description;
<methodsynopsis>
<modifier>public</modifier> <modifier>static</modifier> <type>QuickHashIntHash</type><methodname>QuickHashIntHash::loadFromFile</methodname>
<methodparam><type>string</type><parameter>filename</parameter></methodparam>
<methodparam choice="opt"><type>int</type><parameter>options</parameter></methodparam>
</methodsynopsis>
<para>
This factory method creates a new hash from a definition file on disk. The
file format consists of a signature <literal>'QH\0x11\0'</literal>, the number of elements as
a 32 bit signed integer in system Endianness, followed by 32 bit signed
integers packed together in the Endianness that the system that the code
runs on uses. For each hash element there are two 32 bit signed integers
stored. The first of each element is the key, and the second is the value
belonging to the key. An example could be:
</para>
<para>
<example>
<title>QuickHash IntHash file format</title>
<screen><![CDATA[00000000 51 48 11 00 02 00 00 00 01 00 00 00 01 00 00 00 |QH..............|
00000010 03 00 00 00 09 00 00 00 |........|
00000018
]]></screen>
</example>
</para>
<para>
<example>
<title>QuickHash IntHash file format</title>
<screen><![CDATA[header signature ('QH'; key type: 1; value type: 1; filler: \0x00)
00000000 51 48 11 00
number of elements:
00000004 02 00 00 00
data string:
00000000 01 00 00 00 01 00 00 00 03 00 00 00 09 00 00 00
key/value 1 (key = 1, value = 1)
01 00 00 00 01 00 00 00
key/value 2 (key = 3, value = 9)
03 00 00 00 09 00 00 00
]]></screen>
</example>
</para>
</refsect1>
<refsect1 role="parameters">
&reftitle.parameters;
<para>
<variablelist>
<varlistentry>
<term><parameter>filename</parameter></term>
<listitem>
<para>
The filename of the file to read the hash from.
</para>
</listitem>
</varlistentry>
<varlistentry>
<term><parameter>options</parameter></term>
<listitem>
<para>
The same options that the class' constructor takes; except that the size
option is ignored. It is automatically calculated to be the same as the
number of entries in the hash, rounded up to the nearest power of two
with a maximum limit of <literal>4194304</literal>.
</para>
</listitem>
</varlistentry>
</variablelist>
</para>
</refsect1>
<refsect1 role="returnvalues">
&reftitle.returnvalues;
<para>
Returns a new <classname>QuickHashIntHash</classname>.
</para>
</refsect1>
<refsect1 role="examples">
&reftitle.examples;
<para>
<example>
<title><function>QuickHashIntHash::loadFromFile</function> example</title>
<programlisting role="php">
<![CDATA[
<?php
$file = dirname( __FILE__ ) . "/simple.hash";
$hash = QuickHashIntHash::loadFromFile(
$file,
QuickHashIntHash::DO_NOT_USE_ZEND_ALLOC
);
foreach( range( 0, 0x0f ) as $key )
{
printf( "Key %3d (%2x) is %s\n",
$key, $key,
$hash->exists( $key ) ? 'set' : 'unset'
);
}
?>
]]>
</programlisting>
&example.outputs.similar;
<screen>
<![CDATA[
Key 0 ( 0) is unset
Key 1 ( 1) is set
Key 2 ( 2) is set
Key 3 ( 3) is set
Key 4 ( 4) is unset
Key 5 ( 5) is set
Key 6 ( 6) is unset
Key 7 ( 7) is set
Key 8 ( 8) is unset
Key 9 ( 9) is unset
Key 10 ( a) is unset
Key 11 ( b) is set
Key 12 ( c) is unset
Key 13 ( d) is set
Key 14 ( e) is unset
Key 15 ( f) is unset
]]>
</screen>
</example>
</para>
</refsect1>
</refentry>
<!-- Keep this comment at the end of the file
Local variables:
mode: sgml
sgml-omittag:t
sgml-shorttag:t
sgml-minimize-attributes:nil
sgml-always-quote-attributes:t
sgml-indent-step:1
sgml-indent-data:t
indent-tabs-mode:nil
sgml-parent-document:nil
sgml-default-dtd-file:"~/.phpdoc/manual.ced"
sgml-exposed-tags:nil
sgml-local-catalogs:nil
sgml-local-ecat-files:nil
End:
vim600: syn=xml fen fdm=syntax fdl=2 si
vim: et tw=78 syn=sgml
vi: ts=1 sw=1
-->
|