Ejemplo n.º 1
0
        public ListSegment <TSpan> GetSpans(int startPosition, int length)
        {
            var segmentList      = new SegmentRangeList(Segments);
            var segmentListRange = segmentList.GetReadOnlyList().GetRange(new Range(startPosition, length),
                                                                          (searchRange, segmentRange) => RangeHelper.MinCompare(searchRange, segmentRange, inclusive: true),
                                                                          (searchRange, segmentRange) => RangeHelper.MaxCompare(searchRange, segmentRange, inclusive: true));

            var segmentStart = segmentListRange.Start;
            var segmentCount = segmentListRange.Count;

            var absoluteStart       = segmentStart << SegmentSpanCountBitWidth;
            var absoluteLength      = segmentCount << SegmentSpanCountBitWidth;
            var endSegmentExclusive = segmentStart + segmentCount;

            if (endSegmentExclusive >= Segments.Count)
            {
                absoluteLength -= (SegmentOffsetBitMask - (SegmentOffsetBitMask & (Count - 1)));
            }

            var spanRangeList = IndexableListAdapter.GetReadOnlyList(new SpanRangeList(this));

            var rangeListSegment = new ListSegment <Range>(spanRangeList, absoluteStart, absoluteLength);

            var spanRange = rangeListSegment.GetRange(new Range(startPosition, length),
                                                      (r, start) => RangeHelper.MinCompare(r, start, inclusive: true),
                                                      (r, start) => RangeHelper.MaxCompare(r, start, inclusive: true));

            return(new ListSegment <TSpan>(this.GetReadOnlyList(), rangeListSegment.Start + spanRange.Start, spanRange.Count));
        }