PHP 日本研討會 2024

QuickHashIntHash::loadFromFile

(PECL quickhash >= 未知)

QuickHashIntHash::loadFromFile這個工廠方法從檔案建立雜湊

描述

public static QuickHashIntHash::loadFromFile(string $filename, int $options = ?): QuickHashIntHash

這個工廠方法會從磁碟上的定義檔案建立一個新的雜湊。檔案格式包含一個簽名 'QH\0x11\0',元素的數量以系統位元組序的 32 位元帶符號整數表示,後面跟著以程式碼執行的系統所使用的位元組序封裝在一起的 32 位元帶符號整數。對於每個雜湊元素,都儲存了兩個 32 位元帶符號整數。每個元素的第一個是鍵,第二個是屬於該鍵的值。一個範例可能是

範例 #1 QuickHash IntHash 檔案格式

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

範例 #2 QuickHash IntHash 檔案格式

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

參數

filename

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

options

與類別的建構子所採用的相同選項;除了會忽略 size 選項之外。它會自動計算為與雜湊中的條目數相同,並四捨五入至最接近的二的冪,最大限制為 4194304

回傳值

回傳新的 QuickHashIntHash

範例

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

<?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'
);
}
?>

上面的範例會輸出類似以下的內容

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