custom-permutation 1.0.7 → 1.1.1
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/README.md +65 -49
- package/lib/CustomPermutation.d.ts +6 -7
- package/lib/CustomPermutation.js +19 -60
- package/lib/CustomPermutation.js.map +1 -1
- package/lib/CustomPermutationGenerator.d.ts +26 -32
- package/lib/CustomPermutationGenerator.js +113 -170
- package/lib/CustomPermutationGenerator.js.map +1 -1
- package/lib/PermutationGeneratorForSet.d.ts +23 -28
- package/lib/PermutationGeneratorForSet.js +136 -250
- package/lib/PermutationGeneratorForSet.js.map +1 -1
- package/lib/demo.d.ts +1 -0
- package/lib/demo.js +12 -0
- package/lib/demo.js.map +1 -0
- package/lib/index.d.ts +1 -1
- package/lib/index.js +2 -1
- package/lib/index.js.map +1 -1
- package/package.json +22 -15
- package/lib/Enums.d.ts +0 -39
- package/lib/Enums.js +0 -49
- package/lib/Enums.js.map +0 -1
- package/lib/Permutation.d.ts +0 -26
- package/lib/Permutation.js +0 -265
- package/lib/Permutation.js.map +0 -1
- package/lib/Utils.d.ts +0 -4
- package/lib/Utils.js +0 -34
- package/lib/Utils.js.map +0 -1
|
@@ -1,166 +1,128 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.CustomPermutationGenerator = void 0;
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
function CustomPermutationGenerator(elementList, choicesByIndex, // ChoicesByIndex is relative to sub-sch so we need elementsIndexRel, a index list of sub-sch
|
|
8
|
-
nonChoicesByIndex, // nonChoices is also relative
|
|
9
|
-
elementsOrderAbs, // Actual orders in final schdule
|
|
10
|
-
elementsIndexRel, // Actual relative orders in sub-schedule
|
|
11
|
-
passFunction, randomizechoices) {
|
|
12
|
-
if (choicesByIndex === void 0) { choicesByIndex = {}; }
|
|
13
|
-
if (nonChoicesByIndex === void 0) { nonChoicesByIndex = {}; }
|
|
14
|
-
if (elementsIndexRel === void 0) { elementsIndexRel = []; }
|
|
4
|
+
const PermutationGeneratorForSet_1 = require("./PermutationGeneratorForSet");
|
|
5
|
+
class CustomPermutationGenerator {
|
|
6
|
+
constructor(elementList, choicesByIndex, nonChoicesByIndex, elementsOrderAbsolute, passFunction) {
|
|
15
7
|
this.elementList = elementList;
|
|
16
8
|
this.choicesByIndex = choicesByIndex;
|
|
17
9
|
this.nonChoicesByIndex = nonChoicesByIndex;
|
|
18
|
-
this.
|
|
19
|
-
this.elementsIndexRel = elementsIndexRel;
|
|
10
|
+
this.elementsOrderAbsolute = elementsOrderAbsolute;
|
|
20
11
|
this.passFunction = passFunction;
|
|
21
|
-
this.randomizechoices = randomizechoices;
|
|
22
12
|
this.nextIndexList = [];
|
|
23
|
-
this.
|
|
24
|
-
this.history = [];
|
|
25
|
-
this.historyHashes = [];
|
|
26
|
-
this.current = [];
|
|
13
|
+
this.finalChoicesByIndexInSet = {};
|
|
14
|
+
this.history = [];
|
|
15
|
+
this.historyHashes = [];
|
|
16
|
+
this.current = [];
|
|
27
17
|
this.cursor = 0;
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
this.
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
var indexesOfSameElements = {};
|
|
35
|
-
elementList.forEach(function (element, i) {
|
|
18
|
+
const indexList = Array(elementList.length)
|
|
19
|
+
.fill(0)
|
|
20
|
+
.map((_, ind) => ind);
|
|
21
|
+
this.set = Array.from(new Set(elementList));
|
|
22
|
+
const indexesOfSameElements = {};
|
|
23
|
+
elementList.forEach((element, i) => {
|
|
36
24
|
indexesOfSameElements[i] = [];
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
// // indexesOfSameElements[i] = [i]; // To make an illusion such that zero is different than zero, to make it possible to be consecutive
|
|
40
|
-
// return;
|
|
41
|
-
// }
|
|
42
|
-
elementList.forEach(function (innerElement, j) {
|
|
43
|
-
if (element == innerElement) {
|
|
25
|
+
elementList.forEach((el, j) => {
|
|
26
|
+
if (element === el) {
|
|
44
27
|
indexesOfSameElements[i].push(j);
|
|
45
28
|
}
|
|
46
29
|
});
|
|
47
30
|
});
|
|
48
|
-
// Can be uncomment, since it will increase the permutation number but it should be remain for exact results
|
|
49
31
|
this.extendIndexesOfSameElements(this.choicesByIndex, indexesOfSameElements);
|
|
50
|
-
// not make for choicesByIndex list so that options be little
|
|
51
32
|
this.extendIndexesOfSameElements(this.nonChoicesByIndex, indexesOfSameElements);
|
|
52
|
-
// let choicesByIndexInSetFiltered = Object.keys(this.choicesByIndexInSet).filter(x => elementsIndexRel.indexOf(Number(x)) >= 0)
|
|
53
|
-
// .map(x => this.choicesByIndexInSet[x]);
|
|
54
|
-
// Same like above
|
|
55
|
-
// for(let i = 0; i < this.elementsIndexRel.length; i++) {
|
|
56
|
-
// choicesByIndexInSetFiltered[i] = this.choicesByIndexInSet[elementsIndexRel[i]]
|
|
57
|
-
// }
|
|
58
|
-
this.permutationGenOfSet = new PermutationGeneratorForSet_1.PermutationGeneratorForSet(elementList, indexList, this.choicesByIndexInSet, indexesOfSameElements, elementsOrderAbs, passFunction, randomizechoices);
|
|
59
|
-
}
|
|
60
|
-
// collect indexes of same elements into nonChoicesByIndex array, eg, slot1 should be placed by person 1 whose indexes are 3,4,5
|
|
61
|
-
CustomPermutationGenerator.prototype.extendIndexesOfSameElements = function (choicesByIndex, indexesOfSameElements) {
|
|
62
|
-
if (!choicesByIndex) {
|
|
63
|
-
return;
|
|
64
|
-
}
|
|
65
|
-
var choicesIndexKeys = Object.keys(choicesByIndex);
|
|
66
|
-
for (var i = 0; i < choicesIndexKeys.length; i++) {
|
|
67
|
-
var key = choicesIndexKeys[i];
|
|
68
|
-
if (choicesByIndex[key]) {
|
|
69
|
-
for (var j = 0; j < choicesByIndex[key].length; j++) {
|
|
70
|
-
var ar = choicesByIndex[key].slice();
|
|
71
|
-
// debugger
|
|
72
|
-
if ((indexesOfSameElements[choicesByIndex[key][j]] || []).indexOf(choicesByIndex[key][j]) >= 0) {
|
|
73
|
-
ar = ar.concat(indexesOfSameElements[choicesByIndex[key][j]]);
|
|
74
|
-
}
|
|
75
|
-
}
|
|
76
|
-
choicesByIndex[key] = ar ? ar.filter(function (el, i) { return ar.indexOf(el) == i; }) : [];
|
|
77
|
-
}
|
|
78
|
-
}
|
|
79
|
-
};
|
|
80
|
-
// ? Need indexes to make a set, since element list may not be distinct
|
|
81
|
-
CustomPermutationGenerator.prototype.init = function () {
|
|
82
33
|
if (this.nonChoicesByIndex) {
|
|
83
|
-
this.removeNonChoicesIndexes();
|
|
34
|
+
this.removeNonChoicesIndexes();
|
|
84
35
|
}
|
|
85
36
|
if (this.choicesByIndex) {
|
|
86
|
-
this.setChoicesIndexesInSet();
|
|
87
|
-
}
|
|
88
|
-
this.completeMissingChoicesIndexes();
|
|
89
|
-
};
|
|
90
|
-
CustomPermutationGenerator.prototype.completeMissingChoicesIndexes = function () {
|
|
91
|
-
var allIndexes = Array(this.elementList.length).fill(0).map(function (x, i) { return i; });
|
|
92
|
-
for (var i = 0; i < this.elementList.length; i++) {
|
|
93
|
-
if (!this.choicesByIndexInSet[i]) {
|
|
94
|
-
this.choicesByIndexInSet[i] = allIndexes.slice();
|
|
95
|
-
}
|
|
37
|
+
this.setChoicesIndexesInSet();
|
|
96
38
|
}
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
39
|
+
this.completeRestOfIndexes();
|
|
40
|
+
this.permutationGenOfSet = new PermutationGeneratorForSet_1.PermutationGeneratorForSet(elementList, indexList, this.finalChoicesByIndexInSet, indexesOfSameElements, this.elementsOrderAbsolute, passFunction);
|
|
41
|
+
}
|
|
42
|
+
removeNonChoicesIndexes() {
|
|
43
|
+
const allIndexes = Array(this.elementList.length)
|
|
44
|
+
.fill(0)
|
|
45
|
+
.map((x, i) => i);
|
|
46
|
+
Object.keys(this.nonChoicesByIndex).forEach((key) => {
|
|
47
|
+
let indexes = allIndexes.slice();
|
|
48
|
+
for (const el of this.nonChoicesByIndex[+key]) {
|
|
49
|
+
const indexesToRemove = this.getAllIndexesOfElementInList(el, this.elementList);
|
|
50
|
+
indexes = indexes.filter((x) => indexesToRemove.indexOf(x) < 0);
|
|
107
51
|
}
|
|
108
|
-
|
|
52
|
+
this.finalChoicesByIndexInSet[key] = indexes;
|
|
109
53
|
});
|
|
110
|
-
}
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
var indexes = allIndexes.slice();
|
|
116
|
-
for (var j = 0; j < _this.nonChoicesByIndex[key].length; j++) {
|
|
117
|
-
var indexesToRemove = _this.getAllIndexesOfElementInList(_this.nonChoicesByIndex[key][j], _this.elementList);
|
|
118
|
-
indexes = indexes.filter(function (x) { return indexesToRemove.indexOf(x) < 0; });
|
|
54
|
+
}
|
|
55
|
+
setChoicesIndexesInSet() {
|
|
56
|
+
for (const key in this.choicesByIndex) {
|
|
57
|
+
if (!this.choicesByIndex[+key]) {
|
|
58
|
+
continue;
|
|
119
59
|
}
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
60
|
+
let indexesInList = [];
|
|
61
|
+
for (const el of this.choicesByIndex[+key]) {
|
|
62
|
+
indexesInList = indexesInList.concat(this.getAllIndexesOfElementInList(el, this.elementList));
|
|
63
|
+
}
|
|
64
|
+
this.finalChoicesByIndexInSet[key] = indexesInList;
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
getAllIndexesOfElementInList(el, list) {
|
|
68
|
+
const indexes = [];
|
|
69
|
+
for (let i = 0; i < list.length; i++) {
|
|
70
|
+
if (String(el) === String(list[i])) {
|
|
127
71
|
indexes.push(i);
|
|
128
72
|
}
|
|
129
73
|
}
|
|
130
74
|
return indexes;
|
|
131
|
-
}
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
75
|
+
}
|
|
76
|
+
completeRestOfIndexes() {
|
|
77
|
+
const allIndexes = Array(this.elementList.length)
|
|
78
|
+
.fill(0)
|
|
79
|
+
.map((x, i) => i);
|
|
80
|
+
for (let i = 0; i < this.elementList.length; i++) {
|
|
81
|
+
if (!this.finalChoicesByIndexInSet[i]) {
|
|
82
|
+
this.finalChoicesByIndexInSet[i] = allIndexes.slice();
|
|
83
|
+
}
|
|
135
84
|
}
|
|
136
|
-
}
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
85
|
+
}
|
|
86
|
+
extendIndexesOfSameElements(choicesByIndex, indexesOfSameElements) {
|
|
87
|
+
if (!choicesByIndex) {
|
|
88
|
+
return;
|
|
89
|
+
}
|
|
90
|
+
for (const key in choicesByIndex) {
|
|
91
|
+
if (choicesByIndex[key]) {
|
|
92
|
+
let clone;
|
|
93
|
+
for (const anotherKey of choicesByIndex[key]) {
|
|
94
|
+
clone = choicesByIndex[key].slice();
|
|
95
|
+
if ((indexesOfSameElements[anotherKey] || []).indexOf(anotherKey) >= 0) {
|
|
96
|
+
clone = clone.concat(indexesOfSameElements[anotherKey]);
|
|
97
|
+
}
|
|
147
98
|
}
|
|
99
|
+
choicesByIndex[key] = clone ? clone.filter((el, idx) => clone.indexOf(el) === idx) : [];
|
|
148
100
|
}
|
|
149
|
-
else if (nextDistinct && nextDistinct.done) {
|
|
150
|
-
return null; // PermResultTypeEnum.ENDOFPERMUTATION;
|
|
151
|
-
}
|
|
152
101
|
}
|
|
153
|
-
}
|
|
154
|
-
|
|
102
|
+
}
|
|
103
|
+
prev() {
|
|
104
|
+
if (this.cursor > 1) {
|
|
105
|
+
// cursor-1 is current, cursor-2 is prev
|
|
106
|
+
return this.history[--this.cursor - 1];
|
|
107
|
+
}
|
|
108
|
+
return undefined;
|
|
109
|
+
}
|
|
110
|
+
next() {
|
|
111
|
+
var _a;
|
|
112
|
+
const nextDistinctPerm = this.nextDistinct();
|
|
113
|
+
return !nextDistinctPerm.done ? ((_a = nextDistinctPerm.value) !== null && _a !== void 0 ? _a : null) : null;
|
|
114
|
+
}
|
|
115
|
+
nextDistinct() {
|
|
116
|
+
var _a;
|
|
155
117
|
if (this.cursor < this.history.length) {
|
|
156
118
|
return { value: this.history[this.cursor++], done: false };
|
|
157
119
|
}
|
|
158
|
-
|
|
159
|
-
this.nextIndexList = nextPerm.value;
|
|
160
|
-
|
|
120
|
+
const nextPerm = this.permutationGenOfSet.next();
|
|
121
|
+
this.nextIndexList = (_a = nextPerm.value) !== null && _a !== void 0 ? _a : [];
|
|
122
|
+
let elList;
|
|
161
123
|
if (this.nextIndexList && this.nextIndexList.length > 0) {
|
|
162
124
|
elList = this.getElementListByInitialListIndexes(nextPerm.value);
|
|
163
|
-
|
|
125
|
+
const hash = this.getHash(elList);
|
|
164
126
|
if (this.historyHashes.indexOf(hash) < 0 && (!this.passFunction || this.passFunction(elList))) {
|
|
165
127
|
this.current = elList;
|
|
166
128
|
this.history.push(elList);
|
|
@@ -168,70 +130,51 @@ var CustomPermutationGenerator = /** @class */ (function () {
|
|
|
168
130
|
this.cursor++;
|
|
169
131
|
}
|
|
170
132
|
else {
|
|
171
|
-
return
|
|
133
|
+
return this.nextDistinct();
|
|
172
134
|
}
|
|
173
135
|
}
|
|
174
136
|
return { done: nextPerm.done, value: elList };
|
|
175
|
-
}
|
|
176
|
-
|
|
137
|
+
}
|
|
138
|
+
saveCurrentToHistory() {
|
|
177
139
|
this.history.push(this.current);
|
|
178
|
-
|
|
140
|
+
const hash = this.getHash(this.current);
|
|
179
141
|
this.historyHashes.push(hash);
|
|
180
142
|
this.cursor++;
|
|
181
|
-
}
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
hash += String(elList[i]);
|
|
187
|
-
}
|
|
188
|
-
}
|
|
189
|
-
return hash;
|
|
190
|
-
};
|
|
191
|
-
CustomPermutationGenerator.prototype.getElementListByInitialListIndexes = function (indexes) {
|
|
192
|
-
var _this = this;
|
|
143
|
+
}
|
|
144
|
+
getHash(elList) {
|
|
145
|
+
return JSON.stringify(elList);
|
|
146
|
+
}
|
|
147
|
+
getElementListByInitialListIndexes(indexes) {
|
|
193
148
|
if (!indexes || !indexes.length) {
|
|
194
149
|
return [];
|
|
195
150
|
}
|
|
196
|
-
|
|
197
|
-
indexes.forEach(
|
|
198
|
-
|
|
199
|
-
{
|
|
200
|
-
elList.push(_this.elementList[index]);
|
|
201
|
-
}
|
|
151
|
+
const elList = [];
|
|
152
|
+
indexes.forEach((index) => {
|
|
153
|
+
elList.push(this.elementList[index]);
|
|
202
154
|
});
|
|
203
155
|
return elList;
|
|
204
|
-
}
|
|
205
|
-
|
|
206
|
-
for (var i = 1; i < list.length; i++) {
|
|
207
|
-
if (list[i] == list[i - 1]) {
|
|
208
|
-
return false;
|
|
209
|
-
}
|
|
210
|
-
}
|
|
211
|
-
return true;
|
|
212
|
-
};
|
|
213
|
-
CustomPermutationGenerator.prototype.reset = function () {
|
|
156
|
+
}
|
|
157
|
+
reset() {
|
|
214
158
|
this.cursor = 0;
|
|
215
|
-
}
|
|
216
|
-
|
|
159
|
+
}
|
|
160
|
+
getSet() {
|
|
217
161
|
return this.set || [];
|
|
218
|
-
}
|
|
219
|
-
|
|
162
|
+
}
|
|
163
|
+
isEmpty() {
|
|
220
164
|
return !this.set || this.set.length === 0;
|
|
221
|
-
}
|
|
222
|
-
|
|
165
|
+
}
|
|
166
|
+
getCurrent() {
|
|
223
167
|
if (this.cursor < this.history.length && this.cursor >= 0) {
|
|
224
168
|
return this.history[this.cursor];
|
|
225
169
|
}
|
|
226
170
|
else {
|
|
227
171
|
return null;
|
|
228
172
|
}
|
|
229
|
-
}
|
|
230
|
-
|
|
173
|
+
}
|
|
174
|
+
last() {
|
|
231
175
|
this.cursor = this.history.length - 1;
|
|
232
176
|
return this.history[this.cursor];
|
|
233
|
-
}
|
|
234
|
-
|
|
235
|
-
}());
|
|
177
|
+
}
|
|
178
|
+
}
|
|
236
179
|
exports.CustomPermutationGenerator = CustomPermutationGenerator;
|
|
237
180
|
//# sourceMappingURL=CustomPermutationGenerator.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"CustomPermutationGenerator.js","sourceRoot":"","sources":["../src/CustomPermutationGenerator.ts"],"names":[],"mappings":";;;AAAA,
|
|
1
|
+
{"version":3,"file":"CustomPermutationGenerator.js","sourceRoot":"","sources":["../src/CustomPermutationGenerator.ts"],"names":[],"mappings":";;;AAAA,6EAA0E;AAE1E,MAAa,0BAA0B;IAUrC,YACU,WAAgB,EAChB,cAAmC,EACnC,iBAAsC,EACtC,qBAAgC,EAChC,YAAsC;QAJtC,gBAAW,GAAX,WAAW,CAAK;QAChB,mBAAc,GAAd,cAAc,CAAqB;QACnC,sBAAiB,GAAjB,iBAAiB,CAAqB;QACtC,0BAAqB,GAArB,qBAAqB,CAAW;QAChC,iBAAY,GAAZ,YAAY,CAA0B;QAZhD,kBAAa,GAAa,EAAE,CAAC;QAC7B,6BAAwB,GAAgC,EAAE,CAAC;QAC3D,YAAO,GAAU,EAAE,CAAC;QACpB,kBAAa,GAAa,EAAE,CAAC;QAC7B,YAAO,GAAQ,EAAE,CAAC;QAClB,WAAM,GAAG,CAAC,CAAC;QAST,MAAM,SAAS,GAAG,KAAK,CAAC,WAAW,CAAC,MAAM,CAAC;aACxC,IAAI,CAAC,CAAC,CAAC;aACP,GAAG,CAAC,CAAC,CAAC,EAAE,GAAG,EAAE,EAAE,CAAC,GAAG,CAAC,CAAC;QACxB,IAAI,CAAC,GAAG,GAAG,KAAK,CAAC,IAAI,CAAC,IAAI,GAAG,CAAC,WAAW,CAAC,CAAC,CAAC;QAE5C,MAAM,qBAAqB,GAA6B,EAAE,CAAC;QAE3D,WAAW,CAAC,OAAO,CAAC,CAAC,OAAO,EAAE,CAA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H,OAAO,MAAM,CAAC;IAChB,CAAC;IAED,KAAK;QACH,IAAI,CAAC,MAAM,GAAG,CAAC,CAAC;IAClB,CAAC;IAED,MAAM;QACJ,OAAO,IAAI,CAAC,GAAG,IAAI,EAAE,CAAC;IACxB,CAAC;IAED,OAAO;QACL,OAAO,CAAC,IAAI,CAAC,GAAG,IAAI,IAAI,CAAC,GAAG,CAAC,MAAM,KAAK,CAAC,CAAC;IAC5C,CAAC;IAED,UAAU;QACR,IAAI,IAAI,CAAC,MAAM,GAAG,IAAI,CAAC,OAAO,CAAC,MAAM,IAAI,IAAI,CAAC,MAAM,IAAI,CAAC,EAAE,CAAC;YAC1D,OAAO,IAAI,CAAC,OAAO,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC;QACnC,CAAC;aAAM,CAAC;YACN,OAAO,IAAI,CAAC;QACd,CAAC;IACH,CAAC;IAED,IAAI;QACF,IAAI,CAAC,MAAM,GAAG,IAAI,CAAC,OAAO,CAAC,MAAM,GAAG,CAAC,CAAC;QACtC,OAAO,IAAI,CAAC,OAAO,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC;IACnC,CAAC;CACF;AA3ND,gEA2NC"}
|
|
@@ -1,42 +1,37 @@
|
|
|
1
|
+
type ChoiceEntry = {
|
|
2
|
+
index: number;
|
|
3
|
+
length: number;
|
|
4
|
+
};
|
|
1
5
|
export declare class PermutationGeneratorForSet {
|
|
2
6
|
private elementList;
|
|
3
|
-
private
|
|
7
|
+
private indexList;
|
|
4
8
|
private choicesByIndex?;
|
|
5
9
|
private indexesOfSameElements?;
|
|
6
10
|
private actualOrderOfElements?;
|
|
7
11
|
private passFunction?;
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
currentIndsOfChoices: any[];
|
|
12
|
+
choicesArraysInitial: number[][];
|
|
13
|
+
choicesArrays: number[][];
|
|
14
|
+
size: number;
|
|
15
|
+
currentIndsOfChoices: number[];
|
|
13
16
|
currentElInd: number;
|
|
14
|
-
newPerm:
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
constructor(elementList: any[], set: any[], // set of index
|
|
22
|
-
choicesByIndex?: object, indexesOfSameElements?: any, actualOrderOfElements?: any[], passFunction?: Function, randomizeChoices?: boolean);
|
|
23
|
-
initPrevIndexes(): void;
|
|
24
|
-
isNewPermWithNewElementConsecutivelyDifferent(currentEl: any, elIndInChoices: any, elIndInPerm: any): any;
|
|
25
|
-
isNewPermWithNewElementConsecutivelyDifferent_(currentEl: any, elIndInChoices: any, elIndInPerm: any): any;
|
|
26
|
-
isPreviousElementDifferentOrCanSkipThisFn(currentEl: any, elIndInChoices: any, elIndInPerm: any): boolean;
|
|
17
|
+
newPerm: (number | null)[];
|
|
18
|
+
initialIndexList: number[];
|
|
19
|
+
indexesAndChoicesCountsSortedByLength: ChoiceEntry[];
|
|
20
|
+
indexesAndChoicesCounts: ChoiceEntry[];
|
|
21
|
+
visitedDict: Record<number, boolean>;
|
|
22
|
+
constructor(elementList: any[], indexList: number[], choicesByIndex?: Record<string, number[]> | undefined, indexesOfSameElements?: Record<number, number[]> | undefined, actualOrderOfElements?: number[] | undefined, passFunction?: ((items: any[]) => boolean) | undefined);
|
|
23
|
+
isNewPermutationPassingFunction(currentEl: number, elIndInPerm: number): boolean;
|
|
27
24
|
reorderListAndChoicesAccordingToChoicesCount(): void;
|
|
28
|
-
revertResultPermToInitialOrder(newPerm: any): any[];
|
|
29
25
|
initChoicesArray(): void;
|
|
30
26
|
init(): void;
|
|
31
27
|
next(): {
|
|
32
28
|
done: boolean;
|
|
33
|
-
value?:
|
|
34
|
-
} | {
|
|
35
|
-
done: boolean;
|
|
36
|
-
value: any[];
|
|
29
|
+
value?: number[];
|
|
37
30
|
};
|
|
38
|
-
getNextPerm():
|
|
39
|
-
goBack(newPerm:
|
|
40
|
-
getAndSetPossibleNextElementForNewPerm(newPerm:
|
|
41
|
-
validateParameters(elementSet:
|
|
31
|
+
getNextPerm(): (number | null)[] | undefined;
|
|
32
|
+
goBack(newPerm: (number | null)[], choicesArrayWithIndexes: number[][], selectedIndexesForPerm: number[], elInd: number): boolean;
|
|
33
|
+
getAndSetPossibleNextElementForNewPerm(newPerm: (number | null)[], choices: number[], currentIndsInChoices: number[], elInd: number): number | undefined;
|
|
34
|
+
validateParameters(elementSet: number[], choicesByIndex?: object): boolean;
|
|
35
|
+
revertResultPermToInitialOrder(newPerm: (number | null)[]): (number | null)[];
|
|
42
36
|
}
|
|
37
|
+
export {};
|