1
\$\begingroup\$
/* Convenient Objects Library Extender for PHP 7+
 * -----------------------------------------------------------------------
 * C-OLE is a container super extension for PHP 7+
 * that is to make everything you thought difficult,
 * impossible, or completely outside the grasp of
 * PHPs language restrictions completely doable.
 * It contains each container from Java (- the legacy
 * ones) to make certain projects are as suitable
 * for other coders to continue the work as they
 * can, setting up a dialog between incoming and
 * outgoing programmers. This is all made in the
 * hopes that PHP will one day be able to be used
 * for GUI engagement; in other words: OS based
 * apps that can be made strictly from PHP and JS.
 * -Sincerely, @thexiv
 * All rights to this software are owned by @thexiv.
 * All software contained is under Creative License
 * to anyone out there without fee or payment!
*/

How would you rate this code? It took 2 days to write, and less than 72 hours to debug.

<?
    class Container {
        public $typeOf;
        public $rootType;
        public $dat;

        public function __construct() {

        }

        public function size() {
            return sizeof($this->dat);
        }
     }

    class Vector extends Container {

        public $vectorTemp;
        public $parentType;
        public $childType;
        public $vect;
        private $datCntr;

        public function __construct($type) {
            $this->rootType = 'Container';
            $this->typeOf = 'Vector';
            if ($type == 'Dequeue')
                $this->childType = 'Dequeue';
            else if ($type == 'Queue')
                $this->childType = 'Queue';
            else if ($type == 'Set')
                $this->childType = 'Set';
            else if ($type == 'SortedSet')
                $this->childType = 'SortedSet';
            else if ($type == 'NavigableSet')
                $this->childType = 'NavigableSet';
            else if ($type == 'Map')
                $this->childType = 'Map';
            else if ($type == 'SortedMap')
                $this->childType = 'SortedMap';
            else if ($type == 'NavigableMap')
                $this->childType = 'NavigableMap';
            else if ($type == 'Stack')
                $this->childType = 'Stack';
            else if ($type == 'Thread')
                $this->childType = 'Thread';
            else
                return 0;
            return 1;
        }

        public function add($r, $bool) {
            if ($this->childType == $r->typeOf)
                $this->dat[] = $r;
            else
                return 0;
            $this->cntIncr();
            if ($bool == 1)
                $this->joinVect();
            return 1;
        }

        private function cntIncr() {
            return ++$this->datCntr;
        }

        private function cntDecr() {
            return --$this->datCntr;
        }

        public function getIndex() {
            return $this->datCntr;
        }

        public function setIndex($indx) {
            if ($this->size() == 0) {
                $this->datCntr = 0;
                $this->vect = null;
                return 0;
            }
            if ($indx <= $this->size() && $indx > 0)
                return $this->datCntr = $indx;
        }

        public function newVect() {
            if ($this->childType == 'Dequeue')
                $r = new Dequeue();
            else if ($this->childType == 'Queue')
                $r = new Queue();
            else if ($this->childType == 'Set')
                $r = new Set();
            else if ($this->childType == 'SortedSet')
                $r = new SortedSet();
            else if ($this->childType == 'NavigableSet')
                $r = new NavigableSet();
            else if ($this->childType == 'Map')
                $r = new Map();
            else if ($this->childType == 'SortedMap')
                $r = new SortedMap();
            else if ($this->childType == 'NavigableMap')
                $r = new NavigableMap();
            else if ($this->childType == 'Stack')
                $r = new Stack();
            else if ($this->childType() == 'Thread')
                $r = new Thread();
            else
                return 0;

            $this->add($r, 0);
            return 1;
        }

        public function hasNext() {
            if ($this->size() == 0)
                return 0;
            if ($this->getIndex() < $this->size())
                return 1;
            return 0;
        }

        public function nextVect($bool) {
            if ($this->hasNext() == 1) {
                $this->cntIncr();
                if ($bool == 1)
                    $this->joinVect();
                return 1;
            }
            else if ($this->size() == 1) {
                $this->setIndex(1);
                if ($bool == 1)
                    $this->joinVect();
                return 1;
            }
            else if ($this->size() == 0) {
                $this->setIndex(0);
                $this->vect = null;
                return 0;
            }
        }

        public function cycleVect() {
            if ($this->size() == 0)
                return 0;
            if ($this->hasNext() == 1) {
                $this->nextVect(1);
                $this->joinVect();
                return 1;
            }
            else if ($this->hasPrev() == 1) {
                $this->prevVect(1);
                return 1;
            }
            return 1;
        }

        public function hasPrev() {
            if ($this->size() == 0)
                return 0;
            if ($this->getIndex() - 1 > 0)
                return 1;
            return 0;
        }

        public function prevVect($bool) {
            if ($this->hasNext() == 1) {
                $this->cntDecr();
                if ($bool == 1)
                    $this->joinVect();
                return 1;
            }
            else if ($this->size() == 1) {
                $this->setIndex(1);
                if ($bool == 1)
                    $this->joinVect();
                return 1;
            }
            else if ($this->size() == 0) {
                $this->setIndex(0);
                $this->vect = null;
                return 0;
            }
        }

        public function currVect() {
            return $this->getIndex();
        }

        public function remVect($r) {
            if ($this->size() == 0)
                return 0;
            $tempAneous = array();
            for ($i = 0; $i < $this->size(); $i++) {
                if ($i != $r)
                    $tempAneous[] = $this->dat[$i];
            }
            return $this->dat = $tempAneous;
        }

        public function joinVect() {
            if ($this->size() == 0)
                $this->vect = null;
            if ($this->size() == 1)
                $this->setIndex(1);
            if ($this->getIndex() > $this->size())
                $this->setIndex($this->size());
            $this->vect = $this->dat[$this->getIndex()-1];
            return 1;
        }
    }

    class Dequeue extends Container {

        public $dqueueTemp;
        public $parentType;

        public function __construct() {
            $this->rootType = 'Container';
            $this->parentType = 'Container';
            $this->typeOf = 'Dequeue';
        }

        public function pollFront() {
            $dqueueTemp = '';
            if ($this->size() == 0)
                return 0;
            for ($i = 1; $i < $this->size(); $i++)
                $dqueueTemp[] = $this->dat[$i];
            $j = $this->dat[0];
            $this->dat = $dqueueTemp;
            return $j;
        }

        public function pollBack() {
            $dqueueTemp = '';
            if ($this->size() == 0)
                return 0;
            for ($i = 0; $i < $this->size()-1; $i++)
                $dqueueTemp[] = $this->dat[$i];
            $j = $this->dat[$this->size()-1];
            $this->dat = $dqueueTemp;
            return $j;
        }

        public function push($r) {
            return $this->dat[] = $r;
        }

        public function pop() {
            $dqueueTemp = '';
            if ($this->size() == 0)
                return 0;
            for ($i = 0; $i < $this->size()-1; $i++)
                $dqueueTemp[] = $this->dat[$i];
            $j = $this->dat[$this->size()-1];
            $this->dat = $dqueueTemp;
            return 1;
        }

        public function getFirst() {
            if ($this->size() == 0)
                return 0;
            return $this->dat[0];
        }

        public function getLast() {
            if ($this->size() == 0)
                return 0;
            return $this->dat[$this->size()-1];
        }

        public function clear() {
            $this->dat = array();
            return 1;
        }

        public function removeFirst() {
            $dqueueTemp = '';
            if ($this->size() == 0)
                return 0;
            for ($i = 1; $i < $this->size(); $i++)
                $dqueueTemp[] = $this->dat[$i];
            $this->dat = $dqueueTemp;
            return 1;
        }

        public function removeLast() {
            $dqueueTemp = '';
            if ($this->size() == 0)
                return 0;
            for ($i = 0; $i < $this->size()-1; $i++)
                $dqueueTemp[] = $this->dat[$i];
            $this->dat = $dqueueTemp;
            return 1;
        }

        public function remFirstOcc($r) {
            $dqueueTemp = '';
            if ($this->size() == 0)
                return 0;
            $p = 0;
            if ($r->typeOf != 'Dequeue')
                return 0;
            for ($i = 0; $i < $this->size(); $i++) {
                if ($r == $this->dat[$i] && $p == 0) {
                    $p = 1;
                    continue;
                }
                $dqueueTemp[] = $this->dat[$i];
            }
            $this->dat = $dqueueTemp;
        }

        public function remLastOcc($r) {
            $dqueueTemp = '';
            if ($this->size() == 0)
                return 0;
            $p = 0;
            if ($r->typeOf != 'Dequeue')
                return 0;
            for ($i = 0; $i < $this->size(); $i++) {
                if ($r == $this->dat[$i])
                    $p = $i;
            }

            for ($i = 0; $i < $this->size(); $i++) {
                if ($i == $p)
                    continue;
                $dqueueTemp[] = $this->dat[$i];
            }
            $this->dat = $dqueueTemp;
        }
    }


    class Queue extends Container {

        public $queueTemp;
        public $parentType;

        public function __construct() {
            $this->rootType = 'Container';
            $this->parentType = 'Container';
            $this->typeOf = 'Queue';
        }

        public function poll() {
            $queueTemp = '';
            if ($this->size() == 0)
                return 0;
            for ($i = 1; $i < $this->dat[$i]; $i++) {
                if ($this->dat[$i] == null)
                    continue;
                $queueTemp[] = $this->dat[$i];
            }
            $j = $this->dat[0];
            $this->dat = $queueTemp;
            return $j;
        }

        public function push($r) {
            $queueTemp = '';
            return $this->dat[] = $r;
        }

        public function pop() {
            $queueTemp = '';
            $queueTemp = array();
            if ($this->size() == 0)
                return 0;
            for ($i = 1; $i < $this->size()-1; $i++)
                $queueTemp[] = $this->dat[$i];
            $j = $this->dat[$this->size()-1];
            $this->dat = $queueTemp;
            return 1;
        }

        public function getElement() {
            if ($this->size() == 0)
                return 0;
            return $this->dat[0];
        }

        public function clear() {
            $this->dat = array();
            return 1;
        }
    }

    class Set extends Container {

        public $setTemp;
        public $parentType;

        public function __construct() {
            $this->rootType = 'Container';
            $this->parentType = 'Container';
            $this->typeOf = 'Set';
        }

        public function size() {
            return sizeof($this->dat);
        }

        public function addAll($indx, $r) {
            if ($this->typeOf != $r->typeOf)
                return 0;
            for ($i = 0; $i < $r->size(); $i++)
                $this->add($indx, $r->dat[$i]);
        }

        public function add($indx, $r) {
            $setTemp = '';
            if ($indx < 0 || $indx > $this->size())
                return 0;
            if ($this->size() == 0) {
                $this->dat[] = $r;
                return 1;
            }
            for ($i = 0; $i < $this->size(); $i++)
                if ($this->dat[$i] == $r)
                    return 0;
            for ($i = 0; $i < $indx; $i++)
                $setTemp[] = $this->dat[$i];
            $setTemp[] = $r;
            for ($i = $indx+1; $i < $this->size(); $i++)
                $setTemp[] = $this->dat[$i];
            $this->dat = $setTemp;

            if (($this->typeOf == 'SortedSet' || $this->typeOf == 'NavigableSet') && $this->parentType == 'Set')
                sort($this->dat);

            return 1;
        }

        public function valIsIn($v) {
            if ($this->size() == 0)
                return 0;
            for ($i = 0; $i < $this->size(); $i++) {
                if ($this->dat[$i] == $v)
                    return 1;
            }
            return 0;
        }

        public function compare($r) {
            $temp;
            if ($r->size() != $this->size())
                return 0;
            for ($i = 0; $i < $this->size(); $i++) {
                if ($this->valIsIn($r->dat[$i]))
                    $temp[] = $r->dat[$i];
            }
            return $temp;
        }

        public function get($indx) {
            if ($this->size() == 0 || $indx >= $this->size())
                return 0;
            return $this->dat[$indx];
        }

        public function indxOf($r) {
            if ($this->size() == 0 || $indx >= $this->size())
                return 0;
            for ($i = 0; $i < $this->size(); $i++) {
                if ($this->dat[$i] == $r)
                    return $i;
            }
            return 0;
        }

        public function indxLast($r) {
            if ($this->size() == 0)
                return 0;
            $indx = 0;
            for ($i = 0; $i < $this->size(); $i++) {
                if ($this->dat[$i] == $r)
                    $indx = $i;
            }
            return $indx;
        }

        public function remIndex($indx) {
            $setTemp = '';
            if ($this->size() == 0 || $indx >= $this->size())
                return 0;
            for ($i = 0; $i < $indx; $i++)
                $setTemp[] = $this->dat[$i];
            for ($i = $indx+1; $i < $this->size(); $i++)
                $setTemp[] = $this->dat[$i];
            $this->dat = $setTemp;
            return 1;
        }

        public function remValue($val) {
            $setTemp = '';
            if ($this->size() == 0)
                return 0;
            for ($i = 0; $i < $this->size(); $i++) {
                if ($this->dat[$i] != $val)
                    $setTemp[] = $this->dat[$i];
            }
            $this->dat = $setTemp;
            return 1;
        }

    }

    class SortedSet extends Set {

        public $sSetTemp;
        public $parentType;

        public function __construct() {
            $this->rootType = 'Container';
            $this->parentType = 'Set';
            $this->typeOf = 'SortedSet';
        }

        public function headSet($indx) {
            $sSetTemp = '';
            if ($this->size() == 0 || $indx < 0 || $indx >= $this->size())
                return 0;
            for ($i = 0; $i < $indx; $i++)
                $sSetTemp[] = $this->dat[$i];
            return $sSetTemp;
        }

        public function first() {
            if ($this->size() == 0)
                return 0;
            return $this->dat[0];
        }

        public function last() {
            if ($this->size() == 0)
                return 0;
            return $this->dat[$this->size()-1];
        }

        public function subSet($st, $Lb, $en, $Hb) {
            $sSetTemp = '';
            if ($this->size() == 0)
                return 0;
            for ($i = 0; $i < $this->size(); $i++) {
                if ($Lb == 1) {
                    if ($this->dat[$i] >= $st) {
                        do {
                            $sSetTemp[] = $this->dat[$i];
                            $i++;
                        } while ($st <= $this->dat[$i]);
                    }
                }
                if ($Lb == 0) {
                    if ($this->dat[$i] > $st) {
                        do {
                            $sSetTemp[] = $this->dat[$i];
                            $i++;
                        } while ($st < $this->dat[$i]);
                    }
                }
                if ($Hb == 1) {
                    if ($this->dat[$i] <= $en) {
                        do {
                            $sSetTemp[] = $this->dat[$i];
                            $i++;
                        } while ($en <= $this->dat[$i]);
                    }
                }
                if ($Hb == 0) {
                    if ($this->dat[$i] > $en) {
                        do {
                            $sSetTemp[] = $this->dat[$i];
                            $i++;
                        } while ($en < $this->dat[$i]);
                    }
                }
            }
            return $sSetTemp;
        }

    }

    class NavigableSet extends SortedSet {

        public $navTemp;
        public $parentType;

        public function __construct() {
            $this->rootType = 'Container';
            $this->parentType = 'Set';
            $this->typeOf = 'NavigableSet';
        }

        public function ceiling($r) {
            if ($this->size() == 0)
                return 0;
            for ($i = 0; $i < $this->size(); $i++) {
                if ($r <= $this->dat[$i])
                    return $this->dat[$i];
            }
            return 0;
        }

        public function floor($r) {
            if ($this->size() == 0)
                return 0;
            for ($i = $this->size()-1; $i > 0; $i++) {
                if ($r > $this->dat[$i])
                    return $this->dat[$i-1];
            }
            return 0;
        }

        public function pollFirst() {
            $navTemp = '';
            if ($this->size() == 0)
                return 0;
            for ($i = 1; $i < $this->size(); $i++)
                $navTemp[] = $this->dat[$i];
            $j = $this->dat[0];
            $this->dat = $navTemp;
            return $j;
        }

        public function pollLast() {
            $navTemp = '';
            if ($this->size() == 0)
                return 0;
            for ($i = 0; $i < $this->size()-1; $i++)
                $navTemp[] = $this->dat[$i];
            $j = $this->dat[$this->size()-1];
            $this->dat = $navTemp;
            return $j;
        }

    }

    class Map extends mMap {

        public $mapTempK;
        public $mapTempV;
        public $vMap;
        public $key;
        public $value;
        //for future
        public $keyType;
        public $valueType;
        public $map;

        public function __construct() {
            $this->rootType = 'Container';
            $this->typeOf = 'Map';
        }

        public function size() {
            if (sizeof($this->key) == sizeof($this->value))
                return sizeof($this->key);
            else
                return 'WOOP! WOOOP! ALERT!!! ERROR!';
        }

        public function clear() {
            $this->map = array();
        }

        public function keyIsIn($k) {
            if ($this->size() == 0)
                return -1;
            for ($i = 0; $i < $this->size(); $i++) {
                if ($this->key[$i] == $k)
                    return $i;
            }
            return -1;
        }

        public function valIsIn($v) {
            if ($this->size() == 0)
                return 0;
            for ($i = 0; $i < $this->size(); $i++) {
                if ($this->value[$i] == $v)
                    return 1;
            }
            return 0;
        }

        public function equals($r) {
            if ($r->size() != $this->size())
                return 0;
            for ($i = 0; $i < $this->size(); $i++) {
                if (!($this->keyIsIn($r[$i])))
                    return 0;
                if (!($this->valIsIn($r[$i])))
                    return 0;
            }
            return 1;
        }

        public function get($k) {
            if ($this->size() == 0)
                return 0;
            if (!($this->keyIsIn($r[$i])))
                return 0;
            for ($i = 0; $i < $this->size(); $i++) {
                if ($this->key[$i] == $k)
                    return $this->value[$i];
            }
        }

        public function isEmpty() {
            if ($this->size() == 0)
                return 1;
            else
                return 0;
        }

        public function addAll($r) {
            if ($this->typeOf != $r->typeOf)
                return 0;
            for ($i = 0; $i < $r->size(); $i++)
                $this->add($r->key[$i], $r->value[$i]);
        }

        public function remove($k) {
            $mapTempK = '';
            $mapTempV = '';
            if ($this->size() == 0)
                return 0;
            for ($i = 0; $i < $this->size(); $i++) {
                if ($this->key[$i] != $k) {
                    $mapTempK[] = $this->key[$i];
                    $mapTempV[] = $this->value[$i];
                }
            }
            $this->key = $mapTempK;
            $this->value = $mapTempV;
            return 1;
        }

        public function removeKV($k, $v) {
            $mapTempK = '';
            $mapTempV = '';
            if ($this->size() == 0)
                return 0;
            for ($i = 0; $i < $this->size(); $i++) {
                if ($this->key[$i] != $k && $this->value[$i] != $v) {
                    $mapTempK[] = $this->key[$i];
                    $mapTempV[] = $this->value[$i];
                }
            }
            $this->key = $mapTempK;
            $this->value = $mapTempV;
            return 1;
        }

        public function replace($k, $v) {
            $mapTempK = '';
            $mapTempV = '';
            if ($this->size() == 0)
                return 0;
            $val;
            for ($i = 0; $i < $this->size(); $i++) {
                if ($this->key[$i] != $k) {
                    $mapTempK[] = $this->key[$i];
                    $mapTempV[] = $this->value[$i];
                }
                else {
                    $mapTempK[] = $this->key[$i];
                    $val = $this->value[$i];
                    $mapTempV[] = $v;
                }
            }
            $this->key = $mapTempK;
            $this->value = $mapTempV;
            return $val;
        }

        public function add($k, $v) {
            $mapTempK = '';
            $mapTempV = '';
            $p = (-1);
            if ($this->size() > 0) {
                for ($i = 0; $i < $this->size(); $i++) {
                    if ($this->key[$i] == $k)
                        $p = $i;
                }
            }

            if ($p == (-1)) {
                $this->key[] = $k;
                $this->value[] = $v;
                $p = $this->getIndex();
            }
            else {
                $this->value[$p] = $v;
            }

            if ($this->typeOf == 'SortedMap' || $this->typeOf == 'NavigableMap') {

                if (sizeof($this->key) > 0) {
                    $vals = $this->key;
                    sort($vals);
                    for ($i = 0; $i < $this->size(); $i++) {
                        for ($j = $i; $j < $this->size(); $j++) {
                            if ($vals[$i] == $this->key[$j]) {
                                $mapTempK[] = $this->key[$j];
                                $mapTempV[] = $this->value[$j];
                            }
                        }
                    }
                }
                $this->key = $mapTempK;
                $this->value = $mapTempV;
            }
            return 1;
        }

    }

    //This is the Map-in-Map Extension
    class mMap extends Container {
        public $val;
        public $keys;
        public $dat;
        public $map;
        public $datCntr;
        public $key;
        public $value;
        public $mmap;
        public $name;
        public $reglist;
        public $regreturn;

        public function __construct() {
            $this->typeOf = 'mMap';
            $this->parentType = 'Container';
            $this->rootType = 'Container';
        }

        public function size() {
            return sizeof($this->map);
        }

        public function add($k, $v) {
            $mapTempK = '';
            $mapTempV = '';
            $p = (-1);
            if (sizeof($this->key) > 0) {
                for ($i = 0; $i < sizeof($this->key); $i++) {
                    if ($this->key[$i] == $k)
                        $p = $i;
                }
            }

            if ($p == (-1)) {
                $this->key[] = $k;
                $this->value[] = $v;
                $p = $this->getIndex();
            }
            else {
                $this->value[$p] = $v;
            }

            if (($this->typeOf == 'SortedMap' || $this->typeOf == 'NavigableMap') && $this->parentType == 'Map') {

                if (sizeof($this->key) > 0) {
                    $vals = $this->key;
                    sort($vals);
                    for ($i = 0; $i < $this->size(); $i++) {
                        for ($j = $i; $j < $this->size(); $j++) {
                            if ($vals[$i] == $this->key[$j]) {
                                $mapTempK[] = $this->key[$j];
                                $mapTempV[] = $this->value[$j];
                            }
                        }
                    }
                }
                $this->key = $mapTempK;
                $this->value = $mapTempV;
            }
            return 1;
        }

        public function getMap($regex) {
            $reglist = array();
            $regreturn = array();
            for ($i = 0; $i < $this->size(); $i++) {    
                if (preg_match($regex, $this->map[$i]->name) || preg_match($regex, $this->value[$i]->name)) {
                    if (preg_match($regex, $this->map[$i]->name)) {
                        if (sizeof($reglist) == 0)
                            $reglist = array($this->map[$i]->name);
                        else
                            $reglist = array($reglist,$this->map[$i]->name);
                    } else if (preg_match($regex, $this->value[$i]->name)) {
                        if (sizeof($reglist) == 0)
                            $reglist = array($this->value[$i]->name);
                        else
                            $reglist = array($reglist,$this->value[$i]->name);
                    }
                }
                if (sizeof($regreturn) > 0 && sizeof($reglist) > 0)
                    $regreturn = array($regreturn,$reglist);
                else if (sizeof($regreturn) == 0 && sizeof($reglist) > 0)
                    $regreturn = $reglist;
                $reglist = array();
            }
            return $regreturn;
        }

        public function insNewMap($keys, $r) {
            if ($r == 'Map')
                $this->map[] = new Map();
            else if ($r == 'SortedMap')
                $this->map[] = new SortedMap();
            else if ($r == 'mMap')
                $this->map[] = new mMap();
            else if ($r == 'NavigableMap')
                $this->map[] = new NavigableMap();
            else
                return 0;
            $this->map[$this->size()-1]->name = $keys;
            return 1;
        }

        public function hasNext() {
            if ($this->size() == 0)
                return 0;
            if ($this->getIndex() < $this->size())
                return 1;
            return 0;
        }

        public function nextMap($bool) {
            if ($this->hasNext() == 1) {
                $this->cntIncr();
                if ($bool == 1)
                    $this->joinMap();
                return 1;
            }
            else if ($this->size() == 1) {
                $this->setIndex(1);
                if ($bool == 1)
                    $this->joinMap();
                return 1;
            }
            else if ($this->size() == 0) {
                $this->setIndex(0);
                $this->mmap = null;
                return 0;
            }
        }

        public function findMap($regex) {
            $reglist = array();
            $regreturn = array();
            $reglist2 = array();
            for ($i = 0; $i < $this->size(); $i++) {
                $x = 0;
                $y = 0;
                if (preg_match($regex, $this->map[$i]->name) || preg_match($regex, $this->value[$i]->name)) {
                    if (preg_match($regex, $this->map[$i]->name)) {
                        if (sizeof($reglist2) == 0)
                            $reglist2 = $this->map[$i]->name;
                        else
                            $reglist2 = array($reglist2,$this->map[$i]->name);
                    } else if (preg_match($regex, $this->value[$i]->name)) {
                        if (sizeof($reglist2) == 0)
                            $reglist2 = $this->value[$i]->name;
                        else
                            $reglist2 = array($reglist2,$this->value[$i]->name);
                    }

                    if (isset($this->map[$i]->typeOf)) {
                        for ($j = 0; $j < sizeof($this->map[$i]->map); $j++) {
                            if (preg_match($regex, $this->map[$i]->map[$j]->name)) {
                                if (sizeof($reglist2) == 0)
                                    $reglist2 = $this->map[$i]->map[$j]->name;
                                else
                                    $reglist2 = array($reglist2,$this->map[$i]->map[$j]->name);
                            }
                        }
                    }
                    $reglist = $reglist2;
                }
                if (isset($this->map[$i]->name))
                    $x = 1;
                else if (isset($this->value[$i]->name))
                        $y = 1;
                else if (! isset($this->map[$i]->name) && ! isset($this->value[$i]->name))
                        continue;
                if ($x == 1) {
                    if ($this->map[$i]->typeOf == 'Map' || $this->map[$i]->typeOf == 'SortedMap' || $this->map[$i]->typeOf == 'NavigableMap') {
                        if ($this->map[$i]->findMap($regex) != null && $this->map[$i]->findMap($regex) != "") {
                            if (sizeof($reglist) == 0)
                                $reglist = $this->map[$i]->findMap($regex);
                            else if (sizeof($reglist) > 0)
                                $reglist = array($reglist,$this->map[$i]->findMap($regex));
                        }
                    }
                    if ($this->map[$i]->typeOf == 'mMap') {
                        for ($j = 0; $j < sizeof($this->map[$i]->map); $j++) {
                            if ($this->map[$i]->map[$j]->findMap($regex) != null && $this->map[$i]->map[$j]->findMap($regex) != "") {
                                if (sizeof($reglist) == 0)
                                    $reglist = $this->map[$i]->map[$j]->findMap($regex);
                                else if (sizeof($reglist) > 0)
                                    $reglist = array($reglist,$this->map[$i]->map[$j]->findMap($regex));
                            }
                        }
                    }
                    if (sizeof($regreturn) > 0 && sizeof($reglist) > 0)
                        $regreturn = array($regreturn,$reglist);
                    else if (sizeof($regreturn) == 0 && sizeof($reglist) > 0)
                        $regreturn = $reglist;
                    $reglist = array();
                }
                if ($y == 1) {
                    if ($this->value[$i]->typeOf == 'Map' || $this->value[$i]->typeOf == 'SortedMap' || $this->value[$i]->typeOf == 'NavigableMap') {
                        if ($this->value[$i]->findMap($regex) != null && $this->value[$i]->findMap($regex) != "") {
                            if (sizeof($reglist) == 0)
                                $reglist = $this->value[$i]->findMap($regex);
                            else if (sizeof($reglist) > 0)
                                $reglist = array($reglist,$this->value[$i]->findMap($regex));
                        }
                    }
                    if ($this->value[$i]->typeOf == 'mMap') {
                        for ($j = 0; $j < sizeof($this->value[$i]->map); $j++) {
                            if ($this->value[$i]->map->findMap($regex) != null && $this->value[$i]->map->findMap($regex) != "") {
                                if (sizeof($reglist) == 0)
                                    $reglist = $this->value[$i]->map->findMap($regex);
                                else if (sizeof($reglist) > 0)
                                    $reglist = array($reglist,$this->value[$i]->map->findMap($regex));
                            }
                        }
                    }
                    if (sizeof($regreturn) > 0 && sizeof($reglist) > 0)
                        $regreturn = array($regreturn,$reglist);
                    else if (sizeof($regreturn) == 0 && sizeof($reglist) > 0)
                        $regreturn = $reglist;
                    $reglist = array();
                }
            }
            if (sizeof($regreturn) > 1)
                return $regreturn[1][0];
            else
                return $regreturn;
        }

        public function findKey($regex) {
            $reglist = array();
            $regreturn = array();
            for ($i = 0; $i < $this->size(); $i++) {            
                for ($j = 0; $j < sizeof($this->map[$i]->key); $j++) {
                    if (preg_match($regex, $this->map[$i]->key[$j])) {
                        if (sizeof($reglist) == 0)
                            $reglist = array($this->map[$i]->name,$this->map[$i]->key[$j]);
                        else if (sizeof($reglist) > 0)
                            $reglist = array($reglist,array($this->map[$i]->name,$this->map[$i]->key[$j]));
                    }
                }
                if (sizeof($regreturn) > 0 && sizeof($reglist) > 0)
                    $regreturn = array($regreturn,$reglist);
                else if (sizeof($regreturn) == 0 && sizeof($reglist) > 0)
                    $regreturn = $reglist;
                $reglist = array();
            }
            return $regreturn;
        }

        public function cycleMap() {
            if ($this->size() == 0)
                return 0;
            if ($this->hasNext() == 1) {
                $this->nextMap(1);
                $this->joinMap();
                return 1;
            }
            else if ($this->hasPrev() == 1) {
                $this->prevMap(1);
                $this->joinMap();
                return 1;
            }
            return 1;
        }

        public function hasPrev() {
            if ($this->size() == 0)
                return 0;
            if ($this->getIndex() - 1 > 0)
                return 1;
            return 0;
        }

        public function prevMap($bool) {
            if ($this->hasNext() == 1) {
                $this->cntDecr();
                if ($bool == 1)
                    $this->joinMap();
                return 1;
            }
            else if ($this->size() == 1) {
                $this->setIndex(1);
                if ($bool == 1)
                    $this->joinMap();
                return 1;
            }
            else if ($this->size() == 0) {
                $this->setIndex(0);
                $this->mmap = null;
                return 0;
            }
        }

        public function currMap() {
            return $this->getIndex();
        }

        public function remMap($r) {
            if ($this->size() == 0)
                return 0;
            $tempAneous = array();
            for ($i = 0; $i < $this->size(); $i++) {
                if ($i != $r)
                    $tempAneous[] = $this->dat[$i];
            }
            return $this->dat = $tempAneous;
        }

        public function joinMap() {
            if ($this->size() == 0) {
                $this->mmap = null;
                return 0;
            }
            if ($this->size() == 1)
                $this->setIndex(1);
            if ($this->getIndex() > $this->size())
                $this->setIndex($this->size());
            $this->mmap = $this->map[$this->getIndex()-1];
            $this->mmapName = $this->map[$this->getIndex()-1]->name;
            return 1;
        }

        private function cntIncr() {
            return ++$this->datCntr;
        }

        private function cntDecr() {
            return --$this->datCntr;
        }

        public function getIndex() {
            if ($this->size() > 0)
                return $this->datCntr;
            else
                return 0;
        }

        public function setIndex($indx) {
            if ($this->size() == 0) {
                $this->datCntr = 0;
                $this->mmap = null;
                return 0;
            }
            if ($indx <= $this->size() && $indx > 0)
                return $this->datCntr = $indx;
        }

        public function clear() {
            $this->map= array();
        }

        public function keyIsIn($k) {
            if ($this->size() == 0)
                return 0;
            for ($i = 0; $i < sizeof($this->map); $i++) {
                if ($this->key[$i] == $k)
                    return 1;
            }
            return 0;
        }

        public function valIsIn($v) {
            if ($this->size() == 0)
                return 0;
            for ($i = 0; $i < $this->size(); $i++) {
                if ($this->value[$i] == $v)
                    return 1;
            }
            return 0;
        }

        public function equals($r) {
            if ($r->typeOf != 'Map' || $r->size() != $this->size())
                return 0;
            for ($i = 0; $i < $this->size(); $i++) {
                if (!($this->keyIsIn($r[$i])))
                    return 0;
                if (!($this->valIsIn($r[$i])))
                    return 0;
            }
            return 1;
        }

        public function get($k) {
            if ($this->size() == 0)
                return 0;
            if (!($this->keyIsIn($r[$i])))
                return 0;
            for ($i = 0; $i < $this->size(); $i++) {
                if ($this->key[$i] == $k)
                    return $this->value[$i];
            }
        }

        public function isEmpty() {
            if ($this->size() == 0)
                return 1;
            else
                return 0;
        }

        public function addAll($r) {
            if ($this->typeOf != $r->typeOf)
                return 0;
            for ($i = 0; $i < $r->size(); $i++)
                $this->mmap->add($r->key[$i], $r->value[$i]);
        }

        public function remove($k) {
            $mapTempK = '';
            $mapTempV = '';
            if ($this->size() == 0)
                return 0;
            for ($i = 0; $i < $this->size(); $i++) {
                if ($this->key[$i] != $k) {
                    $mapTempK[] = $this->key[$i];
                    $mapTempV[] = $this->value[$i];
                }
            }
            $this->key = $mapTempK;
            $this->value = $mapTempV;
            return 1;
        }

        public function removeKV($k, $v) {
            $mapTempK = '';
            $mapTempV = '';
            if ($this->size() == 0)
                return 0;
            for ($i = 0; $i < $this->size(); $i++) {
                if ($this->key[$i] != $k && $this->value[$i] != $v) {
                    $mapTempK[] = $this->key[$i];
                    $mapTempV[] = $this->value[$i];
                }
            }
            $this->key = $mapTempK;
            $this->value = $mapTempV;
            return 1;
        }

        public function replace($k, $v) {
            $mapTempK = '';
            $mapTempV = '';
            if ($this->size() == 0)
                return 0;
            $val;
            for ($i = 0; $i < $this->size(); $i++) {
                if ($this->key[$i] != $k) {
                    $mapTempK[] = $this->key[$i];
                    $mapTempV[] = $this->value[$i];
                }
                else {
                    $mapTempK[] = $this->key[$i];
                    $val = $this->value[$i];
                    $mapTempV[] = $v;
                }
            }
            $this->key = $mapTempK;
            $this->value = $mapTempV;
            return $val;
        }
    }

    class SortedMap extends Map {

        public $parentType;

        public function __construct() {
            $this->rootType = 'Container';
            $this->parentType = 'Map';
            $this->typeOf = 'SortedMap';
        }

        public function firstKey() {
            if ($this->size() == 0)
                return 0;
            return array($this->key[0], $this->value[0]);
        }

        public function lastKey() {
            if ($this->size() == 0)
                return 0;
            return array($this->key[$this->size()-1], $this->value[$this->size()-1]);
        }

        public function headMap($v, $vb) {
            $mapTempK = '';
            $mapTempV = '';
            if ($this->size() == 0)
                return 0;
            for ($i = 0; $i < $this->size(); $i++) {
                if ($v <= $vals[$i] && $vb == 1) {
                    $mapTempK[] = $this->key[$i];
                    $mapTempV[] = $this->value[$i];
                }
                if ($v < $vals[$i] && $vb == 0) {
                    $mapTempK[] = $this->key[$i];
                    $mapTempV[] = $this->value[$i];
                }
            }
            $vMap[] = $mapTempK;
            $vMap[] = $mapTempV;
            return $vMap;
        }

        public function subMap($vst, $Lb, $ven, $Hb) {
            $mapTempK = '';
            $mapTempV = '';
            if ($this->size() == 0)
                return 0;
            if ($vst > $ven) {
                $tmp = $ven;
                $ven = $vst;
                $vst = $tmp;
            }
            for ($i = 0; $i < $this->size(); $i++) {
                if ($Lb == 1) {
                    if ($this->value[$i] >= $vst) {
                        do {
                            $mapTempK[] = $this->key[$i];
                            $mapTempV[] = $this->value[$i];
                            $i++;
                        } while ($vst <= $this->value[$i]);
                    }
                }
                if ($Lb == 0) {
                    if ($this->value[$i] > $vst) {
                        do {
                            $mapTempK[] = $this->key[$i];
                            $mapTempV[] = $this->value[$i];
                            $i++;
                        } while ($vst <= $this->value[$i]);
                    }
                }
                if ($Hb == 1) {
                    if ($this->value[$i] <= $ven) {
                        do {
                            $mapTempK[] = $this->key[$i];
                            $mapTempV[] = $this->value[$i];
                            $i++;
                        } while ($ven >= $this->value[$i]);
                    }
                }
                if ($Hb == 0) {
                    if ($this->value[$i] < $ven) {
                        do {
                            $mapTempK[] = $this->key[$i];
                            $mapTempV[] = $this->value[$i];
                            $i++;
                        } while ($ven >= $this->value[$i]);
                    }
                }
            }
            $vMap[] = $mapTempK;
            $vMap[] = $mapTempV;
            return $vMap;
        }

        public function tailMap($st) {
            $mapTempK = '';
            $mapTempV = '';
            if ($this->size() == 0)
                return 0;
            $vals = $this->value;
            sort($vals, SORT_STRING);
            for ($i = 0; $i < $this->size(); $i++) {
                if ($v >= $vals[$i] && $vb == 1) {
                    $mapTempK[] = $this->key[$i];
                    $mapTempV[] = $this->value[$i];
                }
                if ($v > $vals[$i] && $vb == 0) {
                    $mapTempK[] = $this->key[$i];
                    $mapTempV[] = $this->value[$i];
                }
            }
            $vMap[] = $mapTempK;
            $vMap[] = $mapTempV;
            return $vMap;
        }
    }

    class NavigableMap extends SortedMap {

        public $parentType;

        public function __construct() {
            $this->rootType = 'Container';
            $this->parentType = 'Map';
            $this->typeOf = 'NavigableMap';
        }

        public function ceilKey($r) {
            $vMap = '';
            if ($this->size() == 0)
                return 0;
            else if ($this->size() == 1)
                return array($this->key, $this->value);
            for ($i = 0; $i < $this->size(); $i++) {
                if (($r <= $this->value[$i])) {
                    $vMap[] = $this->key[$i-1];
                    $vMap[] = $this->value[$i-1];
                    return $vMap;
                }
            }
            return 0;
        }

        public function descKeySet() {
            $vMap = '';
            if ($this->size() == 0)
                return 0;
            else if ($this->size() == 1)
                return array($this->key, $this->value);     
            $keys = $this->key;
            rsort($keys, SORT_STRING);
            for ($i = 0; $i < $this->size(); $i++) {
                for ($j = $i; $j < $this->size(); $j++) {
                    if ($keys[$i] == $this->value[$j]) {
                        $vMap[] = $this->key[$j];
                        $vMap[] = $this->value[$j];
                        break;
                    }
                }
            }
            $this->key = $mapTempK;
            $this->value = $mapTempV;
            return 1;
        }

        public function descMap() {
            $mapTempK = '';
            $mapTempV = '';
            if ($this->size() == 0)
                return 0;
            else if ($this->size() == 1)
                return array($this->key, $this->value);
            for ($j = $this->size()-1; $j >= 0; $j--) {
                $mapTempK[] = $this->key[$j];
                $mapTempV[] = $this->value[$j];
            }
            $this->key = $mapTempK;
            $this->value = $mapTempV;
            return 1;
        }

        public function floorEntry($v) {
            $vMap = '';
            if ($this->size() == 0)
                return 0;
            else if ($this->size() == 1)
                return array($this->key, $this->value);
            for ($i = 0; $i < $this->size(); $i++) {
                if (! ($v >= $this->value[$i])) {
                    $vMap[] = $this->key[$i-1];
                    $vMap[] = $this->value[$i-1];
                    return $vMap;
                }
            }
            return 0;
        }

        public function navigableKeySet() {
            $mapTempK = '';
            if ($this->size() == 0)
                return 0;
            else if ($this->size() == 1)
                return array($this->key);
            for ($i = 0; $i < $this->size(); $i++) {
                $mapTempK[] = $this->key[$i];
            }
            return $mapTempK;
        }

        public function pollFirst() {
            $mapTempK = '';
            $mapTempV = '';
            if ($this->size() == 0)
                return 0;
            else if ($this->size() == 1)
                return array($this->key, $this->value);
            for ($i = 1; $i < $this->size(); $i++) {
                $mapTempK[] = $this->key[$i];
                $mapTempV[] = $this->value[$i];
                break;
            }
            $j[0] = $this->key[0];
            $j[1] = $this->value[0];
            $this->key = $mapTempK;
            $this->value = $mapTempV;
            return $j;
        }

        public function pollLast() {
            $mapTempK = '';
            $mapTempV = '';
            if ($this->size() == 0)
                return 0;
            else if ($this->size() == 1)
                return array($this->key, $this->value);
            for ($i = 0; $i < $this->size(); $i++) {
                if ($i != $this->size()-1) {
                    $mapTempK[] = $this->key[$i];
                    $mapTempV[] = $this->value[$i];
                    break;
                }
            }
            $j[0] = $this->key[$this->size()-1];
            $j[1] = $this->value[$this->size()-1];
            $this->key = $mapTempK;
            $this->value = $mapTempV;
            return $j;
        }
    }

    function wait($t) {
        $time = time();
        do {    // . . . the hell was he waiting for??
            // You can do this upto 30 secs, per system setup
            } while ($time + $t > time());
    }

    class Streams {

        public $rootType;
        public $parentType;
        public $name;
        public $stream;
        public $typeOf;
        public $seqStrms;
        private $seqCntr;
        public $buffData;
        public $buffSize;
        public $buf;
        private $delim;


        public function __construct() {
            $this->seqCntr = 0;
        }

        private function cntIncr() {
            return ++$this->seqCntr;
        }

        private function cntDecr() {
            return --$this->seqCntr;
        }

        public function getIndex() {
            return $this->seqCntr;
        }

        public function setIndex($indx) {
            return $this->seqCntr = $indx;
        }

        public function touch($filename) {
            if (file_exists($filename))
                return 1;
            else {
                fopen($filename, 'a+');
                if (file_exists($filename)) {
                    fclose($filename);
                    return 1;
                }
                else
                    return 0;
            }
            return 0;
        }

        public function add($r, $bool) {
            $rw = '';
            if ($this->typeOf == 'readStream')
                $rw = 'r';
            else if ($this->typeOf == 'rwStream')
                $rw = 'a';
            else $rw = 'w';
            if ($bool == 1)
                $rw .= '+';
            if ($this->touch($r) == 1)
                $this->seqStrms->add($r, fopen($r, $rw));
            else
                return 0;
            return 1;
        }

        public function size() {
            if (sizeof($this->seqStrms->key) > 0)
                return sizeof($this->seqStrms->key);
            return 0;
        }

        public function hasNext() {
            if ($this->size() == 0)
                return 0;
            if ($this->getIndex() < $this->size())
                return 1;
            return 0;
        }

        public function nextStrm($bool) {
            if ($this->hasNext() == 1) {
                $this->cntIncr();
                if ($bool == 1)
                    $this->joinStrm();
            }
            else if ($this->hasNext() == 0 && $this->size() > 0) {
                $this->setIndex($this->size());
                if ($bool == 1)
                    $this->joinStrm();
                return 1;
            }
            else if ($this->size() == 0) {
                $this->setIndex(0);
                $this->stream = null;
                $this->streamName = null;
                return 0;
            }
            return 1;
        }

        public function hasPrev() {
            if ($this->size() == 0)
                return 0;
            if ($this->getIndex() > 1)
                return 1;
            return 0;
        }

        public function prevStrm($bool) {
            if ($this->hasPrev() == 1) {
                $this->cntDecr();
                if ($bool == 1)
                    $this->joinStrm();
            }
            else if ($this->size() == 1) {
                $this->setIndex(1);
                if ($bool == 1)
                    $this->joinStrm();
                return 1;
            }
            else if ($this->size() == 0) {
                $this->setIndex(0);
                $this->stream = null;
                $this->streamName = null;
                return 0;
            }
            $this->joinStrm();
            return 1;
        }

        public function cycleStrm() {
            if ($this->size() == 0)
                return 0;
            if ($this->size() < $this->getIndex())
                $this->setIndex(1);
            if ($this->hasNext() == 1) {
                $this->nextStrm(1);
                return $this->currStrm();
            }
            else if ($this->hasPrev() == 1) {
                $this->prevStrm(1);
                return $this->currStrm();
            }
            else {
                $this->setIndex($this->size());
                return $this->currStrm();
            }
            return 0;
        }

        public function currStrm() {
            if ($this->size() == 0)
                return 0;
            if ($this->getIndex() > $this->size())
                $this->setIndex($this->size());
            return $this->getIndex();
        }

        public function remSeqStrm($r) {
            if ($this->size() == 0)
                return 0;
            $tempAneous = new Map();
            for ($i = 0; $i < $this->size(); $i++) {
                if ($i != $r) {
                    $tempor[0] = $this->seqStrms->key[$i];
                    $tempor[1] = $this->seqStrms->value[$i];
                    $tempAneous->add($tempor[0], $tempor[1]);
                }
            }
            $this->cycleStrm();
            return $this->seqStrms = $tempAneous;
        }

        public function fileSize() {
            return filesize($this->streamName);
        }

        public function joinStrm() {
            if ($this->size() == 0)
                return 0;
            if ($this->getIndex() == 0 || $this->getIndex() > $this->size())
                $this->setIndex(1);
            $this->stream = $this->seqStrms->value[$this->getIndex()-1];
            $this->streamName = $this->seqStrms->key[$this->getIndex()-1];
            return 1;
        }

        public function resize($s) {
            //add preg to assure $s is integer
            if ($s > 0)
                $this->buffSize = $s;
            else
                return 0;
            return 1;
        }

        public function setDelim($d) {
            return $this->delim = $d;
        }

        public function resetDelim() {
            return $this->delim = '';
        }

        public function clearBuf() {
            return $this->buffData = null;
        }

        public function seek($pos, $flag) {
            if ($flag == 'e')
                $f = 'SEEK_END';
            else if ($flag == 's')
                $f = 'SEEK_SET';
            else if ($flag == 'c')
                $f = 'SEEK_CUR';
            else
                return -1;
            if ($this->stream == null || $this->streamName == null) {
                echo 'Stream Not Available';
                return 0;
            }
            else
                fseek($this->stream, $pos, $f);
            return 1;
        }

        public function eof() {
            if (! feof($this->stream) && $this->streamName != null)
                return 0;
            else
                return 1;
        }

        public function readBuf() {
            if ($this->parentType != 'Streams' && ($this->typeOf != 'rwStream' ^ $this->typeOf != 'readStream'))
                return 0;

            if ($this->size() == 0) {
                echo 'No Stream Available';
                return 0;
            }

            if (!file_exists($this->streamName))
                return 0;
            if ($this->buffSize == 0)
                $this->y = $this->filesize();
            else
                $this->y = $this->buffSize;

            for ($i = 0; $i < $this->y; $i++) {
                $buf = fgetc($this->stream);
                if ($buf == '<')
                    $buf = '&lt;';
                if ($buf == $this->delim || feof($this->stream))
                    break;
                $this->buffData .= $buf;
            }
            return 1;
        }

        public function writeBuf() {
            if ($this->streamName != null && $this->typeOf != 'readStream' && $this->parentType == 'Streams')
                return fwrite($this->stream, $this->buf);
        }

        public function close() {
            $this->remSeqStrm($this->getIndex());

            return fclose($this->stream);
        }
    }

    class readStream extends Streams {

        public $stream;
        public $streamName;
        public $parentType;
        public $delim;

        public function __construct() {
            $this->rootType = 'Streams';
            $this->parentType = 'Streams';
            $this->typeOf = 'readStream';
            $this->seqStrms = new SortedMap();
            $this->buffSize = 16;
            $this->seqCntr = 0;
        }

    }

    class writeStream extends Streams {

        public $stream;
        public $parentType;

        public function __construct() {
            $this->rootType = 'Streams';
            $this->parentType = 'Streams';
            $this->typeOf = 'writeStream';
            $this->seqStrms = new SortedMap();
            $this->seqCntr = 0;
        }

    }

    class rwStream extends Streams {

        public $stream;
        public $parentType;

        public function __construct() {
            $this->rootType = 'Streams';
            $this->parentType = 'Streams';
            $this->typeOf = 'rwStream';
            $this->seqStrms = new SortedMap();
            $this->seqCntr = 0;
            $this->buffSize = 16;
        }
    }

    class DataLayer {
        // require_once("/datalayer.php?SESSID=918274015094890347");
        // how many people have traveled to the index? A: require datalayer.php w/ one SESSID
        // (how many people have a thread?) A: new Map() of md5(HTTP_ORIGIN), server updates in JSONs!!
        // stacks are threads. Keep md5(stack_maps).ini in /ini/ to keep record of each.
        // when to update?
        public $stackcnt;
        public $threadcnt;
        public $threads;
        public $sessid;
        public $time;
        public $msgr;
        public $pages;
        public $stack;
        public $FIFO;
        public $ADDR_OF_STK;
        public $ADDR_STK_CNT;
        public $rootType;

        public function __construct() {
            $this->rootType = 'DataLayer';
        }
    }

    class Thread extends Datalayer {
        // ************* 
        // BEGIN HERE
        // start new thread for Javascript
        // interactions. Pass JSONs dynamically.
        // If a Value changes, it can be reassigned.
        // Setup new Stack(), insert threads
        // and you can have unlimited constructs,
        // like the ones here, in COLE handling
        // the data quite civil to break up boring
        // old but true ways to act. Say, a running
        // SESSID processing, but detached.
        // To enable simultaneous function:
        // after Interval({}) , open md5(user).JSON file
        // and read Array. Dynamically exchange
        // between servers and pages. Keep all
        // code secret by using a rwStream() read to
        // make server updates that fit user needs.
        // Frequency means data congruency
        // between users and admins by JSON.
        // This just personalizes the task.
        // Direct and redirect thru "/ini/" files
        // *************
        public $parentType;
        public $finit;
        private $dir;

        public function __construct() {
            $this->rootType = 'DataLayer';
            $this->parentType = 'DataLayer';
            $this->typeOf = 'Thread';
            $this->finit = new rwStream();
            $this->dir = "/ini/";
            $this->finit->seqCntr = 0;
        }

        private function cntIncr() {
            return ++$this->finit->seqCntr;
        }

        private function cntDecr() {
            return --$this->finit->seqCntr;
        }

        public function getIndex() {
            return $this->finit->seqCntr;
        }

        public function setIndex($indx) {
            return $this->finit->seqCntr = $indx;
        }

        public function changeDir($dir) {
            $this->dir = $dir;
        }

        // $origin mut be Unique to each user.
        // This creates a database of CSV files
        // Each is seemingly randomly named.
        // (Hold sequential $handles in $origin files)
        // Use JSON is CSV is not to your liking.
        public function startThread($origin) {
            $handle = md5($origin);
            if ($this->finit->touch($this->dir . $handle) == 1)
                $this->finit->add($this->dir . $handle, 1);
            else
                return 0;
            $this->finit->cycleStrm();
            return 1;
        }

        public function joinThread() {
            return $this->finit->joinStrm();
        }

        public function nextThread() {
            return $this->finit->nextStrm(0);
        }

        public function prevThread() {
            return $this->finit->prevStrm(0);
        }

        public function cycleThreads() {
            return $this->finit->cycleStrm();
        }

        public function clearThread($origin) {
            $handle = md5($origin);
            if (file_exists($this->dir . $handle) == 1) {
                fopen($this->dir . $handle, 'w');
                if (filesize($this->dir . $handle) == 0)
                    return 1;
                else
                    return 0;
            }
            else
                return 0;
            return 1;
        }

        public function endThread() {
            $this->finit->remSeqStream($this->finit->getIndex());
            $this->finit->cycleStrm();
            return 1;
        }

        public function readThread() {
            $this->finit->setDelim("}");
            $this->finit->resize(0);
            while (! $this->finit->eof()) {
                $this->finit->readBuf();
                $this->json[] = $this->finit->buffData;
                $this->finit->buffData = null;
            }
            return 1;
        }

        public function writeThread($obj_array) {
            $x = json_encode($obj_array);
            if ($this->finit->stream == null || $this->finit->streamName == null)
                return 0;
            fwrite($this->finit->stream, $x);
            return 1;
        }
    }

    class Stack extends Thread {

        public $calipers;
        public $parentType;

        public function __construct() {
            $this->rootType = 'DataLayer';
            $this->parentType = 'Thread';
            $this->typeOf = 'Stack';
            $this->ADDRS_STK_CNT = 100;
            $this->calipers = 60000;
            $this->thrdMngr();
            $this->FIFO = new Queue();
        }

        public function size() {
            return sizeof($this->FIFO);
        }

        public function unstack() {
            //tell each session ID to update..
            while ($this->size() > 0) {
                include($this->FIFO->poll());
            }
        }

        public function thrdMngr() {
            //wait($this->calipers);
            if ($this->size() > $this->ADDRS_STK_CNT)
                $this->unstack();
        }

        public function insert($stackurl) {
            $this->FIFO[] = $stackurl;
        }

        public function clear() {
            $this->FIFO = array();
        }
    }

