{"id":21874583,"url":"https://github.com/smoren/partial-intersection-php","last_synced_at":"2025-07-01T09:31:45.056Z","repository":{"id":91977433,"uuid":"593081821","full_name":"Smoren/partial-intersection-php","owner":"Smoren","description":"M-partial intersection of sets and multisets explanation and examples","archived":false,"fork":false,"pushed_at":"2023-01-28T13:21:53.000Z","size":730,"stargazers_count":3,"open_issues_count":0,"forks_count":1,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-04-02T09:51:11.993Z","etag":null,"topics":["intersection","multiset","multisets","partial-intersection","set","set-theory","sets"],"latest_commit_sha":null,"homepage":"","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/Smoren.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"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,"publiccode":null,"codemeta":null}},"created_at":"2023-01-25T07:26:34.000Z","updated_at":"2024-07-15T11:59:29.000Z","dependencies_parsed_at":null,"dependency_job_id":"8ded69f7-1d4b-4b89-87a9-504b62181f97","html_url":"https://github.com/Smoren/partial-intersection-php","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/Smoren/partial-intersection-php","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Smoren%2Fpartial-intersection-php","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Smoren%2Fpartial-intersection-php/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Smoren%2Fpartial-intersection-php/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Smoren%2Fpartial-intersection-php/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/Smoren","download_url":"https://codeload.github.com/Smoren/partial-intersection-php/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Smoren%2Fpartial-intersection-php/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":262935813,"owners_count":23387259,"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":["intersection","multiset","multisets","partial-intersection","set","set-theory","sets"],"created_at":"2024-11-28T07:12:47.511Z","updated_at":"2025-07-01T09:31:44.996Z","avatar_url":"https://github.com/Smoren.png","language":"PHP","readme":"# M-partial intersection of sets and multisets explanation\n\n[![Scrutinizer Code Quality](https://scrutinizer-ci.com/g/Smoren/partial-intersection-php/badges/quality-score.png?b=master)](https://scrutinizer-ci.com/g/Smoren/partial-intersection-php/?branch=master)\n[![Coverage Status](https://coveralls.io/repos/github/Smoren/partial-intersection-php/badge.svg?branch=master)](https://coveralls.io/github/Smoren/partial-intersection-php?branch=master)\n![Build and test](https://github.com/Smoren/partial-intersection-php/actions/workflows/test_master.yml/badge.svg)\n[![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)\n\n## Theory\n\n### Definition\n\n\u003e An **M**-partial intersection (for **M \u003e 0**) of **N** sets is a set elements\n\u003e in which are contained in at least **M** initial sets.\n\n### Properties\n\nFor any **N** sets:\n\n1. **1**-partial intersection is equivalent to the\n   [union](https://en.wikipedia.org/wiki/Union_(set_theory)) of these sets.\n2. **N**-partial intersection is equivalent to the\n   [common (complete) intersection](https://en.wikipedia.org/wiki/Intersection_(set_theory)) of these sets.\n3. For any **M \u003e N** **M**-partial intersection always equals to the\n   [empty set](https://en.wikipedia.org/wiki/Empty_set).\n\n## Examples\n\n* [Simple integer sets example](#Simple-integer-sets-example)\n* [Iterable integer sets example](#Iterable-integer-sets-example)\n* [Mixed iterable sets example](#Mixed-iterable-sets-example)\n* [Multisets example](#Multisets-example)\n\n### Simple integer sets example\n\nGiven: sets **A**, **B**, **C**, **D** (**N = 4**).\n\n```php\n$a = [1, 2, 3, 4, 5];\n$b = [1, 2, 10, 11];\n$c = [1, 2, 3, 12];\n$d = [1, 4, 13, 14];\n```\n\n#### M = 1\nIt is equivalent to `A ∪ B ∪ C ∪ D`.\n\n![image](docs/images/1.png)\n\n```php\nuse Smoren\\PartialIntersection\\IntegerSetArrayImplementation;\n\n$r = IntegerSetArrayImplementation::partialIntersection(1, $a, $b, $c, $d);\n// [1, 2, 3, 4, 5, 10, 11, 12, 13, 14]\n```\n\n#### M = 2\n![image](docs/images/2.png)\n\n```php\nuse Smoren\\PartialIntersection\\IntegerSetArrayImplementation;\n\n$r = IntegerSetArrayImplementation::partialIntersection(2, $a, $b, $c, $d);\n// [1, 2, 3, 4]\n```\n\n#### M = 3\n\n![image](docs/images/3.png)\n\n```php\nuse Smoren\\PartialIntersection\\IntegerSetArrayImplementation;\n\n$r = IntegerSetArrayImplementation::partialIntersection(3, $a, $b, $c, $d);\n// [1, 2]\n```\n\n#### M = 4 (M = N)\nIt is equivalent to `A ∩ B ∩ C ∩ D`.\n\n![image](docs/images/4.png)\n\n```php\nuse Smoren\\PartialIntersection\\IntegerSetArrayImplementation;\n\n$r = IntegerSetArrayImplementation::partialIntersection(4, $a, $b, $c, $d);\n// [1]\n```\n\n#### M = 5 (M \u003e N)\nEquals to an empty set.\n\n![image](docs/images/5.png)\n\n```php\nuse Smoren\\PartialIntersection\\IntegerSetArrayImplementation;\n\n$r = IntegerSetArrayImplementation::partialIntersection(5, $a, $b, $c, $d);\n// []\n```\n\n### Iterable integer sets example\n```php\n$a = [1, 2, 3, 4, 5];\n$b = [1, 2, 10, 11];\n$c = [1, 2, 3, 12];\n$d = [1, 4, 13, 14];\n\nuse Smoren\\PartialIntersection\\IntegerSetIterableImplementation;\n\n$r = IntegerSetArrayImplementation::partialIntersection(1, $a, $b, $c, $d);\nprint_r(iterator_to_array($r));\n// [1, 2, 3, 4, 5, 10, 11, 12, 13, 14]\n\n$r = IntegerSetArrayImplementation::partialIntersection(2, $a, $b, $c, $d);\nprint_r(iterator_to_array($r));\n// [1, 2, 3, 4]\n\n$r = IntegerSetArrayImplementation::partialIntersection(3, $a, $b, $c, $d);\nprint_r(iterator_to_array($r));\n// [1, 2]\n\n$r = IntegerSetArrayImplementation::partialIntersection(4, $a, $b, $c, $d);\nprint_r(iterator_to_array($r));\n// [1]\n\n$r = IntegerSetArrayImplementation::partialIntersection(5, $a, $b, $c, $d);\nprint_r(iterator_to_array($r));\n// []\n```\n\n### Mixed iterable sets example\n```php\n$a = ['1', 2, 3, 4, 5];\n$b = ['1', 2, 10, 11];\n$c = ['1', 2, 3, 12];\n$d = ['1', 4, 13, 14];\n\nuse Smoren\\PartialIntersection\\MixedSetIterableImplementation;\n\n$r = MixedSetIterableImplementation::partialIntersection(true, 1, $a, $b, $c, $d);\nprint_r(iterator_to_array($r));\n// ['1', 2, 3, 4, 5, 10, 11, 12, 13, 14]\n\n$r = MixedSetIterableImplementation::partialIntersection(true, 2, $a, $b, $c, $d);\nprint_r(iterator_to_array($r));\n// ['1', 2, 3, 4]\n\n$r = MixedSetIterableImplementation::partialIntersection(true, 3, $a, $b, $c, $d);\nprint_r(iterator_to_array($r));\n// ['1', 2]\n\n$r = MixedSetIterableImplementation::partialIntersection(true, 4, $a, $b, $c, $d);\nprint_r(iterator_to_array($r));\n// ['1']\n\n$r = IntegerSetArrayImplementation::partialIntersection(true, 5, $a, $b, $c, $d);\nprint_r(iterator_to_array($r));\n// []\n```\n\n### Multisets example\n\n*Note: If input collections contains duplicate items, then\n[multiset](https://en.wikipedia.org/wiki/Multiset) intersection rules apply.*\n\n```php\n$a = [1, 1, 1, 1, 1];\n$b = [1, 2, 3, 4, 5, 1, 2, 3, 4, 5];\n$c = [5, 5, 5, 5, 5, 1, 5, 5, 1];\n\nuse Smoren\\PartialIntersection\\MultisetIterableImplementation;\n\n$r = MultisetIterableImplementation::partialIntersection(true, 1, $a, $b, $c);\nprint_r(iterator_to_array($r));\n// [1, 1, 1, 1, 1, 2, 2, 3, 3, 4, 4, 5, 5, 5, 5, 5, 5, 5]\n\n$r = MultisetIterableImplementation::partialIntersection(true, 2, $a, $b, $c);\nprint_r(iterator_to_array($r));\n// [1, 1, 5, 5]\n\n$r = MultisetIterableImplementation::partialIntersection(true, 3, $a, $b, $c);\nprint_r(iterator_to_array($r));\n// [1, 1]\n\n$r = MultisetIterableImplementation::partialIntersection(true, 4, $a, $b, $c);\nprint_r(iterator_to_array($r));\n// []\n```\n\n## Unit testing\n```\ncomposer install\ncomposer test-init\ncomposer test\n```\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsmoren%2Fpartial-intersection-php","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fsmoren%2Fpartial-intersection-php","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsmoren%2Fpartial-intersection-php/lists"}