@osmix/core 0.1.10 → 0.2.0
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/CHANGELOG.md +25 -0
- package/LICENSE +21 -0
- package/README.md +86 -69
- package/dist/contracts.d.ts +26 -0
- package/dist/contracts.d.ts.map +1 -0
- package/dist/contracts.js +1 -0
- package/dist/contracts.js.map +1 -0
- package/dist/entities.d.ts +1 -1
- package/dist/entities.d.ts.map +1 -1
- package/dist/entities.js +2 -7
- package/dist/entities.js.map +1 -1
- package/dist/ids.d.ts +2 -0
- package/dist/ids.d.ts.map +1 -1
- package/dist/ids.js +23 -15
- package/dist/ids.js.map +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +0 -1
- package/dist/index.js.map +1 -1
- package/dist/mocks.d.ts.map +1 -1
- package/dist/mocks.js.map +1 -1
- package/dist/nodes.d.ts +9 -3
- package/dist/nodes.d.ts.map +1 -1
- package/dist/nodes.js +6 -13
- package/dist/nodes.js.map +1 -1
- package/dist/osm.d.ts +1 -1
- package/dist/osm.d.ts.map +1 -1
- package/dist/osm.js +1 -4
- package/dist/osm.js.map +1 -1
- package/dist/relations.d.ts +3 -2
- package/dist/relations.d.ts.map +1 -1
- package/dist/relations.js +15 -9
- package/dist/relations.js.map +1 -1
- package/dist/stringtable.d.ts.map +1 -1
- package/dist/stringtable.js +4 -13
- package/dist/stringtable.js.map +1 -1
- package/dist/tags.d.ts +1 -1
- package/dist/tags.d.ts.map +1 -1
- package/dist/tags.js.map +1 -1
- package/dist/typed-arrays.d.ts.map +1 -1
- package/dist/typed-arrays.js.map +1 -1
- package/dist/ways.d.ts +2 -1
- package/dist/ways.d.ts.map +1 -1
- package/dist/ways.js +18 -18
- package/dist/ways.js.map +1 -1
- package/package.json +46 -31
- package/src/contracts.ts +28 -0
- package/src/entities.ts +179 -194
- package/src/ids.ts +228 -235
- package/src/index.ts +12 -9
- package/src/mocks.ts +114 -113
- package/src/nodes.ts +364 -397
- package/src/osm.ts +196 -207
- package/src/relations.ts +530 -558
- package/src/stringtable.ts +174 -183
- package/src/tags.ts +263 -271
- package/src/typed-arrays.ts +184 -194
- package/src/types/geoflatbush.d.ts +28 -33
- package/src/types/geokdbush.d.ts +28 -33
- package/src/types/kdbush.d.ts +34 -34
- package/src/ways.ts +381 -405
- package/test/ids.bench.ts +29 -0
- package/test/ids.test.ts +84 -0
- package/test/memory.test.ts +29 -30
- package/test/relations.bench.ts +27 -0
- package/test/relations.test.ts +101 -0
- package/test/tags-search.test.ts +76 -56
- package/test/typed-arrays.test.ts +100 -99
- package/tsconfig.build.json +6 -6
- package/tsconfig.json +7 -7
|
@@ -1,134 +1,135 @@
|
|
|
1
|
-
import { describe, expect, it } from "
|
|
2
|
-
|
|
1
|
+
import { describe, expect, it } from "vitest";
|
|
2
|
+
|
|
3
|
+
import { BufferConstructor, ResizeableTypedArray } from "../src/typed-arrays";
|
|
3
4
|
|
|
4
5
|
describe("typed array helpers", () => {
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
6
|
+
it("selects the appropriate buffer constructor", () => {
|
|
7
|
+
if (typeof SharedArrayBuffer !== "undefined") {
|
|
8
|
+
expect(BufferConstructor).toBe(SharedArrayBuffer);
|
|
9
|
+
} else {
|
|
10
|
+
expect(BufferConstructor).toBe(ArrayBuffer);
|
|
11
|
+
}
|
|
12
|
+
});
|
|
12
13
|
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
14
|
+
describe("ResizeableTypedArray", () => {
|
|
15
|
+
it("push stores values and returns the index", () => {
|
|
16
|
+
const arr = new ResizeableTypedArray(Float64Array);
|
|
16
17
|
|
|
17
|
-
|
|
18
|
-
|
|
18
|
+
const first = arr.push(1.5);
|
|
19
|
+
const second = arr.push(2.5);
|
|
19
20
|
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
21
|
+
expect(first).toBe(0);
|
|
22
|
+
expect(second).toBe(1);
|
|
23
|
+
expect(arr.length).toBe(2);
|
|
24
|
+
expect(arr.at(0)).toBe(1.5);
|
|
25
|
+
expect(arr.at(1)).toBe(2.5);
|
|
26
|
+
});
|
|
26
27
|
|
|
27
|
-
|
|
28
|
-
|
|
28
|
+
it("should push many values", () => {
|
|
29
|
+
const arr = new ResizeableTypedArray(Float64Array);
|
|
29
30
|
|
|
30
|
-
|
|
31
|
+
arr.pushMany([1.5, 2.5]);
|
|
31
32
|
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
33
|
+
expect(arr.length).toBe(2);
|
|
34
|
+
expect(arr.at(0)).toBe(1.5);
|
|
35
|
+
expect(arr.at(1)).toBe(2.5);
|
|
36
|
+
});
|
|
36
37
|
|
|
37
|
-
|
|
38
|
-
|
|
38
|
+
it("at supports negative indices and guards bounds", () => {
|
|
39
|
+
const arr = new ResizeableTypedArray(Int16Array);
|
|
39
40
|
|
|
40
|
-
|
|
41
|
+
arr.pushMany([10, 20, 30]);
|
|
41
42
|
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
43
|
+
expect(arr.length).toBe(3);
|
|
44
|
+
expect(Array.from(arr.slice(0, arr.length))).toEqual([10, 20, 30]);
|
|
45
|
+
expect(arr.at(-1)).toBe(30);
|
|
46
|
+
expect(arr.at(-3)).toBe(10);
|
|
47
|
+
expect(() => arr.at(-4)).toThrow(/Index out of bounds/);
|
|
48
|
+
expect(() => arr.at(3)).toThrow(/Index out of bounds/);
|
|
49
|
+
});
|
|
49
50
|
|
|
50
|
-
|
|
51
|
-
|
|
51
|
+
it("pushMany appends arrays while preserving order", () => {
|
|
52
|
+
const arr = new ResizeableTypedArray(Uint32Array);
|
|
52
53
|
|
|
53
|
-
|
|
54
|
-
|
|
54
|
+
arr.pushMany([1, 2, 3]);
|
|
55
|
+
arr.pushMany(Uint32Array.from([4, 5]));
|
|
55
56
|
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
57
|
+
expect(arr.length).toBe(5);
|
|
58
|
+
expect(Array.from(arr.slice(0, arr.length))).toEqual([1, 2, 3, 4, 5]);
|
|
59
|
+
});
|
|
59
60
|
|
|
60
|
-
|
|
61
|
-
|
|
61
|
+
it("slice returns a copy of the requested segment", () => {
|
|
62
|
+
const arr = new ResizeableTypedArray(Uint8Array);
|
|
62
63
|
|
|
63
|
-
|
|
64
|
+
arr.pushMany([1, 2, 3, 4]);
|
|
64
65
|
|
|
65
|
-
|
|
66
|
+
const segment = arr.slice(1, 3);
|
|
66
67
|
|
|
67
|
-
|
|
68
|
-
|
|
68
|
+
expect(segment).toBeInstanceOf(Uint8Array);
|
|
69
|
+
expect(Array.from(segment)).toEqual([2, 3]);
|
|
69
70
|
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
71
|
+
segment[0] = 99;
|
|
72
|
+
expect(arr.at(1)).toBe(2);
|
|
73
|
+
});
|
|
73
74
|
|
|
74
|
-
|
|
75
|
-
|
|
75
|
+
it("compact trims unused capacity", () => {
|
|
76
|
+
const arr = new ResizeableTypedArray(Float64Array);
|
|
76
77
|
|
|
77
|
-
|
|
78
|
+
arr.pushMany([5, 6, 7]);
|
|
78
79
|
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
80
|
+
const previousCapacity = arr.array.length;
|
|
81
|
+
const compacted = arr.compact();
|
|
82
|
+
const expectedByteLength = arr.length * Float64Array.BYTES_PER_ELEMENT;
|
|
82
83
|
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
84
|
+
expect(compacted).toBe(arr.array);
|
|
85
|
+
expect(compacted.length).toBe(arr.length);
|
|
86
|
+
expect(compacted.length).toBeLessThan(previousCapacity);
|
|
87
|
+
expect(arr.array.buffer.byteLength).toBe(expectedByteLength);
|
|
88
|
+
});
|
|
88
89
|
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
90
|
+
it("from reuses an existing buffer and grows when needed", () => {
|
|
91
|
+
const backing = new ArrayBuffer(16);
|
|
92
|
+
new Uint32Array(backing).set([1, 2, 3, 4]);
|
|
92
93
|
|
|
93
|
-
|
|
94
|
+
const arr = ResizeableTypedArray.from(Uint32Array, backing);
|
|
94
95
|
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
96
|
+
arr.bufferSize = arr.buffer.byteLength;
|
|
97
|
+
arr.maxByteLength = Math.max(arr.maxByteLength, arr.bufferSize * 2);
|
|
98
|
+
arr.items = arr.array.length;
|
|
98
99
|
|
|
99
|
-
|
|
100
|
-
|
|
100
|
+
expect(arr.length).toBe(4);
|
|
101
|
+
expect(Array.from(arr.slice(0, arr.length))).toEqual([1, 2, 3, 4]);
|
|
101
102
|
|
|
102
|
-
|
|
103
|
+
arr.push(5);
|
|
103
104
|
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
105
|
+
expect(arr.length).toBe(5);
|
|
106
|
+
expect(arr.array.length).toBe(8);
|
|
107
|
+
expect(Array.from(arr.slice(0, arr.length))).toEqual([1, 2, 3, 4, 5]);
|
|
108
|
+
});
|
|
108
109
|
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
110
|
+
if (typeof SharedArrayBuffer !== "undefined") {
|
|
111
|
+
it("grows shared buffers in place", () => {
|
|
112
|
+
const backing = new SharedArrayBuffer(8, {
|
|
113
|
+
maxByteLength: 32,
|
|
114
|
+
});
|
|
115
|
+
const seed = new Uint8Array(backing);
|
|
116
|
+
seed.set([1, 2, 3, 4, 5, 6, 7, 8]);
|
|
116
117
|
|
|
117
|
-
|
|
118
|
+
const arr = ResizeableTypedArray.from(Uint8Array, backing);
|
|
118
119
|
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
120
|
+
arr.bufferSize = arr.buffer.byteLength;
|
|
121
|
+
arr.maxByteLength = backing.maxByteLength;
|
|
122
|
+
arr.items = arr.array.length;
|
|
122
123
|
|
|
123
|
-
|
|
124
|
+
const originalBuffer = arr.buffer;
|
|
124
125
|
|
|
125
|
-
|
|
126
|
+
arr.push(9);
|
|
126
127
|
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
})
|
|
128
|
+
expect(arr.buffer).toBe(originalBuffer);
|
|
129
|
+
expect(arr.array.length).toBe(16);
|
|
130
|
+
expect(arr.buffer.byteLength).toBe(16);
|
|
131
|
+
expect(Array.from(arr.slice(0, 9))).toEqual([1, 2, 3, 4, 5, 6, 7, 8, 9]);
|
|
132
|
+
});
|
|
133
|
+
}
|
|
134
|
+
});
|
|
135
|
+
});
|
package/tsconfig.build.json
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
{
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
2
|
+
"$schema": "https://json.schemastore.org/tsconfig",
|
|
3
|
+
"extends": "./tsconfig.json",
|
|
4
|
+
"include": ["src"],
|
|
5
|
+
"compilerOptions": {
|
|
6
|
+
"rootDir": "./src"
|
|
7
|
+
}
|
|
8
8
|
}
|
package/tsconfig.json
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
{
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
2
|
+
"$schema": "https://json.schemastore.org/tsconfig",
|
|
3
|
+
"extends": "@osmix/shared/tsconfig/base.json",
|
|
4
|
+
"exclude": ["node_modules", "dist"],
|
|
5
|
+
"include": ["src", "test"],
|
|
6
|
+
"compilerOptions": {
|
|
7
|
+
"outDir": "./dist"
|
|
8
|
+
}
|
|
9
9
|
}
|