PHP Conference Japan 2024

QuickHashIntStringHash::loadFromFile

(PECL quickhash >= Unknown)

QuickHashIntStringHash::loadFromFile此工廠方法從檔案建立雜湊

說明

public static QuickHashIntStringHash::loadFromFile(string $filename, int $size = 0, int $options = 0): QuickHashIntStringHash

這個工廠方法會從磁碟上的定義檔案建立新的雜湊。檔案格式包含簽章 'QH\0x12\0'、以系統位元組序的 32 位元有號整數表示的元素數量、一個包含後續元素資料字元數的無號 32 位元整數。這個元素資料包含所有的字串。在標頭和字串之後,會以兩個無號 32 位元整數的成對形式來表示元素,其中第一個是鍵,第二個是元素資料字串的索引。例如:

範例 #1 QuickHash IntString 檔案格式

00000000  51 48 12 00 02 00 00 00  09 00 00 00 4f 4e 45 00  |QH..........ONE.|
00000010  4e 49 4e 45 00 01 00 00  00 00 00 00 00 03 00 00  |NINE............|
00000020  00 04 00 00 00                                    |.....|
00000025

範例 #2 QuickHash IntString 檔案格式

header signature ('QH'; key type: 1; value type: 2; filler: \0x00)
00000000  51 48 12 00

number of elements:
00000004  02 00 00 00

length of string values (9 characters):
00000008  09 00 00 00

string values:
0000000C  4f 4e 45 00 4e 49 4e 45  00

data string:
00000015  01 00 00 00 00 00 00 00  03 00 00 00 04 00 00 00

key/value 1 (key = 1, string index = 0 ("ONE")):
01 00 00 00  00 00 00 00

key/value 2 (key = 3, string index = 4 ("NINE")):
03 00 00 00  04 00 00 00

參數

filename

要從中讀取雜湊的檔案名稱。

size

要設定的 bucket 列表數量。您傳入的數字將會自動四捨五入為下一個 2 的冪。它也會自動限制為 44194304

options

與類別的建構函式接受的選項相同;不同之處在於會忽略 size 選項。它會自動計算為與雜湊中的項目數相同,四捨五入為最接近的 2 的冪,最大限制為 4194304

回傳值

傳回新的 QuickHashIntStringHash

範例

範例 #3 QuickHashIntStringHash::loadFromFile() 範例

<?php
$file
= dirname( __FILE__ ) . "/simple.string.hash";
$hash = QuickHashIntStringHash::loadFromFile(
$file,
QuickHashIntStringHash::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'
);
}
?>

上述範例會輸出類似以下內容:

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

新增註解

使用者貢獻的註解

此頁面沒有使用者貢獻的註解。
To Top