//  if (isset($_GET['url'])) {
//          $thread1->insert($_GET['url']);
//  }

?>
\$\endgroup\$
6
  • \$\begingroup\$ Would you happen to have code examples on how it is used? Presently I can't really say if/how it works, or how I should use it. \$\endgroup\$ – Félix Gagnon-Grenier Oct 6 '17 at 19:01
  • 1
    \$\begingroup\$ Why does the Set have anything to do with indexes and arrays? Set and Map use linear search to determine if keys exist and to get items? Have you looked at how these data structures are typically implemented, eg. in Java? \$\endgroup\$ – BenC Oct 7 '17 at 0:08
  • 1
    \$\begingroup\$ For probably all Java collections there is a good native PHP alternative. We have the humble array, datastructures and many more. Use them! \$\endgroup\$ – KIKO Software Oct 9 '17 at 20:09
  • \$\begingroup\$ I am now working to make a COLE Java implement. At the moment it takes JSONs from PHP and makes them into LinkedHashMaps. Would love ideas for it. All Collections in this Extension will be made available to be pushed from JAVA to PHP to JAVA and back so Good :) \$\endgroup\$ – thexiv Oct 10 '17 at 19:10
  • \$\begingroup\$ I don't have time to review 2K lines of code, but a cursory glance reveals several (what I think are) major problems: a lack of proper documentation, significant (and often inexplicable) deviations from the Java interfaces, and quite a few design issues... Vector appears to simulate generics, but why does it only support a fixed set of types? Why provide a Thread class while PHP already has one? What do threads have to do with CSV files and JSON? Why does Stack extend Thread? Why does Map store keys and values in separate arrays, rather than a single key => value array? And so on... \$\endgroup\$ – Pieter Witvoet Oct 20 '17 at 21:59
