https://github.com/remorhaz/php-int-rangesets
Integer range sets manipulation
https://github.com/remorhaz/php-int-rangesets
integer range ranges set sets
Last synced: 12 months ago
JSON representation
Integer range sets manipulation
- Host: GitHub
- URL: https://github.com/remorhaz/php-int-rangesets
- Owner: remorhaz
- License: mit
- Created: 2020-04-13T19:08:12.000Z (about 6 years ago)
- Default Branch: master
- Last Pushed: 2024-02-11T17:52:43.000Z (over 2 years ago)
- Last Synced: 2025-05-22T03:47:54.140Z (about 1 year ago)
- Topics: integer, range, ranges, set, sets
- Language: PHP
- Size: 59.6 KB
- Stars: 1
- Watchers: 1
- Forks: 1
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- Contributing: CONTRIBUTING.md
- License: LICENSE
Awesome Lists containing this project
README
# Integer Range Sets
[](https://packagist.org/packages/remorhaz/int-rangesets)
[](https://travis-ci.com/remorhaz/php-int-rangesets)
[](https://scrutinizer-ci.com/g/remorhaz/php-int-rangesets/?branch=master)
[](https://codecov.io/gh/remorhaz/php-int-rangesets)
[](https://dashboard.stryker-mutator.io/reports/github.com/remorhaz/php-int-rangesets/master)
[](https://packagist.org/packages/remorhaz/int-rangesets)
This small library allows manipulating integer sets.
# Requirements
- PHP 8.1, 8.2, 8.3.
# Installation
```shell script
composer require remorhaz/int-rangesets
```
# Usage
## Introduction
_Set_ is represented in a form of collection of continuous _ranges_; each range is represented by a pair of integers denoting it's first and last values.
## Range
Range cannot be empty, but can contain only one integer; in that case it's first and last values are the same.
```php
withStart(7);
```
## Range sets
All ranges in a set are normalized: they follow each other in ascending order and are separated by non-empty gaps, so none of them follow immediately after previous one or overlap.
Range sets are also immutable. Any operation on a set creates a new instance, leaving the original one intact.
```php
withRanges(new Range(4, 10));
```
Merging of ranges requires resources, so there's a fast, but unsafe way to initialize set with ranges. In this case constructing code must take full responsibility for normalization of ranges.
```php
createUnion($b);` |
| [Intersection](https://en.wikipedia.org/wiki/Intersection_(set_theory)) | A ∩ B | `$result = $a->createIntersection($b);` |
| [Symmetric difference](https://en.wikipedia.org/wiki/Symmetric_difference) | A ∆ B | `$result = $a->createSymmetricDifference($b);` |
# License
This library is licensed under [MIT license](./LICENSE).