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

Method density

src/licensedcode/spans.py:291–310  ·  view source on GitHub ↗

Return the density of this span as a ratio of its length to its magnitude, a float between 0 and 1. A dense Span has all its integer items contiguous and a maximum density of one. A sparse low density span has some non-contiguous integer items. An empty span has a ze

(self)

Source from the content-addressed store, hash-verified

289 return self.end - self.start + 1
290
291 def density(self):
292 """
293 Return the density of this span as a ratio of its length to its
294 magnitude, a float between 0 and 1. A dense Span has all its integer
295 items contiguous and a maximum density of one. A sparse low density span
296 has some non-contiguous integer items. An empty span has a zero density.
297
298 For example:
299 >>> Span([4, 8]).density()
300 0.4
301 >>> Span([4, 5, 6, 7, 8]).density()
302 1.0
303 >>> Span([0]).density()
304 1.0
305 >>> Span().density()
306 0
307 """
308 if not self._set:
309 return 0
310 return len(self) / self.magnitude()
311
312 def overlap(self, other):
313 """

Callers 1

idensityMethod · 0.80

Calls 1

magnitudeMethod · 0.95

Tested by

no test coverage detected