Skip to content

Commit 54dca08

Browse files
committed
refactoring
1 parent 898f269 commit 54dca08

File tree

2 files changed

+14
-10
lines changed

2 files changed

+14
-10
lines changed

examples/index.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515

1616
// Get array of keys sorted in ascendant order
1717
$sorted_intervals = $tree->getKeys(); // expected array [[1,1],[1,4],[5,7],[5,12],[6,8]]
18+
print_r($sorted_intervals);
1819

1920
// Search items which keys intersect with given interval, and return array of values
2021
$valuesInRange = $tree->iterateIntersections([2,3]);
@@ -26,7 +27,6 @@
2627
echo $tree->hasIntersect([66,83]);
2728
echo $tree->countIntersections([2,3]);
2829

29-
print_r($tree->getIntersections([2,3]));
3030

3131

3232
// $tree = new IntervalTree();

src/IntervalTree.php

+13-9
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,10 @@ public function __construct()
1717

1818
/**
1919
* Returns number of items stored in the interval tree
20-
* @returns {number}
20+
*
21+
* @return int
2122
*/
22-
public function getSize()
23+
public function getSize(): int
2324
{
2425
$count = 0;
2526
$this->treeWalk($this->root, function () use (&$count) {
@@ -30,9 +31,10 @@ public function getSize()
3031

3132
/**
3233
* Returns array of sorted keys in the ascending order
33-
* @returns {Array}
34+
*
35+
* @return void
3436
*/
35-
public function getKeys()
37+
public function getKeys(): array
3638
{
3739
$res = [];
3840

@@ -73,7 +75,8 @@ public function getItems()
7375

7476
/**
7577
* Returns true if tree is empty
76-
* @returns {boolean}
78+
*
79+
* @return boolean
7780
*/
7881
public function isEmpty()
7982
{
@@ -118,11 +121,12 @@ public function countIntersections($interval): int
118121

119122
/**
120123
* Insert new item into interval tree
121-
* @param key - interval object or array of two numbers [low, high]
122-
* @param value - value representing any object (optional)
123-
* @returns {Node} - returns reference to inserted node as an object {key:interval, value: value}
124+
*
125+
* @param array $key - array of two numbers [low, high]
126+
* @param mixed $value - value representing any object (optional)
127+
* @return Node - returns reference to inserted node
124128
*/
125-
public function insert($key, $value = null)
129+
public function insert(array $key, mixed $value = null)
126130
{
127131
if ($key === null) {
128132
return;

0 commit comments

Comments
 (0)