2
\$\begingroup\$

I appreciate you putting all your work on here!

I took your code and have treated it like I would with any code-review!

Please see below

public function indxOf($r) {
    if ($this->size() == 0 || $indx >= $this->size())
        return 0;
    for ($i = 0; $i < $this->size(); $i++) {
        if ($this->dat[$i] == $r)
            return $i;
    }
    return 0;
}

$indx is not referenced anywhere

public function compare($r) {
        $temp;
        if ($r->size() != $this->size())
            return 0;
        for ($i = 0; $i < $this->size(); $i++) {
            if ($this->valIsIn($r->dat[$i]))
                $temp[] = $r->dat[$i];
        }
        return $temp;
    }

$temp should not be assigned like that, you should use $temp = []; instead. I also think naming a variable $temp is not good for readability. Your function is named compare, so I would expect it to return something to do with comparison, but instead, it is returing every element in $r that is also in $this->dat

PHP has a function for this called array_intersect

You are using a for loop but do not need the index, I would recommend using a foreach instead

You are also doing 2 lookups in the array, this can be converted to 1

public function push($r) {
        $queueTemp = '';
        return $this->dat[] = $r;
    }

$queueTemp is not used

public function pop() {
        $queueTemp = '';
        $queueTemp = array();
        if ($this->size() == 0)
            return 0;
        for ($i = 1; $i < $this->size()-1; $i++)
            $queueTemp[] = $this->dat[$i];
        $j = $this->dat[$this->size()-1];
        $this->dat = $queueTemp;
        return 1;
    }

