atomic-fns 0.3.0 → 0.3.2
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/.esdoc.json +2 -2
- package/README.md +48 -13
- package/core/collections/BTree.d.ts +229 -0
- package/core/collections/BTree.js +1165 -0
- package/core/collections/BTree.ts +1340 -0
- package/core/collections/Heap.d.ts +69 -0
- package/core/collections/Heap.js +181 -0
- package/core/collections/Heap.ts +189 -0
- package/core/collections/LRUCache.d.ts +131 -0
- package/core/collections/LRUCache.js +388 -0
- package/core/collections/LRUCache.ts +465 -0
- package/core/collections/SortedMap.d.ts +92 -0
- package/core/collections/SortedMap.js +130 -0
- package/core/collections/SortedMap.ts +146 -0
- package/core/collections/SortedSet.d.ts +63 -0
- package/core/collections/SortedSet.js +93 -0
- package/core/collections/SortedSet.ts +104 -0
- package/core/collections/SortedTree.d.ts +103 -0
- package/core/collections/SortedTree.js +141 -0
- package/core/collections/SortedTree.ts +160 -0
- package/core/collections/SplayTree.d.ts +105 -0
- package/core/collections/SplayTree.js +338 -0
- package/core/collections/SplayTree.ts +354 -0
- package/core/collections/abc.d.ts +152 -0
- package/core/collections/abc.js +39 -0
- package/core/collections/abc.ts +176 -0
- package/core/collections/deque.d.ts +110 -0
- package/core/collections/deque.js +285 -0
- package/core/collections/deque.ts +329 -0
- package/core/collections/frozenset.d.ts +19 -0
- package/core/collections/frozenset.js +33 -0
- package/core/collections/frozenset.ts +37 -0
- package/{src → core}/collections/index.d.ts +12 -161
- package/{src → core}/collections/index.js +13 -164
- package/{src → core}/collections/index.ts +13 -224
- package/core/collections/test.html +10 -0
- package/core/collections/typedArrays.d.ts +31 -0
- package/core/collections/typedArrays.js +143 -0
- package/core/collections/typedArrays.ts +163 -0
- package/{src → core}/datetime/index.d.ts +0 -0
- package/{src → core}/datetime/index.js +0 -0
- package/{src → core}/datetime/index.ts +0 -0
- package/core/datetime/test.html +0 -0
- package/{src → core}/functools/index.d.ts +2 -2
- package/{src → core}/functools/index.js +2 -2
- package/{src → core}/functools/index.ts +2 -2
- package/{src → core}/globals/index.d.ts +2 -7
- package/{src → core}/globals/index.js +5 -2
- package/{src → core}/globals/index.ts +6 -9
- package/{src → core}/index.d.ts +0 -0
- package/{src → core}/index.js +0 -0
- package/{src → core}/index.ts +0 -0
- package/{src → core}/itertools/index.d.ts +9 -7
- package/{src → core}/itertools/index.js +25 -9
- package/{src → core}/itertools/index.ts +39 -16
- package/{src → core}/math/index.d.ts +0 -0
- package/{src → core}/math/index.js +0 -0
- package/{src → core}/math/index.ts +0 -0
- package/core/operators/index.d.ts +148 -0
- package/core/operators/index.js +271 -0
- package/core/operators/index.ts +282 -0
- package/{src → core}/random/index.d.ts +0 -0
- package/{src → core}/random/index.js +0 -0
- package/{src → core}/random/index.ts +0 -0
- package/package.json +7 -4
- package/tests/BTree.spec.ts +143 -0
- package/tests/Cache.spec.ts +161 -0
- package/tests/Heap.spec.ts +66 -0
- package/tests/SortedMap.spec.ts +144 -0
- package/tests/SortedSet.spec.ts +84 -0
- package/tests/SortedTree.spec.ts +164 -0
- package/tests/SplayTree.spec.ts +121 -0
- package/tests/collections.spec.ts +1 -1
- package/tests/deque.spec.ts +107 -0
- package/tests/globals.spec.ts +2 -2
- package/tests/itertools.spec.ts +2 -2
- package/tests/math.spec.ts +1 -1
- package/tests/operators.spec.ts +5 -5
- package/tests/random.spec.ts +10 -10
- package/tsconfig.json +10 -10
- package/tsconfig.node.json +2 -2
- package/tsconfig.xo.json +2 -2
- package/src/operators/index.d.ts +0 -31
- package/src/operators/index.js +0 -171
- package/src/operators/index.ts +0 -175
package/src/operators/index.js
DELETED
|
@@ -1,171 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Generic operations for both values and objects.
|
|
3
|
-
*
|
|
4
|
-
* @module Operators
|
|
5
|
-
*/
|
|
6
|
-
import { call, isNumber, isObject } from '../globals/index.js';
|
|
7
|
-
export const id = (x) => x;
|
|
8
|
-
export const bool = (x) => !!x;
|
|
9
|
-
export const not = (x) => !x;
|
|
10
|
-
export const isinstance = (x, y) => x instanceof y;
|
|
11
|
-
export function comp(x, y) {
|
|
12
|
-
const op = call(x, 'compare', y);
|
|
13
|
-
if (isNumber(op))
|
|
14
|
-
return op;
|
|
15
|
-
if (eq(x, y))
|
|
16
|
-
return 0;
|
|
17
|
-
if (lte(x, y))
|
|
18
|
-
return -1;
|
|
19
|
-
if (gte(x, y))
|
|
20
|
-
return 1;
|
|
21
|
-
return 0;
|
|
22
|
-
}
|
|
23
|
-
export function eq(x, y) {
|
|
24
|
-
const op = call(x, 'eq', y);
|
|
25
|
-
if (op != null)
|
|
26
|
-
return op;
|
|
27
|
-
return x === y;
|
|
28
|
-
}
|
|
29
|
-
export function lt(x, y) {
|
|
30
|
-
const op = call(x, 'lt', y);
|
|
31
|
-
if (op != null)
|
|
32
|
-
return op;
|
|
33
|
-
return x < y;
|
|
34
|
-
}
|
|
35
|
-
export function lte(x, y) {
|
|
36
|
-
let op = call(x, 'lte', y);
|
|
37
|
-
if (op != null)
|
|
38
|
-
return op;
|
|
39
|
-
op = call(x, 'eq', y);
|
|
40
|
-
if (op === true)
|
|
41
|
-
return op;
|
|
42
|
-
op = call(x, 'lt', y);
|
|
43
|
-
if (op != null)
|
|
44
|
-
return op;
|
|
45
|
-
return x <= y;
|
|
46
|
-
}
|
|
47
|
-
export function gt(x, y) {
|
|
48
|
-
const op = call(x, 'gt', y);
|
|
49
|
-
if (op != null)
|
|
50
|
-
return op;
|
|
51
|
-
return x > y;
|
|
52
|
-
}
|
|
53
|
-
export function gte(x, y) {
|
|
54
|
-
let op = call(x, 'gte', y);
|
|
55
|
-
if (op != null)
|
|
56
|
-
return op;
|
|
57
|
-
op = call(x, 'eq', y);
|
|
58
|
-
if (op === true)
|
|
59
|
-
return op;
|
|
60
|
-
op = call(x, 'gt', y);
|
|
61
|
-
if (op != null)
|
|
62
|
-
return op;
|
|
63
|
-
return x >= y;
|
|
64
|
-
}
|
|
65
|
-
export function add(x, y) {
|
|
66
|
-
const op = call(x, 'add', y);
|
|
67
|
-
if (op != null)
|
|
68
|
-
return op;
|
|
69
|
-
return x + y;
|
|
70
|
-
}
|
|
71
|
-
export function sub(x, y) {
|
|
72
|
-
const op = call(x, 'sub', y);
|
|
73
|
-
if (op != null)
|
|
74
|
-
return op;
|
|
75
|
-
return x - y;
|
|
76
|
-
}
|
|
77
|
-
export function mul(x, y) {
|
|
78
|
-
const op = call(x, 'mul', y);
|
|
79
|
-
if (op != null)
|
|
80
|
-
return op;
|
|
81
|
-
return x * y;
|
|
82
|
-
}
|
|
83
|
-
export function div(x, y) {
|
|
84
|
-
const op = call(x, 'div', y);
|
|
85
|
-
if (op != null)
|
|
86
|
-
return op;
|
|
87
|
-
return x / y;
|
|
88
|
-
}
|
|
89
|
-
export function mod(x, y) {
|
|
90
|
-
const op = call(x, 'mod', y);
|
|
91
|
-
if (op != null)
|
|
92
|
-
return op;
|
|
93
|
-
return x % y;
|
|
94
|
-
}
|
|
95
|
-
/**
|
|
96
|
-
* Calculates `x` to the power of `y`. If `x` implements a custom `pow` operator
|
|
97
|
-
* it will return `x.pow(y)`.
|
|
98
|
-
*
|
|
99
|
-
* @param {*} x
|
|
100
|
-
* @param {*} y
|
|
101
|
-
* @return `x` raised to the power `y`
|
|
102
|
-
*/
|
|
103
|
-
export function pow(x, y) {
|
|
104
|
-
const op = call(x, 'pow', y);
|
|
105
|
-
if (op != null)
|
|
106
|
-
return op;
|
|
107
|
-
return x ** y;
|
|
108
|
-
}
|
|
109
|
-
export function shallowEqual(obj, other) {
|
|
110
|
-
if (obj === other)
|
|
111
|
-
return true;
|
|
112
|
-
if (!obj || !other)
|
|
113
|
-
return false;
|
|
114
|
-
if (Array.isArray(obj)) {
|
|
115
|
-
// compare the arrays
|
|
116
|
-
if (obj.length !== other.length)
|
|
117
|
-
return false;
|
|
118
|
-
for (let i = 0; i < obj.length; i++) {
|
|
119
|
-
if (obj[i] !== other[i]) {
|
|
120
|
-
return false;
|
|
121
|
-
}
|
|
122
|
-
}
|
|
123
|
-
return true;
|
|
124
|
-
}
|
|
125
|
-
else if (isObject(obj)) {
|
|
126
|
-
// compare the object keys
|
|
127
|
-
const objKeys = Object.keys(obj);
|
|
128
|
-
const otherKeys = Object.keys(other);
|
|
129
|
-
if (objKeys.length !== otherKeys.length)
|
|
130
|
-
return false;
|
|
131
|
-
for (const key of objKeys) {
|
|
132
|
-
if (!Object.prototype.hasOwnProperty.call(other, key) || obj[key] !== other[key]) {
|
|
133
|
-
return false;
|
|
134
|
-
}
|
|
135
|
-
}
|
|
136
|
-
return true;
|
|
137
|
-
}
|
|
138
|
-
return false;
|
|
139
|
-
}
|
|
140
|
-
export function deepEqual(obj, other, checker = eq) {
|
|
141
|
-
if (checker(obj, other))
|
|
142
|
-
return true;
|
|
143
|
-
if (!obj || !other)
|
|
144
|
-
return false;
|
|
145
|
-
if (Array.isArray(obj)) {
|
|
146
|
-
// compare the arrays
|
|
147
|
-
if (obj.length !== other.length)
|
|
148
|
-
return false;
|
|
149
|
-
for (let i = 0; i < obj.length; i++) {
|
|
150
|
-
if (!deepEqual(obj[i], other[i], checker)) {
|
|
151
|
-
return false;
|
|
152
|
-
}
|
|
153
|
-
}
|
|
154
|
-
return true;
|
|
155
|
-
}
|
|
156
|
-
else if (isObject(obj)) {
|
|
157
|
-
// compare the object keys
|
|
158
|
-
const objKeys = Object.keys(obj);
|
|
159
|
-
const otherKeys = Object.keys(other);
|
|
160
|
-
if (objKeys.length !== otherKeys.length)
|
|
161
|
-
return false;
|
|
162
|
-
for (const key of objKeys) {
|
|
163
|
-
if (!Object.prototype.hasOwnProperty.call(other, key) ||
|
|
164
|
-
!deepEqual(obj[key], other[key], checker)) {
|
|
165
|
-
return false;
|
|
166
|
-
}
|
|
167
|
-
}
|
|
168
|
-
return true;
|
|
169
|
-
}
|
|
170
|
-
return false;
|
|
171
|
-
}
|
package/src/operators/index.ts
DELETED
|
@@ -1,175 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Generic operations for both values and objects.
|
|
3
|
-
*
|
|
4
|
-
* @module Operators
|
|
5
|
-
*/
|
|
6
|
-
|
|
7
|
-
import { call, isNumber, isObject } from '../globals/index.js'
|
|
8
|
-
|
|
9
|
-
export const id = (x) => x
|
|
10
|
-
|
|
11
|
-
export const bool = (x) => !!x
|
|
12
|
-
|
|
13
|
-
export const not = (x) => !x
|
|
14
|
-
|
|
15
|
-
export const isinstance = (x, y) => x instanceof y
|
|
16
|
-
|
|
17
|
-
export function comp(x, y) {
|
|
18
|
-
const op = call(x, 'compare', y)
|
|
19
|
-
if (isNumber(op)) return op as 0 | 1 | -1
|
|
20
|
-
if (eq(x, y)) return 0
|
|
21
|
-
if (lte(x, y)) return -1
|
|
22
|
-
if (gte(x, y)) return 1
|
|
23
|
-
return 0
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
export function eq(x, y) {
|
|
27
|
-
const op = call(x, 'eq', y)
|
|
28
|
-
if (op != null) return op
|
|
29
|
-
return x === y
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
export function lt(x, y) {
|
|
33
|
-
const op = call(x, 'lt', y)
|
|
34
|
-
if (op != null) return op
|
|
35
|
-
return x < y
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
export function lte(x, y) {
|
|
39
|
-
let op = call(x, 'lte', y)
|
|
40
|
-
if (op != null) return op
|
|
41
|
-
op = call(x, 'eq', y)
|
|
42
|
-
if (op === true) return op
|
|
43
|
-
op = call(x, 'lt', y)
|
|
44
|
-
if (op != null) return op
|
|
45
|
-
return x <= y
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
export function gt(x, y) {
|
|
49
|
-
const op = call(x, 'gt', y)
|
|
50
|
-
if (op != null) return op
|
|
51
|
-
return x > y
|
|
52
|
-
}
|
|
53
|
-
|
|
54
|
-
export function gte(x, y) {
|
|
55
|
-
let op = call(x, 'gte', y)
|
|
56
|
-
if (op != null) return op
|
|
57
|
-
op = call(x, 'eq', y)
|
|
58
|
-
if (op === true) return op
|
|
59
|
-
op = call(x, 'gt', y)
|
|
60
|
-
if (op != null) return op
|
|
61
|
-
return x >= y
|
|
62
|
-
}
|
|
63
|
-
|
|
64
|
-
export function add(x, y) {
|
|
65
|
-
const op = call(x, 'add', y)
|
|
66
|
-
if (op != null) return op
|
|
67
|
-
return x + y
|
|
68
|
-
}
|
|
69
|
-
|
|
70
|
-
export function sub(x, y) {
|
|
71
|
-
const op = call(x, 'sub', y)
|
|
72
|
-
if (op != null) return op
|
|
73
|
-
return x - y
|
|
74
|
-
}
|
|
75
|
-
|
|
76
|
-
export function mul(x, y) {
|
|
77
|
-
const op = call(x, 'mul', y)
|
|
78
|
-
if (op != null) return op
|
|
79
|
-
return x * y
|
|
80
|
-
}
|
|
81
|
-
|
|
82
|
-
export function div(x, y) {
|
|
83
|
-
const op = call(x, 'div', y)
|
|
84
|
-
if (op != null) return op
|
|
85
|
-
return x / y
|
|
86
|
-
}
|
|
87
|
-
|
|
88
|
-
export function mod(x, y) {
|
|
89
|
-
const op = call(x, 'mod', y)
|
|
90
|
-
if (op != null) return op
|
|
91
|
-
return x % y
|
|
92
|
-
}
|
|
93
|
-
|
|
94
|
-
/**
|
|
95
|
-
* Calculates `x` to the power of `y`. If `x` implements a custom `pow` operator
|
|
96
|
-
* it will return `x.pow(y)`.
|
|
97
|
-
*
|
|
98
|
-
* @param {*} x
|
|
99
|
-
* @param {*} y
|
|
100
|
-
* @return `x` raised to the power `y`
|
|
101
|
-
*/
|
|
102
|
-
export function pow(x, y) {
|
|
103
|
-
const op = call(x, 'pow', y)
|
|
104
|
-
if (op != null) return op
|
|
105
|
-
return x ** y
|
|
106
|
-
}
|
|
107
|
-
|
|
108
|
-
export function shallowEqual(obj, other) {
|
|
109
|
-
if (obj === other) return true
|
|
110
|
-
|
|
111
|
-
if (!obj || !other) return false
|
|
112
|
-
|
|
113
|
-
if (Array.isArray(obj)) {
|
|
114
|
-
// compare the arrays
|
|
115
|
-
if (obj.length !== other.length) return false
|
|
116
|
-
|
|
117
|
-
for (let i = 0; i < obj.length; i++) {
|
|
118
|
-
if (obj[i] !== other[i]) {
|
|
119
|
-
return false
|
|
120
|
-
}
|
|
121
|
-
}
|
|
122
|
-
return true
|
|
123
|
-
} else if (isObject(obj)) {
|
|
124
|
-
// compare the object keys
|
|
125
|
-
const objKeys = Object.keys(obj)
|
|
126
|
-
const otherKeys = Object.keys(other)
|
|
127
|
-
|
|
128
|
-
if (objKeys.length !== otherKeys.length) return false
|
|
129
|
-
|
|
130
|
-
for (const key of objKeys) {
|
|
131
|
-
if (!Object.prototype.hasOwnProperty.call(other, key) || obj[key] !== other[key]) {
|
|
132
|
-
return false
|
|
133
|
-
}
|
|
134
|
-
}
|
|
135
|
-
return true
|
|
136
|
-
}
|
|
137
|
-
|
|
138
|
-
return false
|
|
139
|
-
}
|
|
140
|
-
|
|
141
|
-
export function deepEqual(obj, other, checker = eq) {
|
|
142
|
-
if (checker(obj, other)) return true
|
|
143
|
-
|
|
144
|
-
if (!obj || !other) return false
|
|
145
|
-
|
|
146
|
-
if (Array.isArray(obj)) {
|
|
147
|
-
// compare the arrays
|
|
148
|
-
if (obj.length !== other.length) return false
|
|
149
|
-
|
|
150
|
-
for (let i = 0; i < obj.length; i++) {
|
|
151
|
-
if (!deepEqual(obj[i], other[i], checker)) {
|
|
152
|
-
return false
|
|
153
|
-
}
|
|
154
|
-
}
|
|
155
|
-
return true
|
|
156
|
-
} else if (isObject(obj)) {
|
|
157
|
-
// compare the object keys
|
|
158
|
-
const objKeys = Object.keys(obj)
|
|
159
|
-
const otherKeys = Object.keys(other)
|
|
160
|
-
|
|
161
|
-
if (objKeys.length !== otherKeys.length) return false
|
|
162
|
-
|
|
163
|
-
for (const key of objKeys) {
|
|
164
|
-
if (
|
|
165
|
-
!Object.prototype.hasOwnProperty.call(other, key) ||
|
|
166
|
-
!deepEqual(obj[key], other[key], checker)
|
|
167
|
-
) {
|
|
168
|
-
return false
|
|
169
|
-
}
|
|
170
|
-
}
|
|
171
|
-
return true
|
|
172
|
-
}
|
|
173
|
-
|
|
174
|
-
return false
|
|
175
|
-
}
|