@nxtedition/lib 19.4.0 → 19.4.1
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/package.json +1 -1
- package/sequence.js +30 -0
package/package.json
CHANGED
package/sequence.js
CHANGED
|
@@ -2,9 +2,27 @@ import assert from 'node:assert'
|
|
|
2
2
|
|
|
3
3
|
export const ID_SEP = '~'
|
|
4
4
|
|
|
5
|
+
// https://github.com/bryc/code/blob/master/jshash/experimental/cyrb53.js
|
|
6
|
+
const cyrb53 = (str, seed = 0) => {
|
|
7
|
+
let h1 = 0xdeadbeef ^ seed
|
|
8
|
+
let h2 = 0x41c6ce57 ^ seed
|
|
9
|
+
for (let i = 0, ch; i < str.length; i++) {
|
|
10
|
+
ch = str.charCodeAt(i)
|
|
11
|
+
h1 = Math.imul(h1 ^ ch, 2654435761)
|
|
12
|
+
h2 = Math.imul(h2 ^ ch, 1597334677)
|
|
13
|
+
}
|
|
14
|
+
h1 = Math.imul(h1 ^ (h1 >>> 16), 2246822507)
|
|
15
|
+
h1 ^= Math.imul(h2 ^ (h2 >>> 13), 3266489909)
|
|
16
|
+
h2 = Math.imul(h2 ^ (h2 >>> 16), 2246822507)
|
|
17
|
+
h2 ^= Math.imul(h1 ^ (h1 >>> 13), 3266489909)
|
|
18
|
+
|
|
19
|
+
return 4294967296 * (2097151 & h2) + (h1 >>> 0)
|
|
20
|
+
}
|
|
21
|
+
|
|
5
22
|
export class Sequence {
|
|
6
23
|
#value
|
|
7
24
|
#parts = []
|
|
25
|
+
#identity
|
|
8
26
|
|
|
9
27
|
constructor(value) {
|
|
10
28
|
try {
|
|
@@ -40,6 +58,18 @@ export class Sequence {
|
|
|
40
58
|
}
|
|
41
59
|
}
|
|
42
60
|
|
|
61
|
+
get identity() {
|
|
62
|
+
if (this.#identity == null) {
|
|
63
|
+
let str
|
|
64
|
+
for (let n = 0; n < this.#parts.length; n += 2) {
|
|
65
|
+
str += this.#parts[n]
|
|
66
|
+
}
|
|
67
|
+
this.#identity = cyrb53(str, this.#parts.length)
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
return this.#identity
|
|
71
|
+
}
|
|
72
|
+
|
|
43
73
|
get length() {
|
|
44
74
|
return this.#parts.length / 2
|
|
45
75
|
}
|