(No version information available, might only be in Git)
QuickHashStringIntHash::loadFromFile — This factory method creates a hash from a file
public static QuickHashStringIntHash::loadFromFile ( string $filename [, int $size = 0 [, int $options = 0 ]] ) : QuickHashStringIntHash
This factory method creates a new hash from a definition file on disk. The file format consists of a signature 'QH\0x21\0', the number of elements as a 32 bit signed integer in system Endianness, an unsigned 32 bit integer containing the number of element data to follow in characters. This element data contains all the strings. The follows another signed 32 bit integer containing the number of bucket lists. After the header and the strings, the elements follow. They are ordered by bucket list so that the keys don't have to be hashed in order to restore the hash. For each bucket list, the following information is stored (all as 32 bit integers): the bucket list index, the number of elements in that list, and then in pairs of two unsigned 32 bit integers the elements, where the first one is the index into the string list containing the keys, and the second one the value. An example could be:
Example #1 QuickHash StringIntHash file format
Example #2 QuickHash IntHash file format
header signature ('QH'; key type: 2; value type: 1; filler: \0x00) 00000000 51 48 21 00 number of elements: 00000004 02 00 00 00 length of string values (9 characters): 00000008 09 00 00 00 number of hash bucket lists (this is configured for hashes as argument to the constructor normally, 64 in this case): 0000000C 40 00 00 00 string values: 00000010 4f 4e 45 00 4e 49 4e 45 00 bucket lists: bucket list 1 (with key 7, and 1 element): header: 07 00 00 00 01 00 00 00 elements (key index: 0 ('ONE'), value = 0): 00 00 00 00 01 00 00 00 bucket list 2 (with key 0x2f, and 1 element): header: 2f 00 00 00 01 00 00 00 elements (key index: 4 ('NINE'), value = 3): 04 00 00 00 03 00 00 00
filename
The filename of the file to read the hash from.
size
The amount of bucket lists to configure. The number you pass in will be automatically rounded up to the next power of two. It is also automatically limited from 4 to 4194304.
options
The same options that the class' constructor takes; except that the size option is ignored. It is read from the file format (unlike the QuickHashIntHash and QuickHashIntStringHash classes, where it is automatically calculated from the number of entries in the hash.)
Returns a new QuickHashStringIntHash.
Example #3 QuickHashStringIntHash::loadFromFile() example
<?php $file = dirname( __FILE__ ) . "/simple.hash.string"; $hash = QuickHashStringIntHash::loadFromFile( $file, QuickHashStringIntHash::DO_NOT_USE_ZEND_ALLOC ); foreach( range( 0, 0x0f ) as $key ) { $i = 48712 + $key * 1631; $k = base_convert( $i, 10, 36 ); echo $k, ' => ', $hash->get( $k ), "\n"; } ?>
The above example will output something similar to:
© 1997–2020 The PHP Documentation Group
Licensed under the Creative Commons Attribution License v3.0 or later.
https://www.php.net/manual/en/quickhashstringinthash.loadfromfile.php