summaryrefslogtreecommitdiff
path: root/includes/bitset.php
diff options
context:
space:
mode:
authorMinteck <contact@minteck.org>2022-08-21 17:31:56 +0200
committerMinteck <contact@minteck.org>2022-08-21 17:31:56 +0200
commita2df9a69dcc14cb70118cda2ded499055e7ee358 (patch)
tree6dd283e4e9452d38bce81ddaaae49b5335755842 /includes/bitset.php
parent84dd0735820b16b60f600284d35183d76547a71f (diff)
downloadpluralconnect-a2df9a69dcc14cb70118cda2ded499055e7ee358.tar.gz
pluralconnect-a2df9a69dcc14cb70118cda2ded499055e7ee358.tar.bz2
pluralconnect-a2df9a69dcc14cb70118cda2ded499055e7ee358.zip
m. update
Diffstat (limited to 'includes/bitset.php')
-rw-r--r--includes/bitset.php73
1 files changed, 73 insertions, 0 deletions
diff --git a/includes/bitset.php b/includes/bitset.php
new file mode 100644
index 0000000..272325a
--- /dev/null
+++ b/includes/bitset.php
@@ -0,0 +1,73 @@
+<?php
+
+function parseBitset ($bitset) {
+ $bin = str_repeat("0", 24 - strlen(decbin($bitset))) . decbin($bitset);
+
+ $sharedMemory = bindec(substr($bin, 0, 2));
+ $median = substr($bin, 2, 1) !== "0";
+ $little = bindec(substr($bin, 3, 2));
+ $protector = substr($bin, 5, 1) !== "0";
+ $fictive = substr($bin, 6, 1) !== "0";
+ $notTalking = substr($bin, 7, 1) !== "0";
+ $host = substr($bin, 8, 1) !== "0";
+ $robot = substr($bin, 21, 1) !== "0";
+ $species1 = substr($bin, 9, 4);
+ $species2 = substr($bin, 13, 4);
+
+ $species1 = match ($species1) {
+ "0001" => "earth",
+ "0010" => "unicorn",
+ "0011" => "pegasus",
+ "0100" => "alicorn",
+ "0101" => "batpony",
+ "0110" => "crystal",
+ default => null,
+ };
+
+ $species2 = match ($species2) {
+ "0001" => "earth",
+ "0010" => "unicorn",
+ "0011" => "pegasus",
+ "0100" => "alicorn",
+ "0101" => "batpony",
+ "0110" => "crystal",
+ default => null,
+ };
+
+ return [
+ 'shared_memory' => $sharedMemory,
+ 'median' => $median,
+ 'protector' => $protector,
+ 'fictive' => $fictive,
+ 'little' => $little,
+ 'not_talking' => $notTalking,
+ 'host' => $host,
+ 'robot' => $robot,
+ 'species' => array_filter([
+ $species1,
+ $species2
+ ], function ($i) {
+ return isset($i);
+ })
+ ];
+}
+
+function parseMetadata ($metadata) {
+ if (isset($metadata)) {
+ if ($metadata["bitset"]) {
+ $m = parseBitset($metadata["bitset"]);
+ $m["marefriends"] = $metadata["marefriends"] ?? [];
+ $m["bitset"] = $metadata["bitset"] ?? [];
+ $m["sisters"] = $metadata["sisters"] ?? [];
+ $m["regression"] = $metadata["regression"] ?? null;
+ $m["caretakers"] = $metadata["caretakers"] ?? [];
+ $m["median"] = $metadata["median"] ?? null;
+ } else {
+ $m = $metadata;
+ }
+
+ return $m;
+ } else {
+ return $metadata;
+ }
+} \ No newline at end of file