$queueTemp is given a value twice.

class rwStream extends Streams {

public $stream;
public $parentType;

public function __construct() {
    $this->rootType = 'Streams';
    $this->parentType = 'Streams';
    $this->typeOf = 'rwStream';
    $this->seqStrms = new SortedMap();
    $this->seqCntr = 0;
    $this->buffSize = 16;
}
}

Class names should always start with a Capital.

$this->seqCntr has private access and cannot be assigned like that

private function cntIncr() {
        return ++$this->finit->seqCntr;
    }

Same here, you cannot do an increment on a private property

public function size() {
        if (sizeof($this->seqStrms->key) > 0)
            return sizeof($this->seqStrms->key);
        return 0;
    }

sizeof will never return anything < 0. Therefor this can be converted to a one-liner: return sizeof($this->seqStrms->key);

You should also consider that the code is now calling sizeof twice.

If you ever need a construction like this above you can do the following: if ($size = sizeof($this->seqStrms->key) > 0) then $size can be used later on in the code

public function prevStrm($bool) {
        if ($this->hasPrev() == 1) {
            $this->cntDecr();
            if ($bool == 1)
                $this->joinStrm();
        }
        else if ($this->size() == 1) {
            $this->setIndex(1);
            if ($bool == 1)
                $this->joinStrm();
            return 1;
        }
        else if ($this->size() == 0) {
            $this->setIndex(0);
            $this->stream = null;
            $this->streamName = null;
            return 0;
        }
        $this->joinStrm();
        return 1;
    }

