@k3000/store 1.4.2 → 1.4.4
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 +19 -28
- package/generator.mjs +6 -5
- package/package.json +1 -1
package/architect.mjs
CHANGED
|
@@ -103,25 +103,6 @@ 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
|
-
export 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
|
-
|
|
125
106
|
/**
|
|
126
107
|
* 加解密的类
|
|
127
108
|
*/
|
|
@@ -242,18 +223,18 @@ export class Entity {
|
|
|
242
223
|
|
|
243
224
|
if (e < s) return s
|
|
244
225
|
|
|
245
|
-
let result =
|
|
226
|
+
let result = buffer.compare(this.#storage.getValue(index[s], length))
|
|
246
227
|
|
|
247
228
|
if (s === e) return result < 0 ? s : s + 1
|
|
248
229
|
if (result <= 0) return s
|
|
249
230
|
|
|
250
|
-
result =
|
|
231
|
+
result = buffer.compare(this.#storage.getValue(index[e], length))
|
|
251
232
|
|
|
252
233
|
if (result >= 0) return e + 1
|
|
253
234
|
|
|
254
235
|
let m = Math.floor((s + e) / 2)
|
|
255
236
|
|
|
256
|
-
result =
|
|
237
|
+
result = buffer.compare(this.#storage.getValue(index[m], length))
|
|
257
238
|
|
|
258
239
|
if (result < 0) return this.#indexPosition(index, buffer, length, s + 1, m - 1)
|
|
259
240
|
if (result > 0) return this.#indexPosition(index, buffer, length, m + 1, e - 1)
|
|
@@ -284,7 +265,7 @@ export class Entity {
|
|
|
284
265
|
|
|
285
266
|
index.splice(i, 1)
|
|
286
267
|
|
|
287
|
-
if (buf >
|
|
268
|
+
if (buf.compare(buffer) > 0) {
|
|
288
269
|
|
|
289
270
|
e = i - 1
|
|
290
271
|
|
|
@@ -722,7 +703,7 @@ export class Entities extends Array {
|
|
|
722
703
|
|
|
723
704
|
let m = Math.floor((s + e) / 2)
|
|
724
705
|
|
|
725
|
-
let result =
|
|
706
|
+
let result = buffer.compare(this.#storage.getValue(index[m], length))
|
|
726
707
|
|
|
727
708
|
if (result < 0) return this.#findByValue(index, buffer, length, s, m - 1)
|
|
728
709
|
if (result > 0) return this.#findByValue(index, buffer, length, m + 1, e)
|
|
@@ -746,6 +727,16 @@ export class Entities extends Array {
|
|
|
746
727
|
return result
|
|
747
728
|
}
|
|
748
729
|
|
|
730
|
+
findByValue2(name, value, value2) {
|
|
731
|
+
|
|
732
|
+
if (value.compare(value2) > 0) {
|
|
733
|
+
|
|
734
|
+
[value, value2] = [value2, value]
|
|
735
|
+
}
|
|
736
|
+
|
|
737
|
+
|
|
738
|
+
}
|
|
739
|
+
|
|
749
740
|
findByValue(name, value) {
|
|
750
741
|
|
|
751
742
|
const index = this.#index[name]
|
|
@@ -761,21 +752,21 @@ export class Entities extends Array {
|
|
|
761
752
|
|
|
762
753
|
let m = Math.floor((s + e) / 2), buffer = this.#storage.getValue(index[m], length)
|
|
763
754
|
|
|
764
|
-
if (
|
|
765
|
-
if (
|
|
755
|
+
if (before.compare(buffer) < 0) return this.#findByTime(index, after, before, length, s, m - 1)
|
|
756
|
+
if (after.compare(buffer) > 0) return this.#findByTime(index, after, before, length, m + 1, e)
|
|
766
757
|
|
|
767
758
|
let result = [index[m]], i
|
|
768
759
|
|
|
769
760
|
for (i = m - 1; i >= 0; i--) {
|
|
770
761
|
|
|
771
|
-
if (this.#storage.getValue(index[i], length) <
|
|
762
|
+
if (this.#storage.getValue(index[i], length).compare(after) < 0) break
|
|
772
763
|
|
|
773
764
|
result.unshift(index[i])
|
|
774
765
|
}
|
|
775
766
|
|
|
776
767
|
for (i = m + 1; i < index.length; i++) {
|
|
777
768
|
|
|
778
|
-
if (this.#storage.getValue(index[i], length) >
|
|
769
|
+
if (this.#storage.getValue(index[i], length).compare(before) > 0) break
|
|
779
770
|
|
|
780
771
|
result.push(index[i])
|
|
781
772
|
}
|
package/generator.mjs
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import {copyFileSync, existsSync, mkdirSync, readdirSync, statSync, writeFileSync} from "node:fs";
|
|
2
|
-
import {buffer, string, Storage, TypeLen, readInt24BE, readUint24BE
|
|
2
|
+
import {buffer, string, Storage, TypeLen, readInt24BE, readUint24BE} from './architect.mjs'
|
|
3
3
|
import {resolve} from 'node:path'
|
|
4
4
|
|
|
5
5
|
const modulePath = import.meta.url.endsWith('?test=true') ? '../../architect.mjs' : '@k3000/store/architect.mjs'
|
|
@@ -874,15 +874,12 @@ const updateIndex2 = function (store, record, struct) {
|
|
|
874
874
|
|
|
875
875
|
case typeMap.string:
|
|
876
876
|
|
|
877
|
-
return record.sort((a, b) =>
|
|
878
|
-
, store.getValue(b, struct.length)))
|
|
877
|
+
return record.sort((a, b) => store.getValue(a, struct.length).compare(store.getValue(b, struct.length)))
|
|
879
878
|
}
|
|
880
879
|
}
|
|
881
880
|
|
|
882
881
|
const updateIndex = function (name, set) {
|
|
883
882
|
|
|
884
|
-
console.log(this.curr.record.index)
|
|
885
|
-
|
|
886
883
|
const struct = this.curr.struct.base[name]
|
|
887
884
|
const index = this.curr.record.index[name]
|
|
888
885
|
|
|
@@ -902,6 +899,8 @@ const updateIndex = function (name, set) {
|
|
|
902
899
|
|
|
903
900
|
struct[key].index = true
|
|
904
901
|
index[key] = indexList
|
|
902
|
+
|
|
903
|
+
console.log(`add ${name} index ${key}`)
|
|
905
904
|
}
|
|
906
905
|
}
|
|
907
906
|
|
|
@@ -909,6 +908,8 @@ const updateIndex = function (name, set) {
|
|
|
909
908
|
|
|
910
909
|
delete struct[key].index
|
|
911
910
|
delete index[key]
|
|
911
|
+
|
|
912
|
+
console.log(`remove ${name} index ${key}`)
|
|
912
913
|
}
|
|
913
914
|
}
|
|
914
915
|
}
|