mirror of
https://github.com/php/doc-ru.git
synced 2025-08-20 23:31:15 +00:00
149 lines
3.3 KiB
XML
149 lines
3.3 KiB
XML
<?xml version="1.0" encoding="utf-8"?>
|
|
<!-- EN-Revision: bfa171ecb7d958d09e9fd576090c95a62caff784 Maintainer: sergey Status: ready -->
|
|
<!-- Reviewed: no -->
|
|
<chapter xml:id="quickhash.examples" xmlns="http://docbook.org/ns/docbook" xmlns:xlink="http://www.w3.org/1999/xlink">
|
|
&reftitle.examples;
|
|
<example>
|
|
<title>Пример использования Quickhash</title>
|
|
<programlisting role="php">
|
|
<![CDATA[
|
|
<?php
|
|
$set = new QuickHashIntSet( 1024, QuickHashIntSet::CHECK_FOR_DUPES );
|
|
$set->add( 1 );
|
|
$set->add( 3 );
|
|
|
|
var_dump( $set->exists( 3 ) );
|
|
var_dump( $set->exists( 4 ) );
|
|
|
|
$set->saveToFile( "/tmp/test-set.set" );
|
|
|
|
$newSet = QuickHashIntSet::loadFromFile(
|
|
"/tmp/test-set.set"
|
|
);
|
|
|
|
var_dump( $newSet->exists( 3 ) );
|
|
var_dump( $newSet->exists( 4 ) );
|
|
?>
|
|
]]>
|
|
</programlisting>
|
|
&example.outputs.similar;
|
|
<screen>
|
|
<![CDATA[
|
|
bool(true)
|
|
bool(false)
|
|
bool(true)
|
|
bool(false)
|
|
]]>
|
|
</screen>
|
|
</example>
|
|
<example>
|
|
<title>Пример использования Quickhash ArrayAccess</title>
|
|
<programlisting role="php">
|
|
<![CDATA[
|
|
<?php
|
|
$hash = new QuickHashIntHash( 64 );
|
|
|
|
// Добавление и обновление записей хеша.
|
|
$hash[3] = 145926;
|
|
$hash[3] = 1415926;
|
|
$hash[2] = 72;
|
|
|
|
// Проверка существования ключей
|
|
var_dump( isset( $hash[3] ) );
|
|
|
|
// Удаление записей хеша
|
|
unset( $hash[2] );
|
|
|
|
// Получение значения, сохранённого для хеша
|
|
echo $hash[3], "\n";
|
|
?>
|
|
]]>
|
|
</programlisting>
|
|
&example.outputs.similar;
|
|
<screen>
|
|
<![CDATA[
|
|
bool(true)
|
|
1415926
|
|
]]>
|
|
</screen>
|
|
</example>
|
|
<example>
|
|
<title>Пример использования Quickhash Iterator</title>
|
|
<programlisting role="php">
|
|
<![CDATA[
|
|
<?php
|
|
$hash = new QuickHashIntHash( 64 );
|
|
|
|
// Добавление записей хеша.
|
|
$hash[1] = 145926;
|
|
$hash[2] = 1415926;
|
|
$hash[3] = 72;
|
|
$hash[4] = 712314;
|
|
$hash[5] = -4234;
|
|
|
|
foreach( $hash as $key => $value )
|
|
{
|
|
echo $key, ' => ', $value, "\n";
|
|
}
|
|
?>
|
|
]]>
|
|
</programlisting>
|
|
&example.outputs.similar;
|
|
<screen>
|
|
<![CDATA[
|
|
5 => -4234
|
|
4 => 712314
|
|
1 => 145926
|
|
2 => 1415926
|
|
3 => 72
|
|
]]>
|
|
</screen>
|
|
</example>
|
|
<example>
|
|
<title>Пример использования Quickhash String Values</title>
|
|
<programlisting role="php">
|
|
<![CDATA[
|
|
<?php
|
|
$hash = new QuickHashIntStringHash( 64 );
|
|
|
|
// Добавление записей хеша.
|
|
$hash[1] = "один миллион четыреста пятнадцать тысяч девятьсот двадцать шесть";
|
|
$hash->add( 2, "ещё один" );
|
|
|
|
foreach( $hash as $key => $value )
|
|
{
|
|
echo $key, ' => ', $value, "\n";
|
|
}
|
|
?>
|
|
]]>
|
|
</programlisting>
|
|
&example.outputs.similar;
|
|
<screen>
|
|
<![CDATA[
|
|
1 => один миллион четыреста пятнадцать тысяч девятьсот двадцать шесть
|
|
2 => ещё один
|
|
]]>
|
|
</screen>
|
|
</example>
|
|
</chapter>
|
|
<!-- Keep this comment at the end of the file
|
|
Local variables:
|
|
mode: sgml
|
|
sgml-omittag:t
|
|
sgml-shorttag:t
|
|
sgml-minimize-attributes:nil
|
|
sgml-always-quote-attributes:t
|
|
sgml-indent-step:1
|
|
sgml-indent-data:t
|
|
indent-tabs-mode:nil
|
|
sgml-parent-document:nil
|
|
sgml-default-dtd-file:"~/.phpdoc/manual.ced"
|
|
sgml-exposed-tags:nil
|
|
sgml-local-catalogs:nil
|
|
sgml-local-ecat-files:nil
|
|
End:
|
|
vim600: syn=xml fen fdm=syntax fdl=2 si
|
|
vim: et tw=78 syn=sgml
|
|
vi: ts=1 sw=1
|
|
-->
|