@k3000/store 1.4.2 → 1.4.3

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 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 = compareBuffer(buffer, this.#storage.getValue(index[s], length))
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 = compareBuffer(buffer, this.#storage.getValue(index[e], length))
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 = compareBuffer(buffer, this.#storage.getValue(index[m], length))
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 > buffer) {
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 = compareBuffer(buffer, this.#storage.getValue(index[m], length))
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,10 @@ export class Entities extends Array {
746
727
  return result
747
728
  }
748
729
 
730
+ findByValue2(name, value, value2) {
731
+
732
+ }
733
+
749
734
  findByValue(name, value) {
750
735
 
751
736
  const index = this.#index[name]
@@ -761,8 +746,8 @@ export class Entities extends Array {
761
746
 
762
747
  let m = Math.floor((s + e) / 2), buffer = this.#storage.getValue(index[m], length)
763
748
 
764
- if (compareBuffer(before, buffer) < 0) return this.#findByTime(index, after, before, length, s, m - 1)
765
- if (compareBuffer(after, buffer) > 0) return this.#findByTime(index, after, before, length, m + 1, e)
749
+ if (before.compare(buffer) < 0) return this.#findByTime(index, after, before, length, s, m - 1)
750
+ if (after.compare(buffer) > 0) return this.#findByTime(index, after, before, length, m + 1, e)
766
751
 
767
752
  let result = [index[m]], i
768
753
 
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, compareBuffer} from './architect.mjs'
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) => compareBuffer(store.getValue(a, struct.length)
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
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@k3000/store",
3
- "version": "1.4.2",
3
+ "version": "1.4.3",
4
4
  "description": "storage",
5
5
  "main": "generator.mjs",
6
6
  "scripts": {