wenay-common 1.0.84 → 1.0.85
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/lib/Common/Common.d.ts +2 -0
- package/lib/Common/Common.js +42 -2
- package/package.json +1 -1
package/lib/Common/Common.d.ts
CHANGED
|
@@ -40,9 +40,11 @@ export declare namespace BSearch {
|
|
|
40
40
|
var LESS_OR_EQUAL: E_MATCH;
|
|
41
41
|
var GREAT_OR_EQUAL: E_MATCH;
|
|
42
42
|
}
|
|
43
|
+
export declare const BSearchAsync: typeof ___BSearchAsync;
|
|
43
44
|
export declare function BSearchDefault<T extends {
|
|
44
45
|
valueOf(): number;
|
|
45
46
|
}>(array: ArrayLike<T>, value: T, match?: SearchMatchMode, mode?: SortMode): number;
|
|
47
|
+
declare function ___BSearchAsync<T>(length: number, compareIndexToValue: (index: number) => Promise<number>, matchMode?: SearchMatchMode, sortMode?: SortMode): Promise<number>;
|
|
46
48
|
export declare function BSearchNearest(array: ArrayLike<number>, searchValue: number, maxDelta?: number): number;
|
|
47
49
|
export declare function BSearchNearest<T>(array: ArrayLike<T>, searchValue: number, arrayGetValue: (element: T) => number, maxDelta?: number): number;
|
|
48
50
|
export declare function _BSearchNearest<T>(array: ArrayLike<T>, searchValue: number, arrayGetValue: (element: T) => number, maxDelta?: number): number;
|
package/lib/Common/Common.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.
|
|
4
|
-
exports.isObjectCastableTo = void 0;
|
|
3
|
+
exports.CCachedValueT = exports.WeakMapExt = exports.MapExt = exports.CObjectID = exports.shallowEqual = exports.deepEqual = exports.copyToClipboard = exports.Mutex = exports.MyTimerInterval = exports.createCancellableTaskWrapper = exports.createCancellableTimer = exports.CancelablePromise = exports.CancelToken = exports.JSON_clone = exports.VirtualItems = exports.ArraySet = exports.ArrayMap = exports.StructSet = exports.StructMap = exports.MyNumMap = exports.MyMap = exports.__MyMap = exports.CreateArrayProxy = exports.ArrayItemHandler = exports.DblToStrAuto = exports.GetDblPrecision = exports.GetDblPrecision2 = exports.MaxCommonDivisorOnArray = exports.MaxCommonDivisor = exports.NormalizeDouble = exports._BSearchNearest = exports.BSearchNearest = exports.BSearchDefault = exports.BSearchAsync = exports.BSearch = exports.E_MATCH = exports.E_SORTMODE = exports.GetEnumValues = exports.CBase = exports.sleepAsync = exports.readonlyFull = exports.toImmutable = exports.deepCloneObjectMutable = exports.deepCloneObject = exports.deepCloneMutable = exports.deepClone = exports._deepClone = exports.shallowClone = exports.isDate = exports.GetEnumKeys = void 0;
|
|
4
|
+
exports.isObjectCastableTo = exports.CCachedValue2 = void 0;
|
|
5
5
|
function GetEnumKeys(T) { return Object.keys(T).filter(k => isNaN(k)); }
|
|
6
6
|
exports.GetEnumKeys = GetEnumKeys;
|
|
7
7
|
function isDate(value) {
|
|
@@ -103,6 +103,8 @@ function BSearch(array, arg2, arg3, ...args) {
|
|
|
103
103
|
BSearchDefault(array, arg2, arg3, ...args);
|
|
104
104
|
}
|
|
105
105
|
exports.BSearch = BSearch;
|
|
106
|
+
const BSearchAsync = (...a) => ___BSearchAsync(...a);
|
|
107
|
+
exports.BSearchAsync = BSearchAsync;
|
|
106
108
|
function BSearchDefault(array, value, match, mode) {
|
|
107
109
|
return __BSearch(array, value, (a, b) => Math.sign(a.valueOf() - b.valueOf()), match, mode);
|
|
108
110
|
}
|
|
@@ -110,6 +112,44 @@ exports.BSearchDefault = BSearchDefault;
|
|
|
110
112
|
function __BSearch(array, value, comparer, matchMode, sortMode) {
|
|
111
113
|
return ___BSearch(array, (item) => comparer(item, value), matchMode, sortMode);
|
|
112
114
|
}
|
|
115
|
+
async function ___BSearchAsync(length, compareIndexToValue, matchMode, sortMode) {
|
|
116
|
+
if (sortMode == undefined)
|
|
117
|
+
sortMode = E_SORTMODE.ASCEND;
|
|
118
|
+
let k = (sortMode === E_SORTMODE.DESCEND || sortMode == "descend" ? -1 : sortMode === E_SORTMODE.ASCEND || sortMode == "ascend" ? 1 : (() => { throw "wrong sortMode: " + JSON.stringify(sortMode); })());
|
|
119
|
+
let match = typeof matchMode != "string" ? matchMode : matchMode == "equal" ? E_MATCH.EQUAL : matchMode == "lessOrEqual" ? E_MATCH.LESS_OR_EQUAL : matchMode == "greatOrEqual" ? E_MATCH.GREAT_OR_EQUAL : (() => { throw ("wrong matchMode!"); })();
|
|
120
|
+
let start = 0;
|
|
121
|
+
let count = length;
|
|
122
|
+
let end = start + count - 1;
|
|
123
|
+
let left = start;
|
|
124
|
+
let right = end;
|
|
125
|
+
let i = left;
|
|
126
|
+
while (left <= right) {
|
|
127
|
+
i = (left + right) >> 1;
|
|
128
|
+
let cmp = await compareIndexToValue(i) * k;
|
|
129
|
+
if (cmp > 0) {
|
|
130
|
+
right = i - 1;
|
|
131
|
+
continue;
|
|
132
|
+
}
|
|
133
|
+
if (cmp < 0) {
|
|
134
|
+
left = i + 1;
|
|
135
|
+
continue;
|
|
136
|
+
}
|
|
137
|
+
return i;
|
|
138
|
+
}
|
|
139
|
+
if (match == E_MATCH.LESS_OR_EQUAL) {
|
|
140
|
+
i = right;
|
|
141
|
+
if (i < start)
|
|
142
|
+
i = -1;
|
|
143
|
+
}
|
|
144
|
+
else if (match == E_MATCH.GREAT_OR_EQUAL) {
|
|
145
|
+
i = left;
|
|
146
|
+
if (i > end)
|
|
147
|
+
i = -1;
|
|
148
|
+
}
|
|
149
|
+
else
|
|
150
|
+
i = -1;
|
|
151
|
+
return i;
|
|
152
|
+
}
|
|
113
153
|
function ___BSearch(array, compareItemToValue, matchMode, sortMode) {
|
|
114
154
|
if (sortMode == undefined)
|
|
115
155
|
sortMode = E_SORTMODE.ASCEND;
|