-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathroot.vugu
543 lines (456 loc) · 27.1 KB
/
root.vugu
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
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
<html>
<head>
<link rel="preconnect" href="https://fonts.googleapis.com">
<link rel="preconnect" href="https://fonts.gstatic.com" crossorigin>
<link href="https://fonts.googleapis.com/css2?family=Comfortaa&display=swap" rel="stylesheet">
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/[email protected]/dist/css/bootstrap.min.css"
integrity="sha384-EVSTQN3/azprG1Anm3QDgpJLIm9Nao0Yz1ztcQTwFspd3yD65VohhpuuCOmLASjC" crossorigin="anonymous">
</head>
<body>
<style>
body {
padding: 0px;
margin: 0px;
}
header {
font-family: 'Comfortaa', cursive;
/* background: linear-gradient(0deg, rgba(255,255,255,1) 48%, rgb(17, 17, 108) 50%); */
/* background-image: linear-gradient(0deg,white, rgb(17, 17, 108)); */
min-height: 15vh;
}
.dark-bg {
background-color: rgb(17, 17, 108);
}
footer {
background-color: #e6e6e6;
font-size:0.75em;
}
.bitcode {
font-weight: bold;
display: grid;
grid-template-columns: 1fr 1fr 1fr 1fr 1fr 1fr 1fr 2fr 1fr 1fr 1fr 1fr 1fr 1fr 1fr 2fr 1fr 1fr 1fr 1fr 1fr 1fr 1fr 2fr 1fr 1fr 1fr 1fr 1fr 1fr 1fr 1fr;
grid-template-rows: 1fr 1fr 1fr 1fr;
gap: 0px 0px;
}
.bg {
background-color: #002b36;
}
.explain {
padding: 1px 8px 2px 8px;
border-radius: 6px;
}
.box {
max-width: 600px;
}
.current-text {
height: 25vh;
display: flex;
justify-content: center;
align-items: flex-end;
width:100%;
}
.light {
color: #fdf6e3;
}
.timestamp {
color:#859900;
}
.version {
color:#dc322f;
}
.variant {
color:#d33682;
}
.random {
color: #fdf6e3;
}
.precision {
color: #b58900;
}
.node {
color: #268bd2;
}
.bits {
cursor: pointer;
font-weight: bold;
}
.counter {
color: #2aa198;
}
.hex {
cursor: pointer;
}
.langs {
float: right;
padding:5px;
}
.lang {
text-decoration:none;
cursor:pointer;
}
.lang>img {
width: 1.5em;
height: 1.5em;
}
</style>
<div class="content">
<header class="dark-bg light">
<div class="langs">
<a class="lang" @click='c.setLang(event, "ru-RU")'>
<img src="data:image/svg+xml;base64,PHN2ZyBpZD0iTGF5ZXJfMSIgZW5hYmxlLWJhY2tncm91bmQ9Im5ldyAwIDAgNTEyIDUxMiIgdmlld0JveD0iMCAwIDUxMiA1MTIiIHhtbG5zPSJodHRwOi8vd3d3LnczLm9yZy8yMDAwL3N2ZyI+PGNpcmNsZSBjeD0iMjU2IiBjeT0iMjU2IiBmaWxsPSIjZjBmMGYwIiByPSIyNTYiLz48cGF0aCBkPSJtNDk2LjA3NyAzNDUuMDQzYzEwLjI5MS0yNy43MzMgMTUuOTIzLTU3LjcyOSAxNS45MjMtODkuMDQzcy01LjYzMi02MS4zMS0xNS45MjMtODkuMDQzaC00ODAuMTU0Yy0xMC4yOSAyNy43MzMtMTUuOTIzIDU3LjcyOS0xNS45MjMgODkuMDQzczUuNjMzIDYxLjMxIDE1LjkyMyA4OS4wNDNsMjQwLjA3NyAyMi4yNjF6IiBmaWxsPSIjMDA1MmI0Ii8+PHBhdGggZD0ibTI1NiA1MTJjMTEwLjA3MSAwIDIwMy45MDYtNjkuNDcyIDI0MC4wNzctMTY2Ljk1N2gtNDgwLjE1NGMzNi4xNzEgOTcuNDg1IDEzMC4wMDYgMTY2Ljk1NyAyNDAuMDc3IDE2Ni45NTd6IiBmaWxsPSIjZDgwMDI3Ii8+PGcvPjxnLz48Zy8+PGcvPjxnLz48Zy8+PGcvPjxnLz48Zy8+PGcvPjxnLz48Zy8+PGcvPjxnLz48Zy8+PC9zdmc+" />
</a>
<a class="lang" @click='c.setLang(event, "en-US")'>
<img src="data:image/svg+xml;base64,PHN2ZyBpZD0iTGF5ZXJfMSIgZW5hYmxlLWJhY2tncm91bmQ9Im5ldyAwI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+PGcvPjxnLz48Zy8+PGcvPjxnLz48Zy8+PGcvPjxnLz48Zy8+PGcvPjxnLz48Zy8+PGcvPjxnLz48Zy8+PC9zdmc+" />
</a>
</div>
<div class="current-text">
<h1 class="display-3" vg-content='c.t("hello-uuid7")'>Hello, UUIDv7!</h1>
</div>
</header>
<main>
<div class="container-fluid">
<div class="row justify-content-center pt-4 pb-4 dark-bg light">
<div class="col col-md-8">
<p vg-content='c.t("description-uuid7")'>
A common case for modern applications is to create a unique
identifier for use as a primary key in a database table. This
identifier usually implements an embedded timestamp that is sortable
using the monotonic creation time in the most significant bits. In
addition the identifier is highly collision resistant, difficult to
guess, and provides minimal security attack surfaces. None of the
existing UUID versions, including UUIDv1, fulfill each of these
requirements in the most efficient possible way.
</p>
<p vg-content='c.t("intro-uuid7")'>
Instead we are introducing UUIDv7. Take a look, we have a freshly generated UUIDv7 right here:
</p>
</div>
</div>
<div class="row fs-4">
</div>
</div>
<div class="container-fluid bg">
<div vg-if="len(c.bits) > 0" class="row justify-content-center font-monospace">
<div class="col text-center p-4">
<span vg-content="c.uuid" class="light display-4"></span>
</div>
</div>
<div class="row justify-content-center">
<div class="col-lg-3 d-flex justify-content-center p-2">
<button class="btn btn-primary" @click="c.GetNewUUID(event)">
<svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" fill="currentColor" class="bi bi-arrow-clockwise" viewBox="0 0 16 16">
<path fill-rule="evenodd" d="M8 3a5 5 0 1 0 4.546 2.914.5.5 0 0 1 .908-.417A6 6 0 1 1 8 2v1z"/>
<path d="M8 4.466V.534a.25.25 0 0 1 .41-.192l2.36 1.966c.12.1.12.284 0 .384L8.41 4.658A.25.25 0 0 1 8 4.466z"/>
</svg>
<span vg-content='c.t("get-new")'></span>
</button>
</div>
<div class="col-lg-3 d-flex justify-content-center p-2">
<button class="btn btn-primary" @click="c.displaySettings = !c.displaySettings">
<svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" fill="currentColor" class="bi bi-gear" viewBox="0 0 16 16">
<path d="M8 4.754a3.246 3.246 0 1 0 0 6.492 3.246 3.246 0 0 0 0-6.492zM5.754 8a2.246 2.246 0 1 1 4.492 0 2.246 2.246 0 0 1-4.492 0z"/>
<path d="M9.796 1.343c-.527-1.79-3.065-1.79-3.592 0l-.094.319a.873.873 0 0 1-1.255.52l-.292-.16c-1.64-.892-3.433.902-2.54 2.541l.159.292a.873.873 0 0 1-.52 1.255l-.319.094c-1.79.527-1.79 3.065 0 3.592l.319.094a.873.873 0 0 1 .52 1.255l-.16.292c-.892 1.64.901 3.434 2.541 2.54l.292-.159a.873.873 0 0 1 1.255.52l.094.319c.527 1.79 3.065 1.79 3.592 0l.094-.319a.873.873 0 0 1 1.255-.52l.292.16c1.64.893 3.434-.902 2.54-2.541l-.159-.292a.873.873 0 0 1 .52-1.255l.319-.094c1.79-.527 1.79-3.065 0-3.592l-.319-.094a.873.873 0 0 1-.52-1.255l.16-.292c.893-1.64-.902-3.433-2.541-2.54l-.292.159a.873.873 0 0 1-1.255-.52l-.094-.319zm-2.633.283c.246-.835 1.428-.835 1.674 0l.094.319a1.873 1.873 0 0 0 2.693 1.115l.291-.16c.764-.415 1.6.42 1.184 1.185l-.159.292a1.873 1.873 0 0 0 1.116 2.692l.318.094c.835.246.835 1.428 0 1.674l-.319.094a1.873 1.873 0 0 0-1.115 2.693l.16.291c.415.764-.42 1.6-1.185 1.184l-.291-.159a1.873 1.873 0 0 0-2.693 1.116l-.094.318c-.246.835-1.428.835-1.674 0l-.094-.319a1.873 1.873 0 0 0-2.692-1.115l-.292.16c-.764.415-1.6-.42-1.184-1.185l.159-.291A1.873 1.873 0 0 0 1.945 8.93l-.319-.094c-.835-.246-.835-1.428 0-1.674l.319-.094A1.873 1.873 0 0 0 3.06 4.377l-.16-.292c-.415-.764.42-1.6 1.185-1.184l.292.159a1.873 1.873 0 0 0 2.692-1.115l.094-.319z"/>
</svg>
<span vg-content='c.t("show-settings")'></span>
</button>
</div>
<div class="col-lg-3 d-flex justify-content-center p-2">
<button class="btn btn-primary" @click="c.displayLog = !c.displayLog">
<svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" fill="currentColor" class="bi bi-info-circle" viewBox="0 0 16 16">
<path d="M8 15A7 7 0 1 1 8 1a7 7 0 0 1 0 14zm0 1A8 8 0 1 0 8 0a8 8 0 0 0 0 16z"/>
<path d="m8.93 6.588-2.29.287-.082.38.45.083c.294.07.352.176.288.469l-.738 3.468c-.194.897.105 1.319.808 1.319.545 0 1.178-.252 1.465-.598l.088-.416c-.2.176-.492.246-.686.246-.275 0-.375-.193-.304-.533L8.93 6.588zM9 4.5a1 1 0 1 1-2 0 1 1 0 0 1 2 0z"/>
</svg>
<span vg-content='c.t("show-log")'></span>
</button>
</div>
</div>
<div class="row justify-content-center">
<div class="box p-2">
<div class="bitcode">
<div vg-for="c.bits" vg-key="key">
<span :class="c.getClass(key)" vg-content="c.display(value)"></span>
</div>
</div>
</div>
</div>
<div vg-if="c.displayLog" class="row justify-content-start light">
<div class="col-md-3 bg">
</div>
<div class="col-md-9 bg">
<span vg-content='c.t("log-parsed")'></span> (<span vg-content='c.oTime'></span>)
</div>
</div>
<div vg-if="c.displayLog" class="row justify-content-start">
<div class="col-md-3 bg timestamp">
</div>
<div class="col-md-9 bg timestamp">
<span vg-content='c.t("log-time")'></span>: <span vg-content='c.rTime'></span> (<span vg-content='c.rTimestamp'></span>)
</div>
</div>
<div vg-if="c.displayLog" class="row justify-content-start">
<div class="col-md-3 bg precision">
</div>
<div class="col-md-9 bg precision">
<span vg-content='c.t("log-precision")'></span>: <span vg-content='c.rMilli'></span>
</div>
</div>
<div vg-if="c.displayLog" class="row justify-content-start">
<div class="col-md-3 bg counter">
</div>
<div class="col-md-9 bg counter">
<span vg-content='c.t("log-counter")'></span>: <span vg-content='c.rCounter'></span>
</div>
</div>
<div vg-if="c.displayLog" class="row justify-content-start">
<div class="col-md-3 bg node">
</div>
<div class="col-md-9 bg node">
<span vg-content='c.t("log-node")'></span>: <span vg-content='c.rNode'></span>
</div>
</div>
<div vg-if="c.displaySettings" class="row justify-content-end">
<div class="col-md-3 d-flex justify-content-center p-2">
<label for="iprecision" vg-content='c.t("tune-precision")' class="light"></label>
<input type="number" id="iprecision" class="form-control" min="1" max="64" :value='c.subsecondPrecisionLength' @change='c.subsecondPrecisionLength, _= strconv.Atoi(event.PropString("target", "value"))'>
</div>
<div class="col-md-3 d-flex justify-content-center p-2">
<label for="icounter" vg-content='c.t("tune-counter")' class="light"></label>
<input type="number" id="icounter" class="form-control" min="1" max="64" :value='c.counterPrecisionLength' @change='c.counterPrecisionLength, _= strconv.Atoi(event.PropString("target", "value"))'>
</div>
<div class="col-md-3 d-flex justify-content-center p-2">
<label for="inodelength" vg-content='c.t("tune-node-length")' class="light"></label>
<input type="number" id="inodelength" class="form-control" min="1" max="16" :value='c.nodePrecisionLength' @change='c.nodePrecisionLength, _= strconv.Atoi(event.PropString("target", "value"))'>
</div>
<div class="col-md-3 d-flex justify-content-center p-2">
<label for="inodevalue" vg-content='c.t("tune-node-value")' class="light" ></label>
<input type="number" id="inodevalue" class="form-control" min="1" max="65355" :value='c.node' @change='c.node, _= strconv.ParseUint(event.PropString("target", "value"), 10,64)'>
</div>
</div>
<div class="row p-4"></div>
</div>
<div class="container">
<div class="row justify-content-center">
<div class="col-md-8 pt-4">
<p>
<span class="timestamp explain bg" vg-content='c.t("unix-timestamp")'>Unix timestamp</span> –
<span vg-content='c.t("unix-timestamp-description")'></span>
</p>
<p>
<span class="precision explain bg" vg-content='c.t("precision")'>Sub-second precision</span> –
<span vg-content='c.t("precision-description")'></span>
</p>
<p>
<span class="counter explain bg" vg-content='c.t("counter")'>Counter</span> –
<span vg-content='c.t("counter")'></span>
</p>
<p>
<span class="node explain bg" vg-content='c.t("node")'>Node</span> –
<span vg-content='c.t("node-description")'></span>
</p>
<p>
<span class="random explain bg" vg-content='c.t("random")'>random</span> –
<span vg-content='c.t("random-description")'></span>
</p>
<p>
<span class="version explain bg" vg-content='c.t("version")'>version</span> –
<span vg-content='c.t("version-description")'></span>
</p>
<p>
<span class="variant explain bg" vg-content='c.t("variant")'>variant</span> –
<span vg-content='c.t("variant-description")'></span>
</p>
</div>
</div>
<div class="row justify-content-center">
<div class="col-md-8">
<p vg-content='c.t("encoding-intro")'>
Special mention to our amazing counter precision encoding algorithm.
</p>
</div>
</div>
<div class="row justify-content-center">
<div class="col-md-8">
<label for="playvalue" vg-content='c.t("play-precision-value")'></label>
<input type="number" min="1" max="9999999999" :value="c.playValue" class="form-control" @change='c.play(event, event.PropString("target", "value"))'></input>
<label for="playprecision" vg-content='c.t("play-precision-precision")'></label>
<input type="number" min="1" max="127" :value="c.playPrecision" class="form-control" @change='c.playPrecision, _= strconv.Atoi(event.PropString("target", "value"))'></input>
<span vg-content='c.t("play-precision-result")'></span>:
<span vg-content="c.playResult"></span>
</div>
</div>
</div>
</main>
<footer class="footer">
<div class="container">
<div class="row pt-5 justify-content-center">
<div class="col-md-8">
<p><a href="https://datatracker.ietf.org/doc/draft-peabody-dispatch-new-uuid-format/" vg-content='c.t("footer-ietf")'>IETF: New UUID formats</a></p>
<p><a href="https://github.com/uuid6/uuid6-ietf-draft" vg-content='c.t("footer-github-draft")'>Github: uuid6-ietf-draft</a></p>
<p><a href="https://github.com/uuid6/uuid6go-proto" vg-content='c.t("footer-golang-gen")'>golang generator uuid6go-proto</a></p>
<p><a href="https://vugu.org" vg-content='c.t("footer-vugu")'>site written in vugu</a></p>
<p><span vg-content='c.t("footer-contact")'></span> <a href="mailto:[email protected]" vg-content='c.t("footer-peabody")'>Brad G. Peabody</a> <span vg-content='c.t("footer-and")'></span> <a href="mailto:[email protected]" vg-content='c.t("footer-davis")'>Kyzer R. Davis</a></p>
<p><span vg-content='c.t("footer-site-support")'></span> <a href="mailto:[email protected]" vg-content='c.t("footer-roganov")'>Ivan Roganov</a></p>
<p class="text-end" vg-content='c.t("footer-copyright")'>Copyright © 2021</p>
<p class="text-end">
Icons made by <a href="https://www.freepik.com" title="Freepik">Freepik</a> from <a href="https://www.flaticon.com/" title="Flaticon">www.flaticon.com</a>
</p>
</div>
</div>
</div>
</footer>
</div>
</body>
<script type="application/x-go">
import (
uuid "github.com/uuid6/uuid6go-proto"
"time"
"strconv"
"math"
"encoding/binary"
)
type Root struct {
selected string `vugu:"data"`
displayLog bool `vugu:"data"`
displaySettings bool `vugu:"data"`
counterPrecisionLength int `vugu:"data"`
nodePrecisionLength int `vugu:"data"`
node uint64 `vugu:"data"`
rTime time.Time `vugu:"data"`
oTime time.Time `vugu:"data"`
rNode uint64 `vugu:"data"`
rCounter uint64 `vugu:"data"`
rMilli float64 `vugu:"data"`
rTimestamp uint64 `vugu:"data"`
subsecondPrecisionLength int `vugu:"data"`
bits []bool `vugu:"data"`
uuid string `vugu:"data"`
lang string `vugu:"data"`
playValue int `vugu:"data"`
playPrecision int `vugu:"data"`
playResult float64 `vugu:"data"`
}
func (c *Root) Init(ctx vugu.InitCtx) {
initTranslation()
var gen uuid.UUIDv7Generator
c.counterPrecisionLength = 8
c.nodePrecisionLength = 4
c.node = 7
c.subsecondPrecisionLength = 16
c.lang = "en-US"
gen.CounterPrecisionLength = c.counterPrecisionLength
gen.NodePrecisionLength = c.nodePrecisionLength
gen.Node = c.node
gen.SubsecondPrecisionLength = c.subsecondPrecisionLength
c.oTime = time.Now()
var uid = gen.Next()
c.rTime = uid.Time()
c.rTimestamp = uid.Timestamp()
c.rMilli , c.rCounter, c.rNode = gen.Parse(&uid)
c.bits = uid.ToBitArray();
c.uuid = uid.ToString();
c.playValue = 1234567890
c.playPrecision = 8
}
func (c *Root) t(str string) string {
return translate(c.lang, str)
}
func (c *Root) getClass(key int) string {
class := ""
if key < 36 {
class = "timestamp"
} else if key == 48 || key == 49 || key == 50 || key == 51 {
class = "version"
} else if key == 64 || key == 65 {
class = "variant"
} else if c.subsecondPrecisionLength !=0 && key < indexer(c.subsecondPrecisionLength+1) {
class = "precision"
} else if c.counterPrecisionLength !=0 && key < indexer(c.subsecondPrecisionLength+c.counterPrecisionLength+1) {
class = "counter"
} else if c.nodePrecisionLength !=0 && key < indexer(c.subsecondPrecisionLength+c.counterPrecisionLength+c.nodePrecisionLength+1) {
class = "node"
} else {
class = "random"
}
return class
}
func (c *Root) display( value bool) string {
val := "0"
if value {
val = "1"
}
return val
}
func (c *Root) setLang(event vugu.DOMEvent, lang string) {
ee := event.EventEnv()
go func() {
ee.Lock()
c.lang = lang
defer ee.UnlockRender()
}()
}
func (c *Root) play( event vugu.DOMEvent, str string) {
val, _ := strconv.Atoi(str)
tmp, _ := encodeDecimal(float64(val), c.playPrecision)
playVal, _ := decodeDecimal(tmp, c.playPrecision)
ee := event.EventEnv()
go func() {
ee.Lock()
c.playValue = val
c.playResult = playVal
defer ee.UnlockRender()
}()
}
func encodeDecimal(sec float64, bits int) (val []byte, err error) {
len := int(math.Log10(sec)) + 1
sec = sec / math.Pow10(len)
num := math.Pow(2, float64(bits))
var part uint64 = uint64(sec * float64(num))
val = make([]byte, 8)
binary.BigEndian.PutUint64(val, part)
return val, nil
}
func decodeDecimal(val []byte, bits int) (sec float64, err error) {
num := math.Pow(2, float64(bits))
ss := float64(toUint64(val)) / float64(num)
return ss, nil
}
// toUint64 converts []byte to uint64
func toUint64(data []byte) uint64 {
var arr [8]byte
copy(arr[len(arr)-len(data):], data)
return binary.BigEndian.Uint64(arr[:])
}
func (c *Root) GetNewUUID(event vugu.DOMEvent) {
ee := event.EventEnv()
go func() {
var gen uuid.UUIDv7Generator
gen.CounterPrecisionLength = c.counterPrecisionLength
gen.NodePrecisionLength = c.nodePrecisionLength
gen.Node = c.node
gen.SubsecondPrecisionLength = c.subsecondPrecisionLength
c.oTime = time.Now()
var uid = gen.Next()
c.rTime = uid.Time()
c.rTimestamp = uid.Timestamp()
c.rMilli , c.rCounter, c.rNode = gen.Parse(&uid)
ee.Lock()
c.bits = uid.ToBitArray();
c.uuid = uid.ToString();
defer ee.UnlockRender()
}()
}
// indexer returns updated index of a bit in the array of bits. It skips bits 48-51 and 64,65
// for those containt information about Version and Variant and can't be populated by the
// precision bits. It also omits first 36 bits of timestamp at the beginning of the GUID
func indexer(input int) int {
out := 35 + input //Skip the TS block and start counting right after ts block
if input > 11 { //If we are bumbing into a ver block, skip it
out += 4
}
if input > 23 { //If we are bumping into a var block
out += 2
}
return out
}
</script>
</html>