public override ClassificationSpanListSegmentModel CreateSegment(ListSegment <ClassificationSpan> segmentSpans)
 {
     return(new ClassificationSpanListSegmentModel()
     {
         LocalSymbolGroupIds = IntegerListModel.Create(segmentSpans, span => span.LocalGroupId)
     });
 }
Example #2
0
        public static IntegerListModel Create <T>(IReadOnlyList <T> values, Func <T, int> selector)
        {
            var minValue  = values.Min(selector);
            var maxValue  = values.Max(v => selector(v) - minValue);
            var byteWidth = NumberUtils.GetByteWidth(maxValue);
            var list      = new IntegerListModel(byteWidth, values.Count, minValue);

            for (int i = 0; i < values.Count; i++)
            {
                list[i] = selector(values[i]);
            }

            return(list);
        }
Example #3
0
        public SpanListModel(
            IReadOnlyList <TSpan> spans,
            IEqualityComparer <TSharedKey> sharedKeyComparer = null,
            IComparer <TSharedKey> sharedKeySorter           = null,
            IComparer <TShared> sharedValueSorter            = null)
            : this()
        {
            Optimize = true;
            Count    = spans.Count;
            List <TSharedKey>            sharedKeys = new List <TSharedKey>();
            Dictionary <TSharedKey, int> sharedMap  = new Dictionary <TSharedKey, int>(sharedKeyComparer ?? EqualityComparer <TSharedKey> .Default);

            foreach (var span in spans)
            {
                var sharedKey = GetSharedKey(span);
                if (!sharedMap.ContainsKey(sharedKey))
                {
                    sharedMap.Add(sharedKey, SharedValues.Count);
                    SharedValues.Add(GetShared(span));
                    sharedKeys.Add(sharedKey);
                }
            }

            if (sharedValueSorter != null || sharedKeySorter != null)
            {
                TSharedKey[] sharedKeyArray   = sharedKeys.ToArray();
                TShared[]    sharedValueArray = SharedValues.ToArray();

                if (sharedValueSorter != null)
                {
                    Array.Sort(sharedValueArray, sharedKeyArray, sharedValueSorter);
                }
                else
                {
                    Array.Sort(sharedKeyArray, sharedValueArray, sharedKeySorter);
                }

                // Ensure shared keys is not used after this point
                sharedKeys = null;
                SharedValues.Clear();
                SharedValues.AddRange(sharedValueArray);
                for (int index = 0; index < sharedKeyArray.Length; index++)
                {
                    sharedMap[sharedKeyArray[index]] = index;
                }
            }

            var segmentsLength = NumberUtils.Ceiling(spans.Count, SegmentSpanCount);
            int offset         = 0;

            for (int segmentIndex = 0; segmentIndex < segmentsLength; segmentIndex++, offset += SegmentSpanCount)
            {
                var length = Math.Min(SegmentSpanCount, spans.Count - offset);
                if (length == 0)
                {
                    break;
                }

                var segmentSpans = new ListSegment <TSpan>(spans, offset, length);
                var segment      = CreateSegment(segmentSpans);
                Segments.Add(segment);

                var firstSpanStart = segmentSpans[0].Start;
                var lastSpan       = segmentSpans[length - 1];

                segment.Starts        = IntegerListModel.Create(segmentSpans, s => GetStart(s, SharedValues[sharedMap[GetSharedKey(s)]]));
                segment.Lengths       = IntegerListModel.Create(segmentSpans, s => s.Length);
                segment.FullLength    = (lastSpan.Start + lastSpan.Length) - firstSpanStart;
                segment.SharedIndices = IntegerListModel.Create(segmentSpans, s => sharedMap[GetSharedKey(s)]);
            }
        }