-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathLRUNode.php
45 lines (37 loc) · 1.11 KB
/
LRUNode.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
<?php
declare(strict_types=1);
namespace leetcode\util;
/**
* @method \leetcode\util\LRUNode setKey(int $key)
* @method int getKey()
* @method \leetcode\util\LRUNode setVal(int $val)
* @method int|string getVal()
* @method \leetcode\util\LRUNode setPrev(\leetcode\util\LRUNode $node)
* @method \leetcode\util\LRUNode getPrev()
* @method \leetcode\util\LRUNode setNext(\leetcode\util\LRUNode $node)
* @method \leetcode\util\LRUNode getNext()
*/
class LRUNode
{
private int $key;
private $val;
private ?LRUNode $prev;
private ?LRUNode $next;
public function __construct(int $key, $val)
{
$this->key = $key;
$this->val = $val;
}
public function __call(string $name, $arguments = null)
{
if (false !== $pos = strpos($name, 'set')) {
$name = strtolower(substr($name, $pos + 3));
$this->{$name} = $arguments[0];
return $this;
}
if (false !== $pos = strpos($name, 'get')) {
$name = strtolower(substr($name, $pos + 3));
return $this->{$name};
}
}
}