natix.CompactDS.WaveletTree.Rank C# (CSharp) Method

Rank() public method

public Rank ( int symbol, int position ) : int
symbol int
position int
return int
        public int Rank(int symbol, int position)
        {
            var coderstream = new BitStream32 ();
            this.Coder.Encode (coderstream, symbol);
            //this.CoderStream.Seek (0);
            var ctx = new BitStreamCtx (0);
            int numbits = (int)coderstream.CountBits;
            var node = this.Root;
            for (int i = 0; i < numbits; i++) {
                bool b = coderstream.Read (ctx);
                if (b) {
                    position = node.B.Rank1 (position) - 1;
                    if (i + 1 < numbits) {
                        node = node.Right as WT_Inner;
                    }
                } else {
                    position = node.B.Rank0 (position) - 1;
                    if (i + 1 < numbits) {
                        node = node.Left as WT_Inner;
                    }
                }
                if (node == null) {
                    return 0;
                }
            }
            return position + 1;
        }