(PECL quickhash >= 未知)
QuickHashIntHash::exists — 此方法檢查雜湊表中是否存在鍵值
key
要檢查是否存在於雜湊表中的項目的鍵值。
範例 #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