@lowentry/utils 1.20.1 → 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 +0 -15
- package/build/classes/TreeSet.d.ts +115 -0
- package/build/index.d.ts +1 -0
- package/index.d.ts +116 -15
- package/index.js +298 -210
- package/index.js.map +1 -1
- package/package.json +1 -1
- package/src/LeUtils.js +14 -189
- package/src/classes/TreeSet.js +235 -0
- package/src/index.js +1 -0
package/build/LeUtils.d.ts
CHANGED
|
@@ -119,21 +119,6 @@ export namespace LeUtils {
|
|
|
119
119
|
function localStorageRemove(id: string): void;
|
|
120
120
|
function isCurrentHostPrivate(): boolean;
|
|
121
121
|
function isGivenHostPrivate(host: string): boolean;
|
|
122
|
-
function createTreeSet(elements: any[], comparator: (valueA: any, valueB: any) => number): {
|
|
123
|
-
getElements: (() => any[]);
|
|
124
|
-
getComparator: (() => ((valueA: any, valueB: any) => number));
|
|
125
|
-
size: (() => number);
|
|
126
|
-
isEmpty: (() => boolean);
|
|
127
|
-
contains: ((value: any) => boolean);
|
|
128
|
-
first: (() => any | undefined);
|
|
129
|
-
last: (() => any | undefined);
|
|
130
|
-
pollFirst: (() => any | undefined);
|
|
131
|
-
pollLast: (() => any | undefined);
|
|
132
|
-
add: ((value: any) => void);
|
|
133
|
-
addAll: ((values: any) => void);
|
|
134
|
-
getEqualValue: ((value: any) => any);
|
|
135
|
-
getEqualValueOrAdd: ((value: any) => any);
|
|
136
|
-
};
|
|
137
122
|
function createTransactionalValue(value?: any): {
|
|
138
123
|
value: any;
|
|
139
124
|
changes: {
|
|
@@ -0,0 +1,115 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* A TreeSet is a set of elements, sorted by a comparator.
|
|
3
|
+
* Binary search is used to find elements, which makes it very fast to find elements.
|
|
4
|
+
*
|
|
5
|
+
* The comparator is also used to determine if two values are equal to each other.
|
|
6
|
+
* 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.
|
|
7
|
+
*/
|
|
8
|
+
export class TreeSet {
|
|
9
|
+
/**
|
|
10
|
+
* Creates a new TreeSet with the given elements and comparator.
|
|
11
|
+
*
|
|
12
|
+
* @param {*[]} [elements=[]] - The initial elements of the set.
|
|
13
|
+
* @param {(valueA:*, valueB:*) => number} [comparator=LeUtils.compare] - The comparator function to use for sorting.
|
|
14
|
+
*/
|
|
15
|
+
constructor(elements?: any[], comparator?: (valueA: any, valueB: any) => number);
|
|
16
|
+
/**
|
|
17
|
+
*
|
|
18
|
+
*
|
|
19
|
+
* @param {*} value - The value to search for in the set.
|
|
20
|
+
* @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).
|
|
21
|
+
* @private
|
|
22
|
+
*/
|
|
23
|
+
private binarySearch;
|
|
24
|
+
/**
|
|
25
|
+
* Returns the elements of the set.
|
|
26
|
+
*/
|
|
27
|
+
getElements(): any[];
|
|
28
|
+
/**
|
|
29
|
+
* Returns the comparator of the set.
|
|
30
|
+
*
|
|
31
|
+
* @returns {(valueA:*, valueB:*) => number}
|
|
32
|
+
*/
|
|
33
|
+
getComparator(): (valueA: any, valueB: any) => number;
|
|
34
|
+
/**
|
|
35
|
+
* Returns the size of the set.
|
|
36
|
+
*
|
|
37
|
+
* @returns {number}
|
|
38
|
+
*/
|
|
39
|
+
size(): number;
|
|
40
|
+
/**
|
|
41
|
+
* Returns true if the set is empty, false otherwise.
|
|
42
|
+
*
|
|
43
|
+
* @returns {boolean}
|
|
44
|
+
*/
|
|
45
|
+
isEmpty(): boolean;
|
|
46
|
+
/**
|
|
47
|
+
* Returns true if the set contains a value that is equal to the given value, returns false otherwise.
|
|
48
|
+
*
|
|
49
|
+
* @param {*} value - The value to check for in the set.
|
|
50
|
+
* @return {boolean} - True if the set contains the value, false otherwise.
|
|
51
|
+
*/
|
|
52
|
+
contains(value: any): boolean;
|
|
53
|
+
/**
|
|
54
|
+
* Returns the first element of the set, or undefined if it is empty.
|
|
55
|
+
*
|
|
56
|
+
* @return {*|undefined} - The first element of the set, or undefined if it is empty.
|
|
57
|
+
*/
|
|
58
|
+
first(): any | undefined;
|
|
59
|
+
/**
|
|
60
|
+
* Returns the last element of the set, or undefined if it is empty.
|
|
61
|
+
*
|
|
62
|
+
* @return {*|undefined} - The last element of the set, or undefined if it is empty.
|
|
63
|
+
*/
|
|
64
|
+
last(): any | undefined;
|
|
65
|
+
/**
|
|
66
|
+
* Removes and returns the first element of the set, or undefined if it is empty.
|
|
67
|
+
*
|
|
68
|
+
* @returns {*|undefined} - The first element of the set, or undefined if it is empty.
|
|
69
|
+
*/
|
|
70
|
+
pollFirst(): any | undefined;
|
|
71
|
+
/**
|
|
72
|
+
* Removes and returns the last element of the set, or undefined if it is empty.
|
|
73
|
+
*
|
|
74
|
+
* @returns {*|undefined} - The last element of the set, or undefined if it is empty.
|
|
75
|
+
*/
|
|
76
|
+
pollLast(): any | undefined;
|
|
77
|
+
/**
|
|
78
|
+
* Adds the given value to the set. Will only do so if no equal value already exists.
|
|
79
|
+
* @param {*} value - The value to add to the set.
|
|
80
|
+
*/
|
|
81
|
+
add(value: any): void;
|
|
82
|
+
/**
|
|
83
|
+
* Adds all the given values to the set. Will only do so if no equal value already exists.
|
|
84
|
+
*
|
|
85
|
+
* @param {*} values - The values to add to the set.
|
|
86
|
+
*/
|
|
87
|
+
addAll(values: any): void;
|
|
88
|
+
/**
|
|
89
|
+
* Returns an equal value that's already in the tree set, or undefined if no equal values in it exist.
|
|
90
|
+
*
|
|
91
|
+
* @param {*} value - The value to search for in the set.
|
|
92
|
+
* @return {*|undefined} - The equal value if found, or undefined if not found.
|
|
93
|
+
*/
|
|
94
|
+
getEqualValue(value: any): any | undefined;
|
|
95
|
+
/**
|
|
96
|
+
* 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.
|
|
97
|
+
*
|
|
98
|
+
* @param {*} value - The value to search for in the set.
|
|
99
|
+
* @return {*} - The equal value if found, or the added value if not found.
|
|
100
|
+
*/
|
|
101
|
+
getEqualValueOrAdd(value: any): any;
|
|
102
|
+
/**
|
|
103
|
+
* Returns a string representation of the TreeSet.
|
|
104
|
+
*
|
|
105
|
+
* @returns {string} - A string representation of the TreeSet, including its elements and comparator.
|
|
106
|
+
*/
|
|
107
|
+
toString(): string;
|
|
108
|
+
/**
|
|
109
|
+
* Returns a JSON representation of the TreeSet.
|
|
110
|
+
*
|
|
111
|
+
* @returns {Object} - An object containing the elements and comparator of the TreeSet.
|
|
112
|
+
*/
|
|
113
|
+
toJSON(): any;
|
|
114
|
+
#private;
|
|
115
|
+
}
|
package/build/index.d.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
export { LeUtils } from "./LeUtils.js";
|
|
2
2
|
export { LinkedList } from "./classes/LinkedList.js";
|
|
3
3
|
export { SerializableMap } from "./classes/SerializableMap.js";
|
|
4
|
+
export { TreeSet } from "./classes/TreeSet.js";
|
|
4
5
|
export { ISSET, IS_ARRAY, ARRAY, IS_OBJECT, OBJECT, STRING, STRING_ANY, INT, INT_ANY, FLOAT, FLOAT_ANY, INT_LAX, INT_LAX_ANY, FLOAT_LAX, FLOAT_LAX_ANY } from "./LeTypes.js";
|
package/index.d.ts
CHANGED
|
@@ -143,21 +143,6 @@ export declare namespace LeUtils {
|
|
|
143
143
|
export function localStorageRemove(id: string): void;
|
|
144
144
|
export function isCurrentHostPrivate(): boolean;
|
|
145
145
|
export function isGivenHostPrivate(host: string): boolean;
|
|
146
|
-
export function createTreeSet(elements: any[], comparator: (valueA: any, valueB: any) => number): {
|
|
147
|
-
getElements: (() => any[]);
|
|
148
|
-
getComparator: (() => ((valueA: any, valueB: any) => number));
|
|
149
|
-
size: (() => number);
|
|
150
|
-
isEmpty: (() => boolean);
|
|
151
|
-
contains: ((value: any) => boolean);
|
|
152
|
-
first: (() => any | undefined);
|
|
153
|
-
last: (() => any | undefined);
|
|
154
|
-
pollFirst: (() => any | undefined);
|
|
155
|
-
pollLast: (() => any | undefined);
|
|
156
|
-
add: ((value: any) => void);
|
|
157
|
-
addAll: ((values: any) => void);
|
|
158
|
-
getEqualValue: ((value: any) => any);
|
|
159
|
-
getEqualValueOrAdd: ((value: any) => any);
|
|
160
|
-
};
|
|
161
146
|
export function createTransactionalValue(value?: any): {
|
|
162
147
|
value: any;
|
|
163
148
|
changes: {
|
|
@@ -299,4 +284,120 @@ export declare function STRING(value: any): string;
|
|
|
299
284
|
|
|
300
285
|
export declare function STRING_ANY(...values: any): string;
|
|
301
286
|
|
|
287
|
+
/**
|
|
288
|
+
* A TreeSet is a set of elements, sorted by a comparator.
|
|
289
|
+
* Binary search is used to find elements, which makes it very fast to find elements.
|
|
290
|
+
*
|
|
291
|
+
* The comparator is also used to determine if two values are equal to each other.
|
|
292
|
+
* 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.
|
|
293
|
+
*/
|
|
294
|
+
export declare class TreeSet {
|
|
295
|
+
/**
|
|
296
|
+
* Creates a new TreeSet with the given elements and comparator.
|
|
297
|
+
*
|
|
298
|
+
* @param {*[]} [elements=[]] - The initial elements of the set.
|
|
299
|
+
* @param {(valueA:*, valueB:*) => number} [comparator=LeUtils.compare] - The comparator function to use for sorting.
|
|
300
|
+
*/
|
|
301
|
+
constructor(elements?: any[], comparator?: (valueA: any, valueB: any) => number);
|
|
302
|
+
/**
|
|
303
|
+
*
|
|
304
|
+
*
|
|
305
|
+
* @param {*} value - The value to search for in the set.
|
|
306
|
+
* @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).
|
|
307
|
+
* @private
|
|
308
|
+
*/
|
|
309
|
+
private binarySearch;
|
|
310
|
+
/**
|
|
311
|
+
* Returns the elements of the set.
|
|
312
|
+
*/
|
|
313
|
+
getElements(): any[];
|
|
314
|
+
/**
|
|
315
|
+
* Returns the comparator of the set.
|
|
316
|
+
*
|
|
317
|
+
* @returns {(valueA:*, valueB:*) => number}
|
|
318
|
+
*/
|
|
319
|
+
getComparator(): (valueA: any, valueB: any) => number;
|
|
320
|
+
/**
|
|
321
|
+
* Returns the size of the set.
|
|
322
|
+
*
|
|
323
|
+
* @returns {number}
|
|
324
|
+
*/
|
|
325
|
+
size(): number;
|
|
326
|
+
/**
|
|
327
|
+
* Returns true if the set is empty, false otherwise.
|
|
328
|
+
*
|
|
329
|
+
* @returns {boolean}
|
|
330
|
+
*/
|
|
331
|
+
isEmpty(): boolean;
|
|
332
|
+
/**
|
|
333
|
+
* Returns true if the set contains a value that is equal to the given value, returns false otherwise.
|
|
334
|
+
*
|
|
335
|
+
* @param {*} value - The value to check for in the set.
|
|
336
|
+
* @return {boolean} - True if the set contains the value, false otherwise.
|
|
337
|
+
*/
|
|
338
|
+
contains(value: any): boolean;
|
|
339
|
+
/**
|
|
340
|
+
* Returns the first element of the set, or undefined if it is empty.
|
|
341
|
+
*
|
|
342
|
+
* @return {*|undefined} - The first element of the set, or undefined if it is empty.
|
|
343
|
+
*/
|
|
344
|
+
first(): any | undefined;
|
|
345
|
+
/**
|
|
346
|
+
* Returns the last element of the set, or undefined if it is empty.
|
|
347
|
+
*
|
|
348
|
+
* @return {*|undefined} - The last element of the set, or undefined if it is empty.
|
|
349
|
+
*/
|
|
350
|
+
last(): any | undefined;
|
|
351
|
+
/**
|
|
352
|
+
* Removes and returns the first element of the set, or undefined if it is empty.
|
|
353
|
+
*
|
|
354
|
+
* @returns {*|undefined} - The first element of the set, or undefined if it is empty.
|
|
355
|
+
*/
|
|
356
|
+
pollFirst(): any | undefined;
|
|
357
|
+
/**
|
|
358
|
+
* Removes and returns the last element of the set, or undefined if it is empty.
|
|
359
|
+
*
|
|
360
|
+
* @returns {*|undefined} - The last element of the set, or undefined if it is empty.
|
|
361
|
+
*/
|
|
362
|
+
pollLast(): any | undefined;
|
|
363
|
+
/**
|
|
364
|
+
* Adds the given value to the set. Will only do so if no equal value already exists.
|
|
365
|
+
* @param {*} value - The value to add to the set.
|
|
366
|
+
*/
|
|
367
|
+
add(value: any): void;
|
|
368
|
+
/**
|
|
369
|
+
* Adds all the given values to the set. Will only do so if no equal value already exists.
|
|
370
|
+
*
|
|
371
|
+
* @param {*} values - The values to add to the set.
|
|
372
|
+
*/
|
|
373
|
+
addAll(values: any): void;
|
|
374
|
+
/**
|
|
375
|
+
* Returns an equal value that's already in the tree set, or undefined if no equal values in it exist.
|
|
376
|
+
*
|
|
377
|
+
* @param {*} value - The value to search for in the set.
|
|
378
|
+
* @return {*|undefined} - The equal value if found, or undefined if not found.
|
|
379
|
+
*/
|
|
380
|
+
getEqualValue(value: any): any | undefined;
|
|
381
|
+
/**
|
|
382
|
+
* 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.
|
|
383
|
+
*
|
|
384
|
+
* @param {*} value - The value to search for in the set.
|
|
385
|
+
* @return {*} - The equal value if found, or the added value if not found.
|
|
386
|
+
*/
|
|
387
|
+
getEqualValueOrAdd(value: any): any;
|
|
388
|
+
/**
|
|
389
|
+
* Returns a string representation of the TreeSet.
|
|
390
|
+
*
|
|
391
|
+
* @returns {string} - A string representation of the TreeSet, including its elements and comparator.
|
|
392
|
+
*/
|
|
393
|
+
toString(): string;
|
|
394
|
+
/**
|
|
395
|
+
* Returns a JSON representation of the TreeSet.
|
|
396
|
+
*
|
|
397
|
+
* @returns {Object} - An object containing the elements and comparator of the TreeSet.
|
|
398
|
+
*/
|
|
399
|
+
toJSON(): any;
|
|
400
|
+
#private;
|
|
401
|
+
}
|
|
402
|
+
|
|
302
403
|
export { }
|