PHP Conference Japan 2024

QuickHashIntSet::exists

(PECL quickhash >= 未知)

QuickHashIntSet::exists此方法檢查鍵值是否存在於集合中

說明

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

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

參數

鍵值

用於檢查項目是否存在於集合中的鍵值。

返回值

當找到項目時返回 true,當找不到項目時返回 false

範例

範例 #1 QuickHashIntSet::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";
$set = new QuickHashIntSet( 100000 );
echo
"新增元素:", microtime( true ), "\n";
foreach(
$existingEntries as $key )
{
$set->add( $key );
}

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

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

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

新增註釋

使用者貢獻的筆記

此頁面尚無使用者貢獻的筆記。
To Top