‪TYPO3CMS  9.5
SortedTreeNodeCollection.php
Go to the documentation of this file.
1 <?php
3 
4 /*
5  * This file is part of the TYPO3 CMS project.
6  *
7  * It is free software; you can redistribute it and/or modify it under
8  * the terms of the GNU General Public License, either version 2
9  * of the License, or any later version.
10  *
11  * For the full copyright and license information, please read the
12  * LICENSE.txt file that was distributed with this source code.
13  *
14  * The TYPO3 project - inspiring people to share!
15  */
16 
24 {
31  public function ‪contains(\‪TYPO3\CMS\Backend\Tree\‪TreeNode $node)
32  {
33  return $this->‪offsetOf($node) !== -1;
34  }
35 
42  protected function ‪offsetOf(\‪TYPO3\CMS\Backend\Tree\‪TreeNode $node)
43  {
44  return $this->‪binarySearch($node, 0, $this->count() - 1);
45  }
46 
55  protected function ‪binarySearch(\‪TYPO3\CMS\Backend\Tree\‪TreeNode $node, $start, $end)
56  {
57  if (!$start && $end - $start >= 2 || $end - $start > 2) {
58  $divider = ceil(($end - $start) / 2);
59  if ($this->offsetGet($divider)->equals($node)) {
60  return $divider;
61  }
62  if ($this->offsetGet($divider)->compareTo($node) > 0) {
63  return $this->‪binarySearch($node, $start, $divider - 1);
64  }
65  return $this->‪binarySearch($node, $divider + 1, $end);
66  }
67  if ($this->offsetGet($start)->equals($node)) {
68  return $start;
69  }
70  if ($this->offsetGet($end)->equals($node)) {
71  return $end;
72  }
73  return -1;
74  }
75 
79  protected function ‪normalize()
80  {
81  $nodes = [];
82  foreach ($this as $node) {
83  $nodes[] = $node;
84  }
85  $this->exchangeArray($nodes);
86  }
87 
93  public function ‪append($node)
94  {
95  parent::append($node);
96  $this->‪asort();
97  $this->‪normalize();
98  }
99 }
‪TYPO3
‪TYPO3\CMS\Backend\Tree\SortedTreeNodeCollection\offsetOf
‪int offsetOf(\TYPO3\CMS\Backend\Tree\TreeNode $node)
Definition: SortedTreeNodeCollection.php:42
‪TYPO3\CMS\Backend\Tree
Definition: AbstractTree.php:2
‪TYPO3\CMS\Backend\Tree\SortedTreeNodeCollection\normalize
‪normalize()
Definition: SortedTreeNodeCollection.php:79
‪TYPO3\CMS\Backend\Tree\SortedTreeNodeCollection\append
‪append($node)
Definition: SortedTreeNodeCollection.php:93
‪TYPO3\CMS\Backend\Tree\TreeNodeCollection
Definition: TreeNodeCollection.php:21
‪TYPO3\CMS\Backend\Tree\TreeNode
Definition: TreeNode.php:23
‪TYPO3\CMS\Backend\Tree\SortedTreeNodeCollection
Definition: SortedTreeNodeCollection.php:24
‪TYPO3\CMS\Backend\Tree\SortedTreeNodeCollection\contains
‪bool contains(\TYPO3\CMS\Backend\Tree\TreeNode $node)
Definition: SortedTreeNodeCollection.php:31
‪TYPO3\CMS\Backend\Tree\SortedTreeNodeCollection\binarySearch
‪int binarySearch(\TYPO3\CMS\Backend\Tree\TreeNode $node, $start, $end)
Definition: SortedTreeNodeCollection.php:55
‪TYPO3\CMS\Backend\Tree\TreeNodeCollection\asort
‪asort()
Definition: TreeNodeCollection.php:41