@k3000/store 1.2.2 → 1.3.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/architect.mjs +43 -14
- package/package.json +1 -1
package/architect.mjs
CHANGED
|
@@ -103,6 +103,25 @@ export const TypeLen = {
|
|
|
103
103
|
string: 12
|
|
104
104
|
}
|
|
105
105
|
|
|
106
|
+
/**
|
|
107
|
+
* @param {Buffer} a
|
|
108
|
+
* @param {Buffer} b
|
|
109
|
+
* @returns {-1 | 0 | 1}
|
|
110
|
+
*/
|
|
111
|
+
const compareBuffer = (a, b) => {
|
|
112
|
+
|
|
113
|
+
if (a.length > b.length) return 1
|
|
114
|
+
if (a.length < b.length) return -1
|
|
115
|
+
|
|
116
|
+
for (let i = 0; i < a.length; i++) {
|
|
117
|
+
|
|
118
|
+
if (a[i] > b[i]) return 1
|
|
119
|
+
if (a[i] < b[i]) return -1
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
return 0
|
|
123
|
+
}
|
|
124
|
+
|
|
106
125
|
/**
|
|
107
126
|
* 加解密的类
|
|
108
127
|
*/
|
|
@@ -222,14 +241,22 @@ export class Entity {
|
|
|
222
241
|
#indexPosition(index, buffer, length, s, e) {
|
|
223
242
|
|
|
224
243
|
if (e < s) return s
|
|
225
|
-
if (s === e) return buffer < this.#storage.getValue(index[s], length) ? s : s + 1
|
|
226
|
-
if (buffer <= this.#storage.getValue(index[s], length)) return s
|
|
227
|
-
if (buffer >= this.#storage.getValue(index[e], length)) return e + 1
|
|
228
244
|
|
|
229
|
-
let
|
|
245
|
+
let result = compareBuffer(buffer, this.#storage.getValue(index[s], length))
|
|
230
246
|
|
|
231
|
-
if (
|
|
232
|
-
if (
|
|
247
|
+
if (s === e) return result < 0 ? s : s + 1
|
|
248
|
+
if (result <= 0) return s
|
|
249
|
+
|
|
250
|
+
result = compareBuffer(buffer, this.#storage.getValue(index[e], length))
|
|
251
|
+
|
|
252
|
+
if (result >= 0) return e + 1
|
|
253
|
+
|
|
254
|
+
let m = Math.floor((s + e) / 2)
|
|
255
|
+
|
|
256
|
+
result = compareBuffer(buffer, this.#storage.getValue(index[m], length))
|
|
257
|
+
|
|
258
|
+
if (result < 0) return this.#indexPosition(index, buffer, length, s + 1, m - 1)
|
|
259
|
+
if (result > 0) return this.#indexPosition(index, buffer, length, m + 1, e - 1)
|
|
233
260
|
|
|
234
261
|
return m
|
|
235
262
|
}
|
|
@@ -693,21 +720,23 @@ export class Entities extends Array {
|
|
|
693
720
|
|
|
694
721
|
if (e < s) return []
|
|
695
722
|
|
|
696
|
-
let m = Math.floor((s + e) / 2)
|
|
723
|
+
let m = Math.floor((s + e) / 2)
|
|
697
724
|
|
|
698
|
-
|
|
699
|
-
if (buffer > buf) return this.#findByValue(index, buffer, length, m + 1, e)
|
|
725
|
+
let result = compareBuffer(buffer, this.#storage.getValue(index[m], length))
|
|
700
726
|
|
|
701
|
-
|
|
727
|
+
if (result < 0) return this.#findByValue(index, buffer, length, s, m - 1)
|
|
728
|
+
if (result > 0) return this.#findByValue(index, buffer, length, m + 1, e)
|
|
702
729
|
|
|
703
|
-
|
|
730
|
+
result = [index[m]]
|
|
731
|
+
|
|
732
|
+
for (let i = m - 1; i >= 0; i--) {
|
|
704
733
|
|
|
705
734
|
if (!this.#storage.getValue(index[i], length).equals(buffer)) break
|
|
706
735
|
|
|
707
736
|
result.unshift(index[i])
|
|
708
737
|
}
|
|
709
738
|
|
|
710
|
-
for (i = m + 1; i < index.length; i++) {
|
|
739
|
+
for (let i = m + 1; i < index.length; i++) {
|
|
711
740
|
|
|
712
741
|
if (!this.#storage.getValue(index[i], length).equals(buffer)) break
|
|
713
742
|
|
|
@@ -732,8 +761,8 @@ export class Entities extends Array {
|
|
|
732
761
|
|
|
733
762
|
let m = Math.floor((s + e) / 2), buffer = this.#storage.getValue(index[m], length)
|
|
734
763
|
|
|
735
|
-
if (before
|
|
736
|
-
if (after
|
|
764
|
+
if (compareBuffer(before, buffer)) return this.#findByTime(index, after, before, length, s, m - 1)
|
|
765
|
+
if (compareBuffer(after, buffer)) return this.#findByTime(index, after, before, length, m + 1, e)
|
|
737
766
|
|
|
738
767
|
let result = [index[m]], i
|
|
739
768
|
|