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