WTM_Node LoadNode(BinaryReader Input, WTM_Inner parent) { // Console.WriteLine ("xxxxxxxxx LoadNode"); var isInner = Input.ReadBoolean (); if (isInner) { var arity = Input.ReadInt32 (); var node = new WTM_Inner (arity, parent, false); node.SEQ = GenericIO<Sequence>.Load(Input); node.CHILDREN = new WTM_Node[arity]; for (int i = 0; i < arity; ++i) { if (Input.ReadBoolean()) { node.CHILDREN[i] = 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 WTM_Leaf (parent, symbol, count); var leaf = new WTM_Leaf (parent, symbol); this.Alphabet[symbol] = leaf; return leaf; } }
protected void Add(int symbol, List<WTM_Symbol> list) { list.Clear(); list = this.SymbolCoder.Encode (symbol, list); var node = this.Root; var plen = list.Count; for (int i = 0; i < plen; ++i) { var code = list[i]; (node.SEQ as FakeSeq).Add (code.symbol); // Console.WriteLine ("== i: {0}, plen: {1}, symbol: {2}, code.symbol: {3}, code.numbits: {4}, children-count: {5}", // i, plen, symbol, code.symbol, code.numbits, node.CHILDREN.Length); if (i+1 == plen) { var leaf = node.CHILDREN[code.symbol] as WTM_Leaf; if (leaf == null) { leaf = new WTM_Leaf(node, symbol); this.Alphabet[symbol] = leaf; // } else { // leaf.Increment(); } node.CHILDREN[code.symbol] = leaf; } else { var inner = node.CHILDREN[code.symbol] as WTM_Inner; if (inner == null) { var arity = 1 << list[i+1].numbits; inner = new WTM_Inner(arity, node, true); // Console.WriteLine("*** children-length: {0}, next-children-length: {1}", node.CHILDREN.Length, inner.CHILDREN.Length); } node.CHILDREN[code.symbol] = inner; node = inner; } } }