(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