Skip to main content

a Range class implementing compact integer ranges with a set-like API, and associated functions

Project description

A Range is an object resembling a set but optimised for contiguous ranges of int members.

Latest release 20230619:

  • Span: sanity check .start and .end.
  • Range.issubset: efficient comparison with another Range, also .issuperset.

Function overlap(span1, span2)

Return a list [start,end] denoting the overlap of two spans.

Example:

>>> overlap([1,9], [5,13])
[5, 9]

Class Range

A collection of ints that collates adjacent ints.

The interface is as for a set with additional methods:

  • spans(): return an iterable of Spans, with .start included in each Span and .end just beyond

Additionally, the update/remove/etc methods have a secondary calling signature: (start,end), which is the same as passing in Range(start,end) but much more efficient.

Method Range.__init__(self, start=None, end=None, debug=None): Initialise the Range.

Called with start and end, these specify the initial Span of the Range. If called with just one argument that argument instead be an iterable of integer values comprising the values in the Range.

Class Span(Span, builtins.tuple)

A namedtuple with .start and .end attributes.

Function spans(items)

Return an iterable of Spans for all contiguous sequences in items.

Example:

>>> list(spans([1,2,3,7,8,11,5]))
[1:4, 7:9, 11:12, 5:6]

Release Log

Release 20230619:

  • Span: sanity check .start and .end.
  • Range.issubset: efficient comparison with another Range, also .issuperset.

Release 20230518: Span,Range: new as_list() methods.

Release 20190102: Span: provide len.

Release 20171231:

  • Add Range.span0, returning the first Span.
  • Implement bool and__nonzero__.
  • Accept a Span in contains.
  • Some small bugfixes.

Release 20160828:

  • Add Range.start like existing Range.end.
  • Use "install_requires" instead of "requires" in DISTINFO.
  • Small bugfix.

Release 20150116: First PyPI release.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

cs.range-20230619.tar.gz (8.3 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

cs.range-20230619-py3-none-any.whl (7.4 kB view details)

Uploaded Python 3

File details

Details for the file cs.range-20230619.tar.gz.

File metadata

  • Download URL: cs.range-20230619.tar.gz
  • Upload date:
  • Size: 8.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.10.6

File hashes

Hashes for cs.range-20230619.tar.gz
Algorithm Hash digest
SHA256 baabdca34638a14dd3b31fe4cee6c0f48994bb01e3d1136385dee3ad3d8ab7e6
MD5 edd36de3c424d996403b8e9177d1f573
BLAKE2b-256 2c2f699f536de8e135addf8b1e68e7b3beaf9c0584e2e8f49a693544216bc014

See more details on using hashes here.

File details

Details for the file cs.range-20230619-py3-none-any.whl.

File metadata

  • Download URL: cs.range-20230619-py3-none-any.whl
  • Upload date:
  • Size: 7.4 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.10.6

File hashes

Hashes for cs.range-20230619-py3-none-any.whl
Algorithm Hash digest
SHA256 d5c0bc24a3f514b889f920dd1ebbe473e2826ca557180a6d10e5255fefcc91dd
MD5 bcd8c3fdec616130a55ebf2303e9fbb9
BLAKE2b-256 6275194cb58f6277b2694845da9f47172f478857b3d71420ecd5d677808a1ac8

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page