@slimlib/refine-partition 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +32 -0
- package/dist/index.cjs +40 -0
- package/dist/index.d.ts +1 -0
- package/dist/index.mjs +38 -0
- package/package.json +65 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2023 Konstantin Shutkin
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
# Refine Partition
|
|
2
|
+
|
|
3
|
+
Simple refine partition implementation
|
|
4
|
+
|
|
5
|
+
https://en.wikipedia.org/wiki/Partition_refinement
|
|
6
|
+
|
|
7
|
+
> To perform a refinement operation, the algorithm loops through the elements of the given set X. For each such element x, it finds the set Si that contains x, and checks whether a second set for Si ∩ X has already been started. If not, it creates the second set and adds Si to a list L of the sets that are split by the operation. Then, regardless of whether a new set was formed, the algorithm removes x from Si and adds it to Si ∩ X. In the representation in which all elements are stored in a single array, moving x from one set to another may be performed by swapping x with the final element of Si and then decrementing the end index of Si and the start index of the new set. Finally, after all elements of X have been processed in this way, the algorithm loops through L, separating each current set Si from the second set that has been split from it, and reports both of these sets as being newly formed by the refinement operation.
|
|
8
|
+
|
|
9
|
+
## API
|
|
10
|
+
|
|
11
|
+
### `<T>() => (newPartitionCandidate?: Iterable<T>) => Iterable<Iterable<T>>`
|
|
12
|
+
|
|
13
|
+
Create refiner funtion.
|
|
14
|
+
|
|
15
|
+
Pass to it new candidates for refinement.
|
|
16
|
+
|
|
17
|
+
Returns refined partition.
|
|
18
|
+
|
|
19
|
+
### Example
|
|
20
|
+
|
|
21
|
+
```typescript
|
|
22
|
+
import refiner from '../src';
|
|
23
|
+
|
|
24
|
+
const refineNext = refiner();
|
|
25
|
+
refineNext(['a', 'b', 'c']);
|
|
26
|
+
refineNext(['b', 'c', 'e']);
|
|
27
|
+
console.log(refineNext()); // Iterable of Iterables: ((a), (b, c), (e))
|
|
28
|
+
```
|
|
29
|
+
|
|
30
|
+
# License
|
|
31
|
+
|
|
32
|
+
[MIT](./LICENSE)
|
package/dist/index.cjs
ADDED
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
function index () {
|
|
4
|
+
const processed = new Set();
|
|
5
|
+
return (newPartitionCandidate) => {
|
|
6
|
+
if (newPartitionCandidate) {
|
|
7
|
+
const intersections = new Map();
|
|
8
|
+
for (const element of newPartitionCandidate) {
|
|
9
|
+
for (const partitionItem of processed) {
|
|
10
|
+
if (partitionItem.has(element)) {
|
|
11
|
+
let intersection = intersections.get(partitionItem);
|
|
12
|
+
if (intersection === undefined) {
|
|
13
|
+
intersection = new Set();
|
|
14
|
+
intersections.set(partitionItem, intersection);
|
|
15
|
+
}
|
|
16
|
+
intersection.add(element);
|
|
17
|
+
partitionItem.delete(element);
|
|
18
|
+
if (partitionItem.size === 0) {
|
|
19
|
+
processed.delete(partitionItem);
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
const newPartitionItem = new Set(newPartitionCandidate);
|
|
25
|
+
for (const intersection of intersections.values()) {
|
|
26
|
+
processed.add(intersection);
|
|
27
|
+
for (const element of intersection) {
|
|
28
|
+
newPartitionItem.delete(element);
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
intersections.clear();
|
|
32
|
+
if (newPartitionItem.size > 0) {
|
|
33
|
+
processed.add(newPartitionItem);
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
return processed;
|
|
37
|
+
};
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
module.exports = index;
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export default function <T>(): (newPartitionCandidate?: Iterable<T> | undefined) => Iterable<Iterable<T>>;
|
package/dist/index.mjs
ADDED
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
function index () {
|
|
2
|
+
const processed = new Set();
|
|
3
|
+
return (newPartitionCandidate) => {
|
|
4
|
+
if (newPartitionCandidate) {
|
|
5
|
+
const intersections = new Map();
|
|
6
|
+
for (const element of newPartitionCandidate) {
|
|
7
|
+
for (const partitionItem of processed) {
|
|
8
|
+
if (partitionItem.has(element)) {
|
|
9
|
+
let intersection = intersections.get(partitionItem);
|
|
10
|
+
if (intersection === undefined) {
|
|
11
|
+
intersection = new Set();
|
|
12
|
+
intersections.set(partitionItem, intersection);
|
|
13
|
+
}
|
|
14
|
+
intersection.add(element);
|
|
15
|
+
partitionItem.delete(element);
|
|
16
|
+
if (partitionItem.size === 0) {
|
|
17
|
+
processed.delete(partitionItem);
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
const newPartitionItem = new Set(newPartitionCandidate);
|
|
23
|
+
for (const intersection of intersections.values()) {
|
|
24
|
+
processed.add(intersection);
|
|
25
|
+
for (const element of intersection) {
|
|
26
|
+
newPartitionItem.delete(element);
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
intersections.clear();
|
|
30
|
+
if (newPartitionItem.size > 0) {
|
|
31
|
+
processed.add(newPartitionItem);
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
return processed;
|
|
35
|
+
};
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
export { index as default };
|
package/package.json
ADDED
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": "1.0.0",
|
|
3
|
+
"license": "MIT",
|
|
4
|
+
"name": "@slimlib/refine-partition",
|
|
5
|
+
"author": "Konstantin Shutkin",
|
|
6
|
+
"type": "module",
|
|
7
|
+
"exports": {
|
|
8
|
+
".": {
|
|
9
|
+
"require": "./dist/index.cjs",
|
|
10
|
+
"default": "./dist/index.mjs"
|
|
11
|
+
}
|
|
12
|
+
},
|
|
13
|
+
"main": "./dist/index.cjs",
|
|
14
|
+
"module": "./dist/index.mjs",
|
|
15
|
+
"typings": "./dist/index.d.ts",
|
|
16
|
+
"files": [
|
|
17
|
+
"dist",
|
|
18
|
+
"LICENSE"
|
|
19
|
+
],
|
|
20
|
+
"engines": {
|
|
21
|
+
"node": ">=15"
|
|
22
|
+
},
|
|
23
|
+
"repository": {
|
|
24
|
+
"type": "git",
|
|
25
|
+
"url": "git+https://github.com/kshutkin/slimlib.git"
|
|
26
|
+
},
|
|
27
|
+
"bugs": {
|
|
28
|
+
"url": "https://github.com/kshutkin/slimlib/issues"
|
|
29
|
+
},
|
|
30
|
+
"homepage": "https://github.com/kshutkin/slimlib/blob/main/refine-partition/README.md",
|
|
31
|
+
"readme": "README.md",
|
|
32
|
+
"description": "Simple refine partition implementation",
|
|
33
|
+
"keywords": [
|
|
34
|
+
"@slimlib",
|
|
35
|
+
"list",
|
|
36
|
+
"linked list",
|
|
37
|
+
"doubly linked list"
|
|
38
|
+
],
|
|
39
|
+
"scripts": {
|
|
40
|
+
"build": "pkgbld",
|
|
41
|
+
"test": "jest --collectCoverage",
|
|
42
|
+
"lint": "eslint ./src",
|
|
43
|
+
"semantic-release": "npx semantic-release"
|
|
44
|
+
},
|
|
45
|
+
"devDependencies": {
|
|
46
|
+
"@semantic-release/changelog": "6.0.1",
|
|
47
|
+
"@semantic-release/commit-analyzer": "9.0.2",
|
|
48
|
+
"@semantic-release/git": "10.0.1",
|
|
49
|
+
"@semantic-release/npm": "9.0.0",
|
|
50
|
+
"@semantic-release/release-notes-generator": "10.0.3",
|
|
51
|
+
"@types/jest": "27.4.0",
|
|
52
|
+
"@typescript-eslint/eslint-plugin": "5.11.0",
|
|
53
|
+
"@typescript-eslint/parser": "5.11.0",
|
|
54
|
+
"conventional-changelog-angular": "5.0.13",
|
|
55
|
+
"eslint": "8.8.0",
|
|
56
|
+
"jest": "27.5.1",
|
|
57
|
+
"semantic-release": "19.0.2",
|
|
58
|
+
"semantic-release-monorepo": "7.0.5",
|
|
59
|
+
"ts-jest": "27.1.3",
|
|
60
|
+
"typescript": "4.5.x",
|
|
61
|
+
"update-monorepo-package-json": "0.2.0",
|
|
62
|
+
"pkgbld": "1.1.9"
|
|
63
|
+
},
|
|
64
|
+
"dependencies": {}
|
|
65
|
+
}
|