©
本文档使用
php.cn手册 发布
(PECL quickhash >= Unknown)
QuickHashIntHash::loadFromFile — This factory method creates a hash from a file
$filename
[, int $options
] )This factory method creates a new hash from a definition file on disk. The file format consists of a signature 'QH\0x11\0', 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:
Example #1 QuickHash IntHash file format
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
Example #2 QuickHash IntHash file format
header signature ('QH'; key type: 1; value type: 1; filler: \0x00) 00000000 51 48 11 00number of elements: 00000004 02 00 00 00data string: 00000000 01 00 00 00 01 00 00 00 03 00 00 00 09 00 00 00key/value 1 (key = 1, value = 1) 01 00 00 00 01 00 00 00key/value 2 (key = 3, value = 9) 03 00 00 00 09 00 00 00
filename
The filename of the file to read the hash from.
options
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 4194304.
Returns a new QuickHashIntHash.
Example #3 QuickHashIntHash::loadFromFile() example
<?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'
);
}
?>
以上例程的输出类似于:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 |
|