{"id":17045709,"url":"https://github.com/remorhaz/php-int-rangesets","last_synced_at":"2025-06-17T21:33:20.819Z","repository":{"id":57047011,"uuid":"255418514","full_name":"remorhaz/php-int-rangesets","owner":"remorhaz","description":"Integer range sets manipulation","archived":false,"fork":false,"pushed_at":"2024-02-11T17:52:43.000Z","size":61,"stargazers_count":1,"open_issues_count":1,"forks_count":1,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-05-22T03:47:54.140Z","etag":null,"topics":["integer","range","ranges","set","sets"],"latest_commit_sha":null,"homepage":null,"language":"PHP","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/remorhaz.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":"CONTRIBUTING.md","funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null}},"created_at":"2020-04-13T19:08:12.000Z","updated_at":"2023-10-25T23:33:46.000Z","dependencies_parsed_at":"2024-02-11T18:42:48.633Z","dependency_job_id":null,"html_url":"https://github.com/remorhaz/php-int-rangesets","commit_stats":{"total_commits":22,"total_committers":1,"mean_commits":22.0,"dds":0.0,"last_synced_commit":"fe1cb976bc10738e9066714bf3e861ddb9effe4d"},"previous_names":[],"tags_count":5,"template":false,"template_full_name":null,"purl":"pkg:github/remorhaz/php-int-rangesets","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/remorhaz%2Fphp-int-rangesets","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/remorhaz%2Fphp-int-rangesets/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/remorhaz%2Fphp-int-rangesets/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/remorhaz%2Fphp-int-rangesets/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/remorhaz","download_url":"https://codeload.github.com/remorhaz/php-int-rangesets/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/remorhaz%2Fphp-int-rangesets/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":260442638,"owners_count":23009878,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["integer","range","ranges","set","sets"],"created_at":"2024-10-14T09:38:10.059Z","updated_at":"2025-06-17T21:33:15.802Z","avatar_url":"https://github.com/remorhaz.png","language":"PHP","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Integer Range Sets\n[![Latest Stable Version](https://poser.pugx.org/remorhaz/int-rangesets/v/stable)](https://packagist.org/packages/remorhaz/int-rangesets)\n[![Build Status](https://travis-ci.com/remorhaz/php-int-rangesets.svg?branch=master)](https://travis-ci.com/remorhaz/php-int-rangesets)\n[![Scrutinizer Code Quality](https://scrutinizer-ci.com/g/remorhaz/php-int-rangesets/badges/quality-score.png?b=master)](https://scrutinizer-ci.com/g/remorhaz/php-int-rangesets/?branch=master)\n[![codecov](https://codecov.io/gh/remorhaz/php-int-rangesets/branch/master/graph/badge.svg)](https://codecov.io/gh/remorhaz/php-int-rangesets)\n[![Mutation testing badge](https://img.shields.io/endpoint?style=flat\u0026url=https%3A%2F%2Fbadge-api.stryker-mutator.io%2Fgithub.com%2Fremorhaz%2Fphp-int-rangesets%2Fmaster)](https://dashboard.stryker-mutator.io/reports/github.com/remorhaz/php-int-rangesets/master)\n[![License](https://poser.pugx.org/remorhaz/int-rangesets/license)](https://packagist.org/packages/remorhaz/int-rangesets)\n\nThis small library allows manipulating integer sets.\n\n# Requirements\n\n- PHP 8.1, 8.2, 8.3.\n\n# Installation\n\n```shell script\ncomposer require remorhaz/int-rangesets\n```\n\n# Usage\n## Introduction \n_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.\n\n## Range \nRange cannot be empty, but can contain only one integer; in that case it's first and last values are the same.\n\n```php\n\u003c?php\n\nuse Remorhaz\\IntRangeSets\\Range;\n\n// Contains values: 5, 6, 7, 8\n$range1 = new Range(5, 8);\n\n// Contains value 12\n$range2 = new Range(12);\n``` \nRanges are immutable. Any operation on a range creates a new instance, leaving the original one intact.\n```php\n\u003c?php\n\nuse Remorhaz\\IntRangeSets\\Range;\n\n// Contains values: 5, 6, 7, 8\n$range1 = new Range(5, 8);\n\n// New range has first value replaced and contains values: 7, 8\n$range2 = $range1-\u003ewithStart(7);\n```\n\n## Range sets \nAll 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.\n\nRange sets are also immutable. Any operation on a set creates a new instance, leaving the original one intact.\n\n```php\n\u003c?php\n\nuse Remorhaz\\IntRangeSets\\Range;\nuse Remorhaz\\IntRangeSets\\RangeSet;\n\n// Contains single range [3..5]\n$rangeSet1 = RangeSet::create(new Range(3, 5));\n\n// Added range [4..10] partially overlaps already existing one.\n// Resulting range set contains single merged range [3..10].\n$rangeSet2 = $rangeSet1-\u003ewithRanges(new Range(4, 10));\n``` \n\nMerging 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.\n\n```php\n\u003c?php\n\nuse Remorhaz\\IntRangeSets\\Range;\nuse Remorhaz\\IntRangeSets\\RangeSet;\n\n// Creates range with two ranges: [2..5] and [7..8].\n$rangeSet1 = RangeSet::createUnsafe(new Range(2, 5), new Range(7, 8));\n\n```\n\n**WARNING:** Operations on non-normalized range sets will return incorrect results! Use `create()` method with arbitrary range lists.\n\n### Available operations\nIn all examples `$a`, `$b` and `$result` are objects implementing `\\Remorhaz\\IntRangeSets\\RangeSetInterface`.\n\n| Operation                                                                  | Formula | Example                                        |\n|----------------------------------------------------------------------------|---------|------------------------------------------------|\n| [Union](https://en.wikipedia.org/wiki/Union_(set_theory))                  | A ∪ B   | `$result = $a-\u003ecreateUnion($b);`               |\n| [Intersection](https://en.wikipedia.org/wiki/Intersection_(set_theory))    | A ∩ B   | `$result = $a-\u003ecreateIntersection($b);`        |\n| [Symmetric difference](https://en.wikipedia.org/wiki/Symmetric_difference) | A ∆ B   | `$result = $a-\u003ecreateSymmetricDifference($b);` |\n\n# License\nThis library is licensed under [MIT license](./LICENSE).\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fremorhaz%2Fphp-int-rangesets","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fremorhaz%2Fphp-int-rangesets","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fremorhaz%2Fphp-int-rangesets/lists"}