PythonRangeable
Reference Python implementation of Rangeable<Element> — a generic, integer-coordinate, closed-interval set container with first-insert ordered active queries.
Installation
pip install rangeable
Usage
from dataclasses import dataclass
from rangeable import Rangeable
@dataclass(frozen=True, slots=True)
class Strong: pass
@dataclass(frozen=True, slots=True)
class Italic: pass
@dataclass(frozen=True, slots=True)
class Link:
url: str
r: Rangeable = Rangeable()
r.insert(Strong(), start=2, end=5)
r.insert(Strong(), start=3, end=7) # merges with [2, 5] → [2, 7]
r.insert(Strong(), start=9, end=11) # disjoint
r.insert(Italic(), start=3, end=8)
r.get_range(Strong()) # [(2, 7), (9, 11)]
r.get_range(Italic()) # [(3, 8)]
r[4].objs # (Strong(), Italic()) first-insert order
r[8].objs # (Italic(),)
r[10].objs # (Strong(),)
Sweep iteration via transitions
for event in r.transitions(lo=0, hi=15):
print(event.coordinate, event.kind.value, event.element)
API
| Member | Returns | Notes |
|---|---|---|
Rangeable() |
constructor | empty container |
r.insert(e, *, start, end) |
Rangeable (chainable) |
raises InvalidIntervalError on start > end |
r[i] |
Slot[E] |
Slot.objs is the active-set tuple |
r.get_range(e) |
list[tuple[int, int]] |
merged disjoint ranges |
r.transitions(*, lo, hi) |
list[TransitionEvent[E]] |
hi=None means +∞ |
r.count / len(r) |
int |
distinct elements |
r.empty / bool(r) |
bool |
|
iter(r) |
Iterator[(E, list[(int, int)])] |
first-insert order |
r.copy() |
Rangeable[E] |
deep copy |
r.version |
int |
unchanged on idempotent insert |
Semantics
- End is inclusive:
[a, b]coversa..=b, both ends. - Same-element merging: equal elements (by
__eq__+__hash__) merge on overlap or integer adjacency.[2, 4] ∪ [5, 7] = [2, 7]. - Idempotent insert: re-inserting a contained interval does not bump
version. - Out-of-order rejected:
r.insert(e, start=5, end=2)raisesInvalidIntervalError. - Active-set ordering: deterministic — first-insert order of the element.
- Coordinate sentinel: a close event for an interval ending at the optional
int_maxsentinel carriescoordinate is None(None == +∞ per RFC §4.7). Python ints are unbounded, so this only matters when integrating with bounded-int languages; the fixture does not exercise it.
See RangeableRFC § 4 for normative semantics and § 10 for the 23-case test contract.
Cross-language consistency
This Python implementation joins the Ruby, Swift, JS, Kotlin and Go implementations. All six share a 160-op / 86-probe JSON fixture and produce byte-identical outputs.
See also
- RangeableRFC — normative specification.
- RubyRangeable — Ruby reference (
gem install rangeable). - SwiftRangeable — Swift reference (SPM).
- JSRangeable — TypeScript reference (
npm i rangeable-js). - KotlinRangeable — Kotlin/JVM reference (JitPack).
- GoRangeable — Go reference (
go get github.com/ZhgChgLi/GoRangeable).
Development
python -m pip install -e ".[dev]"
pytest -q
The suite covers the full RFC § 10 contract, the cross-language fixture replay, and a property test against a brute-force oracle.
License
MIT (c) ZhgChgLi
Metadata
Release files for rangeable 2.0.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| rangeable-2.0.0.tar.gz | 14.8 kB | Without provenance | Details for rangeable-2.0.0.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| rangeable-2.0.0-py3-none-any.whl | Python 3 | none | any | Details for rangeable-2.0.0-py3-none-any.whl |
Total release size: 32.6 kB
Release files / rangeable-2.0.0.tar.gz
| Download URL | rangeable-2.0.0.tar.gz |
|---|---|
| Size | 14.8 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
0934fa3ba93218767d2dde1a831287102a5b93b9fd6ddd47e2f1f4da280bce3a
|
|
BLAKE2b-256 checksum How to use checksums |
beb7db2966a1bd2aeb6577360dae0990ed88d2cc02c982464b1c957ff644c425
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.14.4
|
Release files / rangeable-2.0.0-py3-none-any.whl
| Download URL | rangeable-2.0.0-py3-none-any.whl |
|---|---|
| Size | 17.7 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
2cf5b62fcad50f3546ffcfe55584bb0894bdef09520aa9973d1f53afa5b7a5c3
|
|
BLAKE2b-256 checksum How to use checksums |
272f8a17c1c0dde6b58e8a24894d339c04e2d1c613907031997ff35c1635668e
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.14.4
|
Security for rangeable 2.0.0
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.