-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsus-collections-SplitMut.html
386 lines (357 loc) · 15.5 KB
/
sus-collections-SplitMut.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
<!DOCTYPE html>
<html>
<head>
<meta content="text/html;charset=utf-8" http-equiv="Content-Type"></meta>
<meta name="generator" content="subdoc"></meta>
<meta name="viewport" content="width=device-width, initial-scale=1"></meta>
<meta property="og:type" content="website"></meta>
<meta property="og:site_name" content="Subspace"></meta>
<meta property="og:url" content="https://suslib.cc/sus-collections-SplitMut.html"></meta>
<title>sus::collections::SplitMut - Subspace</title>
<meta property="og:title" content="sus::collections::SplitMut - Subspace"></meta>
<meta name="description" content="An iterator over subslices separated by elements that match a predicate function."></meta>
<meta property="og:description" content="An iterator over subslices separated by elements that match a predicate function."></meta>
<script src="https://unpkg.com/lunr/lunr.js"></script>
<script src="./search_db.js"></script>
<script>
// Delayed loading of whatever was in the search box.
var searchDelayLoad;
// The search box's dynamic behaviour.
document.addEventListener("keyup", e => {
if (e.key === 's') {
document.querySelector('.search-input').focus();
}
if (e.key === 'Escape') {
document.querySelector('.search-input').blur();
navigateToSearch(null);
e.preventDefault();
}
});
function navigateToSearch(query) {
window.clearTimeout(searchDelayLoad);
searchDelayLoad = null;
let without_search =
window.location.origin + window.location.pathname;
if (query) {
window.history.replaceState(null, "",
without_search + "?" + `search=${query}`);
} else {
window.history.replaceState(null, "", without_search);
}
maybeShowSearchResults();
}
addEventListener("load", event => {
document.querySelector(".search-input").oninput = (e) => {
window.clearTimeout(searchDelayLoad);
searchDelayLoad = window.setTimeout(() => {
navigateToSearch(e.target.value);
}, 1000);
};
document.querySelector(".search-input").onkeypress = (e) => {
if (e.key == "Enter") {
navigateToSearch(e.target.value);
e.preventDefault();
}
};
var searchPlaceholder;
document.querySelector(".search-input").onfocus = (e) => {
searchPlaceholder = e.target.placeholder;
e.target.placeholder = "Type your search here.";
navigateToSearch(e.target.value);
};
document.querySelector(".search-input").onblur = (e) => {
e.target.placeholder = searchPlaceholder;
searchPlaceholder = null;
};
});
// Show or hide any DOM element.
function showHide(selector, show) {
if (show)
document.querySelector(selector).classList.remove("hidden");
else
document.querySelector(selector).classList.add("hidden");
}
function searchQuery() {
const params = new Proxy(
new URLSearchParams(window.location.search), {
get: (searchParams, prop) => searchParams.get(prop),
}
);
return params.search;
}
// Showing search results.
async function populateSearchResults(loaded) {
const search_db = loaded.search_db;
const idx = loaded.idx;
// lunrjs treats `:` specially and `::` breaks the query syntax, so
// just split into two words.
const query = searchQuery().split("::").join(" ");
let content = '';
try {
const results = idx.search(query);
for (r of results) {
const item = search_db[r.ref];
const type = item.type;
const url = item.url;
const name = item.name;
const full_name = item.full_name;
const summmary = item.summary ? item.summary : "";
content += `\
<a class="search-results-link" href="${url}">
<span class="search-results-type"><div>${type}</div></span>\
<span class="search-results-name"><div>${full_name}</div></span>\
<span class="search-results-summary"><div>${summmary}</div></span>\
</a>\
`
}
} catch (err) {
content +=
`<div class="search-error">Search error: ${err.message}</div>`;
}
let content_elem = document.querySelector(".search-results-content");
content_elem.innerHTML = content;
let header_elem = document.querySelector(".search-results-header");
header_elem.innerText = "Search results";
}
var cache_idx;
// Searching via https://lunrjs.com.
//
// Load the JSON search database, which will be turned into a search
// index. Returns an object with two fields:
// - search_db: the contents of the search.json file.
// - idx: the lunr search index.
// Documented at https://lunrjs.com/docs/lunr.Index.html.
async function loadSearchIndex() {
// This is not widely supported yet (not on Safari), so instead we
// turned the json file into a js file that sets a global variable. :|
//async function load_search_db() {
// let x = await import('./search.json', {
// with: {type: 'json'}
// });
// return x.default;
//}
async function load_idx(search_db) {
let idx = lunr(function () {
this.ref('index');
this.field('name', {
'boost': 2,
editDistance: 0
});
this.field('full_name', {
'boost': 2,
editDistance: 2
});
this.field('split_name', {
'boost': 0.5,
editDistance: 2
});
// No stemming and no stopwords (like `into` and `from`).
this.pipeline = new lunr.Pipeline();
this.searchPipeline = new lunr.Pipeline();
// Queries are split by these tokens.
const splitBy = /(\s+|_+|(::)+)/
this.use(builder => {
function splitTokens(token) {
return token.toString().split(splitBy).map(str => {
return token.clone().update(() => { return str })
})
}
lunr.Pipeline.registerFunction(splitTokens, 'splitTokens')
builder.searchPipeline.add(splitTokens)
});
search_db.forEach(item => {
const weights = {
"concept": 3,
"class": 2,
"struct": 2,
"union": 2,
"function": 1.75,
"variable": 1.75,
"namespace": 1.2,
"method": 1,
"constructor": 1,
"macro": 1,
"project": 1,
"field": 0.9,
"conversion": 0.5,
"type alias": 0.5,
"concept alias": 0.5,
"function alias": 0.5,
"method alias": 0.5,
"enum value alias": 0.5,
"variable alias": 0.5,
}
let weight = weights[item.type];
if (!weight) {
console.log(`WARNING: search item type ${item.type} ` +
`has no weight defined`);
weight = 1;
}
this.add(item, {
'boost': weight
})
}, this);
});
let out = {};
out.search_db = search_db;
out.idx = idx;
return out;
};
if (!cache_idx) {
cache_idx = await load_idx(g_search_db);
}
return cache_idx;
}
// If there's a search query, hide the other content and asynchronously
// show the search results. Otherwise, hide search content and show the
// rest immediately.
function maybeShowSearchResults() {
const query = searchQuery();
if (query) {
showHide(".main-content", false);
let input = document.querySelector(".search-input");
input.value = query;
let header_elem = document.querySelector(".search-results-header");
header_elem.innerText = "Loading search results...";
let content_ele = document.querySelector(".search-results-content");
content_ele.innerText = "";
loadSearchIndex().then(populateSearchResults)
} else {
showHide(".main-content", true);
let header_elem = document.querySelector(".search-results-header");
header_elem.innerText = "";
let content_ele = document.querySelector(".search-results-content");
content_ele.innerText = "";
}
}
</script>
<link rel="stylesheet" href="subdoc-test-style.css">
<link rel="icon" type="image/png" href="logo.png">
<link rel="alternate icon" type="image/png" href="logo32.png">
<meta property="og:image" content="logo.png"></meta>
</head>
<body>
<nav class="topbar">
<button class="sidebar-menu-button" onclick="let e = document.getElementsByClassName('sidebar')[0];e.classList.toggle('shown');">
☰
</button>
<a class="topbar-logo-link" href="index.html"><div class="topbar-logo-border">
<img class="topbar-logo" src="logo.png"></img>
</div></a>
<span class="topbar-text-area">
<span class="topbar-title">
<a href="#">SplitMut</a>
</span>
</span>
</nav>
<nav class="sidebar">
<a class="sidebar-logo-link" href="index.html"><div class="sidebar-logo-border">
<img class="sidebar-logo" src="logo.png"></img>
</div></a>
<div class="sidebar-pretitle sidebar-text">
class
</div>
<div class="sidebar-title sidebar-text">
<a href="#">SplitMut</a>
</div>
<div class="sidebar-subtitle sidebar-text">
</div>
<div class="sidebar-links sidebar-text">
<ul>
<li>
<a class="sidebar-header" href="#methods">Methods</a>
</li>
<li>
<a class="sidebar-item" href="sus-collections-SplitMut.html#method.next">next</a>
</li>
<li>
<a class="sidebar-item" href="sus-collections-SplitMut.html#method.next_back">next_back</a>
</li>
<li>
<a class="sidebar-item" href="sus-collections-SplitMut.html#method.size_hint">size_hint</a>
</li>
</ul>
</div>
</nav>
<main>
<nav class="search-nav">
<form class="search-form">
<input class="search-input" name="search" autocomplete="off" spellcheck="false" placeholder="Click or press 'S' to search...">
</input>
</form>
</nav>
<section class="search-results">
<h1 class="search-results-header">
</h1>
<div class="search-results-content">
</div>
</section>
<section class="main-content">
<script>maybeShowSearchResults()</script>
<div class="type record class">
<div class="section overview">
<h1 class="section-header">
<span>
Class
</span>
<a class="project-name" href="index.html">Subspace</a>
<span class="namespace-dots">::</span>
<a class="namespace-name" href="namespace.sus.html">sus</a>
<span class="namespace-dots">::</span>
<a class="namespace-name" href="sus-namespace.collections.html">collections</a>
<span class="namespace-dots">::</span>
<a class="type-name" href="#">SplitMut</a>
</h1>
<div class="type-signature"><div class="src rightside"><a href="https://github.com/chromium/subspace/blob/main/sus/collections/iterators/split.h#L195">source</a></div><pre class="template">template <class ItemT, class Pred></pre><span class="class">
class
</span><span class="type-name">
SplitMut
</span><span class="final">
final
</span><div class="requires">
<span class="requires-keyword keyword">
requires
</span>
<div class="requires-constraint"><pre class="requires-constraint-line">sus::fn::FnMut<Pred, _Bool (const ItemT &)></pre></div>
</div><div class="record-body">
{ ... };
</div></div>
<div class="description long">
<p>An iterator over subslices separated by elements that match a predicate
function.</p>
<p>This struct is created by the <code>split_mut()</code> method on slices.</p>
</div>
</div>
<div class="section methods nonstatic">
<h1 class="section-header">
<a name="methods" href="#methods">Methods</a>
</h1>
<div class="section-items">
<div class="overload-set item-name">
<div class="overload">
<div class="function-signature"><div class="src rightside"><a href="https://github.com/chromium/subspace/blob/main/sus/collections/iterators/split.h#L203">source</a></div><a name="method.next"></a><span class="function-auto">auto</span> <a class="function-name" href="sus-collections-SplitMut.html#method.next">next</a>() -> <a class="type-name" href="sus-option-Option.html" title="sus::option::Option">Option</a><sus::collections::SplitMut::Item></div>
</div>
</div>
<div class="description long">
</div>
<div class="overload-set item-name">
<div class="overload">
<div class="function-signature"><div class="src rightside"><a href="https://github.com/chromium/subspace/blob/main/sus/collections/iterators/split.h#L228">source</a></div><a name="method.next_back"></a><span class="function-auto">auto</span> <a class="function-name" href="sus-collections-SplitMut.html#method.next_back">next_back</a>() -> <a class="type-name" href="sus-option-Option.html" title="sus::option::Option">Option</a><sus::collections::SplitMut::Item></div>
</div>
</div>
<div class="description long">
</div>
<div class="overload-set item-name">
<div class="overload">
<div class="function-signature"><div class="src rightside"><a href="https://github.com/chromium/subspace/blob/main/sus/collections/iterators/split.h#L253">source</a></div><a name="method.size_hint"></a><span class="function-auto">auto</span> <a class="function-name" href="sus-collections-SplitMut.html#method.size_hint">size_hint</a>() const -> <a class="type-name" href="sus-iter-SizeHint.html" title="sus::iter::SizeHint">SizeHint</a></div>
</div>
</div>
<div class="description long">
</div>
</div>
</div>
</div>
</section>
</main>
</body>
</html>