public Item(TernaryTreeIterator _enclosing, TernaryTreeIterator.Item i)
 {
     this._enclosing = _enclosing;
     this.parent     = i.parent;
     this.child      = i.child;
 }
        /// <summary>traverse upwards</summary>
        private int Up()
        {
            TernaryTreeIterator.Item i = new TernaryTreeIterator.Item(this);
            int res = 0;

            if (ns.Count == 0)
            {
                return(-1);
            }
            if (cur != 0 && tt.sc[cur] == 0)
            {
                return(tt.lo[cur]);
            }
            bool climb = true;

            while (climb)
            {
                i = (TernaryTreeIterator.Item)ns.Pop();
                i.child++;
                switch (i.child)
                {
                case (char)1: {
                    if (tt.sc[i.parent] != 0)
                    {
                        res = tt.eq[i.parent];
                        ns.Push(new TernaryTreeIterator.Item(this, i));
                        ks.Append(tt.sc[i.parent]);
                    }
                    else
                    {
                        i.child++;
                        ns.Push(new TernaryTreeIterator.Item(this, i));
                        res = tt.hi[i.parent];
                    }
                    climb = false;
                    break;
                }

                case (char)2: {
                    res = tt.hi[i.parent];
                    ns.Push(new TernaryTreeIterator.Item(this, i));
                    if (ks.Length > 0)
                    {
                        // pop
                        ks.Length = ks.Length - 1;
                    }
                    climb = false;
                    break;
                }

                default: {
                    if (ns.Count == 0)
                    {
                        return(-1);
                    }
                    climb = true;
                    break;
                }
                }
            }
            return(res);
        }