Beispiel #1
0
        private ushort TraverseTree(ushort *tree, BitSource bitsource)
        {
            uint  branch        = 0;
            uint  availableBits = 0;
            ulong bits          = 0;

            while (branch < TreeNode.Threshold)
            {
                ulong consumed = 0;
                availableBits = (uint)bitsource.AvailableBits();
                bits          = bitsource.PeekBits();

                while (availableBits > consumed && branch < TreeNode.Threshold)
                {
                    var bit = bits & 1;
                    bits >>= 1;
                    branch = tree[branch * 2 + bit];
                    consumed++;
                }

                bitsource.Consume(consumed);

                if (branch < TreeNode.Threshold)
                {
                    var bit = bitsource.CurrentBitValue();
                    branch = tree[branch * 2 + bit];
                }
            }

            return((ushort)branch);
        }