(PECL quickhash >= Unknown)
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