goscript 0.0.39 → 0.0.40
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/compiler/analysis.go +15 -6
- package/compiler/compiler.go +184 -34
- package/compiler/expr-call.go +7 -9
- package/compiler/field.go +17 -3
- package/compiler/gs_dependencies_test.go +80 -0
- package/compiler/lit.go +1 -6
- package/compiler/output.go +10 -4
- package/compiler/spec.go +15 -2
- package/compiler/type-assert.go +111 -21
- package/compiler/type.go +37 -8
- package/dist/gs/builtin/builtin.d.ts +10 -0
- package/dist/gs/builtin/builtin.js +16 -0
- package/dist/gs/builtin/builtin.js.map +1 -1
- package/dist/gs/builtin/slice.js +13 -0
- package/dist/gs/builtin/slice.js.map +1 -1
- package/dist/gs/bytes/bytes.gs.js +110 -14
- package/dist/gs/bytes/bytes.gs.js.map +1 -1
- package/dist/gs/fmt/fmt.d.ts +49 -0
- package/dist/gs/fmt/fmt.js +322 -0
- package/dist/gs/fmt/fmt.js.map +1 -0
- package/dist/gs/fmt/index.d.ts +1 -0
- package/dist/gs/fmt/index.js +2 -0
- package/dist/gs/fmt/index.js.map +1 -0
- package/dist/gs/path/filepath/index.d.ts +3 -0
- package/dist/gs/path/filepath/index.js +3 -0
- package/dist/gs/path/filepath/index.js.map +1 -0
- package/dist/gs/path/filepath/match.d.ts +3 -0
- package/dist/gs/path/filepath/match.js +212 -0
- package/dist/gs/path/filepath/match.js.map +1 -0
- package/dist/gs/path/filepath/path.d.ts +25 -0
- package/dist/gs/path/filepath/path.js +265 -0
- package/dist/gs/path/filepath/path.js.map +1 -0
- package/dist/gs/reflect/value.js +13 -5
- package/dist/gs/reflect/value.js.map +1 -1
- package/dist/gs/sort/index.d.ts +4 -0
- package/dist/gs/sort/index.js +4 -0
- package/dist/gs/sort/index.js.map +1 -0
- package/dist/gs/sort/search.gs.d.ts +6 -0
- package/dist/gs/sort/search.gs.js +125 -0
- package/dist/gs/sort/search.gs.js.map +1 -0
- package/dist/gs/sort/slice.gs.d.ts +4 -0
- package/dist/gs/sort/slice.gs.js +49 -0
- package/dist/gs/sort/slice.gs.js.map +1 -0
- package/dist/gs/sort/sort.gs.d.ts +37 -0
- package/dist/gs/sort/sort.gs.js +203 -0
- package/dist/gs/sort/sort.gs.js.map +1 -0
- package/gs/builtin/builtin.ts +17 -0
- package/gs/builtin/slice.ts +17 -1
- package/gs/bytes/bytes.gs.ts +122 -14
- package/gs/bytes/metadata.go +12 -0
- package/gs/fmt/fmt.ts +407 -0
- package/gs/fmt/godoc.txt +382 -0
- package/gs/fmt/index.ts +31 -0
- package/gs/fmt/metadata.go +7 -0
- package/gs/internal/metadata.go +7 -0
- package/gs/io/metadata.go +11 -0
- package/gs/maps/metadata.go +8 -0
- package/gs/math/metadata.go +7 -0
- package/gs/os/metadata.go +17 -0
- package/gs/path/filepath/godoc.txt +35 -0
- package/gs/path/filepath/index.ts +27 -0
- package/gs/path/filepath/match.test.ts +274 -0
- package/gs/path/filepath/match.ts +249 -0
- package/gs/path/filepath/path.test.ts +246 -0
- package/gs/path/filepath/path.ts +328 -0
- package/gs/path/metadata.go +8 -0
- package/gs/reflect/metadata.go +7 -0
- package/gs/reflect/value.ts +13 -5
- package/gs/sort/godoc.txt +27 -0
- package/gs/sort/index.ts +24 -0
- package/gs/sort/search.gs.ts +128 -0
- package/gs/sort/slice.gs.ts +59 -0
- package/gs/sort/sort.gs.ts +227 -0
- package/gs/strconv/metadata.go +7 -0
- package/gs/strings/metadata.go +11 -0
- package/gs/sync/metadata.go +7 -0
- package/package.json +1 -1
|
@@ -0,0 +1,265 @@
|
|
|
1
|
+
// Package filepath implements utility routines for manipulating filename paths
|
|
2
|
+
// in a way compatible with the target operating system-defined file paths.
|
|
3
|
+
// Path separator constants
|
|
4
|
+
export const Separator = '/';
|
|
5
|
+
export const ListSeparator = ':';
|
|
6
|
+
// Error constants
|
|
7
|
+
export const SkipDir = new Error('skip this directory');
|
|
8
|
+
export const SkipAll = new Error('skip everything and stop the walk');
|
|
9
|
+
// Base returns the last element of path.
|
|
10
|
+
// Trailing path separators are removed before extracting the last element.
|
|
11
|
+
// If the path is empty, Base returns ".".
|
|
12
|
+
// If the path consists entirely of separators, Base returns a single separator.
|
|
13
|
+
export function Base(path) {
|
|
14
|
+
if (path === '') {
|
|
15
|
+
return '.';
|
|
16
|
+
}
|
|
17
|
+
// Strip trailing slashes
|
|
18
|
+
path = path.replace(/\/+$/, '');
|
|
19
|
+
if (path === '') {
|
|
20
|
+
return '/';
|
|
21
|
+
}
|
|
22
|
+
// Find the last slash
|
|
23
|
+
const i = path.lastIndexOf('/');
|
|
24
|
+
if (i >= 0) {
|
|
25
|
+
return path.substring(i + 1);
|
|
26
|
+
}
|
|
27
|
+
return path;
|
|
28
|
+
}
|
|
29
|
+
// Dir returns all but the last element of path, typically the path's directory.
|
|
30
|
+
// After dropping the final element, Dir calls Clean on the path and trailing
|
|
31
|
+
// slashes are removed. If the path is empty, Dir returns ".".
|
|
32
|
+
// If the path consists entirely of separators, Dir returns a single separator.
|
|
33
|
+
export function Dir(path) {
|
|
34
|
+
if (path === '') {
|
|
35
|
+
return '.';
|
|
36
|
+
}
|
|
37
|
+
// Strip trailing slashes
|
|
38
|
+
path = path.replace(/\/+$/, '');
|
|
39
|
+
if (path === '') {
|
|
40
|
+
return '/';
|
|
41
|
+
}
|
|
42
|
+
// Find the last slash
|
|
43
|
+
const i = path.lastIndexOf('/');
|
|
44
|
+
if (i >= 0) {
|
|
45
|
+
const dir = path.substring(0, i);
|
|
46
|
+
return Clean(dir === '' ? '/' : dir);
|
|
47
|
+
}
|
|
48
|
+
return '.';
|
|
49
|
+
}
|
|
50
|
+
// Ext returns the file name extension used by path.
|
|
51
|
+
// The extension is the suffix beginning at the final dot
|
|
52
|
+
// in the final element of path; it is empty if there is no dot.
|
|
53
|
+
export function Ext(path) {
|
|
54
|
+
const base = Base(path);
|
|
55
|
+
// Handle special case: if the base starts with a dot and has no other dots,
|
|
56
|
+
// it's a hidden file with no extension
|
|
57
|
+
if (base.startsWith('.') && base.indexOf('.', 1) === -1) {
|
|
58
|
+
return '';
|
|
59
|
+
}
|
|
60
|
+
const i = base.lastIndexOf('.');
|
|
61
|
+
if (i >= 0) {
|
|
62
|
+
return base.substring(i);
|
|
63
|
+
}
|
|
64
|
+
return '';
|
|
65
|
+
}
|
|
66
|
+
// Clean returns the shortest path name equivalent to path
|
|
67
|
+
// by purely lexical processing.
|
|
68
|
+
export function Clean(path) {
|
|
69
|
+
if (path === '') {
|
|
70
|
+
return '.';
|
|
71
|
+
}
|
|
72
|
+
const isAbs = path.startsWith('/');
|
|
73
|
+
const segments = path
|
|
74
|
+
.split('/')
|
|
75
|
+
.filter((segment) => segment !== '' && segment !== '.');
|
|
76
|
+
const result = [];
|
|
77
|
+
for (const segment of segments) {
|
|
78
|
+
if (segment === '..') {
|
|
79
|
+
if (result.length > 0 && result[result.length - 1] !== '..') {
|
|
80
|
+
result.pop();
|
|
81
|
+
}
|
|
82
|
+
else if (!isAbs) {
|
|
83
|
+
result.push('..');
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
else {
|
|
87
|
+
result.push(segment);
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
let cleaned = result.join('/');
|
|
91
|
+
if (isAbs) {
|
|
92
|
+
cleaned = '/' + cleaned;
|
|
93
|
+
}
|
|
94
|
+
return (cleaned === '' ?
|
|
95
|
+
isAbs ? '/'
|
|
96
|
+
: '.'
|
|
97
|
+
: cleaned);
|
|
98
|
+
}
|
|
99
|
+
// Join joins any number of path elements into a single path,
|
|
100
|
+
// separating them with an OS specific Separator. Empty elements
|
|
101
|
+
// are ignored. The result is Cleaned. However, if the argument
|
|
102
|
+
// list is empty or all its elements are empty, Join returns
|
|
103
|
+
// an empty string.
|
|
104
|
+
export function Join(...elem) {
|
|
105
|
+
if (elem.length === 0) {
|
|
106
|
+
return '';
|
|
107
|
+
}
|
|
108
|
+
// Filter out empty elements but handle absolute paths
|
|
109
|
+
const parts = [];
|
|
110
|
+
for (const e of elem) {
|
|
111
|
+
if (e === '') {
|
|
112
|
+
continue;
|
|
113
|
+
}
|
|
114
|
+
// If this element is absolute, start over from here
|
|
115
|
+
if (IsAbs(e)) {
|
|
116
|
+
parts.length = 0; // Clear previous parts
|
|
117
|
+
parts.push(e);
|
|
118
|
+
}
|
|
119
|
+
else {
|
|
120
|
+
parts.push(e);
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
if (parts.length === 0) {
|
|
124
|
+
return '';
|
|
125
|
+
}
|
|
126
|
+
return Clean(parts.join('/'));
|
|
127
|
+
}
|
|
128
|
+
// Split splits path immediately following the final Separator,
|
|
129
|
+
// separating it into a directory and file name component.
|
|
130
|
+
// If there is no Separator in path, Split returns an empty dir
|
|
131
|
+
// and file set to path. The returned values have the property
|
|
132
|
+
// that path = dir+file.
|
|
133
|
+
export function Split(path) {
|
|
134
|
+
const i = path.lastIndexOf('/');
|
|
135
|
+
if (i < 0) {
|
|
136
|
+
return ['', path];
|
|
137
|
+
}
|
|
138
|
+
return [path.substring(0, i + 1), path.substring(i + 1)];
|
|
139
|
+
}
|
|
140
|
+
// IsAbs reports whether the path is absolute.
|
|
141
|
+
export function IsAbs(path) {
|
|
142
|
+
return path.startsWith('/');
|
|
143
|
+
}
|
|
144
|
+
// ToSlash returns the result of replacing each separator character
|
|
145
|
+
// in path with a slash ('/') character. Multiple separators are
|
|
146
|
+
// replaced by multiple slashes.
|
|
147
|
+
export function ToSlash(path) {
|
|
148
|
+
// On Unix-like systems (including our JS environment), the separator is already '/'
|
|
149
|
+
// so backslashes are just regular characters and should not be converted
|
|
150
|
+
// This matches Go's behavior on Unix systems
|
|
151
|
+
return path;
|
|
152
|
+
}
|
|
153
|
+
// FromSlash returns the result of replacing each slash ('/') character
|
|
154
|
+
// in path with a separator character. Multiple slashes are replaced
|
|
155
|
+
// by multiple separators.
|
|
156
|
+
export function FromSlash(path) {
|
|
157
|
+
// On Unix-like systems (including our JS environment), separator is '/'
|
|
158
|
+
// so no conversion needed
|
|
159
|
+
return path;
|
|
160
|
+
}
|
|
161
|
+
// VolumeName returns leading volume name.
|
|
162
|
+
// Given "C:\foo\bar" it returns "C:" on Windows.
|
|
163
|
+
// Given "\\host\share\foo" it returns "\\host\share".
|
|
164
|
+
// On other systems, it returns "".
|
|
165
|
+
export function VolumeName(_path) {
|
|
166
|
+
// In our JS environment, we don't have volume names
|
|
167
|
+
return '';
|
|
168
|
+
}
|
|
169
|
+
// IsLocal reports whether path, using lexical analysis only,
|
|
170
|
+
// has all of these properties:
|
|
171
|
+
// - is within the subtree rooted at the directory in which path is evaluated
|
|
172
|
+
// - is not an absolute path
|
|
173
|
+
// - is not empty
|
|
174
|
+
// - on Windows, is not a reserved name such as "NUL"
|
|
175
|
+
export function IsLocal(path) {
|
|
176
|
+
if (path === '' || IsAbs(path)) {
|
|
177
|
+
return false;
|
|
178
|
+
}
|
|
179
|
+
// Check for .. components that would escape
|
|
180
|
+
const segments = path.split('/');
|
|
181
|
+
let depth = 0;
|
|
182
|
+
for (const segment of segments) {
|
|
183
|
+
if (segment === '..') {
|
|
184
|
+
depth--;
|
|
185
|
+
if (depth < 0) {
|
|
186
|
+
return false;
|
|
187
|
+
}
|
|
188
|
+
}
|
|
189
|
+
else if (segment !== '.' && segment !== '') {
|
|
190
|
+
depth++;
|
|
191
|
+
}
|
|
192
|
+
}
|
|
193
|
+
return true;
|
|
194
|
+
}
|
|
195
|
+
// SplitList splits a list of paths joined by the OS-specific ListSeparator,
|
|
196
|
+
// usually found in PATH or GOPATH environment variables.
|
|
197
|
+
// Unlike strings.Split, SplitList returns an empty slice when passed an empty string.
|
|
198
|
+
export function SplitList(path) {
|
|
199
|
+
if (path === '') {
|
|
200
|
+
return [];
|
|
201
|
+
}
|
|
202
|
+
return path.split(ListSeparator);
|
|
203
|
+
}
|
|
204
|
+
// HasPrefix tests whether the path p begins with prefix.
|
|
205
|
+
export function HasPrefix(p, prefix) {
|
|
206
|
+
if (prefix === '') {
|
|
207
|
+
return true;
|
|
208
|
+
}
|
|
209
|
+
// Normalize both paths
|
|
210
|
+
const normalP = Clean(p);
|
|
211
|
+
const normalPrefix = Clean(prefix);
|
|
212
|
+
if (normalP === normalPrefix) {
|
|
213
|
+
return true;
|
|
214
|
+
}
|
|
215
|
+
// Check if p starts with prefix followed by a separator
|
|
216
|
+
if (normalP.startsWith(normalPrefix)) {
|
|
217
|
+
const remaining = normalP.substring(normalPrefix.length);
|
|
218
|
+
return remaining.startsWith('/');
|
|
219
|
+
}
|
|
220
|
+
return false;
|
|
221
|
+
}
|
|
222
|
+
// Stubs for functions that require filesystem operations
|
|
223
|
+
// These are simplified implementations for compatibility
|
|
224
|
+
export function Abs(path) {
|
|
225
|
+
if (IsAbs(path)) {
|
|
226
|
+
return [Clean(path), null];
|
|
227
|
+
}
|
|
228
|
+
// In a real implementation, this would resolve relative to current working directory
|
|
229
|
+
// For our purposes, we'll just prepend a fake absolute path
|
|
230
|
+
return ['/' + Clean(path), null];
|
|
231
|
+
}
|
|
232
|
+
export function Rel(basepath, targpath) {
|
|
233
|
+
// Simplified implementation - in reality this is much more complex
|
|
234
|
+
const base = Clean(basepath);
|
|
235
|
+
const targ = Clean(targpath);
|
|
236
|
+
if (base === targ) {
|
|
237
|
+
return ['.', null];
|
|
238
|
+
}
|
|
239
|
+
// Very basic relative path calculation
|
|
240
|
+
if (targ.startsWith(base + '/')) {
|
|
241
|
+
return [targ.substring(base.length + 1), null];
|
|
242
|
+
}
|
|
243
|
+
return [targ, null];
|
|
244
|
+
}
|
|
245
|
+
export function EvalSymlinks(path) {
|
|
246
|
+
// No filesystem support, just return the cleaned path
|
|
247
|
+
return [Clean(path), null];
|
|
248
|
+
}
|
|
249
|
+
export function Glob(_pattern) {
|
|
250
|
+
// No filesystem support, return empty array
|
|
251
|
+
return [[], null];
|
|
252
|
+
}
|
|
253
|
+
export function Walk(root, walkFn) {
|
|
254
|
+
// No filesystem support, just call the function with the root
|
|
255
|
+
return walkFn(root, null, new Error('filesystem not supported'));
|
|
256
|
+
}
|
|
257
|
+
export function WalkDir(_root, _walkFn) {
|
|
258
|
+
// No filesystem support
|
|
259
|
+
return new Error('filesystem not supported');
|
|
260
|
+
}
|
|
261
|
+
// Localize is a stub - in Go it's used for Windows path localization
|
|
262
|
+
export function Localize(path) {
|
|
263
|
+
return [path, null];
|
|
264
|
+
}
|
|
265
|
+
//# sourceMappingURL=path.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"path.js","sourceRoot":"","sources":["../../../../gs/path/filepath/path.ts"],"names":[],"mappings":"AAAA,+EAA+E;AAC/E,2EAA2E;AAE3E,2BAA2B;AAC3B,MAAM,CAAC,MAAM,SAAS,GAAG,GAAG,CAAA;AAC5B,MAAM,CAAC,MAAM,aAAa,GAAG,GAAG,CAAA;AAEhC,kBAAkB;AAClB,MAAM,CAAC,MAAM,OAAO,GAAG,IAAI,KAAK,CAAC,qBAAqB,CAAC,CAAA;AACvD,MAAM,CAAC,MAAM,OAAO,GAAG,IAAI,KAAK,CAAC,mCAAmC,CAAC,CAAA;AAErE,yCAAyC;AACzC,2EAA2E;AAC3E,0CAA0C;AAC1C,gFAAgF;AAChF,MAAM,UAAU,IAAI,CAAC,IAAY;IAC/B,IAAI,IAAI,KAAK,EAAE,EAAE,CAAC;QAChB,OAAO,GAAG,CAAA;IACZ,CAAC;IAED,yBAAyB;IACzB,IAAI,GAAG,IAAI,CAAC,OAAO,CAAC,MAAM,EAAE,EAAE,CAAC,CAAA;IAE/B,IAAI,IAAI,KAAK,EAAE,EAAE,CAAC;QAChB,OAAO,GAAG,CAAA;IACZ,CAAC;IAED,sBAAsB;IACtB,MAAM,CAAC,GAAG,IAAI,CAAC,WAAW,CAAC,GAAG,CAAC,CAAA;IAC/B,IAAI,CAAC,IAAI,CAAC,EAAE,CAAC;QACX,OAAO,IAAI,CAAC,SAAS,CAAC,CAAC,GAAG,CAAC,CAAC,CAAA;IAC9B,CAAC;IAED,OAAO,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B,MAAM,IAAI,GAAG,KAAK,CAAC,QAAQ,CAAC,CAAA;IAE5B,IAAI,IAAI,KAAK,IAAI,EAAE,CAAC;QAClB,OAAO,CAAC,GAAG,EAAE,IAAI,CAAC,CAAA;IACpB,CAAC;IAED,uCAAuC;IACvC,IAAI,IAAI,CAAC,UAAU,CAAC,IAAI,GAAG,GAAG,CAAC,EAAE,CAAC;QAChC,OAAO,CAAC,IAAI,CAAC,SAAS,CAAC,IAAI,CAAC,MAAM,GAAG,CAAC,CAAC,EAAE,IAAI,CAAC,CAAA;IAChD,CAAC;IAED,OAAO,CAAC,IAAI,EAAE,IAAI,CAAC,CAAA;AACrB,CAAC;AAED,MAAM,UAAU,YAAY,CAAC,IAAY;IACvC,sDAAsD;IACtD,OAAO,CAAC,KAAK,CAAC,IAAI,CAAC,EAAE,IAAI,CAAC,CAAA;AAC5B,CAAC;AAED,MAAM,UAAU,IAAI,CAAC,QAAgB;IACnC,4CAA4C;IAC5C,OAAO,CAAC,EAAE,EAAE,IAAI,CAAC,CAAA;AACnB,CAAC;AAaD,MAAM,UAAU,IAAI,CAAC,IAAY,EAAE,MAAgB;IACjD,8DAA8D;IAC9D,OAAO,MAAM,CAAC,IAAI,EAAE,IAAI,EAAE,IAAI,KAAK,CAAC,0BAA0B,CAAC,CAAC,CAAA;AAClE,CAAC;AAED,MAAM,UAAU,OAAO,CAAC,KAAa,EAAE,OAAY;IACjD,wBAAwB;IACxB,OAAO,IAAI,KAAK,CAAC,0BAA0B,CAAC,CAAA;AAC9C,CAAC;AAED,qEAAqE;AACrE,MAAM,UAAU,QAAQ,CAAC,IAAY;IACnC,OAAO,CAAC,IAAI,EAAE,IAAI,CAAC,CAAA;AACrB,CAAC"}
|
package/dist/gs/reflect/value.js
CHANGED
|
@@ -148,11 +148,19 @@ export function MakeChan(typ, buffer) {
|
|
|
148
148
|
export function Select(cases) {
|
|
149
149
|
// Extract the backing array from the GoScript slice
|
|
150
150
|
let selectCases = [];
|
|
151
|
-
if (cases && typeof cases === 'object'
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
151
|
+
if (cases && typeof cases === 'object') {
|
|
152
|
+
if ('__meta__' in cases) {
|
|
153
|
+
// This is a GoScript SliceProxy, extract the backing array
|
|
154
|
+
const meta = cases.__meta__;
|
|
155
|
+
if (meta && meta.backing) {
|
|
156
|
+
const offset = meta.offset ?? 0;
|
|
157
|
+
const length = meta.length ?? meta.backing.length;
|
|
158
|
+
selectCases = meta.backing.slice(offset, offset + length);
|
|
159
|
+
}
|
|
160
|
+
}
|
|
161
|
+
else if (globalThis.Array.isArray(cases)) {
|
|
162
|
+
// This is a plain array (optimized case where offset=0 and length=capacity)
|
|
163
|
+
selectCases = cases;
|
|
156
164
|
}
|
|
157
165
|
}
|
|
158
166
|
// Check for ready channels (channels with queued values)
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"value.js","sourceRoot":"","sources":["../../../gs/reflect/value.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,KAAK,EACL,IAAI,EACJ,OAAO,EACP,OAAO,EACP,GAAG,EACH,KAAK,EACL,KAAK,EACL,KAAK,EACL,IAAI,EACJ,GAAG,EACH,SAAS,EACT,GAAG,EACH,KAAK,EACL,MAAM,EAEN,IAAI,EACJ,MAAM,EACN,MAAM,EACN,MAAM,EACN,KAAK,EACL,OAAO,EACP,KAAK,EACL,IAAI,EACJ,SAAS,EACT,OAAO,GACR,MAAM,WAAW,CAAA;AAClB,OAAO,EAA4B,UAAU,EAAE,aAAa,EAAE,MAAM,YAAY,CAAA;AAChF,OAAO,KAAK,CAAC,MAAM,8BAA8B,CAAA;AAOjD,mDAAmD;AACnD,OAAO,EAAE,OAAO,EAAE,MAAM,QAAQ,CAAA;AAEhC,2EAA2E;AAC3E,MAAM,UAAU,IAAI,CAAC,GAAS;IAC5B,IAAI,SAAuB,CAAA;IAE3B,QAAQ,GAAG,CAAC,IAAI,EAAE,CAAC,OAAO,EAAE,EAAE,CA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AAC;gBACb,MAAM,OAAO,GAAG,IAAI,CAAC,QAAQ,CAAC,CAAA;gBAC9B,OAAO,CAAC,CAAC,EAAE,OAAO,EAAE,IAAI,CAAC,CAAA;YAC3B,CAAC;QACH,CAAC;QACD,OAAO,CAAC,CAAC,EAAE,IAAI,KAAK,CAAC,IAAI,EAAE,IAAI,SAAS,CAAC,OAAO,EAAE,SAAS,CAAC,CAAC,EAAE,KAAK,CAAC,CAAA;IACvE,CAAC;IAED,WAAW;IACX,OAAO,CAAC,CAAC,EAAE,IAAI,KAAK,CAAC,IAAI,EAAE,IAAI,SAAS,CAAC,OAAO,EAAE,SAAS,CAAC,CAAC,EAAE,KAAK,CAAC,CAAA;AACvE,CAAC"}
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
export { Find, Search, SearchFloat64s, SearchInts, SearchStrings, } from './search.gs';
|
|
2
|
+
export { Slice, SliceIsSorted, SliceStable } from './slice.gs';
|
|
3
|
+
export { Float64Slice, Float64s, Float64sAreSorted, IntSlice, Ints, IntsAreSorted, IsSorted, Reverse, Sort, Stable, StringSlice, Strings, StringsAreSorted, } from './sort.gs';
|
|
4
|
+
export type { Interface } from './sort.gs';
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
export { Find, Search, SearchFloat64s, SearchInts, SearchStrings, } from './search.gs';
|
|
2
|
+
export { Slice, SliceIsSorted, SliceStable } from './slice.gs';
|
|
3
|
+
export { Float64Slice, Float64s, Float64sAreSorted, IntSlice, Ints, IntsAreSorted, IsSorted, Reverse, Sort, Stable, StringSlice, Strings, StringsAreSorted, } from './sort.gs';
|
|
4
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../gs/sort/index.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,IAAI,EACJ,MAAM,EACN,cAAc,EACd,UAAU,EACV,aAAa,GACd,MAAM,aAAa,CAAA;AACpB,OAAO,EAAE,KAAK,EAAE,aAAa,EAAE,WAAW,EAAE,MAAM,YAAY,CAAA;AAC9D,OAAO,EACL,YAAY,EACZ,QAAQ,EACR,iBAAiB,EACjB,QAAQ,EACR,IAAI,EACJ,aAAa,EACb,QAAQ,EACR,OAAO,EACP,IAAI,EACJ,MAAM,EACN,WAAW,EACX,OAAO,EACP,gBAAgB,GACjB,MAAM,WAAW,CAAA"}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import * as $ from "@goscript/builtin/builtin.js";
|
|
2
|
+
export declare function Search(n: number, f: (i: number) => boolean): number;
|
|
3
|
+
export declare function Find(n: number, cmp: (i: number) => number): [number, boolean];
|
|
4
|
+
export declare function SearchInts(a: $.Slice<number>, x: number): number;
|
|
5
|
+
export declare function SearchFloat64s(a: $.Slice<number>, x: number): number;
|
|
6
|
+
export declare function SearchStrings(a: $.Slice<string>, x: string): number;
|
|
@@ -0,0 +1,125 @@
|
|
|
1
|
+
import * as $ from "@goscript/builtin/builtin.js";
|
|
2
|
+
// Search uses binary search to find and return the smallest index i
|
|
3
|
+
// in [0, n) at which f(i) is true, assuming that on the range [0, n),
|
|
4
|
+
// f(i) == true implies f(i+1) == true. That is, Search requires that
|
|
5
|
+
// f is false for some (possibly empty) prefix of the input range [0, n)
|
|
6
|
+
// and then true for the (possibly empty) remainder; Search returns
|
|
7
|
+
// the first true index. If there is no such index, Search returns n.
|
|
8
|
+
// (Note that the "not found" return value is not -1 as in, for instance,
|
|
9
|
+
// strings.Index.)
|
|
10
|
+
// Search calls f(i) only for i in the range [0, n).
|
|
11
|
+
//
|
|
12
|
+
// A common use of Search is to find the index i for a value x in
|
|
13
|
+
// a sorted, indexable data structure such as an array or slice.
|
|
14
|
+
// In this case, the argument f, typically a closure, captures the value
|
|
15
|
+
// to be searched for, and how the data structure is indexed and
|
|
16
|
+
// ordered.
|
|
17
|
+
//
|
|
18
|
+
// For instance, given a slice data sorted in ascending order,
|
|
19
|
+
// the call Search(len(data), func(i int) bool { return data[i] >= 23 })
|
|
20
|
+
// returns the smallest index i such that data[i] >= 23. If the caller
|
|
21
|
+
// wants to find whether 23 is in the slice, it must test data[i] == 23
|
|
22
|
+
// separately.
|
|
23
|
+
//
|
|
24
|
+
// Searching data sorted in descending order would use the <=
|
|
25
|
+
// operator instead of the >= operator.
|
|
26
|
+
//
|
|
27
|
+
// To complete the example above, the following code tries to find the value
|
|
28
|
+
// x in an integer slice data sorted in ascending order:
|
|
29
|
+
//
|
|
30
|
+
// x := 23
|
|
31
|
+
// i := sort.Search(len(data), func(i int) bool { return data[i] >= x })
|
|
32
|
+
// if i < len(data) && data[i] == x {
|
|
33
|
+
// // x is present at data[i]
|
|
34
|
+
// } else {
|
|
35
|
+
// // x is not present in data,
|
|
36
|
+
// // but i is the index where it would be inserted.
|
|
37
|
+
// }
|
|
38
|
+
//
|
|
39
|
+
// As a more whimsical example, this program guesses your number:
|
|
40
|
+
//
|
|
41
|
+
// func GuessingGame() {
|
|
42
|
+
// var s string
|
|
43
|
+
// fmt.Printf("Pick an integer from 0 to 100.\n")
|
|
44
|
+
// answer := sort.Search(100, func(i int) bool {
|
|
45
|
+
// fmt.Printf("Is your number <= %d? ", i)
|
|
46
|
+
// fmt.Scanf("%s", &s)
|
|
47
|
+
// return s != "" && s[0] == 'y'
|
|
48
|
+
// })
|
|
49
|
+
// fmt.Printf("Your number is %d.\n", answer)
|
|
50
|
+
// }
|
|
51
|
+
export function Search(n, f) {
|
|
52
|
+
let left = 0;
|
|
53
|
+
let right = n;
|
|
54
|
+
while (left < right) {
|
|
55
|
+
const mid = Math.floor((left + right) / 2);
|
|
56
|
+
if (f(mid)) {
|
|
57
|
+
right = mid;
|
|
58
|
+
}
|
|
59
|
+
else {
|
|
60
|
+
left = mid + 1;
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
return left;
|
|
64
|
+
}
|
|
65
|
+
// Find uses binary search to find and return the smallest index i in [0, n)
|
|
66
|
+
// at which cmp(i) <= 0. If there is no such index i, Find returns i = n.
|
|
67
|
+
// The found result is true if i < n and cmp(i) == 0.
|
|
68
|
+
// Find calls cmp(i) only for i in the range [0, n).
|
|
69
|
+
//
|
|
70
|
+
// To permit binary search, Find requires that cmp(i) > 0 for a leading
|
|
71
|
+
// prefix of the range, cmp(i) == 0 in the middle, and cmp(i) < 0 for
|
|
72
|
+
// the final suffix of the range. (Each subrange could be empty.)
|
|
73
|
+
// The usual way to establish this condition is to interpret cmp(i)
|
|
74
|
+
// as a comparison of a desired target value t against entry i in an
|
|
75
|
+
// underlying indexed data structure x, returning <0, 0, and >0
|
|
76
|
+
// when t < x[i], t == x[i], and t > x[i], respectively.
|
|
77
|
+
//
|
|
78
|
+
// For example, to look for a particular string in a sorted, random-access
|
|
79
|
+
// list of strings:
|
|
80
|
+
//
|
|
81
|
+
// i, found := sort.Find(x.Len(), func(i int) int {
|
|
82
|
+
// return strings.Compare(target, x.At(i))
|
|
83
|
+
// })
|
|
84
|
+
// if found {
|
|
85
|
+
// fmt.Printf("found %s at entry %d\n", target, i)
|
|
86
|
+
// } else {
|
|
87
|
+
// fmt.Printf("%s not found, would insert at %d", target, i)
|
|
88
|
+
// }
|
|
89
|
+
export function Find(n, cmp) {
|
|
90
|
+
let left = 0;
|
|
91
|
+
let right = n;
|
|
92
|
+
while (left < right) {
|
|
93
|
+
const mid = Math.floor((left + right) / 2);
|
|
94
|
+
if (cmp(mid) <= 0) {
|
|
95
|
+
right = mid;
|
|
96
|
+
}
|
|
97
|
+
else {
|
|
98
|
+
left = mid + 1;
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
const found = left < n && cmp(left) === 0;
|
|
102
|
+
return [left, found];
|
|
103
|
+
}
|
|
104
|
+
// SearchInts searches for x in a sorted slice of ints and returns the index
|
|
105
|
+
// as specified by Search. The return value is the index to insert x if x is
|
|
106
|
+
// not present (it could be len(a)).
|
|
107
|
+
// The slice must be sorted in ascending order.
|
|
108
|
+
export function SearchInts(a, x) {
|
|
109
|
+
return Search($.len(a), (i) => $.index(a, i) >= x);
|
|
110
|
+
}
|
|
111
|
+
// SearchFloat64s searches for x in a sorted slice of float64s and returns the index
|
|
112
|
+
// as specified by Search. The return value is the index to insert x if x is not
|
|
113
|
+
// present (it could be len(a)).
|
|
114
|
+
// The slice must be sorted in ascending order.
|
|
115
|
+
export function SearchFloat64s(a, x) {
|
|
116
|
+
return Search($.len(a), (i) => $.index(a, i) >= x);
|
|
117
|
+
}
|
|
118
|
+
// SearchStrings searches for x in a sorted slice of strings and returns the index
|
|
119
|
+
// as specified by Search. The return value is the index to insert x if x is not
|
|
120
|
+
// present (it could be len(a)).
|
|
121
|
+
// The slice must be sorted in ascending order.
|
|
122
|
+
export function SearchStrings(a, x) {
|
|
123
|
+
return Search($.len(a), (i) => $.index(a, i) >= x);
|
|
124
|
+
}
|
|
125
|
+
//# sourceMappingURL=search.gs.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"search.gs.js","sourceRoot":"","sources":["../../../gs/sort/search.gs.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,CAAC,MAAM,8BAA8B,CAAC;AAElD,oEAAoE;AACpE,sEAAsE;AACtE,qEAAqE;AACrE,wEAAwE;AACxE,mEAAmE;AACnE,qEAAqE;AACrE,yEAAyE;AACzE,kBAAkB;AAClB,oDAAoD;AACpD,EAAE;AACF,iEAAiE;AACjE,gEAAgE;AAChE,wEAAwE;AACxE,gEAAgE;AAChE,WAAW;AACX,EAAE;AACF,8DAA8D;AAC9D,wEAAwE;AACxE,sEAAsE;AACtE,uEAAuE;AACvE,cAAc;AACd,EAAE;AACF,6DAA6D;AAC7D,uCAAuC;AACvC,EAAE;AACF,4EAA4E;AAC5E,wDAAwD;AACxD,EAAE;AACF,UAAU;AACV,wEAAwE;AACxE,qCAAqC;AACrC,8BAA8B;AAC9B,WAAW;AACX,gCAAgC;AAChC,qDAAqD;AACrD,IAAI;AACJ,EAAE;AACF,iEAAiE;AACjE,EAAE;AACF,wBAAwB;AACxB,gBAAg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, less: (i: number, j: number) => boolean): void;
|
|
3
|
+
export declare function SliceIsSorted(x: $.Slice<any>, less: (i: number, j: number) => boolean): boolean;
|
|
4
|
+
export declare function SliceStable(x: $.Slice<any>, less: (i: number, j: number) => boolean): void;
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
import * as $ from "../builtin/builtin.js";
|
|
2
|
+
// Helper function to swap elements in a slice
|
|
3
|
+
function swapInSlice(slice, i, j) {
|
|
4
|
+
if (!slice)
|
|
5
|
+
return;
|
|
6
|
+
const temp = $.index(slice, i);
|
|
7
|
+
if (Array.isArray(slice)) {
|
|
8
|
+
const val_j = $.index(slice, j);
|
|
9
|
+
const val_i = temp;
|
|
10
|
+
slice[i] = val_j;
|
|
11
|
+
slice[j] = val_i;
|
|
12
|
+
}
|
|
13
|
+
else if (typeof slice === 'object' && '__meta__' in slice) {
|
|
14
|
+
const meta = slice.__meta__;
|
|
15
|
+
const backing = meta.backing;
|
|
16
|
+
backing[meta.offset + i] = $.index(slice, j);
|
|
17
|
+
backing[meta.offset + j] = temp;
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
// Slice sorts the slice x given the provided less function
|
|
21
|
+
export function Slice(x, less) {
|
|
22
|
+
if (!x)
|
|
23
|
+
return;
|
|
24
|
+
// Simple insertion sort using the provided less function
|
|
25
|
+
const n = $.len(x);
|
|
26
|
+
for (let i = 1; i < n; i++) {
|
|
27
|
+
for (let j = i; j > 0 && less(j, j - 1); j--) {
|
|
28
|
+
swapInSlice(x, j, j - 1);
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
// SliceIsSorted reports whether the slice x is sorted according to the provided less function
|
|
33
|
+
export function SliceIsSorted(x, less) {
|
|
34
|
+
if (!x)
|
|
35
|
+
return true;
|
|
36
|
+
const n = $.len(x);
|
|
37
|
+
for (let i = n - 1; i > 0; i--) {
|
|
38
|
+
if (less(i, i - 1)) {
|
|
39
|
+
return false;
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
return true;
|
|
43
|
+
}
|
|
44
|
+
// SliceStable sorts the slice x while keeping the original order of equal elements
|
|
45
|
+
export function SliceStable(x, less) {
|
|
46
|
+
// For simplicity, use the same sort - can be improved later
|
|
47
|
+
Slice(x, less);
|
|
48
|
+
}
|
|
49
|
+
//# sourceMappingURL=slice.gs.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"slice.gs.js","sourceRoot":"","sources":["../../../gs/sort/slice.gs.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,CAAC,MAAM,uBAAuB,CAAC;AAU3C,8CAA8C;AAC9C,SAAS,WAAW,CAAI,KAAiB,EAAE,CAAS,EAAE,CAAS;IAC7D,IAAI,CAAC,KAAK;QAAE,OAAM;IAElB,MAAM,IAAI,GAAG,CAAC,CAAC,KAAK,CAAC,KAAK,EAAE,CAAC,CAAC,CAAA;IAC9B,IAAI,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC,EAAE,CAAC;QACzB,MAAM,KAAK,GAAG,CAAC,CAAC,KAAK,CAAC,KAAK,EAAE,CAAC,CAAC,CAAA;QAC/B,MAAM,KAAK,GAAG,IAAI,CAAA;QAClB,KAAK,CAAC,CAAC,CAAC,GAAG,KAAU,CAAA;QACrB,KAAK,CAAC,CAAC,CAAC,GAAG,KAAU,CAAA;IACvB,CAAC;SAAM,IAAI,OAAO,KAAK,KAAK,QAAQ,IAAI,UAAU,IAAI,KAAK,EAAE,CAAC;QAC5D,MAAM,IAAI,GAAI,KAAa,CAAC,QAA4B,CAAA;QACxD,MAAM,OAAO,GAAG,IAAI,CAAC,OAAO,CAAA;QAC5B,OAAO,CAAC,IAAI,CAAC,MAAM,GAAG,CAAC,CAAC,GAAG,CAAC,CAAC,KAAK,CAAC,KAAK,EAAE,CAAC,CAAM,CAAA;QACjD,OAAO,CAAC,IAAI,CAAC,MAAM,GAAG,CAAC,CAAC,GAAG,IAAS,CAAA;IACtC,CAAC;AACH,CAAC;AAED,2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|
5
|
+
Swap(i: number, j: number): void;
|
|
6
|
+
}
|
|
7
|
+
export declare class IntSlice {
|
|
8
|
+
private _value;
|
|
9
|
+
constructor(_value: $.Slice<number>);
|
|
10
|
+
Len(): number;
|
|
11
|
+
Less(i: number, j: number): boolean;
|
|
12
|
+
Swap(i: number, j: number): void;
|
|
13
|
+
}
|
|
14
|
+
export declare class Float64Slice {
|
|
15
|
+
private _value;
|
|
16
|
+
constructor(_value: $.Slice<number>);
|
|
17
|
+
Len(): number;
|
|
18
|
+
Less(i: number, j: number): boolean;
|
|
19
|
+
Swap(i: number, j: number): void;
|
|
20
|
+
}
|
|
21
|
+
export declare class StringSlice {
|
|
22
|
+
private _value;
|
|
23
|
+
constructor(_value: $.Slice<string>);
|
|
24
|
+
Len(): number;
|
|
25
|
+
Less(i: number, j: number): boolean;
|
|
26
|
+
Swap(i: number, j: number): void;
|
|
27
|
+
}
|
|
28
|
+
export declare function Sort(data: Interface): void;
|
|
29
|
+
export declare function Stable(data: Interface): void;
|
|
30
|
+
export declare function IsSorted(data: Interface): boolean;
|
|
31
|
+
export declare function Reverse(data: Interface): Interface;
|
|
32
|
+
export declare function Ints(x: $.Slice<number>): void;
|
|
33
|
+
export declare function IntsAreSorted(x: $.Slice<number>): boolean;
|
|
34
|
+
export declare function Float64s(x: $.Slice<number>): void;
|
|
35
|
+
export declare function Float64sAreSorted(x: $.Slice<number>): boolean;
|
|
36
|
+
export declare function Strings(x: $.Slice<string>): void;
|
|
37
|
+
export declare function StringsAreSorted(x: $.Slice<string>): boolean;
|