Total Complexity | 8 |
Total Lines | 47 |
Duplicated Lines | 0 % |
Changes | 1 | ||
Bugs | 0 | Features | 0 |
1 | <?php |
||
10 | class HuffmanNodeQueue |
||
11 | { |
||
12 | private $nodes = []; |
||
13 | |||
14 | /** |
||
15 | * put the new node into the queue, keeping it in order by weight |
||
16 | * NOTE: schliemel going on here! |
||
17 | */ |
||
18 | public function addNode(HuffmanNode $node) |
||
19 | { |
||
20 | if (\count($this->nodes) == 0) { |
||
21 | $this->nodes = [$node]; |
||
22 | |||
23 | return; |
||
24 | } |
||
25 | |||
26 | $index = 0; |
||
27 | while (isset($this->nodes[$index]) && $this->nodes[$index]->getWeight() < $node->getWeight()) { |
||
28 | ++$index; |
||
29 | } |
||
30 | array_splice($this->nodes, $index, 0, [$node]); |
||
31 | } |
||
32 | |||
33 | /** |
||
34 | * get the two nodes with the lowest weights from the front of the queue. |
||
35 | */ |
||
36 | public function popTwoNodes() |
||
45 | } |
||
46 | } |
||
47 | |||
48 | /** |
||
49 | * once there's only one node left, extract it. |
||
50 | */ |
||
51 | public function getOnlyNode() |
||
57 | } |
||
58 | } |
||
60 |