PHP code example of orieg / expanse
1. Go to this page and download the library: Download orieg/expanse 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/ */
orieg / expanse example snippets
use Expanse\Set;
use Expanse\Map;
use Expanse\StrMap;
use Expanse\BlobMap;
// 1. Dynamic sparse 64-bit integer set (Judy1)
$set = new Set();
$set->add(42);
$set->add(100_000);
echo $set->contains(42) ? "Found\n" : "Missing\n";
echo $set->rank(100_000); // O(depth) rank
// 2. Ordered 64-bit key-value map (JudyL)
$map = new Map();
$map->set(42, 1000);
$map[100] = 5000;
echo $map->get(42); // 1000
// 3. String trie with path folding (JudySL)
$strMap = new StrMap();
$strMap->set("/api/v1/users", 200);
// 4. Large-value blob map with hot metadata
$blobs = new BlobMap();
$blobs->set(1, "small inline payload"); // 0 heap allocations
$blobs->set(2, "large JSON payload", hotMeta: 0x42);
// 5. 1:1 legacy php-judy drop-in compatibility
$judy = new Judy(Judy::INT_TO_INT);
$judy[42] = 999;
echo $judy[42]; // 999