Exemplo n.º 1
0
        public int RemoveRun(DataRun run)
        {
            int idx = DataRuns.IndexOf(run);

            if (idx < 0)
            {
                throw new ArgumentException("Attempt to remove non-existant run", nameof(run));
            }

            DataRuns.RemoveAt(idx);
            return(idx);
        }
Exemplo n.º 2
0
        public AttributeRecord Split(int suggestedSplitIdx)
        {
            int splitIdx;

            if (suggestedSplitIdx <= 0 || suggestedSplitIdx >= DataRuns.Count)
            {
                splitIdx = DataRuns.Count / 2;
            }
            else
            {
                splitIdx = suggestedSplitIdx;
            }

            long splitVcn = (long)_startingVCN;
            long splitLcn = 0;

            for (int i = 0; i < splitIdx; ++i)
            {
                splitVcn += DataRuns[i].RunLength;
                splitLcn += DataRuns[i].RunOffset;
            }

            List <DataRun> newRecordRuns = new List <DataRun>();

            while (DataRuns.Count > splitIdx)
            {
                DataRun run = DataRuns[splitIdx];

                DataRuns.RemoveAt(splitIdx);
                newRecordRuns.Add(run);
            }

            // Each extent has implicit start LCN=0, so have to make stored runs match reality.
            // However, take care not to stomp on 'sparse' runs that may be at the start of the
            // new extent (indicated by Zero run offset).
            for (int i = 0; i < newRecordRuns.Count; ++i)
            {
                if (!newRecordRuns[i].IsSparse)
                {
                    newRecordRuns[i].RunOffset += splitLcn;
                    break;
                }
            }

            _lastVCN = (ulong)splitVcn - 1;

            return(new NonResidentAttributeRecord(_type, _name, 0, _flags, splitVcn, newRecordRuns));
        }