mirror of
https://github.com/Karaka-Management/phpOMS.git
synced 2026-02-10 22:18:40 +00:00
Drafting
This commit is contained in:
parent
e47ece41af
commit
4640872d7e
67
Stdlib/Graph/BinaryTree.php
Normal file
67
Stdlib/Graph/BinaryTree.php
Normal file
|
|
@ -0,0 +1,67 @@
|
||||||
|
<?php
|
||||||
|
/**
|
||||||
|
* Orange Management
|
||||||
|
*
|
||||||
|
* PHP Version 7.0
|
||||||
|
*
|
||||||
|
* @category TBD
|
||||||
|
* @package TBD
|
||||||
|
* @author OMS Development Team <dev@oms.com>
|
||||||
|
* @author Dennis Eichhorn <d.eichhorn@oms.com>
|
||||||
|
* @copyright 2013 Dennis Eichhorn
|
||||||
|
* @license OMS License 1.0
|
||||||
|
* @version 1.0.0
|
||||||
|
* @link http://orange-management.com
|
||||||
|
*/
|
||||||
|
namespace phpOMS\Datatypes;
|
||||||
|
|
||||||
|
use phpOMS\Validation\Base\IbanEnum;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Tree class.
|
||||||
|
*
|
||||||
|
* @category Framework
|
||||||
|
* @package phpOMS\Datatypes
|
||||||
|
* @author OMS Development Team <dev@oms.com>
|
||||||
|
* @author Dennis Eichhorn <d.eichhorn@oms.com>
|
||||||
|
* @license OMS License 1.0
|
||||||
|
* @link http://orange-management.com
|
||||||
|
* @since 1.0.0
|
||||||
|
*
|
||||||
|
* @todo : there is a bug with Hungary ibans since they have two k (checksums) in their definition
|
||||||
|
*/
|
||||||
|
class BinaryTree extends Tree
|
||||||
|
{
|
||||||
|
public static function invert($list) : BinaryTree
|
||||||
|
{
|
||||||
|
if (empty($list->getNodes())) {
|
||||||
|
return $list;
|
||||||
|
}
|
||||||
|
|
||||||
|
$left = $list->getLeft();
|
||||||
|
$list->setLeft($list->invert($list->nodes[1]));
|
||||||
|
$list->setRight($list->invert($left));
|
||||||
|
|
||||||
|
return $list;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getLeft() {
|
||||||
|
return $this->nodes[0];
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getRight() {
|
||||||
|
return $this->nodes[1];
|
||||||
|
}
|
||||||
|
|
||||||
|
public function setLeft(BinaryTree $left) {
|
||||||
|
$this->nodes[0] = $left;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function setRight(BinaryTree $right) {
|
||||||
|
$this->nodes[1] = $right;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function inOrder() {
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
0
Stdlib/Graph/Graph.php
Normal file
0
Stdlib/Graph/Graph.php
Normal file
97
Stdlib/Graph/Tree.php
Normal file
97
Stdlib/Graph/Tree.php
Normal file
|
|
@ -0,0 +1,97 @@
|
||||||
|
<?php
|
||||||
|
/**
|
||||||
|
* Orange Management
|
||||||
|
*
|
||||||
|
* PHP Version 7.0
|
||||||
|
*
|
||||||
|
* @category TBD
|
||||||
|
* @package TBD
|
||||||
|
* @author OMS Development Team <dev@oms.com>
|
||||||
|
* @author Dennis Eichhorn <d.eichhorn@oms.com>
|
||||||
|
* @copyright 2013 Dennis Eichhorn
|
||||||
|
* @license OMS License 1.0
|
||||||
|
* @version 1.0.0
|
||||||
|
* @link http://orange-management.com
|
||||||
|
*/
|
||||||
|
namespace phpOMS\Datatypes;
|
||||||
|
|
||||||
|
use phpOMS\Validation\Base\IbanEnum;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Tree class.
|
||||||
|
*
|
||||||
|
* @category Framework
|
||||||
|
* @package phpOMS\Datatypes
|
||||||
|
* @author OMS Development Team <dev@oms.com>
|
||||||
|
* @author Dennis Eichhorn <d.eichhorn@oms.com>
|
||||||
|
* @license OMS License 1.0
|
||||||
|
* @link http://orange-management.com
|
||||||
|
* @since 1.0.0
|
||||||
|
*
|
||||||
|
* @todo : there is a bug with Hungary ibans since they have two k (checksums) in their definition
|
||||||
|
*/
|
||||||
|
class Tree extends Graph
|
||||||
|
{
|
||||||
|
private $nodes = [];
|
||||||
|
|
||||||
|
public function getMaxDepth() : int
|
||||||
|
{
|
||||||
|
$depth = [0];
|
||||||
|
|
||||||
|
foreach($nodes as $node) {
|
||||||
|
$depth[] = $node->getMaxDepth();
|
||||||
|
}
|
||||||
|
|
||||||
|
return max($depth) + 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getMinDepth() : int
|
||||||
|
{
|
||||||
|
$depth = [0];
|
||||||
|
|
||||||
|
foreach($nodes as $node) {
|
||||||
|
$depth[] = $node->getMinDepth();
|
||||||
|
}
|
||||||
|
|
||||||
|
return min($depth) + 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function postOrder()
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
public function preOrder()
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
public function levelOrder()
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
public function levelOrder2()
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
public function verticalOrder()
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
public function isLeaf() : bool
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
public function isSymmetric() : bool {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getDimension() : int
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
39
Stdlib/Queue/PriorityMode.php
Normal file
39
Stdlib/Queue/PriorityMode.php
Normal file
|
|
@ -0,0 +1,39 @@
|
||||||
|
<?php
|
||||||
|
/**
|
||||||
|
* Orange Management
|
||||||
|
*
|
||||||
|
* PHP Version 7.0
|
||||||
|
*
|
||||||
|
* @category TBD
|
||||||
|
* @package TBD
|
||||||
|
* @author OMS Development Team <dev@oms.com>
|
||||||
|
* @author Dennis Eichhorn <d.eichhorn@oms.com>
|
||||||
|
* @copyright 2013 Dennis Eichhorn
|
||||||
|
* @license OMS License 1.0
|
||||||
|
* @version 1.0.0
|
||||||
|
* @link http://orange-management.com
|
||||||
|
*/
|
||||||
|
namespace phpOMS\Stdlib\Queue;
|
||||||
|
|
||||||
|
use phpOMS\Datatypes\Enum;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Account type enum.
|
||||||
|
*
|
||||||
|
* @category Framework
|
||||||
|
* @package phpOMS\Stdlib
|
||||||
|
* @author OMS Development Team <dev@oms.com>
|
||||||
|
* @author Dennis Eichhorn <d.eichhorn@oms.com>
|
||||||
|
* @license OMS License 1.0
|
||||||
|
* @link http://orange-management.com
|
||||||
|
* @since 1.0.0
|
||||||
|
*/
|
||||||
|
abstract class PrioirtyMode extends Enum
|
||||||
|
{
|
||||||
|
const FIFO = 0;
|
||||||
|
const LIFO = 0;
|
||||||
|
const EARLIEST_DEADLINE = 0;
|
||||||
|
const SHORTEST_JOB = 0;
|
||||||
|
const HIGHEST = 0;
|
||||||
|
const LOWEST = 0;
|
||||||
|
}
|
||||||
|
|
@ -45,13 +45,15 @@ class PriorityQueue implements \Countable, \Serializable
|
||||||
*/
|
*/
|
||||||
private $queue = [];
|
private $queue = [];
|
||||||
|
|
||||||
|
private $mode = 0;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Constructor.
|
* Constructor.
|
||||||
*
|
*
|
||||||
* @since 1.0.0
|
* @since 1.0.0
|
||||||
* @author Dennis Eichhorn <d.eichhorn@oms.com>
|
* @author Dennis Eichhorn <d.eichhorn@oms.com>
|
||||||
*/
|
*/
|
||||||
public function __construct()
|
public function __construct($mode = '')
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -246,6 +246,18 @@ class ArrayUtils
|
||||||
return trim($args[$key + 1], '" ');
|
return trim($args[$key + 1], '" ');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Flatten array
|
||||||
|
*
|
||||||
|
* Reduces multi dimensional array to one dimensional array. Flatten tries to maintain the index as far as possible.
|
||||||
|
*
|
||||||
|
* @param array $array Multi dimensional array to flatten
|
||||||
|
*
|
||||||
|
* @return array
|
||||||
|
*
|
||||||
|
* @since 1.0.0
|
||||||
|
* @author Dennis Eichhorn <d.eichhorn@oms.com>
|
||||||
|
*/
|
||||||
public static function arrayFlatten(array $array) : array
|
public static function arrayFlatten(array $array) : array
|
||||||
{
|
{
|
||||||
|
|
||||||
|
|
@ -265,6 +277,9 @@ class ArrayUtils
|
||||||
return $flat;
|
return $flat;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* todo: what did i smoke? what is this?
|
||||||
|
*/
|
||||||
public static function arraySum(array $array, int $start = 0, int $count = 0)
|
public static function arraySum(array $array, int $start = 0, int $count = 0)
|
||||||
{
|
{
|
||||||
$count = $count === 0 ? count($array) : $count;
|
$count = $count === 0 ? count($array) : $count;
|
||||||
|
|
@ -281,6 +296,16 @@ class ArrayUtils
|
||||||
return $sum;
|
return $sum;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Sum multi dimensional array
|
||||||
|
*
|
||||||
|
* @param array $array Multi dimensional array to flatten
|
||||||
|
*
|
||||||
|
* @return mixed
|
||||||
|
*
|
||||||
|
* @since 1.0.0
|
||||||
|
* @author Dennis Eichhorn <d.eichhorn@oms.com>
|
||||||
|
*/
|
||||||
public static function arraySumRecursive(array $array)
|
public static function arraySumRecursive(array $array)
|
||||||
{
|
{
|
||||||
return array_sum(self::arrayFlatten($array));
|
return array_sum(self::arrayFlatten($array));
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue
Block a user