2024 年日本 PHP 研討會

QuickHashIntStringHash::loadFromString

(PECL quickhash >= 未知)

QuickHashIntStringHash::loadFromString此工廠方法從字串建立雜湊

描述

公開 靜態 QuickHashIntStringHash::loadFromString(字串 $contents, 整數 $size = 0, 整數 $options = 0): QuickHashIntStringHash

這個工廠方法會從字串定義建立新的雜湊表。格式與「loadFromFile」中使用的格式相同。

參數

contents

包含雜湊表序列化格式的字串。

size

要配置的桶列表數量。您傳入的數字將自動向上捨入到下一個 2 的次方數。它也會自動限制在 4 到 4194304 之間。

options

與類別建構函式相同的選項;但大小選項會被忽略。它會自動計算為與雜湊表中的項目數相同,向上捨入到最接近的 2 的次方數,最大限制為 4194304。

回傳值

回傳一個新的 QuickHashIntStringHash。

範例

範例 #1 QuickHashIntStringHash::loadFromString() 範例

<?php
$contents
= file_get_contents( dirname( __FILE__ ) . "/simple.hash" );
$hash = QuickHashIntStringHash::loadFromString(
$contents,
QuickHashIntStringHash::DO_NOT_USE_ZEND_ALLOC
);
foreach(
range( 0, 0x0f ) as $key )
{
printf( "鍵 %3d (%2x) 為 %s\n",
$key, $key,
$hash->exists( $key ) ? '已設定' : '未設定'
);
}
?>

上述範例將輸出類似以下的內容

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