Skip to content

Commit

Permalink
Merge pull request #130 from octoenergy/half-finite-range-set
Browse files Browse the repository at this point in the history
Add HalfFiniteRangeSet (copy of FiniteRangeSet)
  • Loading branch information
benthorner authored Dec 11, 2023
2 parents 8aee09e + 2df97ce commit 76c1d76
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 1 deletion.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# Changelog

## v4.9.2 - 2023-12-07

- Add HalfFiniteRangeSet class to better support working with sets of such ranges

## v4.9.1 - 2023-11-20

- Include py.typed files in package data to restore correct type checking [#127](https://github.com/octoenergy/xocto/pull/127)
Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta"

[project]
name = "xocto"
version = "4.9.1"
version = "4.9.2"
requires-python = ">=3.9"
description = "Kraken Technologies Python service utilities"
readme = "README.md"
Expand Down
21 changes: 21 additions & 0 deletions xocto/ranges.py
Original file line number Diff line number Diff line change
Expand Up @@ -726,6 +726,27 @@ def __sub__(self, other: RangeSet[T]) -> RangeSet[T]:
return self.difference(other)


class HalfFiniteRangeSet(RangeSet[T], Generic[T]):
"""
This subclass is useful when dealing with half-finite intervals as we can offer stronger guarantees
than we can get with normal RangeSets - mostly around intersections being half-finite etc.
"""

_ranges: Sequence[HalfFiniteRange[T]]

def __iter__(self) -> Iterator[HalfFiniteRange[T]]:
yield from self._ranges

def intersection(self, other: Range[T] | RangeSet[T]) -> "HalfFiniteRangeSet[T]":
return cast("HalfFiniteRangeSet[T]", super().intersection(other))

def pop(self) -> HalfFiniteRange[T]:
return cast(HalfFiniteRange[T], super().pop())

def __and__(self, other: RangeSet[T]) -> "HalfFiniteRangeSet[T]":
return self.intersection(other)


class FiniteRangeSet(RangeSet[T]):
"""
This subclass is useful when dealing with finite intervals as we can offer stronger guarantees
Expand Down

0 comments on commit 76c1d76

Please # to comment.