TYPO3 CMS  TYPO3_6-2
SortedTreeNodeCollection.php
Go to the documentation of this file.
1 <?php
2 namespace TYPO3\CMS\Backend\Tree;
3 
26 
33  public function contains(\TYPO3\CMS\Backend\Tree\TreeNode $node) {
34  return $this->offsetOf($node) !== -1;
35  }
36 
43  protected function offsetOf(\TYPO3\CMS\Backend\Tree\TreeNode $node) {
44  return $this->binarySearch($node, 0, $this->count() - 1);
45  }
46 
55  protected function binarySearch(\TYPO3\CMS\Backend\Tree\TreeNode $node, $start, $end) {
56  if (!$start && $end - $start >= 2 || $end - $start > 2) {
57  $divider = ceil(($end - $start) / 2);
58  if ($this->offsetGet($divider)->equals($node)) {
59  return $divider;
60  } elseif ($this->offsetGet($divider)->compareTo($node) > 0) {
61  return $this->binarySearch($node, $start, $divider - 1);
62  } else {
63  return $this->binarySearch($node, $divider + 1, $end);
64  }
65  } else {
66  if ($this->offsetGet($start)->equals($node)) {
67  return $start;
68  } elseif ($this->offsetGet($end)->equals($node)) {
69  return $end;
70  } else {
71  return -1;
72  }
73  }
74  }
75 
81  protected function normalize() {
82  $nodes = array();
83  foreach ($this as $node) {
84  $nodes[] = $node;
85  }
86  $this->exchangeArray($nodes);
87  }
88 
95  public function append(\TYPO3\CMS\Backend\Tree\TreeNode $node) {
96  parent::append($node);
97  $this->asort();
98  $this->normalize();
99  }
100 
101 }
offsetOf(\TYPO3\CMS\Backend\Tree\TreeNode $node)
append(\TYPO3\CMS\Backend\Tree\TreeNode $node)
contains(\TYPO3\CMS\Backend\Tree\TreeNode $node)
binarySearch(\TYPO3\CMS\Backend\Tree\TreeNode $node, $start, $end)