recursive-set 1.1.0 → 2.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/README.md +14 -0
- package/dist/cjs/index.js +115 -192
- package/dist/cjs/index.js.map +1 -1
- package/dist/esm/index.d.ts +2 -103
- package/dist/esm/index.d.ts.map +1 -1
- package/dist/esm/index.js +108 -188
- package/dist/esm/index.js.map +1 -1
- package/package.json +5 -1
package/README.md
CHANGED
|
@@ -21,6 +21,20 @@ Supports arbitrary nesting, detects cycles (Foundation axiom), and includes all
|
|
|
21
21
|
|
|
22
22
|
---
|
|
23
23
|
|
|
24
|
+
## Implementation Details
|
|
25
|
+
|
|
26
|
+
This library enforces strict **ZFC Set Theory** semantics, differing from native JavaScript `Set`s:
|
|
27
|
+
|
|
28
|
+
- **Extensionality:** Two sets are considered equal if they contain the same elements, regardless of object reference identity.
|
|
29
|
+
- Example: `new RecursiveSet(1).equals(new RecursiveSet(1))` is `true`.
|
|
30
|
+
- Native `Set` would treat them as distinct objects.
|
|
31
|
+
- **Foundation Axiom:** The library performs cycle detection to prevent sets from containing themselves (recursively).
|
|
32
|
+
- **Performance:** Internally powered by **Functional Red-Black Trees** (via `functional-red-black-tree`).
|
|
33
|
+
- Operations like insertion, deletion, and lookup are **O(log n)**.
|
|
34
|
+
- This allows for stable ordering and efficient deep comparison of nested sets.
|
|
35
|
+
|
|
36
|
+
---
|
|
37
|
+
|
|
24
38
|
## Installation
|
|
25
39
|
|
|
26
40
|
```
|
package/dist/cjs/index.js
CHANGED
|
@@ -1,305 +1,228 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
*/
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
6
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
7
6
|
exports.RecursiveSet = void 0;
|
|
8
7
|
exports.emptySet = emptySet;
|
|
9
8
|
exports.singleton = singleton;
|
|
10
9
|
exports.fromIterable = fromIterable;
|
|
10
|
+
const functional_red_black_tree_1 = __importDefault(require("functional-red-black-tree"));
|
|
11
11
|
/**
|
|
12
|
-
*
|
|
13
|
-
*
|
|
14
|
-
*
|
|
15
|
-
* - Extensionality: Sets with same elements are equal
|
|
16
|
-
* - Foundation (Regularity): No membership cycles allowed
|
|
17
|
-
* - Power Set: Can construct 𝒫(A) for any set A
|
|
18
|
-
* - Union: Can construct A ∪ B for any sets A, B
|
|
19
|
-
* - Pairing: Can construct {a, b} for any elements a, b
|
|
12
|
+
* @module recursive-set
|
|
13
|
+
* A mutable recursive set implementation enforcing Cantor's ZFC axioms
|
|
14
|
+
* Powered by Red-Black Trees for O(log n) operations
|
|
20
15
|
*/
|
|
16
|
+
/**
|
|
17
|
+
* Comparator function for ZFC sets
|
|
18
|
+
* Returns -1 if a < b, 1 if a > b, 0 if a == b (structural equality)
|
|
19
|
+
*/
|
|
20
|
+
function compare(a, b) {
|
|
21
|
+
// 1. Identity optimization
|
|
22
|
+
if (a === b)
|
|
23
|
+
return 0;
|
|
24
|
+
// 2. Type separation: Sets are "greater" than primitives
|
|
25
|
+
const isSetA = a instanceof RecursiveSet;
|
|
26
|
+
const isSetB = b instanceof RecursiveSet;
|
|
27
|
+
if (isSetA !== isSetB)
|
|
28
|
+
return isSetA ? 1 : -1;
|
|
29
|
+
// 3. Primitives
|
|
30
|
+
if (!isSetA) {
|
|
31
|
+
if (typeof a !== typeof b) {
|
|
32
|
+
return typeof a > typeof b ? 1 : -1;
|
|
33
|
+
}
|
|
34
|
+
return a < b ? -1 : 1;
|
|
35
|
+
}
|
|
36
|
+
// 4. Recursive Sets
|
|
37
|
+
const sizeA = a.size;
|
|
38
|
+
const sizeB = b.size;
|
|
39
|
+
if (sizeA !== sizeB)
|
|
40
|
+
return sizeA < sizeB ? -1 : 1;
|
|
41
|
+
// Lexicographical comparison
|
|
42
|
+
const itA = a[Symbol.iterator]();
|
|
43
|
+
const itB = b[Symbol.iterator]();
|
|
44
|
+
let nextA = itA.next();
|
|
45
|
+
let nextB = itB.next();
|
|
46
|
+
while (!nextA.done) {
|
|
47
|
+
const cmp = compare(nextA.value, nextB.value);
|
|
48
|
+
if (cmp !== 0)
|
|
49
|
+
return cmp;
|
|
50
|
+
nextA = itA.next();
|
|
51
|
+
nextB = itB.next();
|
|
52
|
+
}
|
|
53
|
+
return 0;
|
|
54
|
+
}
|
|
21
55
|
class RecursiveSet {
|
|
22
|
-
|
|
56
|
+
// Red-Black Tree (immutable structure, we replace on mutation)
|
|
57
|
+
_tree; // Type from functional-red-black-tree
|
|
23
58
|
constructor(...elements) {
|
|
24
|
-
this.
|
|
59
|
+
this._tree = (0, functional_red_black_tree_1.default)(compare);
|
|
25
60
|
for (const el of elements) {
|
|
26
|
-
this.
|
|
27
|
-
}
|
|
28
|
-
this._checkInvariants();
|
|
29
|
-
}
|
|
30
|
-
/**
|
|
31
|
-
* Internal: Add element with cycle detection (Foundation axiom)
|
|
32
|
-
*/
|
|
33
|
-
_addElement(el) {
|
|
34
|
-
if (el instanceof RecursiveSet) {
|
|
35
|
-
if (this._wouldCreateCycle(el)) {
|
|
36
|
-
throw new Error("Foundation axiom violated: adding this element would create a membership cycle");
|
|
37
|
-
}
|
|
61
|
+
this.add(el);
|
|
38
62
|
}
|
|
39
|
-
this._elements.add(el);
|
|
40
63
|
}
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
while (toCheck.length > 0) {
|
|
48
|
-
const current = toCheck.pop();
|
|
49
|
-
if (current === this) {
|
|
50
|
-
return true;
|
|
51
|
-
}
|
|
52
|
-
if (visited.has(current)) {
|
|
53
|
-
continue;
|
|
54
|
-
}
|
|
55
|
-
visited.add(current);
|
|
56
|
-
for (const el of current._elements) {
|
|
57
|
-
if (el instanceof RecursiveSet) {
|
|
58
|
-
toCheck.push(el);
|
|
64
|
+
// === Mutable Operations ===
|
|
65
|
+
add(element) {
|
|
66
|
+
if (element instanceof RecursiveSet) {
|
|
67
|
+
if (!this.has(element)) {
|
|
68
|
+
if (this._wouldCreateCycle(element)) {
|
|
69
|
+
throw new Error("Foundation axiom violated: membership cycle detected");
|
|
59
70
|
}
|
|
60
71
|
}
|
|
61
72
|
}
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
* Verify class invariants (Design by Contract)
|
|
66
|
-
*/
|
|
67
|
-
_checkInvariants() {
|
|
68
|
-
// Extensionality: enforced by Set semantics
|
|
69
|
-
// Foundation: enforced by _wouldCreateCycle
|
|
70
|
-
// Well-definedness: enforced by TypeScript type system
|
|
71
|
-
// Additional runtime checks can be added here
|
|
72
|
-
if (process.env.NODE_ENV === 'development') {
|
|
73
|
-
// More expensive checks only in development
|
|
74
|
-
}
|
|
75
|
-
}
|
|
76
|
-
// === Mutable Operations ===
|
|
77
|
-
/**
|
|
78
|
-
* Add element to this set (Pairing axiom)
|
|
79
|
-
* @returns this for method chaining
|
|
80
|
-
*/
|
|
81
|
-
add(element) {
|
|
82
|
-
this._addElement(element);
|
|
83
|
-
this._checkInvariants();
|
|
73
|
+
// Immutable insert - returns new tree
|
|
74
|
+
// We replace our internal tree (mutable API, immutable data structure)
|
|
75
|
+
this._tree = this._tree.insert(element, true);
|
|
84
76
|
return this;
|
|
85
77
|
}
|
|
86
|
-
/**
|
|
87
|
-
* Remove element from this set
|
|
88
|
-
* @returns this for method chaining
|
|
89
|
-
*/
|
|
90
78
|
remove(element) {
|
|
91
|
-
this.
|
|
79
|
+
this._tree = this._tree.remove(element);
|
|
92
80
|
return this;
|
|
93
81
|
}
|
|
94
|
-
/**
|
|
95
|
-
* Remove all elements
|
|
96
|
-
* @returns this for method chaining
|
|
97
|
-
*/
|
|
98
82
|
clear() {
|
|
99
|
-
this.
|
|
83
|
+
this._tree = (0, functional_red_black_tree_1.default)(compare);
|
|
100
84
|
return this;
|
|
101
85
|
}
|
|
102
|
-
// === Immutable Operations
|
|
103
|
-
/**
|
|
104
|
-
* Union of two sets (Union axiom)
|
|
105
|
-
* Returns A ∪ B
|
|
106
|
-
*/
|
|
86
|
+
// === Immutable Operations ===
|
|
107
87
|
union(other) {
|
|
108
88
|
const result = new RecursiveSet();
|
|
109
|
-
|
|
89
|
+
for (const el of this)
|
|
90
|
+
result.add(el);
|
|
91
|
+
for (const el of other)
|
|
92
|
+
result.add(el);
|
|
110
93
|
return result;
|
|
111
94
|
}
|
|
112
|
-
/**
|
|
113
|
-
* Intersection of two sets
|
|
114
|
-
* Returns A ∩ B
|
|
115
|
-
*/
|
|
116
95
|
intersection(other) {
|
|
117
96
|
const result = new RecursiveSet();
|
|
118
|
-
for (const el of this
|
|
97
|
+
for (const el of this) {
|
|
119
98
|
if (other.has(el)) {
|
|
120
|
-
result.
|
|
99
|
+
result.add(el);
|
|
121
100
|
}
|
|
122
101
|
}
|
|
123
102
|
return result;
|
|
124
103
|
}
|
|
125
|
-
/**
|
|
126
|
-
* Set difference
|
|
127
|
-
* Returns A \ B (elements in A but not in B)
|
|
128
|
-
*/
|
|
129
104
|
difference(other) {
|
|
130
105
|
const result = new RecursiveSet();
|
|
131
|
-
for (const el of this
|
|
106
|
+
for (const el of this) {
|
|
132
107
|
if (!other.has(el)) {
|
|
133
|
-
result.
|
|
108
|
+
result.add(el);
|
|
134
109
|
}
|
|
135
110
|
}
|
|
136
111
|
return result;
|
|
137
112
|
}
|
|
138
|
-
/**
|
|
139
|
-
* Symmetric difference
|
|
140
|
-
* Returns A △ B (elements in either but not both)
|
|
141
|
-
*/
|
|
142
113
|
symmetricDifference(other) {
|
|
143
114
|
return this.union(other).difference(this.intersection(other));
|
|
144
115
|
}
|
|
145
|
-
/**
|
|
146
|
-
* Power set construction (Power Set axiom)
|
|
147
|
-
* Returns 𝒫(A) - set of all subsets
|
|
148
|
-
*/
|
|
149
116
|
powerset() {
|
|
150
|
-
const elements =
|
|
117
|
+
const elements = [];
|
|
118
|
+
this._tree.forEach((key) => elements.push(key));
|
|
151
119
|
const subsets = [];
|
|
152
|
-
// Generate all 2^n subsets
|
|
153
120
|
const n = elements.length;
|
|
154
121
|
for (let i = 0; i < (1 << n); i++) {
|
|
155
122
|
const subset = new RecursiveSet();
|
|
156
123
|
for (let j = 0; j < n; j++) {
|
|
157
124
|
if (i & (1 << j)) {
|
|
158
|
-
subset.
|
|
125
|
+
subset.add(elements[j]);
|
|
159
126
|
}
|
|
160
127
|
}
|
|
161
128
|
subsets.push(subset);
|
|
162
129
|
}
|
|
163
130
|
return new RecursiveSet(...subsets);
|
|
164
131
|
}
|
|
165
|
-
/**
|
|
166
|
-
* Cartesian product
|
|
167
|
-
* Returns A × B as set of ordered pairs {{a}, {a,b}}
|
|
168
|
-
*/
|
|
169
132
|
cartesianProduct(other) {
|
|
170
133
|
const pairs = [];
|
|
171
|
-
for (const x of this
|
|
172
|
-
for (const y of other
|
|
173
|
-
|
|
174
|
-
const
|
|
134
|
+
for (const x of this) {
|
|
135
|
+
for (const y of other) {
|
|
136
|
+
const valX = x;
|
|
137
|
+
const valY = y;
|
|
138
|
+
const pair = new RecursiveSet(new RecursiveSet(valX), new RecursiveSet(valX, valY));
|
|
175
139
|
pairs.push(pair);
|
|
176
140
|
}
|
|
177
141
|
}
|
|
178
142
|
return new RecursiveSet(...pairs);
|
|
179
143
|
}
|
|
180
144
|
// === Predicates ===
|
|
181
|
-
/**
|
|
182
|
-
* Check membership (∈)
|
|
183
|
-
*/
|
|
184
145
|
has(element) {
|
|
185
|
-
return this.
|
|
146
|
+
return this._tree.get(element) !== undefined;
|
|
186
147
|
}
|
|
187
|
-
/**
|
|
188
|
-
* Check if subset (⊆)
|
|
189
|
-
*/
|
|
190
148
|
isSubset(other) {
|
|
191
|
-
for (const el of this
|
|
192
|
-
if (!other.has(el))
|
|
149
|
+
for (const el of this) {
|
|
150
|
+
if (!other.has(el))
|
|
193
151
|
return false;
|
|
194
|
-
}
|
|
195
152
|
}
|
|
196
153
|
return true;
|
|
197
154
|
}
|
|
198
|
-
/**
|
|
199
|
-
* Check if superset (⊇)
|
|
200
|
-
*/
|
|
201
155
|
isSuperset(other) {
|
|
202
156
|
return other.isSubset(this);
|
|
203
157
|
}
|
|
204
|
-
/**
|
|
205
|
-
* Check if proper subset (⊂)
|
|
206
|
-
*/
|
|
207
158
|
isProperSubset(other) {
|
|
208
159
|
return this.isSubset(other) && !this.equals(other);
|
|
209
160
|
}
|
|
210
|
-
/**
|
|
211
|
-
* Check if empty set
|
|
212
|
-
*/
|
|
213
161
|
isEmpty() {
|
|
214
|
-
return this.
|
|
162
|
+
return this.size === 0;
|
|
215
163
|
}
|
|
216
|
-
// === Extensionality (Equality) ===
|
|
217
|
-
/**
|
|
218
|
-
* Structural equality (Extensionality axiom)
|
|
219
|
-
* Two sets are equal iff they have the same elements
|
|
220
|
-
*/
|
|
221
164
|
equals(other) {
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
165
|
+
return compare(this, other) === 0;
|
|
166
|
+
}
|
|
167
|
+
// === Internals ===
|
|
168
|
+
_wouldCreateCycle(element) {
|
|
169
|
+
const visited = new Set();
|
|
170
|
+
const stack = [element];
|
|
171
|
+
while (stack.length > 0) {
|
|
172
|
+
const current = stack.pop();
|
|
173
|
+
if (current === this)
|
|
174
|
+
return true;
|
|
175
|
+
if (visited.has(current))
|
|
176
|
+
continue;
|
|
177
|
+
visited.add(current);
|
|
178
|
+
for (const child of current) {
|
|
179
|
+
if (child instanceof RecursiveSet) {
|
|
180
|
+
stack.push(child);
|
|
234
181
|
}
|
|
235
|
-
if (!found)
|
|
236
|
-
return false;
|
|
237
|
-
}
|
|
238
|
-
else {
|
|
239
|
-
if (!other.has(el))
|
|
240
|
-
return false;
|
|
241
182
|
}
|
|
242
183
|
}
|
|
243
|
-
return
|
|
184
|
+
return false;
|
|
244
185
|
}
|
|
245
186
|
// === Utility ===
|
|
246
|
-
/**
|
|
247
|
-
* Cardinality |A|
|
|
248
|
-
*/
|
|
249
187
|
get size() {
|
|
250
|
-
return this.
|
|
188
|
+
return this._tree.length;
|
|
251
189
|
}
|
|
252
|
-
/**
|
|
253
|
-
* Convert to native Set (shallow)
|
|
254
|
-
*/
|
|
255
190
|
toSet() {
|
|
256
|
-
|
|
191
|
+
const result = new Set();
|
|
192
|
+
this._tree.forEach((key) => result.add(key));
|
|
193
|
+
return result;
|
|
257
194
|
}
|
|
258
|
-
/**
|
|
259
|
-
* Iterate over elements
|
|
260
|
-
*/
|
|
261
195
|
*[Symbol.iterator]() {
|
|
262
|
-
|
|
196
|
+
const keys = [];
|
|
197
|
+
this._tree.forEach((key) => keys.push(key));
|
|
198
|
+
yield* keys;
|
|
263
199
|
}
|
|
264
|
-
/**
|
|
265
|
-
* Pretty print with mathematical notation
|
|
266
|
-
*/
|
|
267
200
|
toString() {
|
|
268
|
-
if (this.isEmpty())
|
|
201
|
+
if (this.isEmpty())
|
|
269
202
|
return "∅";
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
if (
|
|
273
|
-
|
|
203
|
+
const elements = [];
|
|
204
|
+
this._tree.forEach((key) => {
|
|
205
|
+
if (key instanceof RecursiveSet) {
|
|
206
|
+
elements.push(key.toString());
|
|
207
|
+
}
|
|
208
|
+
else {
|
|
209
|
+
elements.push(String(key));
|
|
274
210
|
}
|
|
275
|
-
return String(el);
|
|
276
211
|
});
|
|
277
212
|
return `{${elements.join(", ")}}`;
|
|
278
213
|
}
|
|
279
|
-
/**
|
|
280
|
-
* For console.log
|
|
281
|
-
*/
|
|
282
214
|
[Symbol.for('nodejs.util.inspect.custom')]() {
|
|
283
215
|
return this.toString();
|
|
284
216
|
}
|
|
285
217
|
}
|
|
286
218
|
exports.RecursiveSet = RecursiveSet;
|
|
287
|
-
// ===
|
|
288
|
-
/**
|
|
289
|
-
* Create empty set (Null Set axiom)
|
|
290
|
-
*/
|
|
219
|
+
// === Helpers ===
|
|
291
220
|
function emptySet() {
|
|
292
221
|
return new RecursiveSet();
|
|
293
222
|
}
|
|
294
|
-
/**
|
|
295
|
-
* Create singleton set
|
|
296
|
-
*/
|
|
297
223
|
function singleton(element) {
|
|
298
224
|
return new RecursiveSet(element);
|
|
299
225
|
}
|
|
300
|
-
/**
|
|
301
|
-
* Create set from iterable
|
|
302
|
-
*/
|
|
303
226
|
function fromIterable(iterable) {
|
|
304
227
|
return new RecursiveSet(...iterable);
|
|
305
228
|
}
|
package/dist/cjs/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":";;;;;;AA0PA,4BAEC;AAED,8BAEC;AAED,oCAEC;AApQD,0FAAmD;AAEnD;;;;GAIG;AAEH;;;GAGG;AACH,SAAS,OAAO,CAAC,CAAM,EAAE,CAAM;IAC3B,2BAA2B;IAC3B,IAAI,CAAC,KAAK,CAAC;QAAE,OAAO,CAAC,CAAC;IAEtB,yDAAyD;IACzD,MAAM,MAAM,GAAG,CAAC,YAAY,YAAY,CAAC;IACzC,MAAM,MAAM,GAAG,CAAC,YAAY,YAAY,CAAC;IACzC,IAAI,MAAM,KAAK,MAAM;QAAE,OAAO,MAAM,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;IAE9C,gBAAgB;IAChB,IAAI,CAAC,MAAM,EAAE,CAAC;QACV,IAAI,OAAO,CAAC,KAAK,OAAO,CAAC,EAAE,CAAC;YACxB,OAAO,OAAO,CAAC,GAAG,OAAO,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;QACxC,CAAC;QACD,OAAO,CAAC,GAAG,CA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IAAI,CAAC;IAChB,CAAC;IAED,QAAQ;QACJ,IAAI,IAAI,CAAC,OAAO,EAAE;YAAE,OAAO,GAAG,CAAC;QAC/B,MAAM,QAAQ,GAAa,EAAE,CAAC;QAC9B,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC,GAAQ,EAAE,EAAE;YAC5B,IAAI,GAAG,YAAY,YAAY,EAAE,CAAC;gBAC9B,QAAQ,CAAC,IAAI,CAAC,GAAG,CAAC,QAAQ,EAAE,CAAC,CAAC;YAClC,CAAC;iBAAM,CAAC;gBACJ,QAAQ,CAAC,IAAI,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC,CAAC;YAC/B,CAAC;QACL,CAAC,CAAC,CAAC;QACH,OAAO,IAAI,QAAQ,CAAC,IAAI,CAAC,IAAI,CAAC,GAAG,CAAC;IACtC,CAAC;IAED,CAAC,MAAM,CAAC,GAAG,CAAC,4BAA4B,CAAC,CAAC;QACtC,OAAO,IAAI,CAAC,QAAQ,EAAE,CAAC;IAC3B,CAAC;CACJ;AApMD,oCAoMC;AAED,kBAAkB;AAClB,SAAgB,QAAQ;IACpB,OAAO,IAAI,YAAY,EAAK,CAAC;AACjC,CAAC;AAED,SAAgB,SAAS,CAAI,OAAU;IACnC,OAAO,IAAI,YAAY,CAAI,OAAO,CAAC,CAAC;AACxC,CAAC;AAED,SAAgB,YAAY,CAAI,QAAqB;IACjD,OAAO,IAAI,YAAY,CAAI,GAAG,QAAQ,CAAC,CAAC;AAC5C,CAAC"}
|
package/dist/esm/index.d.ts
CHANGED
|
@@ -1,129 +1,28 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* @module recursive-set
|
|
3
|
-
* A mutable recursive set implementation enforcing Cantor's ZFC axioms
|
|
4
|
-
*/
|
|
5
|
-
/**
|
|
6
|
-
* RecursiveSet: Mutable set with arbitrary nesting depth
|
|
7
|
-
*
|
|
8
|
-
* Enforced ZFC Axioms (as class invariants):
|
|
9
|
-
* - Extensionality: Sets with same elements are equal
|
|
10
|
-
* - Foundation (Regularity): No membership cycles allowed
|
|
11
|
-
* - Power Set: Can construct 𝒫(A) for any set A
|
|
12
|
-
* - Union: Can construct A ∪ B for any sets A, B
|
|
13
|
-
* - Pairing: Can construct {a, b} for any elements a, b
|
|
14
|
-
*/
|
|
15
1
|
export declare class RecursiveSet<T = any> {
|
|
16
|
-
private
|
|
2
|
+
private _tree;
|
|
17
3
|
constructor(...elements: Array<T | RecursiveSet<T>>);
|
|
18
|
-
/**
|
|
19
|
-
* Internal: Add element with cycle detection (Foundation axiom)
|
|
20
|
-
*/
|
|
21
|
-
private _addElement;
|
|
22
|
-
/**
|
|
23
|
-
* Check if adding element would violate Foundation axiom
|
|
24
|
-
*/
|
|
25
|
-
private _wouldCreateCycle;
|
|
26
|
-
/**
|
|
27
|
-
* Verify class invariants (Design by Contract)
|
|
28
|
-
*/
|
|
29
|
-
private _checkInvariants;
|
|
30
|
-
/**
|
|
31
|
-
* Add element to this set (Pairing axiom)
|
|
32
|
-
* @returns this for method chaining
|
|
33
|
-
*/
|
|
34
4
|
add(element: T | RecursiveSet<T>): this;
|
|
35
|
-
/**
|
|
36
|
-
* Remove element from this set
|
|
37
|
-
* @returns this for method chaining
|
|
38
|
-
*/
|
|
39
5
|
remove(element: T | RecursiveSet<T>): this;
|
|
40
|
-
/**
|
|
41
|
-
* Remove all elements
|
|
42
|
-
* @returns this for method chaining
|
|
43
|
-
*/
|
|
44
6
|
clear(): this;
|
|
45
|
-
/**
|
|
46
|
-
* Union of two sets (Union axiom)
|
|
47
|
-
* Returns A ∪ B
|
|
48
|
-
*/
|
|
49
7
|
union(other: RecursiveSet<T>): RecursiveSet<T>;
|
|
50
|
-
/**
|
|
51
|
-
* Intersection of two sets
|
|
52
|
-
* Returns A ∩ B
|
|
53
|
-
*/
|
|
54
8
|
intersection(other: RecursiveSet<T>): RecursiveSet<T>;
|
|
55
|
-
/**
|
|
56
|
-
* Set difference
|
|
57
|
-
* Returns A \ B (elements in A but not in B)
|
|
58
|
-
*/
|
|
59
9
|
difference(other: RecursiveSet<T>): RecursiveSet<T>;
|
|
60
|
-
/**
|
|
61
|
-
* Symmetric difference
|
|
62
|
-
* Returns A △ B (elements in either but not both)
|
|
63
|
-
*/
|
|
64
10
|
symmetricDifference(other: RecursiveSet<T>): RecursiveSet<T>;
|
|
65
|
-
/**
|
|
66
|
-
* Power set construction (Power Set axiom)
|
|
67
|
-
* Returns 𝒫(A) - set of all subsets
|
|
68
|
-
*/
|
|
69
11
|
powerset(): RecursiveSet<RecursiveSet<T>>;
|
|
70
|
-
/**
|
|
71
|
-
* Cartesian product
|
|
72
|
-
* Returns A × B as set of ordered pairs {{a}, {a,b}}
|
|
73
|
-
*/
|
|
74
12
|
cartesianProduct<U>(other: RecursiveSet<U>): RecursiveSet<RecursiveSet<T | U>>;
|
|
75
|
-
/**
|
|
76
|
-
* Check membership (∈)
|
|
77
|
-
*/
|
|
78
13
|
has(element: T | RecursiveSet<T>): boolean;
|
|
79
|
-
/**
|
|
80
|
-
* Check if subset (⊆)
|
|
81
|
-
*/
|
|
82
14
|
isSubset(other: RecursiveSet<T>): boolean;
|
|
83
|
-
/**
|
|
84
|
-
* Check if superset (⊇)
|
|
85
|
-
*/
|
|
86
15
|
isSuperset(other: RecursiveSet<T>): boolean;
|
|
87
|
-
/**
|
|
88
|
-
* Check if proper subset (⊂)
|
|
89
|
-
*/
|
|
90
16
|
isProperSubset(other: RecursiveSet<T>): boolean;
|
|
91
|
-
/**
|
|
92
|
-
* Check if empty set
|
|
93
|
-
*/
|
|
94
17
|
isEmpty(): boolean;
|
|
95
|
-
/**
|
|
96
|
-
* Structural equality (Extensionality axiom)
|
|
97
|
-
* Two sets are equal iff they have the same elements
|
|
98
|
-
*/
|
|
99
18
|
equals(other: RecursiveSet<T>): boolean;
|
|
100
|
-
|
|
101
|
-
* Cardinality |A|
|
|
102
|
-
*/
|
|
19
|
+
private _wouldCreateCycle;
|
|
103
20
|
get size(): number;
|
|
104
|
-
/**
|
|
105
|
-
* Convert to native Set (shallow)
|
|
106
|
-
*/
|
|
107
21
|
toSet(): Set<T | RecursiveSet<T>>;
|
|
108
|
-
/**
|
|
109
|
-
* Iterate over elements
|
|
110
|
-
*/
|
|
111
22
|
[Symbol.iterator](): Iterator<T | RecursiveSet<T>>;
|
|
112
|
-
/**
|
|
113
|
-
* Pretty print with mathematical notation
|
|
114
|
-
*/
|
|
115
23
|
toString(): string;
|
|
116
24
|
}
|
|
117
|
-
/**
|
|
118
|
-
* Create empty set (Null Set axiom)
|
|
119
|
-
*/
|
|
120
25
|
export declare function emptySet<T = any>(): RecursiveSet<T>;
|
|
121
|
-
/**
|
|
122
|
-
* Create singleton set
|
|
123
|
-
*/
|
|
124
26
|
export declare function singleton<T>(element: T): RecursiveSet<T>;
|
|
125
|
-
/**
|
|
126
|
-
* Create set from iterable
|
|
127
|
-
*/
|
|
128
27
|
export declare function fromIterable<T>(iterable: Iterable<T>): RecursiveSet<T>;
|
|
129
28
|
//# sourceMappingURL=index.d.ts.map
|
package/dist/esm/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAmDA,qBAAa,YAAY,CAAC,CAAC,GAAG,GAAG;IAE7B,OAAO,CAAC,KAAK,CAAM;gBAEP,GAAG,QAAQ,EAAE,KAAK,CAAC,CAAC,GAAG,YAAY,CAAC,CAAC,CAAC,CAAC;IAUnD,GAAG,CAAC,OAAO,EAAE,CAAC,GAAG,YAAY,CAAC,CAAC,CAAC,GAAG,IAAI;IAevC,MAAM,CAAC,OAAO,EAAE,CAAC,GAAG,YAAY,CAAC,CAAC,CAAC,GAAG,IAAI;IAK1C,KAAK,IAAI,IAAI;IAOb,KAAK,CAAC,KAAK,EAAE,YAAY,CAAC,CAAC,CAAC,GAAG,YAAY,C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,EAAE,OAAO,EAAE,CAAC,GAAG,YAAY,CAAC,CAAC,CAAC,CAExD;AAED,wBAAgB,YAAY,CAAC,CAAC,EAAE,QAAQ,EAAE,QAAQ,CAAC,CAAC,CAAC,GAAG,YAAY,CAAC,CAAC,CAAC,CAEtE"}
|
package/dist/esm/index.js
CHANGED
|
@@ -1,298 +1,218 @@
|
|
|
1
|
+
import createTree from 'functional-red-black-tree';
|
|
1
2
|
/**
|
|
2
3
|
* @module recursive-set
|
|
3
4
|
* A mutable recursive set implementation enforcing Cantor's ZFC axioms
|
|
5
|
+
* Powered by Red-Black Trees for O(log n) operations
|
|
4
6
|
*/
|
|
5
7
|
/**
|
|
6
|
-
*
|
|
7
|
-
*
|
|
8
|
-
* Enforced ZFC Axioms (as class invariants):
|
|
9
|
-
* - Extensionality: Sets with same elements are equal
|
|
10
|
-
* - Foundation (Regularity): No membership cycles allowed
|
|
11
|
-
* - Power Set: Can construct 𝒫(A) for any set A
|
|
12
|
-
* - Union: Can construct A ∪ B for any sets A, B
|
|
13
|
-
* - Pairing: Can construct {a, b} for any elements a, b
|
|
8
|
+
* Comparator function for ZFC sets
|
|
9
|
+
* Returns -1 if a < b, 1 if a > b, 0 if a == b (structural equality)
|
|
14
10
|
*/
|
|
11
|
+
function compare(a, b) {
|
|
12
|
+
// 1. Identity optimization
|
|
13
|
+
if (a === b)
|
|
14
|
+
return 0;
|
|
15
|
+
// 2. Type separation: Sets are "greater" than primitives
|
|
16
|
+
const isSetA = a instanceof RecursiveSet;
|
|
17
|
+
const isSetB = b instanceof RecursiveSet;
|
|
18
|
+
if (isSetA !== isSetB)
|
|
19
|
+
return isSetA ? 1 : -1;
|
|
20
|
+
// 3. Primitives
|
|
21
|
+
if (!isSetA) {
|
|
22
|
+
if (typeof a !== typeof b) {
|
|
23
|
+
return typeof a > typeof b ? 1 : -1;
|
|
24
|
+
}
|
|
25
|
+
return a < b ? -1 : 1;
|
|
26
|
+
}
|
|
27
|
+
// 4. Recursive Sets
|
|
28
|
+
const sizeA = a.size;
|
|
29
|
+
const sizeB = b.size;
|
|
30
|
+
if (sizeA !== sizeB)
|
|
31
|
+
return sizeA < sizeB ? -1 : 1;
|
|
32
|
+
// Lexicographical comparison
|
|
33
|
+
const itA = a[Symbol.iterator]();
|
|
34
|
+
const itB = b[Symbol.iterator]();
|
|
35
|
+
let nextA = itA.next();
|
|
36
|
+
let nextB = itB.next();
|
|
37
|
+
while (!nextA.done) {
|
|
38
|
+
const cmp = compare(nextA.value, nextB.value);
|
|
39
|
+
if (cmp !== 0)
|
|
40
|
+
return cmp;
|
|
41
|
+
nextA = itA.next();
|
|
42
|
+
nextB = itB.next();
|
|
43
|
+
}
|
|
44
|
+
return 0;
|
|
45
|
+
}
|
|
15
46
|
export class RecursiveSet {
|
|
16
|
-
|
|
47
|
+
// Red-Black Tree (immutable structure, we replace on mutation)
|
|
48
|
+
_tree; // Type from functional-red-black-tree
|
|
17
49
|
constructor(...elements) {
|
|
18
|
-
this.
|
|
50
|
+
this._tree = createTree(compare);
|
|
19
51
|
for (const el of elements) {
|
|
20
|
-
this.
|
|
21
|
-
}
|
|
22
|
-
this._checkInvariants();
|
|
23
|
-
}
|
|
24
|
-
/**
|
|
25
|
-
* Internal: Add element with cycle detection (Foundation axiom)
|
|
26
|
-
*/
|
|
27
|
-
_addElement(el) {
|
|
28
|
-
if (el instanceof RecursiveSet) {
|
|
29
|
-
if (this._wouldCreateCycle(el)) {
|
|
30
|
-
throw new Error("Foundation axiom violated: adding this element would create a membership cycle");
|
|
31
|
-
}
|
|
52
|
+
this.add(el);
|
|
32
53
|
}
|
|
33
|
-
this._elements.add(el);
|
|
34
54
|
}
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
while (toCheck.length > 0) {
|
|
42
|
-
const current = toCheck.pop();
|
|
43
|
-
if (current === this) {
|
|
44
|
-
return true;
|
|
45
|
-
}
|
|
46
|
-
if (visited.has(current)) {
|
|
47
|
-
continue;
|
|
48
|
-
}
|
|
49
|
-
visited.add(current);
|
|
50
|
-
for (const el of current._elements) {
|
|
51
|
-
if (el instanceof RecursiveSet) {
|
|
52
|
-
toCheck.push(el);
|
|
55
|
+
// === Mutable Operations ===
|
|
56
|
+
add(element) {
|
|
57
|
+
if (element instanceof RecursiveSet) {
|
|
58
|
+
if (!this.has(element)) {
|
|
59
|
+
if (this._wouldCreateCycle(element)) {
|
|
60
|
+
throw new Error("Foundation axiom violated: membership cycle detected");
|
|
53
61
|
}
|
|
54
62
|
}
|
|
55
63
|
}
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
* Verify class invariants (Design by Contract)
|
|
60
|
-
*/
|
|
61
|
-
_checkInvariants() {
|
|
62
|
-
// Extensionality: enforced by Set semantics
|
|
63
|
-
// Foundation: enforced by _wouldCreateCycle
|
|
64
|
-
// Well-definedness: enforced by TypeScript type system
|
|
65
|
-
// Additional runtime checks can be added here
|
|
66
|
-
if (process.env.NODE_ENV === 'development') {
|
|
67
|
-
// More expensive checks only in development
|
|
68
|
-
}
|
|
69
|
-
}
|
|
70
|
-
// === Mutable Operations ===
|
|
71
|
-
/**
|
|
72
|
-
* Add element to this set (Pairing axiom)
|
|
73
|
-
* @returns this for method chaining
|
|
74
|
-
*/
|
|
75
|
-
add(element) {
|
|
76
|
-
this._addElement(element);
|
|
77
|
-
this._checkInvariants();
|
|
64
|
+
// Immutable insert - returns new tree
|
|
65
|
+
// We replace our internal tree (mutable API, immutable data structure)
|
|
66
|
+
this._tree = this._tree.insert(element, true);
|
|
78
67
|
return this;
|
|
79
68
|
}
|
|
80
|
-
/**
|
|
81
|
-
* Remove element from this set
|
|
82
|
-
* @returns this for method chaining
|
|
83
|
-
*/
|
|
84
69
|
remove(element) {
|
|
85
|
-
this.
|
|
70
|
+
this._tree = this._tree.remove(element);
|
|
86
71
|
return this;
|
|
87
72
|
}
|
|
88
|
-
/**
|
|
89
|
-
* Remove all elements
|
|
90
|
-
* @returns this for method chaining
|
|
91
|
-
*/
|
|
92
73
|
clear() {
|
|
93
|
-
this.
|
|
74
|
+
this._tree = createTree(compare);
|
|
94
75
|
return this;
|
|
95
76
|
}
|
|
96
|
-
// === Immutable Operations
|
|
97
|
-
/**
|
|
98
|
-
* Union of two sets (Union axiom)
|
|
99
|
-
* Returns A ∪ B
|
|
100
|
-
*/
|
|
77
|
+
// === Immutable Operations ===
|
|
101
78
|
union(other) {
|
|
102
79
|
const result = new RecursiveSet();
|
|
103
|
-
|
|
80
|
+
for (const el of this)
|
|
81
|
+
result.add(el);
|
|
82
|
+
for (const el of other)
|
|
83
|
+
result.add(el);
|
|
104
84
|
return result;
|
|
105
85
|
}
|
|
106
|
-
/**
|
|
107
|
-
* Intersection of two sets
|
|
108
|
-
* Returns A ∩ B
|
|
109
|
-
*/
|
|
110
86
|
intersection(other) {
|
|
111
87
|
const result = new RecursiveSet();
|
|
112
|
-
for (const el of this
|
|
88
|
+
for (const el of this) {
|
|
113
89
|
if (other.has(el)) {
|
|
114
|
-
result.
|
|
90
|
+
result.add(el);
|
|
115
91
|
}
|
|
116
92
|
}
|
|
117
93
|
return result;
|
|
118
94
|
}
|
|
119
|
-
/**
|
|
120
|
-
* Set difference
|
|
121
|
-
* Returns A \ B (elements in A but not in B)
|
|
122
|
-
*/
|
|
123
95
|
difference(other) {
|
|
124
96
|
const result = new RecursiveSet();
|
|
125
|
-
for (const el of this
|
|
97
|
+
for (const el of this) {
|
|
126
98
|
if (!other.has(el)) {
|
|
127
|
-
result.
|
|
99
|
+
result.add(el);
|
|
128
100
|
}
|
|
129
101
|
}
|
|
130
102
|
return result;
|
|
131
103
|
}
|
|
132
|
-
/**
|
|
133
|
-
* Symmetric difference
|
|
134
|
-
* Returns A △ B (elements in either but not both)
|
|
135
|
-
*/
|
|
136
104
|
symmetricDifference(other) {
|
|
137
105
|
return this.union(other).difference(this.intersection(other));
|
|
138
106
|
}
|
|
139
|
-
/**
|
|
140
|
-
* Power set construction (Power Set axiom)
|
|
141
|
-
* Returns 𝒫(A) - set of all subsets
|
|
142
|
-
*/
|
|
143
107
|
powerset() {
|
|
144
|
-
const elements =
|
|
108
|
+
const elements = [];
|
|
109
|
+
this._tree.forEach((key) => elements.push(key));
|
|
145
110
|
const subsets = [];
|
|
146
|
-
// Generate all 2^n subsets
|
|
147
111
|
const n = elements.length;
|
|
148
112
|
for (let i = 0; i < (1 << n); i++) {
|
|
149
113
|
const subset = new RecursiveSet();
|
|
150
114
|
for (let j = 0; j < n; j++) {
|
|
151
115
|
if (i & (1 << j)) {
|
|
152
|
-
subset.
|
|
116
|
+
subset.add(elements[j]);
|
|
153
117
|
}
|
|
154
118
|
}
|
|
155
119
|
subsets.push(subset);
|
|
156
120
|
}
|
|
157
121
|
return new RecursiveSet(...subsets);
|
|
158
122
|
}
|
|
159
|
-
/**
|
|
160
|
-
* Cartesian product
|
|
161
|
-
* Returns A × B as set of ordered pairs {{a}, {a,b}}
|
|
162
|
-
*/
|
|
163
123
|
cartesianProduct(other) {
|
|
164
124
|
const pairs = [];
|
|
165
|
-
for (const x of this
|
|
166
|
-
for (const y of other
|
|
167
|
-
|
|
168
|
-
const
|
|
125
|
+
for (const x of this) {
|
|
126
|
+
for (const y of other) {
|
|
127
|
+
const valX = x;
|
|
128
|
+
const valY = y;
|
|
129
|
+
const pair = new RecursiveSet(new RecursiveSet(valX), new RecursiveSet(valX, valY));
|
|
169
130
|
pairs.push(pair);
|
|
170
131
|
}
|
|
171
132
|
}
|
|
172
133
|
return new RecursiveSet(...pairs);
|
|
173
134
|
}
|
|
174
135
|
// === Predicates ===
|
|
175
|
-
/**
|
|
176
|
-
* Check membership (∈)
|
|
177
|
-
*/
|
|
178
136
|
has(element) {
|
|
179
|
-
return this.
|
|
137
|
+
return this._tree.get(element) !== undefined;
|
|
180
138
|
}
|
|
181
|
-
/**
|
|
182
|
-
* Check if subset (⊆)
|
|
183
|
-
*/
|
|
184
139
|
isSubset(other) {
|
|
185
|
-
for (const el of this
|
|
186
|
-
if (!other.has(el))
|
|
140
|
+
for (const el of this) {
|
|
141
|
+
if (!other.has(el))
|
|
187
142
|
return false;
|
|
188
|
-
}
|
|
189
143
|
}
|
|
190
144
|
return true;
|
|
191
145
|
}
|
|
192
|
-
/**
|
|
193
|
-
* Check if superset (⊇)
|
|
194
|
-
*/
|
|
195
146
|
isSuperset(other) {
|
|
196
147
|
return other.isSubset(this);
|
|
197
148
|
}
|
|
198
|
-
/**
|
|
199
|
-
* Check if proper subset (⊂)
|
|
200
|
-
*/
|
|
201
149
|
isProperSubset(other) {
|
|
202
150
|
return this.isSubset(other) && !this.equals(other);
|
|
203
151
|
}
|
|
204
|
-
/**
|
|
205
|
-
* Check if empty set
|
|
206
|
-
*/
|
|
207
152
|
isEmpty() {
|
|
208
|
-
return this.
|
|
153
|
+
return this.size === 0;
|
|
209
154
|
}
|
|
210
|
-
// === Extensionality (Equality) ===
|
|
211
|
-
/**
|
|
212
|
-
* Structural equality (Extensionality axiom)
|
|
213
|
-
* Two sets are equal iff they have the same elements
|
|
214
|
-
*/
|
|
215
155
|
equals(other) {
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
156
|
+
return compare(this, other) === 0;
|
|
157
|
+
}
|
|
158
|
+
// === Internals ===
|
|
159
|
+
_wouldCreateCycle(element) {
|
|
160
|
+
const visited = new Set();
|
|
161
|
+
const stack = [element];
|
|
162
|
+
while (stack.length > 0) {
|
|
163
|
+
const current = stack.pop();
|
|
164
|
+
if (current === this)
|
|
165
|
+
return true;
|
|
166
|
+
if (visited.has(current))
|
|
167
|
+
continue;
|
|
168
|
+
visited.add(current);
|
|
169
|
+
for (const child of current) {
|
|
170
|
+
if (child instanceof RecursiveSet) {
|
|
171
|
+
stack.push(child);
|
|
228
172
|
}
|
|
229
|
-
if (!found)
|
|
230
|
-
return false;
|
|
231
|
-
}
|
|
232
|
-
else {
|
|
233
|
-
if (!other.has(el))
|
|
234
|
-
return false;
|
|
235
173
|
}
|
|
236
174
|
}
|
|
237
|
-
return
|
|
175
|
+
return false;
|
|
238
176
|
}
|
|
239
177
|
// === Utility ===
|
|
240
|
-
/**
|
|
241
|
-
* Cardinality |A|
|
|
242
|
-
*/
|
|
243
178
|
get size() {
|
|
244
|
-
return this.
|
|
179
|
+
return this._tree.length;
|
|
245
180
|
}
|
|
246
|
-
/**
|
|
247
|
-
* Convert to native Set (shallow)
|
|
248
|
-
*/
|
|
249
181
|
toSet() {
|
|
250
|
-
|
|
182
|
+
const result = new Set();
|
|
183
|
+
this._tree.forEach((key) => result.add(key));
|
|
184
|
+
return result;
|
|
251
185
|
}
|
|
252
|
-
/**
|
|
253
|
-
* Iterate over elements
|
|
254
|
-
*/
|
|
255
186
|
*[Symbol.iterator]() {
|
|
256
|
-
|
|
187
|
+
const keys = [];
|
|
188
|
+
this._tree.forEach((key) => keys.push(key));
|
|
189
|
+
yield* keys;
|
|
257
190
|
}
|
|
258
|
-
/**
|
|
259
|
-
* Pretty print with mathematical notation
|
|
260
|
-
*/
|
|
261
191
|
toString() {
|
|
262
|
-
if (this.isEmpty())
|
|
192
|
+
if (this.isEmpty())
|
|
263
193
|
return "∅";
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
if (
|
|
267
|
-
|
|
194
|
+
const elements = [];
|
|
195
|
+
this._tree.forEach((key) => {
|
|
196
|
+
if (key instanceof RecursiveSet) {
|
|
197
|
+
elements.push(key.toString());
|
|
198
|
+
}
|
|
199
|
+
else {
|
|
200
|
+
elements.push(String(key));
|
|
268
201
|
}
|
|
269
|
-
return String(el);
|
|
270
202
|
});
|
|
271
203
|
return `{${elements.join(", ")}}`;
|
|
272
204
|
}
|
|
273
|
-
/**
|
|
274
|
-
* For console.log
|
|
275
|
-
*/
|
|
276
205
|
[Symbol.for('nodejs.util.inspect.custom')]() {
|
|
277
206
|
return this.toString();
|
|
278
207
|
}
|
|
279
208
|
}
|
|
280
|
-
// ===
|
|
281
|
-
/**
|
|
282
|
-
* Create empty set (Null Set axiom)
|
|
283
|
-
*/
|
|
209
|
+
// === Helpers ===
|
|
284
210
|
export function emptySet() {
|
|
285
211
|
return new RecursiveSet();
|
|
286
212
|
}
|
|
287
|
-
/**
|
|
288
|
-
* Create singleton set
|
|
289
|
-
*/
|
|
290
213
|
export function singleton(element) {
|
|
291
214
|
return new RecursiveSet(element);
|
|
292
215
|
}
|
|
293
|
-
/**
|
|
294
|
-
* Create set from iterable
|
|
295
|
-
*/
|
|
296
216
|
export function fromIterable(iterable) {
|
|
297
217
|
return new RecursiveSet(...iterable);
|
|
298
218
|
}
|
package/dist/esm/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA;;;GAGG;
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,UAAU,MAAM,2BAA2B,CAAC;AAEnD;;;;GAIG;AAEH;;;GAGG;AACH,SAAS,OAAO,CAAC,CAAM,EAAE,CAAM;IAC3B,2BAA2B;IAC3B,IAAI,CAAC,KAAK,CAAC;QAAE,OAAO,CAAC,CAAC;IAEtB,yDAAyD;IACzD,MAAM,MAAM,GAAG,CAAC,YAAY,YAAY,CAAC;IACzC,MAAM,MAAM,GAAG,CAAC,YAAY,YAAY,CAAC;IACzC,IAAI,MAAM,KAAK,MAAM;QAAE,OAAO,MAAM,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;IAE9C,gBAAgB;IAChB,IAAI,CAAC,MAAM,EAAE,CAAC;QACV,IAAI,OAAO,CAAC,KAAK,OAAO,CAAC,EAAE,CAAC;YACxB,OAAO,OAAO,CAAC,GAAG,OAAO,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,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AAI,CAAC,GAAG,CAAC,CAAC,CAAC;QACjD,KAAK,CAAC,CAAC,IAAI,CAAC;IAChB,CAAC;IAED,QAAQ;QACJ,IAAI,IAAI,CAAC,OAAO,EAAE;YAAE,OAAO,GAAG,CAAC;QAC/B,MAAM,QAAQ,GAAa,EAAE,CAAC;QAC9B,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC,GAAQ,EAAE,EAAE;YAC5B,IAAI,GAAG,YAAY,YAAY,EAAE,CAAC;gBAC9B,QAAQ,CAAC,IAAI,CAAC,GAAG,CAAC,QAAQ,EAAE,CAAC,CAAC;YAClC,CAAC;iBAAM,CAAC;gBACJ,QAAQ,CAAC,IAAI,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC,CAAC;YAC/B,CAAC;QACL,CAAC,CAAC,CAAC;QACH,OAAO,IAAI,QAAQ,CAAC,IAAI,CAAC,IAAI,CAAC,GAAG,CAAC;IACtC,CAAC;IAED,CAAC,MAAM,CAAC,GAAG,CAAC,4BAA4B,CAAC,CAAC;QACtC,OAAO,IAAI,CAAC,QAAQ,EAAE,CAAC;IAC3B,CAAC;CACJ;AAED,kBAAkB;AAClB,MAAM,UAAU,QAAQ;IACpB,OAAO,IAAI,YAAY,EAAK,CAAC;AACjC,CAAC;AAED,MAAM,UAAU,SAAS,CAAI,OAAU;IACnC,OAAO,IAAI,YAAY,CAAI,OAAO,CAAC,CAAC;AACxC,CAAC;AAED,MAAM,UAAU,YAAY,CAAI,QAAqB;IACjD,OAAO,IAAI,YAAY,CAAI,GAAG,QAAQ,CAAC,CAAC;AAC5C,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "recursive-set",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "2.0.0",
|
|
4
4
|
"description": "Mutable recursive sets with ZFC axioms for TypeScript",
|
|
5
5
|
"main": "./dist/cjs/index.js",
|
|
6
6
|
"types": "./dist/esm/index.d.ts",
|
|
@@ -43,9 +43,13 @@
|
|
|
43
43
|
},
|
|
44
44
|
"homepage": "https://github.com/cstrerath/recursive-set#readme",
|
|
45
45
|
"devDependencies": {
|
|
46
|
+
"@types/functional-red-black-tree": "^1.0.6",
|
|
46
47
|
"@types/node": "^20.0.0",
|
|
47
48
|
"rimraf": "^6.1.2",
|
|
48
49
|
"tsx": "^4.20.6",
|
|
49
50
|
"typescript": "^5.6.0"
|
|
51
|
+
},
|
|
52
|
+
"dependencies": {
|
|
53
|
+
"functional-red-black-tree": "^1.0.1"
|
|
50
54
|
}
|
|
51
55
|
}
|