(PECL quickhash >= 未知)
QuickHashIntSet::exists — 此方法檢查鍵值是否存在於集合中
鍵值
用於檢查項目是否存在於集合中的鍵值。
範例 #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