Esempio n. 1
0
File: WTM.cs Progetto: sadit/natix
 public WTM_Leaf(WTM_Inner parent, int symbol)
     : base(parent)
 {
     // this.Count = 1;
     this.Symbol = symbol;
 }
Esempio n. 2
0
File: WTM.cs Progetto: sadit/natix
        void Walk(WTM_Inner node,
		           Func<WTM_Inner, object> preorder,
		           //Func<WInner, object> inorder,
		           Func<WTM_Inner, object> postorder)
        {
            if (node == null) {
                return;
            }
            if (preorder != null) {
                preorder (node);
            }
            foreach (var child in node.CHILDREN) {
                this.Walk (child as WTM_Inner, preorder, postorder);
            }
            /*if (inorder != null) {
                inorder (node);
            }*/

            if (postorder != null) {
                postorder (node);
            }
        }
Esempio n. 3
0
File: WTM.cs Progetto: sadit/natix
 public WTM_Inner(int arity, WTM_Inner parent, bool building)
     : base(parent)
 {
     if (building) {
         this.SEQ = new FakeSeq(arity);
     }
     this.CHILDREN = new WTM_Node[ arity ];
 }
Esempio n. 4
0
File: WTM.cs Progetto: sadit/natix
 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;
     }
 }
Esempio n. 5
0
File: WTM.cs Progetto: sadit/natix
 void FinishBuild(WTM_Inner node, SequenceBuilder seq_builder, int sigma)
 {
     if (node == null) {
         return;
     }
     var s = node.SEQ as FakeSeq;
     node.SEQ = seq_builder (s.SEQ, s.Sigma);
     foreach (var child in node.CHILDREN) {
         this.FinishBuild(child as WTM_Inner, seq_builder, sigma);
     }
 }
Esempio n. 6
0
File: WTM.cs Progetto: sadit/natix
 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;
         }
     }
 }
Esempio n. 7
0
File: WTM.cs Progetto: sadit/natix
 public void Load(BinaryReader Input)
 {
     var size = Input.ReadInt32 ();
     this.SymbolCoder = SymbolCoderGenericIO.Load (Input);
     this.Alphabet = new WTM_Leaf[size];
     this.Root = this.LoadNode (Input, null) as WTM_Inner;
 }
Esempio n. 8
0
File: WTM.cs Progetto: sadit/natix
 public void Build(IList<int> text, int alphabet_size, ISymbolCoder symbol_split = null, SequenceBuilder seq_builder = null)
 {
     if (symbol_split == null) {
         symbol_split = new EqualSizeCoder(4, alphabet_size-1);
     }
     this.SymbolCoder = symbol_split;
     var list = this.SymbolCoder.Encode(0, null);
     var numbits = list[0].numbits;
     var arity = (short)(1 << numbits);
     this.Alphabet = new WTM_Leaf[alphabet_size];
     this.Root = new WTM_Inner (arity, null, true);
     for (int i = 0; i < text.Count; i++) {
         this.Add (text [i], list);
     }
     if (seq_builder == null) {
         seq_builder = SequenceBuilders.GetSeqPlain(arity);
     }
     this.FinishBuild (this.Root, seq_builder, arity);
 }