Skip to content

Commit 906962b

Browse files
committed
fixed typo
1 parent f1ea20b commit 906962b

File tree

4 files changed

+44
-44
lines changed

4 files changed

+44
-44
lines changed

src/PhpTrees/BinarySearchTree.php

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -17,27 +17,27 @@ class BinarySearchTree implements \Iterator
1717
/* used for iterating through the tree */
1818
private $iteratorStack = null;
1919
/* if set, used to comparing non literal values */
20-
private $comparitor = null;
20+
private $comparator = null;
2121

2222
/**
2323
* constructs a new BinarySearchTree
2424
* @param mixed $rootValue the initial value of the tree's root
2525
*/
26-
public function __construct($rootValue = null, ?callable $comparitor = null)
26+
public function __construct($rootValue = null, ?callable $comparator = null)
2727
{
2828
if ($rootValue !== null) {
2929
$this->root = new BstNode($rootValue);
3030
}
31-
if ($comparitor !== null) {
32-
$this->setComparitor($comparitor);
31+
if ($comparator !== null) {
32+
$this->setComparator($comparator);
3333
}
3434
}
3535

36-
public function setComparitor(callable $comparitor) : void
36+
public function setComparator(callable $comparator) : void
3737
{
38-
$this->comparitor = $comparitor;
38+
$this->comparator = $comparator;
3939
if ($this->root !== null) {
40-
$this->root->setComparitor($this->comparitor);
40+
$this->root->setComparator($this->comparator);
4141
}
4242
}
4343

@@ -52,8 +52,8 @@ public function insert($value) : void
5252
}
5353
else {
5454
$this->root = new BstNode($value);
55-
if ($this->comparitor !== null) {
56-
$this->root->setComparitor($this->comparitor);
55+
if ($this->comparator !== null) {
56+
$this->root->setComparator($this->comparator);
5757
}
5858
}
5959
}
@@ -98,8 +98,8 @@ public function find($value, BstNode $node = null) : ?BstNode
9898
return $node;
9999
}
100100
else {
101-
if ($this->comparitor !== null) {
102-
return $this->findComparitor($value, $node);
101+
if ($this->comparator !== null) {
102+
return $this->findComparator($value, $node);
103103
}
104104
if ($value > $node->getValue() && $node->getRightChild() !== null) {
105105
return $this->find($value, $node->getRightChild());
@@ -112,13 +112,13 @@ public function find($value, BstNode $node = null) : ?BstNode
112112
}
113113

114114
/**
115-
* finds a node based on the given comparitor
115+
* finds a node based on the given comparator
116116
* @param mixed $value the value to look for
117117
* @return BstNode the node with the given value or null
118118
*/
119-
private function findComparitor($value, BstNode $node = null) : ?BstNode
119+
private function findComparator($value, BstNode $node = null) : ?BstNode
120120
{
121-
$cmp = $this->comparitor->__invoke($node->getValue(), $value);
121+
$cmp = $this->comparator->__invoke($node->getValue(), $value);
122122
if ($cmp === true && $node->getRightChild() !== null) {
123123
return $this->find($value, $node->getRightChild());
124124
}
@@ -265,12 +265,12 @@ public function delete(BstNode $node) : void
265265
}
266266

267267
/**
268-
* if the tree has a custom comparitor or not
269-
* @return bool true if a custom comparitor has been set
268+
* if the tree has a custom comparator or not
269+
* @return bool true if a custom comparator has been set
270270
*/
271-
public function hasComparitor() : bool
271+
public function hasComparator() : bool
272272
{
273-
if ($this->comparitor !== null) {
273+
if ($this->comparator !== null) {
274274
return true;
275275
}
276276
return false;

src/PhpTrees/BstNode.php

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ class BstNode
1818
/* the node's id, used for iterating over the tree */
1919
private $id = 0;
2020
/* if set, used to comparing non literal values */
21-
private $comparitor = null;
21+
private $comparator = null;
2222

2323
/**
2424
* constructs the node with the given value also generates a unique id for the node
@@ -35,12 +35,12 @@ public function __construct($value, BstNode $parent = null)
3535
}
3636

3737
/**
38-
* sets the comparitor for the tree
39-
* @param callable $comparitor the comparitor to use when adding children must take in 2 values the nodes value, and the value to add, and return a boolean denoting if the new value is higher or equal to the current one
38+
* sets the comparator for the tree
39+
* @param callable $comparator the comparator to use when adding children must take in 2 values the nodes value, and the value to add, and return a boolean denoting if the new value is higher or equal to the current one
4040
*/
41-
public function setComparitor(callable $comparitor) : void
41+
public function setComparator(callable $comparator) : void
4242
{
43-
$this->comparitor = $comparitor;
43+
$this->comparator = $comparator;
4444
}
4545

4646
/**
@@ -49,8 +49,8 @@ public function setComparitor(callable $comparitor) : void
4949
*/
5050
public function addChild($value) : void
5151
{
52-
if ($this->comparitor !== null) {
53-
$this->addChildComparitor($value);
52+
if ($this->comparator !== null) {
53+
$this->addChildComparator($value);
5454
return;
5555
}
5656
if ($value >= $this->value) {
@@ -71,25 +71,25 @@ public function addChild($value) : void
7171
}
7272
}
7373

74-
private function addChildComparitor($value) : void
74+
private function addChildComparator($value) : void
7575
{
76-
$cmp = $this->comparitor->__invoke($this->value, $value);
76+
$cmp = $this->comparator->__invoke($this->value, $value);
7777
if ($cmp === true) {
7878
if ($this->right === null) {
7979
$this->right = new BstNode($value, $this);
80-
$this->right->setComparitor($this->comparitor);
80+
$this->right->setComparator($this->comparator);
8181
}
8282
else {
83-
$this->right->addChildComparitor($value);
83+
$this->right->addChildComparator($value);
8484
}
8585
}
8686
else {
8787
if ($this->left === null) {
8888
$this->left = new BstNode($value, $this);
89-
$this->left->setComparitor($this->comparitor);
89+
$this->left->setComparator($this->comparator);
9090
}
9191
else {
92-
$this->left->addChildComparitor($value);
92+
$this->left->addChildComparator($value);
9393
}
9494
}
9595
}
@@ -227,11 +227,11 @@ public function setParent(BstNode $parent) : void
227227
}
228228

229229
/**
230-
* checks if the node has a custom comparitor set
230+
* checks if the node has a custom comparator set
231231
*/
232-
public function hasComparitor() : bool
232+
public function hasComparator() : bool
233233
{
234-
if ($this->comparitor === null) {
234+
if ($this->comparator === null) {
235235
return false;
236236
}
237237
return true;

tests/PhpTrees/BinarySearchTreeTest.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -235,16 +235,16 @@ public function testClone()
235235
$this->assertSame($b->getMaxValue(), 22);
236236
}
237237

238-
public function testComparitor()
238+
public function testComparator()
239239
{
240240
$b = new PhpTrees\BinarySearchTree("12345", function($val, $val2) {
241241
return (strlen($val) <= strlen($val2));
242242
});
243-
$this->assertTrue($b->hasComparitor());
243+
$this->assertTrue($b->hasComparator());
244244

245245
$b = new PhpTrees\BinarySearchTree();
246-
$this->assertFalse($b->hasComparitor());
247-
$b->setComparitor(function($val, $val2) {
246+
$this->assertFalse($b->hasComparator());
247+
$b->setComparator(function($val, $val2) {
248248
return (strlen($val) <= strlen($val2));
249249
});
250250

tests/PhpTrees/BstNodeTest.php

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -79,10 +79,10 @@ public function testHasChild()
7979
$this->assertTrue(($n->hasChild($n->getLeftChild())));
8080
}
8181

82-
public function testAddComparitor()
82+
public function testAddComparator()
8383
{
8484
$n = new BstNode("12345");
85-
$n->setComparitor(function($val, $val2) {
85+
$n->setComparator(function($val, $val2) {
8686
return (strlen($val) <= strlen($val2));
8787
});
8888
$n->addChild("1234");
@@ -97,14 +97,14 @@ public function testAddComparitor()
9797
$this->assertSame($n->getLeftChild()->getRightChild()->getValue(), "1234");
9898
}
9999

100-
public function testHasComparitor()
100+
public function testHasComparator()
101101
{
102102
$n = new BstNode("12345");
103-
$this->assertFalse($n->hasComparitor());
103+
$this->assertFalse($n->hasComparator());
104104

105-
$n->setComparitor(function($v, $v2){
105+
$n->setComparator(function($v, $v2){
106106
return true;
107107
});
108-
$this->assertTrue($n->hasComparitor());
108+
$this->assertTrue($n->hasComparator());
109109
}
110110
}

0 commit comments

Comments
 (0)