@noldova/context.collections 0.0.1 → 0.0.3
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/README.md +32 -0
- package/package.json +1 -1
package/README.md
ADDED
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
# noldova.context.collections
|
|
2
|
+
|
|
3
|
+
Collection algorithms for CONTEXT libraries. Today it holds
|
|
4
|
+
`BinarySearchService`, which finds positions in ascending numeric arrays, such
|
|
5
|
+
as the line that holds a character offset.
|
|
6
|
+
|
|
7
|
+
## Install
|
|
8
|
+
|
|
9
|
+
```bash
|
|
10
|
+
npm install @noldova/context.collections
|
|
11
|
+
```
|
|
12
|
+
|
|
13
|
+
## Use
|
|
14
|
+
|
|
15
|
+
```ts
|
|
16
|
+
import { BinarySearchService } from "@noldova/context.collections";
|
|
17
|
+
|
|
18
|
+
const lineStarts = [0, 12, 30, 41];
|
|
19
|
+
|
|
20
|
+
BinarySearchService.floorIndex(lineStarts, 30); // 2: an exact match.
|
|
21
|
+
BinarySearchService.floorIndex(lineStarts, 35); // 2: the nearest lower value is 30.
|
|
22
|
+
BinarySearchService.floorIndex(lineStarts, 0); // 0
|
|
23
|
+
BinarySearchService.floorIndex([], 5); // -1: no value qualifies.
|
|
24
|
+
```
|
|
25
|
+
|
|
26
|
+
The array must be sorted from smallest to greatest; the search does not check
|
|
27
|
+
or change it. The declaration file `api/index.d.ts` documents every member with
|
|
28
|
+
its contract and examples.
|
|
29
|
+
|
|
30
|
+
## License
|
|
31
|
+
|
|
32
|
+
MIT; see `LICENSE`.
|