* moved "binPlayers" into libEmbedVideo (more modular folder layout)
[lhc/web/wiklou.git] / js2 / mwEmbed / libEmbedVideo / binPlayers / omtk-fx / src / as / org / omtk / util / HuffmanNode.as
1 /*
2
3 Copyright 2008 Tor-Einar Jarnbjo
4
5 Licensed under the Apache License, Version 2.0 (the "License");
6 you may not use this file except in compliance with the License.
7 You may obtain a copy of the License at
8
9 http://www.apache.org/licenses/LICENSE-2.0
10
11 Unless required by applicable law or agreed to in writing, software
12 distributed under the License is distributed on an "AS IS" BASIS,
13 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 See the License for the specific language governing permissions and
15 limitations under the License.
16
17 */
18 package org.omtk.util {
19
20 public class HuffmanNode {
21
22 private var _parent:HuffmanNode;
23
24 public var _o0:HuffmanNode;
25 public var _o1:HuffmanNode;
26
27 private var _depth:int;
28
29 public var _value:int;
30 public var hasValue: Boolean;
31 private var _full:Boolean = false;
32
33 public function HuffmanNode(parent:HuffmanNode = null, value:int = -1) {
34 _parent = parent;
35 if(_parent != null) {
36 _depth = _parent.depth+1;
37 }
38 _value = value;
39 _full = value >= 0;
40 hasValue = value >= 0;
41 }
42
43 public function setNewValue(depth:int, value:uint):Boolean {
44 if (full) {
45 return false;
46 }
47 if (depth == 1) {
48 if (_o0 == null) {
49 _o0 = new HuffmanNode(this, value);
50 return true;
51 } else if (_o1 == null) {
52 _o1 = new HuffmanNode(this, value);
53 return true;
54 } else {
55 return false;
56 }
57 } else {
58 return o0.setNewValue(depth - 1, value)
59 ? true : o1.setNewValue(depth - 1, value);
60 }
61 }
62
63 public function get value():uint {
64 return _value;
65 }
66
67 public function get o0():HuffmanNode {
68 if(_o0 == null) {
69 _o0 = new HuffmanNode(this);
70 }
71 return _o0;
72 }
73
74 public function get o1():HuffmanNode {
75 if(_o1 == null) {
76 _o1 = new HuffmanNode(this);
77 }
78 return _o1;
79 }
80
81 public function get depth():int {
82 return _depth;
83 }
84
85 public function get full():Boolean {
86 return _full ? true
87 : (_full = (_o0 != null && _o0.full && _o1 != null && _o1.full));
88 }
89
90 }
91
92 }