@noldova/context.collections 0.0.0-stage → 0.0.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/LICENSE +21 -0
- package/api/index.d.ts +40 -0
- package/api/index.js +9 -0
- package/api/index.js.map +1 -0
- package/package.json +19 -4
- package/services/binary-search.service.js +22 -0
- package/services/binary-search.service.js.map +1 -0
- package/README.md +0 -3
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) Noldova
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/api/index.d.ts
ADDED
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @license
|
|
3
|
+
* Copyright (c) Noldova.
|
|
4
|
+
*
|
|
5
|
+
* This source code is licensed under the license found in the
|
|
6
|
+
* LICENSE file in the root directory of this source tree.
|
|
7
|
+
*/
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* Provides binary-search operations for ascending numeric arrays.
|
|
11
|
+
*/
|
|
12
|
+
export declare class BinarySearchService {
|
|
13
|
+
/**
|
|
14
|
+
* Finds the last array position whose value is less than or equal to the target.
|
|
15
|
+
*
|
|
16
|
+
* @param values The numbers to search, sorted from smallest to greatest.
|
|
17
|
+
* Equal consecutive values are allowed.
|
|
18
|
+
* @param target The inclusive comparison limit. An exact match is not required;
|
|
19
|
+
* when none exists, the search finds the nearest lower value.
|
|
20
|
+
* @returns The zero-based index of the last qualifying value. If that value
|
|
21
|
+
* occurs more than once, returns its last index. Returns `-1` when no value
|
|
22
|
+
* qualifies, including an empty array or a target below the first value.
|
|
23
|
+
*
|
|
24
|
+
* @remarks
|
|
25
|
+
* Ordering is a caller precondition and is not checked. The method does not sort,
|
|
26
|
+
* modify, copy, or retain the array. It performs O(log n) comparisons and uses
|
|
27
|
+
* O(1) additional storage, where n is the number of values.
|
|
28
|
+
*
|
|
29
|
+
* @example
|
|
30
|
+
* ```ts
|
|
31
|
+
* BinarySearchService.floorIndex([1, 3, 5, 7], 5); // 2: exact match.
|
|
32
|
+
* BinarySearchService.floorIndex([1, 3, 5, 7], 4); // 1: the nearest lower value is 3.
|
|
33
|
+
* BinarySearchService.floorIndex([1, 3, 3, 5], 3); // 2: the last duplicate.
|
|
34
|
+
* BinarySearchService.floorIndex([1, 3, 5], 9); // 2: the last value is below the target.
|
|
35
|
+
* BinarySearchService.floorIndex([1, 3, 5], 0); // -1: all values exceed the target.
|
|
36
|
+
* BinarySearchService.floorIndex([], 5); // -1: the array is empty.
|
|
37
|
+
* ```
|
|
38
|
+
*/
|
|
39
|
+
public static floorIndex(values: readonly number[], target: number): number;
|
|
40
|
+
}
|
package/api/index.js
ADDED
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @license
|
|
3
|
+
* Copyright (c) Noldova.
|
|
4
|
+
*
|
|
5
|
+
* This source code is licensed under the license found in the
|
|
6
|
+
* LICENSE file in the root directory of this source tree.
|
|
7
|
+
*/
|
|
8
|
+
export { BinarySearchService } from "../services/binary-search.service.js";
|
|
9
|
+
//# sourceMappingURL=index.js.map
|
package/api/index.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../src/noldova.context.collections/src/api/index.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,OAAO,EAAE,mBAAmB,EAAE,MAAM,sCAAsC,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,21 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@noldova/context.collections",
|
|
3
|
-
"version": "0.0.
|
|
4
|
-
"
|
|
5
|
-
"
|
|
6
|
-
|
|
3
|
+
"version": "0.0.2",
|
|
4
|
+
"type": "module",
|
|
5
|
+
"main": "api/index.js",
|
|
6
|
+
"types": "api/index.d.ts",
|
|
7
|
+
"license": "MIT",
|
|
8
|
+
"repository": {
|
|
9
|
+
"type": "git",
|
|
10
|
+
"url": "git+https://github.com/noldova-com/context.git",
|
|
11
|
+
"directory": "src/noldova.context.collections"
|
|
12
|
+
},
|
|
13
|
+
"homepage": "https://github.com/noldova-com/context#readme",
|
|
14
|
+
"bugs": {
|
|
15
|
+
"url": "https://github.com/noldova-com/context/issues"
|
|
16
|
+
},
|
|
17
|
+
"publishConfig": {
|
|
18
|
+
"access": "public",
|
|
19
|
+
"registry": "https://registry.npmjs.org/"
|
|
20
|
+
}
|
|
21
|
+
}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @license
|
|
3
|
+
* Copyright (c) Noldova.
|
|
4
|
+
*
|
|
5
|
+
* This source code is licensed under the license found in the
|
|
6
|
+
* LICENSE file in the root directory of this source tree.
|
|
7
|
+
*/
|
|
8
|
+
export class BinarySearchService {
|
|
9
|
+
static floorIndex(values, target) {
|
|
10
|
+
let lowerIndex = 0;
|
|
11
|
+
let upperIndex = values.length - 1;
|
|
12
|
+
while (lowerIndex <= upperIndex) {
|
|
13
|
+
const middleIndex = lowerIndex + ((upperIndex - lowerIndex) >>> 1);
|
|
14
|
+
if (values[middleIndex] <= target)
|
|
15
|
+
lowerIndex = middleIndex + 1;
|
|
16
|
+
else
|
|
17
|
+
upperIndex = middleIndex - 1;
|
|
18
|
+
}
|
|
19
|
+
return upperIndex;
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
//# sourceMappingURL=binary-search.service.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"binary-search.service.js","sourceRoot":"","sources":["../../../../src/noldova.context.collections/src/services/binary-search.service.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,MAAM,OAAO,mBAAmB;IACvB,MAAM,CAAC,UAAU,CAAC,MAAyB,EAAE,MAAc;QAChE,IAAI,UAAU,GAAG,CAAC,CAAC;QACnB,IAAI,UAAU,GAAG,MAAM,CAAC,MAAM,GAAG,CAAC,CAAC;QAEnC,OAAO,UAAU,IAAI,UAAU,EAAE,CAAC;YAChC,MAAM,WAAW,GAAG,UAAU,GAAG,CAAC,CAAC,UAAU,GAAG,UAAU,CAAC,KAAK,CAAC,CAAC,CAAC;YACnE,IAAI,MAAM,CAAC,WAAW,CAAE,IAAI,MAAM;gBAChC,UAAU,GAAG,WAAW,GAAG,CAAC,CAAC;;gBAE7B,UAAU,GAAG,WAAW,GAAG,CAAC,CAAC;QACjC,CAAC;QAED,OAAO,UAAU,CAAC;IACpB,CAAC;CACF"}
|
package/README.md
DELETED