2024 年 PHP Conference Japan

QuickHashIntHash::exists

(PECL quickhash >= 未知)

QuickHashIntHash::exists此方法檢查雜湊表中是否存在鍵值

說明

public QuickHashIntHash::exists(int $key): bool

此方法檢查雜湊表中是否存在具有指定鍵值的項目。

參數

key

要檢查是否存在於雜湊表中的項目的鍵值。

傳回值

如果找到項目,則返回 true,如果找不到項目,則返回 false

範例

範例 #1 QuickHashIntHash::exists() 範例

<?php
// 產生 200000 個元素
$array = range( 0, 199999 );
$existingEntries = array_rand( array_flip( $array ), 180000 );
$testForEntries = array_rand( array_flip( $array ), 1000 );
$foundCount = 0;

echo
"建立雜湊表: ", microtime( true ), "\n";
$hash = new QuickHashIntHash( 100000 );
echo
"新增元素: ", microtime( true ), "\n";
foreach(
$existingEntries as $key )
{
$hash->add( $key, 56 );
}

echo
"執行 1000 次測試: ", microtime( true ), "\n";
foreach(
$testForEntries as $key )
{
$foundCount += $hash->exists( $key );
}
echo
"完成,找到 $foundCount 個: ", microtime( true ), "\n";
?>

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

Creating hash: 1263588703.0748
Adding elements: 1263588703.0757
Doing 1000 tests: 1263588703.7851
Done, 898 found: 1263588703.7897

新增註釋

使用者貢獻的註釋

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