PHP code example of buexplain / bitmap
1. Go to this page and download the library: Download buexplain/bitmap library . Choose the download type require .
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
buexplain / bitmap example snippets
itMap\ClientFactory;
$b1 = ClientFactory::make();
$b2 = ClientFactory::make();
//求并集,并将结果保存到$b1
$b1->addMany([1, 2]);
$b2->addMany([2, 3]);
$b1->or($b2);
print_r($b1->toArray()); //[1,2,3]
//求交集,并将结果保存到$b1
$b1->clear()->addMany([1, 2, 3]);
$b2->clear()->addMany([2, 3, 4]);
$b1->and($b2);
print_r($b1->toArray()); //[2,3]
//求差集,并将结果保存到$b1
$b1->clear()->addMany([1, 2, 3]);
$b2->clear()->addMany([1, 3, 4]);
$b1->andNot($b2);
print_r($b1->toArray()); //[2]
//求对称差集,并将结果保存到$b1
$b1->clear()->addMany([1, 2, 3]);
$b2->clear()->addMany([3, 4, 5]);
$b1->xOr($b2);
print_r($b1->toArray()); //[1,2,4,5]
//迭代,每次从$b1中弹出2个元素,所有迭代完成后,$b1中的元素个数是0
$b1->clear()->addMany([1, 2, 3, 4, 5, 200000000, 6, 20, 200000001]);
while ($tmp = $b1->iterate(2)) {
print_r($tmp); // [1,2], [3,4], [5,6], [20,200000000], [200000001]
}
var_dump($b1->getCardinality() == 0); //true