public int Access(int position)
{
//Console.WriteLine("=== Access position: {0}", position);
var node = this.Root;
WTM_Inner tmp;
var codes = new List<int>();
for (int i = 0; true; i++) {
var code = node.SEQ.Access(position);
codes.Add(code);
// Console.WriteLine ("== i: {0}, position: {1}, code: {2}, children-count: {3} ", i, position, code, node.CHILDREN.Length);
tmp = node.CHILDREN[code] as WTM_Inner;
if (tmp == null) {
var symcode = this.SymbolCoder.Decode(codes);
// var sym = (node.CHILDREN[code] as WTM_Leaf).Symbol;
// Console.WriteLine (" symbol: {0}", sym);
// return sym;
// if (sym != symcode) {
// throw new Exception("symcode and sym are not equal");
// }
return symcode;
}
position = node.SEQ.Rank (code, position) - 1;
node = tmp;
}
}