Return the maximal length represented by this span start and end. The magnitude is the same as the length for a contiguous span. It will be greater than the length for a span with non-contiguous int items. An empty span has a zero magnitude. For example:
(self)
| 260 | return sorted(spans, key=key) |
| 261 | |
| 262 | def magnitude(self): |
| 263 | """ |
| 264 | Return the maximal length represented by this span start and end. The |
| 265 | magnitude is the same as the length for a contiguous span. It will be |
| 266 | greater than the length for a span with non-contiguous int items. |
| 267 | An empty span has a zero magnitude. |
| 268 | |
| 269 | For example: |
| 270 | >>> Span([4, 8]).magnitude() |
| 271 | 5 |
| 272 | >>> len(Span([4, 8])) |
| 273 | 2 |
| 274 | >>> len(Span([4, 5, 6, 7, 8])) |
| 275 | 5 |
| 276 | |
| 277 | >>> Span([4, 5, 6, 14 , 12, 128]).magnitude() |
| 278 | 125 |
| 279 | |
| 280 | >>> Span([4, 5, 6, 7, 8]).magnitude() |
| 281 | 5 |
| 282 | >>> Span([0]).magnitude() |
| 283 | 1 |
| 284 | >>> Span([0]).magnitude() |
| 285 | 1 |
| 286 | """ |
| 287 | if not self._set: |
| 288 | return 0 |
| 289 | return self.end - self.start + 1 |
| 290 | |
| 291 | def density(self): |
| 292 | """ |
no outgoing calls
no test coverage detected