$this->streamName is dynamically declared

public function clearThread($origin) {
        $handle = md5($origin);
        if (file_exists($this->dir . $handle) == 1) {
            fopen($this->dir . $handle, 'w');
            if (filesize($this->dir . $handle) == 0)
                return 1;
            else
                return 0;
        }
        else
            return 0;
        return 1;
    }

return 1 is dead code

I would suggest using tools such as CodeSniffer and MessDetector to help you out with most issues.

It would have been good to have some docblocks on the more complex functions.

I hope you will pick some of these things up in your next version!

\$\endgroup\$
1
  • \$\begingroup\$ github.com/wise-penny/wise I've given most of it docblocks. I've also added so much in this time it's ridiculous. So if you like it, please fork or clone. Thanks for your great words of acclamation! \$\endgroup\$ – thexiv Dec 19 '20 at 16:08
1
\$\begingroup\$

In your vector constructor, you have this:

public function __construct($type) {
    $this->rootType = 'Container';
    $this->typeOf = 'Vector';
    if ($type == 'Dequeue')
        $this->childType = 'Dequeue';
    else if ($type == 'Queue')
        $this->childType = 'Queue';
    else if ($type == 'Set')
        $this->childType = 'Set';
    else if ($type == 'SortedSet')
        $this->childType = 'SortedSet';
    else if ($type == 'NavigableSet')
        $this->childType = 'NavigableSet';
    else if ($type == 'Map')
        $this->childType = 'Map';
    else if ($type == 'SortedMap')
        $this->childType = 'SortedMap';
    else if ($type == 'NavigableMap')
        $this->childType = 'NavigableMap';
    else if ($type == 'Stack')
        $this->childType = 'Stack';
    else if ($type == 'Thread')
        $this->childType = 'Thread';
    else
        return 0;
    return 1;
}

One could change the if/else conditions for switch/case, but I'm not a fan of switch/case in nearly all circumstances. In stead, I use this sort of PHP scripting:

$childTypes = array(
    'Dequeue',
    'Queue',
    'Set',
    'SortedSet',
    'NavigableSet',
    'NavigableSet',
    'Map',
    'SortedMap',
    'NavigableMap',
    'Stack',
    'Thread'   
);

and then you can simply:

if(in_array($type, $childTypes)){
    $this->childType = $type;
}

This way of using a look-up table will mean that you only have to add another condition to the array without the need to add another else or else/if condition.

Or you could use getters and setters to make your constructors smaller - see here: PHP: Getters and Setters

An example of the look-up in action, using a simple test function is here: Using the look-up

\$\endgroup\$
1
  • 1
    \$\begingroup\$ That is very much appreciated. Thank you. \$\endgroup\$ – thexiv Oct 26 '17 at 17:42

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.