public WT_Inner(WT_Inner parent, bool building) : base(parent) { if (building) { this.B = new FakeBitmap (); } this.Left = null; this.Right = null; }
public WT_Leaf(WT_Inner parent, int symbol) : base(parent) { // this.Count = 1; this.Symbol = symbol; }
void Walk(WT_Inner node, Func<WT_Inner, object> preorder, Func<WT_Inner, object> inorder, Func<WT_Inner, object> postorder) { if (node == null) { return; } if (preorder != null) { preorder (node); } this.Walk (node.Left as WT_Inner, preorder, inorder, postorder); if (inorder != null) { inorder (node); } this.Walk (node.Right as WT_Inner, preorder, inorder, postorder); if (postorder != null) { postorder (node); } }
WT_Node LoadNode(BinaryReader Input, WT_Inner parent) { // Console.WriteLine ("xxxxxxxxx LoadNode"); var isInner = Input.ReadBoolean (); if (isInner) { var node = new WT_Inner (parent, false); node.B = GenericIO<Bitmap>.Load (Input); var hasLeft = Input.ReadBoolean (); if (hasLeft) { node.Left = this.LoadNode (Input, node); } var hasRight = Input.ReadBoolean (); if (hasRight) { node.Right = this.LoadNode (Input, node); } return node; } else { // var count = Input.ReadInt32 (); var symbol = Input.ReadInt32 (); // Console.WriteLine ("--leaf> count: {0}, symbol: {1}", count, symbol); //var leaf = new WT_Leaf (parent, symbol, count); var leaf = new WT_Leaf (parent, symbol); this.Alphabet[symbol] = leaf; return leaf; } }
void FinishBuild(WT_Inner node) { if (node == null) { return; } node.B = this.BitmapBuilder(node.B as FakeBitmap); this.FinishBuild (node.Left as WT_Inner); this.FinishBuild (node.Right as WT_Inner); }
public void Load(BinaryReader Input) { var size = Input.ReadInt32 (); this.Alphabet = new WT_Leaf[size]; this.Coder = IEncoder32GenericIO.Load (Input); // Console.WriteLine ("Input.Position: {0}", Input.BaseStream.Position); this.Root = this.LoadNode (Input, null) as WT_Inner; }
public void Build(IList<int> text, int alphabet_size, IIEncoder32 coder = null) { this.Alphabet = new WT_Leaf[alphabet_size]; this.Root = new WT_Inner (null, true); if (coder == null) { coder = new BinaryCoding(ListIFS.GetNumBits(alphabet_size-1)); } this.Coder = coder; for (int i = 0; i < text.Count; i++) { this.Add (text [i]); } this.FinishBuild (this.Root); }