Exemplo n.º 1
0
        private void ExpandStarts()
        {
            Contract.Assert(Lengths.CompressedData == null, "Lengths must be decompressed prior to optimizing starts");
            var count       = Starts.Count;
            int priorStart  = Starts.MinValue;
            int priorLength = 0;
            int max         = 0;

            for (int i = 0; i < count; i++)
            {
                int startOffset = Starts.GetIndexDirect(i);
                int newValue;
                if (startOffset == 0)
                {
                    // 0 is reserved to indicate this span starts at the same position as the prior start
                    newValue = priorStart;
                }
                else
                {
                    // This is a delta from the end of the previous span + 1 (0 is reserved)
                    var priorEnd = priorStart + priorLength;
                    newValue = priorEnd + startOffset - 1;
                }

                Starts[i]   = newValue;
                priorStart  = newValue;
                priorLength = Lengths[i];
                max         = Math.Max(newValue, max);
            }

            var newStartsMinByteWidth = NumberUtils.GetByteWidth(max - Starts.MinValue);

            Contract.Assert(newStartsMinByteWidth == Starts.ValueByteWidth);
        }