MCPcopy Create free account
hub / github.com/aboutcode-org/scancode-toolkit / from_ints

Method from_ints

src/licensedcode/spans.py:438–452  ·  view source on GitHub ↗

Return a sequence of Spans from an iterable of ints. A new Span is created for each group of monotonously increasing int items. >>> Span.from_ints([1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12]) [Span(1, 12)] >>> Span.from_ints([1, 2, 3, 5, 6, 7, 8, 9, 10, 11, 12])

(ints)

Source from the content-addressed store, hash-verified

436
437 @staticmethod
438 def from_ints(ints):
439 """
440 Return a sequence of Spans from an iterable of ints. A new Span is
441 created for each group of monotonously increasing int items.
442
443 >>> Span.from_ints([1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12])
444 [Span(1, 12)]
445 >>> Span.from_ints([1, 2, 3, 5, 6, 7, 8, 9, 10, 11, 12])
446 [Span(1, 3), Span(5, 12)]
447 >>> Span.from_ints([0, 2, 3, 5, 6, 7, 8, 9, 10, 11, 13])
448 [Span(0), Span(2, 3), Span(5, 11), Span(13)]
449 """
450 ints = sorted(set(ints))
451 groups = (group for _, group in groupby(ints, lambda group, c=count(): next(c) - group))
452 return [Span(g) for g in groups]
453
454 def subspans(self):
455 """

Callers 1

subspansMethod · 0.80

Calls 3

countFunction · 0.85
SpanClass · 0.85
nextFunction · 0.50

Tested by

no test coverage detected