@lowentry/utils 1.19.4 → 1.21.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/build/LeUtils.d.ts +1 -15
- package/build/classes/TreeSet.d.ts +115 -0
- package/build/index.d.ts +1 -0
- package/index.d.ts +117 -15
- package/index.js +361 -211
- package/index.js.map +1 -1
- package/package.json +1 -1
- package/src/LeUtils.js +84 -190
- package/src/classes/TreeSet.js +235 -0
- package/src/index.js +1 -0
- package/tests/equals.test.js +216 -0
package/index.js
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import _toConsumableArray from '@babel/runtime/helpers/toConsumableArray';
|
|
2
2
|
import _defineProperty from '@babel/runtime/helpers/defineProperty';
|
|
3
3
|
import _asyncToGenerator from '@babel/runtime/helpers/asyncToGenerator';
|
|
4
|
-
import _slicedToArray from '@babel/runtime/helpers/slicedToArray';
|
|
5
4
|
import _typeof from '@babel/runtime/helpers/typeof';
|
|
5
|
+
import _slicedToArray from '@babel/runtime/helpers/slicedToArray';
|
|
6
6
|
import '@babel/runtime/helpers/awaitAsyncGenerator';
|
|
7
7
|
import _wrapAsyncGenerator from '@babel/runtime/helpers/wrapAsyncGenerator';
|
|
8
8
|
import _regeneratorRuntime from '@babel/runtime/regenerator';
|
|
@@ -257,6 +257,68 @@ var LeUtils = {
|
|
|
257
257
|
equals: function equals(value, other) {
|
|
258
258
|
return FastDeepEqual(value, other);
|
|
259
259
|
},
|
|
260
|
+
/**
|
|
261
|
+
* Performs a deep equality comparison between two collections (objects, maps, arrays, etc), sorting on the keys before comparing them.
|
|
262
|
+
*
|
|
263
|
+
* This is useful for comparing objects that have the same properties, but in a different order, and/or in a different collection type (like Maps vs Objects).
|
|
264
|
+
*
|
|
265
|
+
* @param {*} elementsA The elements to compare.
|
|
266
|
+
* @param {*} elementsB The other elements to compare.
|
|
267
|
+
* @param {string[]} [ignoreKeys=[]] An array of keys to ignore when comparing the elements. This is useful for ignoring properties that are not relevant for the comparison.
|
|
268
|
+
* @return {boolean} Returns true if the given values are equivalent, ignoring the order of properties.
|
|
269
|
+
*/
|
|
270
|
+
equalsMapLike: function () {
|
|
271
|
+
var sortKeyValueArrays = function sortKeyValueArrays(pairA, pairB) {
|
|
272
|
+
return LeUtils.compare(pairA[0], pairB[0]);
|
|
273
|
+
};
|
|
274
|
+
return function (elementsA, elementsB) {
|
|
275
|
+
var ignoreKeys = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : [];
|
|
276
|
+
elementsA = LeUtils.mapToArray(elementsA, function (value, key) {
|
|
277
|
+
return [key, value];
|
|
278
|
+
}).sort(sortKeyValueArrays);
|
|
279
|
+
elementsB = LeUtils.mapToArray(elementsB, function (value, key) {
|
|
280
|
+
return [key, value];
|
|
281
|
+
}).sort(sortKeyValueArrays);
|
|
282
|
+
ignoreKeys = typeof ignoreKeys === 'string' ? ARRAY(ignoreKeys) : LeUtils.mapToArray(ignoreKeys);
|
|
283
|
+
var indexA = 0;
|
|
284
|
+
var indexB = 0;
|
|
285
|
+
while (indexA < elementsA.length && indexB < elementsB.length) {
|
|
286
|
+
var _elementsA$indexA = _slicedToArray(elementsA[indexA], 2),
|
|
287
|
+
mapKey = _elementsA$indexA[0],
|
|
288
|
+
mapValue = _elementsA$indexA[1];
|
|
289
|
+
var _elementsB$indexB = _slicedToArray(elementsB[indexB], 2),
|
|
290
|
+
ownMapKey = _elementsB$indexB[0],
|
|
291
|
+
ownMapValue = _elementsB$indexB[1];
|
|
292
|
+
var ignoreKeysIncludesMapKey = ignoreKeys.includes(mapKey);
|
|
293
|
+
var ignoreKeysIncludesOwnMapKey = ignoreKeys.includes(ownMapKey);
|
|
294
|
+
if (ignoreKeysIncludesMapKey) {
|
|
295
|
+
indexA++;
|
|
296
|
+
if (ignoreKeysIncludesOwnMapKey) {
|
|
297
|
+
indexB++;
|
|
298
|
+
}
|
|
299
|
+
continue;
|
|
300
|
+
} else if (ignoreKeysIncludesOwnMapKey) {
|
|
301
|
+
indexB++;
|
|
302
|
+
continue;
|
|
303
|
+
}
|
|
304
|
+
if (!LeUtils.equals(mapKey, ownMapKey) || !LeUtils.equals(mapValue, ownMapValue)) {
|
|
305
|
+
return false;
|
|
306
|
+
}
|
|
307
|
+
indexA++;
|
|
308
|
+
indexB++;
|
|
309
|
+
}
|
|
310
|
+
while (indexA < elementsA.length && ignoreKeys.includes(elementsA[indexA][0])) {
|
|
311
|
+
indexA++;
|
|
312
|
+
}
|
|
313
|
+
if (indexA < elementsA.length) {
|
|
314
|
+
return false;
|
|
315
|
+
}
|
|
316
|
+
while (indexB < elementsB.length && ignoreKeys.includes(elementsB[indexB][0])) {
|
|
317
|
+
indexB++;
|
|
318
|
+
}
|
|
319
|
+
return indexB >= elementsB.length;
|
|
320
|
+
};
|
|
321
|
+
}(),
|
|
260
322
|
/**
|
|
261
323
|
* Returns a deep copy of the given value.
|
|
262
324
|
*
|
|
@@ -2972,6 +3034,15 @@ var LeUtils = {
|
|
|
2972
3034
|
* @returns {boolean}
|
|
2973
3035
|
*/
|
|
2974
3036
|
isGivenHostPrivate: function isGivenHostPrivate(host) {
|
|
3037
|
+
host = STRING(host).trim();
|
|
3038
|
+
if (!host) {
|
|
3039
|
+
return false;
|
|
3040
|
+
}
|
|
3041
|
+
try {
|
|
3042
|
+
host = new URL(host).hostname;
|
|
3043
|
+
} catch (e) {
|
|
3044
|
+
host = host.split(':')[0];
|
|
3045
|
+
}
|
|
2975
3046
|
host = STRING(host).trim().toLowerCase();
|
|
2976
3047
|
if (host === 'localhost' || host === '127.0.0.1') {
|
|
2977
3048
|
return true;
|
|
@@ -2986,178 +3057,6 @@ var LeUtils = {
|
|
|
2986
3057
|
// 172.16.0.0 - 172.31.255.255
|
|
2987
3058
|
parts[0] === '192' && parts[1] === '168'; // 192.168.0.0 - 192.168.255.255
|
|
2988
3059
|
},
|
|
2989
|
-
/**
|
|
2990
|
-
* Creates and returns a new TreeSet.
|
|
2991
|
-
* A TreeSet is a set of elements, sorted by a comparator.
|
|
2992
|
-
* Binary search is used to find elements, which makes it very fast to find elements.
|
|
2993
|
-
*
|
|
2994
|
-
* The comparator is also used to determine if two values are equal to each other.
|
|
2995
|
-
* This way, you can have values that aren't the same be treated as if they are. This can be used to deal with issues such as floating point errors for example.
|
|
2996
|
-
*
|
|
2997
|
-
* @param {*[]} elements
|
|
2998
|
-
* @param {(valueA:*, valueB:*) => number} comparator
|
|
2999
|
-
* @returns {{getElements:(()=>*[]), getComparator:(()=>((valueA:*,valueB:*)=>number)), size:(()=>number), isEmpty:(()=>boolean), contains:((value:*)=>boolean), first:(()=>*|undefined), last:(()=>*|undefined), pollFirst:(()=>*|undefined), pollLast:(()=>*|undefined), add:((value:*)=>void), addAll:((values:*)=>void), getEqualValue:((value:*)=>*), getEqualValueOrAdd:((value:*)=>*)}}
|
|
3000
|
-
*/
|
|
3001
|
-
createTreeSet: function createTreeSet(elements, comparator) {
|
|
3002
|
-
comparator = comparator || LeUtils.compare;
|
|
3003
|
-
elements = elements || [];
|
|
3004
|
-
elements.sort(comparator);
|
|
3005
|
-
|
|
3006
|
-
/**
|
|
3007
|
-
* Performs a binary search on the elements, and returns the result.
|
|
3008
|
-
*
|
|
3009
|
-
* @param {*} value
|
|
3010
|
-
* @returns {{found: boolean, index: number, value: *|undefined}}
|
|
3011
|
-
*/
|
|
3012
|
-
var binarySearch = function binarySearch(value) {
|
|
3013
|
-
var low = 0;
|
|
3014
|
-
var high = elements.length - 1;
|
|
3015
|
-
while (low <= high) {
|
|
3016
|
-
var mid = Math.floor((low + high) / 2);
|
|
3017
|
-
var midValue = elements[mid];
|
|
3018
|
-
var cmp = comparator(midValue, value);
|
|
3019
|
-
if (cmp < 0) {
|
|
3020
|
-
low = mid + 1;
|
|
3021
|
-
} else if (cmp > 0) {
|
|
3022
|
-
high = mid - 1;
|
|
3023
|
-
} else {
|
|
3024
|
-
return {
|
|
3025
|
-
found: true,
|
|
3026
|
-
index: mid,
|
|
3027
|
-
value: midValue
|
|
3028
|
-
};
|
|
3029
|
-
}
|
|
3030
|
-
}
|
|
3031
|
-
return {
|
|
3032
|
-
found: false,
|
|
3033
|
-
index: low,
|
|
3034
|
-
value: undefined
|
|
3035
|
-
};
|
|
3036
|
-
};
|
|
3037
|
-
var treeSet = {
|
|
3038
|
-
/**
|
|
3039
|
-
* Returns the elements of the set.
|
|
3040
|
-
*
|
|
3041
|
-
* @returns {*[]}
|
|
3042
|
-
*/
|
|
3043
|
-
getElements: function getElements() {
|
|
3044
|
-
return elements;
|
|
3045
|
-
},
|
|
3046
|
-
/**
|
|
3047
|
-
* Returns the comparator of the set.
|
|
3048
|
-
*
|
|
3049
|
-
* @returns {(valueA:*, valueB:*) => number}
|
|
3050
|
-
*/
|
|
3051
|
-
getComparator: function getComparator() {
|
|
3052
|
-
return comparator;
|
|
3053
|
-
},
|
|
3054
|
-
/**
|
|
3055
|
-
* Returns the size of the set.
|
|
3056
|
-
*
|
|
3057
|
-
* @returns {number}
|
|
3058
|
-
*/
|
|
3059
|
-
size: function size() {
|
|
3060
|
-
return elements.length;
|
|
3061
|
-
},
|
|
3062
|
-
/**
|
|
3063
|
-
* Returns true if the set is empty, false otherwise.
|
|
3064
|
-
*
|
|
3065
|
-
* @returns {boolean}
|
|
3066
|
-
*/
|
|
3067
|
-
isEmpty: function isEmpty() {
|
|
3068
|
-
return elements.length <= 0;
|
|
3069
|
-
},
|
|
3070
|
-
/**
|
|
3071
|
-
* Returns true if the set contains a value that is equal to the given value, returns false otherwise.
|
|
3072
|
-
*
|
|
3073
|
-
* @param {*} value
|
|
3074
|
-
* @returns {boolean}
|
|
3075
|
-
*/
|
|
3076
|
-
contains: function contains(value) {
|
|
3077
|
-
return binarySearch(value).found;
|
|
3078
|
-
},
|
|
3079
|
-
/**
|
|
3080
|
-
* Returns the first element of the set, or undefined if it is empty.
|
|
3081
|
-
*
|
|
3082
|
-
* @returns {*|undefined}
|
|
3083
|
-
*/
|
|
3084
|
-
first: function first() {
|
|
3085
|
-
return elements.length > 0 ? elements[0] : undefined;
|
|
3086
|
-
},
|
|
3087
|
-
/**
|
|
3088
|
-
* Returns the last element of the set, or undefined if it is empty.
|
|
3089
|
-
*
|
|
3090
|
-
* @returns {*|undefined}
|
|
3091
|
-
*/
|
|
3092
|
-
last: function last() {
|
|
3093
|
-
return elements.length > 0 ? elements[elements.length - 1] : undefined;
|
|
3094
|
-
},
|
|
3095
|
-
/**
|
|
3096
|
-
* Removes and returns the first element of the set, or undefined if it is empty.
|
|
3097
|
-
*
|
|
3098
|
-
* @returns {*|undefined}
|
|
3099
|
-
*/
|
|
3100
|
-
pollFirst: function pollFirst() {
|
|
3101
|
-
return elements.length > 0 ? elements.splice(0, 1)[0] : undefined;
|
|
3102
|
-
},
|
|
3103
|
-
/**
|
|
3104
|
-
* Removes and returns the last element of the set, or undefined if it is empty.
|
|
3105
|
-
*
|
|
3106
|
-
* @returns {*|undefined}
|
|
3107
|
-
*/
|
|
3108
|
-
pollLast: function pollLast() {
|
|
3109
|
-
return elements.length > 0 ? elements.splice(elements.length - 1, 1)[0] : undefined;
|
|
3110
|
-
},
|
|
3111
|
-
/**
|
|
3112
|
-
* Adds the given value to the set. Will only do so if no equal value already exists.
|
|
3113
|
-
*
|
|
3114
|
-
* @param {*} value
|
|
3115
|
-
*/
|
|
3116
|
-
add: function add(value) {
|
|
3117
|
-
var result = binarySearch(value);
|
|
3118
|
-
if (result.found) {
|
|
3119
|
-
return;
|
|
3120
|
-
}
|
|
3121
|
-
elements.splice(result.index, 0, value);
|
|
3122
|
-
},
|
|
3123
|
-
/**
|
|
3124
|
-
* Adds all the given values to the set. Will only do so if no equal value already exists.
|
|
3125
|
-
*
|
|
3126
|
-
* @param {*} values
|
|
3127
|
-
*/
|
|
3128
|
-
addAll: function addAll(values) {
|
|
3129
|
-
LeUtils.each(values, treeSet.add);
|
|
3130
|
-
},
|
|
3131
|
-
/**
|
|
3132
|
-
* Returns an equal value that's already in the tree set, or undefined if no equal values in it exist.
|
|
3133
|
-
*
|
|
3134
|
-
* @param {*} value
|
|
3135
|
-
* @returns {*|undefined}
|
|
3136
|
-
*/
|
|
3137
|
-
getEqualValue: function getEqualValue(value) {
|
|
3138
|
-
var result = binarySearch(value);
|
|
3139
|
-
if (result.found) {
|
|
3140
|
-
return result.value;
|
|
3141
|
-
}
|
|
3142
|
-
return undefined;
|
|
3143
|
-
},
|
|
3144
|
-
/**
|
|
3145
|
-
* Returns an equal value that's already in the tree set. If no equal values in it exist, the given value will be added and returned.
|
|
3146
|
-
*
|
|
3147
|
-
* @param {*} value
|
|
3148
|
-
* @returns {*}
|
|
3149
|
-
*/
|
|
3150
|
-
getEqualValueOrAdd: function getEqualValueOrAdd(value) {
|
|
3151
|
-
var result = binarySearch(value);
|
|
3152
|
-
if (result.found) {
|
|
3153
|
-
return result.value;
|
|
3154
|
-
}
|
|
3155
|
-
elements.splice(result.index, 0, value);
|
|
3156
|
-
return value;
|
|
3157
|
-
}
|
|
3158
|
-
};
|
|
3159
|
-
return treeSet;
|
|
3160
|
-
},
|
|
3161
3060
|
/**
|
|
3162
3061
|
* @typedef {Object} LeUtils_TransactionalValue
|
|
3163
3062
|
* @property {*} value
|
|
@@ -3526,11 +3425,11 @@ var LeUtils = {
|
|
|
3526
3425
|
}()
|
|
3527
3426
|
};
|
|
3528
3427
|
|
|
3529
|
-
function _classPrivateFieldInitSpec(e, t, a) { _checkPrivateRedeclaration(e, t), t.set(e, a); }
|
|
3530
|
-
function _checkPrivateRedeclaration(e, t) { if (t.has(e)) throw new TypeError("Cannot initialize the same private elements twice on an object"); }
|
|
3531
|
-
function _classPrivateFieldSet(s, a, r) { return s.set(_assertClassBrand(s, a), r), r; }
|
|
3532
|
-
function _classPrivateFieldGet(s, a) { return s.get(_assertClassBrand(s, a)); }
|
|
3533
|
-
function _assertClassBrand(e, t, n) { if ("function" == typeof e ? e === t : e.has(t)) return arguments.length < 3 ? t : n; throw new TypeError("Private element is not present on this object"); }
|
|
3428
|
+
function _classPrivateFieldInitSpec$1(e, t, a) { _checkPrivateRedeclaration$1(e, t), t.set(e, a); }
|
|
3429
|
+
function _checkPrivateRedeclaration$1(e, t) { if (t.has(e)) throw new TypeError("Cannot initialize the same private elements twice on an object"); }
|
|
3430
|
+
function _classPrivateFieldSet$1(s, a, r) { return s.set(_assertClassBrand$1(s, a), r), r; }
|
|
3431
|
+
function _classPrivateFieldGet$1(s, a) { return s.get(_assertClassBrand$1(s, a)); }
|
|
3432
|
+
function _assertClassBrand$1(e, t, n) { if ("function" == typeof e ? e === t : e.has(t)) return arguments.length < 3 ? t : n; throw new TypeError("Private element is not present on this object"); }
|
|
3534
3433
|
var LinkedListNode = /*#__PURE__*/_createClass(
|
|
3535
3434
|
/**
|
|
3536
3435
|
* @param {*} value
|
|
@@ -3552,11 +3451,11 @@ var LinkedList = /*#__PURE__*/function () {
|
|
|
3552
3451
|
function LinkedList() {
|
|
3553
3452
|
_classCallCheck(this, LinkedList);
|
|
3554
3453
|
/** @type {LinkedListNode|null} */
|
|
3555
|
-
_classPrivateFieldInitSpec(this, _head, null);
|
|
3454
|
+
_classPrivateFieldInitSpec$1(this, _head, null);
|
|
3556
3455
|
/** @type {LinkedListNode|null} */
|
|
3557
|
-
_classPrivateFieldInitSpec(this, _tail, null);
|
|
3456
|
+
_classPrivateFieldInitSpec$1(this, _tail, null);
|
|
3558
3457
|
/** @type {number} */
|
|
3559
|
-
_classPrivateFieldInitSpec(this, _size, 0);
|
|
3458
|
+
_classPrivateFieldInitSpec$1(this, _size, 0);
|
|
3560
3459
|
}
|
|
3561
3460
|
|
|
3562
3461
|
/**
|
|
@@ -3567,7 +3466,7 @@ var LinkedList = /*#__PURE__*/function () {
|
|
|
3567
3466
|
return _createClass(LinkedList, [{
|
|
3568
3467
|
key: "size",
|
|
3569
3468
|
get: function get() {
|
|
3570
|
-
return _classPrivateFieldGet(_size, this);
|
|
3469
|
+
return _classPrivateFieldGet$1(_size, this);
|
|
3571
3470
|
}
|
|
3572
3471
|
|
|
3573
3472
|
/**
|
|
@@ -3580,15 +3479,15 @@ var LinkedList = /*#__PURE__*/function () {
|
|
|
3580
3479
|
value: function unshift(value) {
|
|
3581
3480
|
var _this$size;
|
|
3582
3481
|
var newNode = new LinkedListNode(value);
|
|
3583
|
-
if (_classPrivateFieldGet(_head, this) === null) {
|
|
3584
|
-
_classPrivateFieldSet(_head, this, newNode);
|
|
3585
|
-
_classPrivateFieldSet(_tail, this, newNode);
|
|
3482
|
+
if (_classPrivateFieldGet$1(_head, this) === null) {
|
|
3483
|
+
_classPrivateFieldSet$1(_head, this, newNode);
|
|
3484
|
+
_classPrivateFieldSet$1(_tail, this, newNode);
|
|
3586
3485
|
} else {
|
|
3587
|
-
newNode.next = _classPrivateFieldGet(_head, this);
|
|
3588
|
-
_classPrivateFieldGet(_head, this).previous = newNode;
|
|
3589
|
-
_classPrivateFieldSet(_head, this, newNode);
|
|
3486
|
+
newNode.next = _classPrivateFieldGet$1(_head, this);
|
|
3487
|
+
_classPrivateFieldGet$1(_head, this).previous = newNode;
|
|
3488
|
+
_classPrivateFieldSet$1(_head, this, newNode);
|
|
3590
3489
|
}
|
|
3591
|
-
_classPrivateFieldSet(_size, this, (_this$size = _classPrivateFieldGet(_size, this), _this$size++, _this$size));
|
|
3490
|
+
_classPrivateFieldSet$1(_size, this, (_this$size = _classPrivateFieldGet$1(_size, this), _this$size++, _this$size));
|
|
3592
3491
|
}
|
|
3593
3492
|
|
|
3594
3493
|
/**
|
|
@@ -3601,15 +3500,15 @@ var LinkedList = /*#__PURE__*/function () {
|
|
|
3601
3500
|
value: function push(value) {
|
|
3602
3501
|
var _this$size3;
|
|
3603
3502
|
var newNode = new LinkedListNode(value);
|
|
3604
|
-
if (_classPrivateFieldGet(_tail, this) === null) {
|
|
3605
|
-
_classPrivateFieldSet(_head, this, newNode);
|
|
3606
|
-
_classPrivateFieldSet(_tail, this, newNode);
|
|
3503
|
+
if (_classPrivateFieldGet$1(_tail, this) === null) {
|
|
3504
|
+
_classPrivateFieldSet$1(_head, this, newNode);
|
|
3505
|
+
_classPrivateFieldSet$1(_tail, this, newNode);
|
|
3607
3506
|
} else {
|
|
3608
|
-
newNode.previous = _classPrivateFieldGet(_tail, this);
|
|
3609
|
-
_classPrivateFieldGet(_tail, this).next = newNode;
|
|
3610
|
-
_classPrivateFieldSet(_tail, this, newNode);
|
|
3507
|
+
newNode.previous = _classPrivateFieldGet$1(_tail, this);
|
|
3508
|
+
_classPrivateFieldGet$1(_tail, this).next = newNode;
|
|
3509
|
+
_classPrivateFieldSet$1(_tail, this, newNode);
|
|
3611
3510
|
}
|
|
3612
|
-
_classPrivateFieldSet(_size, this, (_this$size3 = _classPrivateFieldGet(_size, this), _this$size3++, _this$size3));
|
|
3511
|
+
_classPrivateFieldSet$1(_size, this, (_this$size3 = _classPrivateFieldGet$1(_size, this), _this$size3++, _this$size3));
|
|
3613
3512
|
}
|
|
3614
3513
|
|
|
3615
3514
|
/**
|
|
@@ -3621,17 +3520,17 @@ var LinkedList = /*#__PURE__*/function () {
|
|
|
3621
3520
|
key: "shift",
|
|
3622
3521
|
value: function shift() {
|
|
3623
3522
|
var _this$size5;
|
|
3624
|
-
if (_classPrivateFieldGet(_head, this) === null) {
|
|
3523
|
+
if (_classPrivateFieldGet$1(_head, this) === null) {
|
|
3625
3524
|
return undefined;
|
|
3626
3525
|
}
|
|
3627
|
-
var value = _classPrivateFieldGet(_head, this).value;
|
|
3628
|
-
_classPrivateFieldSet(_head, this, _classPrivateFieldGet(_head, this).next);
|
|
3629
|
-
if (_classPrivateFieldGet(_head, this) !== null) {
|
|
3630
|
-
_classPrivateFieldGet(_head, this).previous = null;
|
|
3526
|
+
var value = _classPrivateFieldGet$1(_head, this).value;
|
|
3527
|
+
_classPrivateFieldSet$1(_head, this, _classPrivateFieldGet$1(_head, this).next);
|
|
3528
|
+
if (_classPrivateFieldGet$1(_head, this) !== null) {
|
|
3529
|
+
_classPrivateFieldGet$1(_head, this).previous = null;
|
|
3631
3530
|
} else {
|
|
3632
|
-
_classPrivateFieldSet(_tail, this, null);
|
|
3531
|
+
_classPrivateFieldSet$1(_tail, this, null);
|
|
3633
3532
|
}
|
|
3634
|
-
_classPrivateFieldSet(_size, this, (_this$size5 = _classPrivateFieldGet(_size, this), _this$size5--, _this$size5));
|
|
3533
|
+
_classPrivateFieldSet$1(_size, this, (_this$size5 = _classPrivateFieldGet$1(_size, this), _this$size5--, _this$size5));
|
|
3635
3534
|
return value;
|
|
3636
3535
|
}
|
|
3637
3536
|
|
|
@@ -3644,17 +3543,17 @@ var LinkedList = /*#__PURE__*/function () {
|
|
|
3644
3543
|
key: "pop",
|
|
3645
3544
|
value: function pop() {
|
|
3646
3545
|
var _this$size7;
|
|
3647
|
-
if (_classPrivateFieldGet(_tail, this) === null) {
|
|
3546
|
+
if (_classPrivateFieldGet$1(_tail, this) === null) {
|
|
3648
3547
|
return undefined;
|
|
3649
3548
|
}
|
|
3650
|
-
var value = _classPrivateFieldGet(_tail, this).value;
|
|
3651
|
-
_classPrivateFieldSet(_tail, this, _classPrivateFieldGet(_tail, this).previous);
|
|
3652
|
-
if (_classPrivateFieldGet(_tail, this) !== null) {
|
|
3653
|
-
_classPrivateFieldGet(_tail, this).next = null;
|
|
3549
|
+
var value = _classPrivateFieldGet$1(_tail, this).value;
|
|
3550
|
+
_classPrivateFieldSet$1(_tail, this, _classPrivateFieldGet$1(_tail, this).previous);
|
|
3551
|
+
if (_classPrivateFieldGet$1(_tail, this) !== null) {
|
|
3552
|
+
_classPrivateFieldGet$1(_tail, this).next = null;
|
|
3654
3553
|
} else {
|
|
3655
|
-
_classPrivateFieldSet(_head, this, null);
|
|
3554
|
+
_classPrivateFieldSet$1(_head, this, null);
|
|
3656
3555
|
}
|
|
3657
|
-
_classPrivateFieldSet(_size, this, (_this$size7 = _classPrivateFieldGet(_size, this), _this$size7--, _this$size7));
|
|
3556
|
+
_classPrivateFieldSet$1(_size, this, (_this$size7 = _classPrivateFieldGet$1(_size, this), _this$size7--, _this$size7));
|
|
3658
3557
|
return value;
|
|
3659
3558
|
}
|
|
3660
3559
|
}]);
|
|
@@ -3687,5 +3586,256 @@ var SerializableMap = /*#__PURE__*/function (_Map) {
|
|
|
3687
3586
|
}]);
|
|
3688
3587
|
}(/*#__PURE__*/_wrapNativeSuper(Map));
|
|
3689
3588
|
|
|
3690
|
-
|
|
3589
|
+
function _classPrivateFieldInitSpec(e, t, a) { _checkPrivateRedeclaration(e, t), t.set(e, a); }
|
|
3590
|
+
function _checkPrivateRedeclaration(e, t) { if (t.has(e)) throw new TypeError("Cannot initialize the same private elements twice on an object"); }
|
|
3591
|
+
function _classPrivateFieldGet(s, a) { return s.get(_assertClassBrand(s, a)); }
|
|
3592
|
+
function _classPrivateFieldSet(s, a, r) { return s.set(_assertClassBrand(s, a), r), r; }
|
|
3593
|
+
function _assertClassBrand(e, t, n) { if ("function" == typeof e ? e === t : e.has(t)) return arguments.length < 3 ? t : n; throw new TypeError("Private element is not present on this object"); }
|
|
3594
|
+
|
|
3595
|
+
/**
|
|
3596
|
+
* A TreeSet is a set of elements, sorted by a comparator.
|
|
3597
|
+
* Binary search is used to find elements, which makes it very fast to find elements.
|
|
3598
|
+
*
|
|
3599
|
+
* The comparator is also used to determine if two values are equal to each other.
|
|
3600
|
+
* This way, you can have values that aren't the same be treated as if they are. This can be used to deal with issues such as floating point errors for example.
|
|
3601
|
+
*/
|
|
3602
|
+
var _elements = /*#__PURE__*/new WeakMap();
|
|
3603
|
+
var _comparator = /*#__PURE__*/new WeakMap();
|
|
3604
|
+
var TreeSet = /*#__PURE__*/function () {
|
|
3605
|
+
/**
|
|
3606
|
+
* Creates a new TreeSet with the given elements and comparator.
|
|
3607
|
+
*
|
|
3608
|
+
* @param {*[]} [elements=[]] - The initial elements of the set.
|
|
3609
|
+
* @param {(valueA:*, valueB:*) => number} [comparator=LeUtils.compare] - The comparator function to use for sorting.
|
|
3610
|
+
*/
|
|
3611
|
+
function TreeSet(elements, comparator) {
|
|
3612
|
+
_classCallCheck(this, TreeSet);
|
|
3613
|
+
/** @type {*[]} */
|
|
3614
|
+
_classPrivateFieldInitSpec(this, _elements, void 0);
|
|
3615
|
+
/** @type {(valueA:*, valueB:*) => number} */
|
|
3616
|
+
_classPrivateFieldInitSpec(this, _comparator, void 0);
|
|
3617
|
+
_classPrivateFieldSet(_comparator, this, comparator || LeUtils.compare);
|
|
3618
|
+
_classPrivateFieldSet(_elements, this, elements || []);
|
|
3619
|
+
_classPrivateFieldGet(_elements, this).sort(_classPrivateFieldGet(_comparator, this));
|
|
3620
|
+
}
|
|
3621
|
+
|
|
3622
|
+
/**
|
|
3623
|
+
*
|
|
3624
|
+
*
|
|
3625
|
+
* @param {*} value - The value to search for in the set.
|
|
3626
|
+
* @returns {{found:boolean, index:number, value:*|undefined}} - An object containing whether the value was found, the index where it would be inserted, and the value at that index (if found).
|
|
3627
|
+
* @private
|
|
3628
|
+
*/
|
|
3629
|
+
return _createClass(TreeSet, [{
|
|
3630
|
+
key: "binarySearch",
|
|
3631
|
+
value: function binarySearch(value) {
|
|
3632
|
+
var low = 0;
|
|
3633
|
+
var high = _classPrivateFieldGet(_elements, this).length - 1;
|
|
3634
|
+
while (low <= high) {
|
|
3635
|
+
var mid = Math.floor((low + high) / 2);
|
|
3636
|
+
var midValue = _classPrivateFieldGet(_elements, this)[mid];
|
|
3637
|
+
var cmp = _classPrivateFieldGet(_comparator, this).call(this, midValue, value);
|
|
3638
|
+
if (cmp < 0) {
|
|
3639
|
+
low = mid + 1;
|
|
3640
|
+
} else if (cmp > 0) {
|
|
3641
|
+
high = mid - 1;
|
|
3642
|
+
} else {
|
|
3643
|
+
return {
|
|
3644
|
+
found: true,
|
|
3645
|
+
index: mid,
|
|
3646
|
+
value: midValue
|
|
3647
|
+
};
|
|
3648
|
+
}
|
|
3649
|
+
}
|
|
3650
|
+
return {
|
|
3651
|
+
found: false,
|
|
3652
|
+
index: low,
|
|
3653
|
+
value: undefined
|
|
3654
|
+
};
|
|
3655
|
+
}
|
|
3656
|
+
}, {
|
|
3657
|
+
key: "getElements",
|
|
3658
|
+
value:
|
|
3659
|
+
/**
|
|
3660
|
+
* Returns the elements of the set.
|
|
3661
|
+
*/
|
|
3662
|
+
function getElements() {
|
|
3663
|
+
return _classPrivateFieldGet(_elements, this);
|
|
3664
|
+
}
|
|
3665
|
+
|
|
3666
|
+
/**
|
|
3667
|
+
* Returns the comparator of the set.
|
|
3668
|
+
*
|
|
3669
|
+
* @returns {(valueA:*, valueB:*) => number}
|
|
3670
|
+
*/
|
|
3671
|
+
}, {
|
|
3672
|
+
key: "getComparator",
|
|
3673
|
+
value: function getComparator() {
|
|
3674
|
+
return _classPrivateFieldGet(_comparator, this);
|
|
3675
|
+
}
|
|
3676
|
+
|
|
3677
|
+
/**
|
|
3678
|
+
* Returns the size of the set.
|
|
3679
|
+
*
|
|
3680
|
+
* @returns {number}
|
|
3681
|
+
*/
|
|
3682
|
+
}, {
|
|
3683
|
+
key: "size",
|
|
3684
|
+
value: function size() {
|
|
3685
|
+
return _classPrivateFieldGet(_elements, this).length;
|
|
3686
|
+
}
|
|
3687
|
+
|
|
3688
|
+
/**
|
|
3689
|
+
* Returns true if the set is empty, false otherwise.
|
|
3690
|
+
*
|
|
3691
|
+
* @returns {boolean}
|
|
3692
|
+
*/
|
|
3693
|
+
}, {
|
|
3694
|
+
key: "isEmpty",
|
|
3695
|
+
value: function isEmpty() {
|
|
3696
|
+
return _classPrivateFieldGet(_elements, this).length <= 0;
|
|
3697
|
+
}
|
|
3698
|
+
|
|
3699
|
+
/**
|
|
3700
|
+
* Returns true if the set contains a value that is equal to the given value, returns false otherwise.
|
|
3701
|
+
*
|
|
3702
|
+
* @param {*} value - The value to check for in the set.
|
|
3703
|
+
* @return {boolean} - True if the set contains the value, false otherwise.
|
|
3704
|
+
*/
|
|
3705
|
+
}, {
|
|
3706
|
+
key: "contains",
|
|
3707
|
+
value: function contains(value) {
|
|
3708
|
+
return this.binarySearch(value).found;
|
|
3709
|
+
}
|
|
3710
|
+
|
|
3711
|
+
/**
|
|
3712
|
+
* Returns the first element of the set, or undefined if it is empty.
|
|
3713
|
+
*
|
|
3714
|
+
* @return {*|undefined} - The first element of the set, or undefined if it is empty.
|
|
3715
|
+
*/
|
|
3716
|
+
}, {
|
|
3717
|
+
key: "first",
|
|
3718
|
+
value: function first() {
|
|
3719
|
+
return _classPrivateFieldGet(_elements, this).length > 0 ? _classPrivateFieldGet(_elements, this)[0] : undefined;
|
|
3720
|
+
}
|
|
3721
|
+
|
|
3722
|
+
/**
|
|
3723
|
+
* Returns the last element of the set, or undefined if it is empty.
|
|
3724
|
+
*
|
|
3725
|
+
* @return {*|undefined} - The last element of the set, or undefined if it is empty.
|
|
3726
|
+
*/
|
|
3727
|
+
}, {
|
|
3728
|
+
key: "last",
|
|
3729
|
+
value: function last() {
|
|
3730
|
+
return _classPrivateFieldGet(_elements, this).length > 0 ? _classPrivateFieldGet(_elements, this)[_classPrivateFieldGet(_elements, this).length - 1] : undefined;
|
|
3731
|
+
}
|
|
3732
|
+
|
|
3733
|
+
/**
|
|
3734
|
+
* Removes and returns the first element of the set, or undefined if it is empty.
|
|
3735
|
+
*
|
|
3736
|
+
* @returns {*|undefined} - The first element of the set, or undefined if it is empty.
|
|
3737
|
+
*/
|
|
3738
|
+
}, {
|
|
3739
|
+
key: "pollFirst",
|
|
3740
|
+
value: function pollFirst() {
|
|
3741
|
+
return _classPrivateFieldGet(_elements, this).length > 0 ? _classPrivateFieldGet(_elements, this).splice(0, 1)[0] : undefined;
|
|
3742
|
+
}
|
|
3743
|
+
|
|
3744
|
+
/**
|
|
3745
|
+
* Removes and returns the last element of the set, or undefined if it is empty.
|
|
3746
|
+
*
|
|
3747
|
+
* @returns {*|undefined} - The last element of the set, or undefined if it is empty.
|
|
3748
|
+
*/
|
|
3749
|
+
}, {
|
|
3750
|
+
key: "pollLast",
|
|
3751
|
+
value: function pollLast() {
|
|
3752
|
+
return _classPrivateFieldGet(_elements, this).length > 0 ? _classPrivateFieldGet(_elements, this).splice(_classPrivateFieldGet(_elements, this).length - 1, 1)[0] : undefined;
|
|
3753
|
+
}
|
|
3754
|
+
|
|
3755
|
+
/**
|
|
3756
|
+
* Adds the given value to the set. Will only do so if no equal value already exists.
|
|
3757
|
+
* @param {*} value - The value to add to the set.
|
|
3758
|
+
*/
|
|
3759
|
+
}, {
|
|
3760
|
+
key: "add",
|
|
3761
|
+
value: function add(value) {
|
|
3762
|
+
var result = this.binarySearch(value);
|
|
3763
|
+
if (result.found) {
|
|
3764
|
+
return;
|
|
3765
|
+
}
|
|
3766
|
+
_classPrivateFieldGet(_elements, this).splice(result.index, 0, value);
|
|
3767
|
+
}
|
|
3768
|
+
|
|
3769
|
+
/**
|
|
3770
|
+
* Adds all the given values to the set. Will only do so if no equal value already exists.
|
|
3771
|
+
*
|
|
3772
|
+
* @param {*} values - The values to add to the set.
|
|
3773
|
+
*/
|
|
3774
|
+
}, {
|
|
3775
|
+
key: "addAll",
|
|
3776
|
+
value: function addAll(values) {
|
|
3777
|
+
LeUtils.each(values, this.add.bind(this));
|
|
3778
|
+
}
|
|
3779
|
+
|
|
3780
|
+
/**
|
|
3781
|
+
* Returns an equal value that's already in the tree set, or undefined if no equal values in it exist.
|
|
3782
|
+
*
|
|
3783
|
+
* @param {*} value - The value to search for in the set.
|
|
3784
|
+
* @return {*|undefined} - The equal value if found, or undefined if not found.
|
|
3785
|
+
*/
|
|
3786
|
+
}, {
|
|
3787
|
+
key: "getEqualValue",
|
|
3788
|
+
value: function getEqualValue(value) {
|
|
3789
|
+
var result = this.binarySearch(value);
|
|
3790
|
+
if (result.found) {
|
|
3791
|
+
return result.value;
|
|
3792
|
+
}
|
|
3793
|
+
return undefined;
|
|
3794
|
+
}
|
|
3795
|
+
|
|
3796
|
+
/**
|
|
3797
|
+
* Returns an equal value that's already in the tree set. If no equal values in it exist, the given value will be added and returned.
|
|
3798
|
+
*
|
|
3799
|
+
* @param {*} value - The value to search for in the set.
|
|
3800
|
+
* @return {*} - The equal value if found, or the added value if not found.
|
|
3801
|
+
*/
|
|
3802
|
+
}, {
|
|
3803
|
+
key: "getEqualValueOrAdd",
|
|
3804
|
+
value: function getEqualValueOrAdd(value) {
|
|
3805
|
+
var result = this.binarySearch(value);
|
|
3806
|
+
if (result.found) {
|
|
3807
|
+
return result.value;
|
|
3808
|
+
}
|
|
3809
|
+
_classPrivateFieldGet(_elements, this).splice(result.index, 0, value);
|
|
3810
|
+
return value;
|
|
3811
|
+
}
|
|
3812
|
+
|
|
3813
|
+
/**
|
|
3814
|
+
* Returns a string representation of the TreeSet.
|
|
3815
|
+
*
|
|
3816
|
+
* @returns {string} - A string representation of the TreeSet, including its elements and comparator.
|
|
3817
|
+
*/
|
|
3818
|
+
}, {
|
|
3819
|
+
key: "toString",
|
|
3820
|
+
value: function toString() {
|
|
3821
|
+
return "TreeSet{elements:".concat(_classPrivateFieldGet(_elements, this), ", comparator:").concat(_classPrivateFieldGet(_comparator, this), "}");
|
|
3822
|
+
}
|
|
3823
|
+
|
|
3824
|
+
/**
|
|
3825
|
+
* Returns a JSON representation of the TreeSet.
|
|
3826
|
+
*
|
|
3827
|
+
* @returns {Object} - An object containing the elements and comparator of the TreeSet.
|
|
3828
|
+
*/
|
|
3829
|
+
}, {
|
|
3830
|
+
key: "toJSON",
|
|
3831
|
+
value: function toJSON() {
|
|
3832
|
+
return {
|
|
3833
|
+
elements: _classPrivateFieldGet(_elements, this),
|
|
3834
|
+
comparator: _classPrivateFieldGet(_comparator, this).toString()
|
|
3835
|
+
};
|
|
3836
|
+
}
|
|
3837
|
+
}]);
|
|
3838
|
+
}();
|
|
3839
|
+
|
|
3840
|
+
export { ARRAY, FLOAT, FLOAT_ANY, FLOAT_LAX, FLOAT_LAX_ANY, INT, INT_ANY, INT_LAX, INT_LAX_ANY, ISSET, IS_ARRAY, IS_OBJECT, LeUtils, LinkedList, OBJECT, STRING, STRING_ANY, SerializableMap, TreeSet };
|
|
3691
3841
|
//# sourceMappingURL=index.js.map
|