@k3000/store 1.5.5 → 1.6.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 CHANGED
@@ -221,23 +221,14 @@ export class Entity {
221
221
 
222
222
  #indexPosition(index, buffer, length, s, e) {
223
223
 
224
- if (e < s) return s
224
+ if (s + 1 === e) return e
225
225
 
226
- let result = buffer.compare(this.#storage.getValue(index[s], length))
227
-
228
- if (s === e) return result < 0 ? s : s + 1
229
- if (result <= 0) return s
230
-
231
- result = buffer.compare(this.#storage.getValue(index[e], length))
232
-
233
- if (result >= 0) return e + 1
234
-
235
- let m = Math.floor((s + e) / 2)
226
+ const m = Math.round((s + e) / 2)
236
227
 
237
- result = buffer.compare(this.#storage.getValue(index[m], length))
228
+ const result = buffer.compare(this.#storage.getValue(index[m], length))
238
229
 
239
- if (result < 0) return this.#indexPosition(index, buffer, length, s + 1, m - 1)
240
- if (result > 0) return this.#indexPosition(index, buffer, length, m + 1, e - 1)
230
+ if (result < 0) return this.#indexPosition(index, buffer, length, s, m)
231
+ if (result > 0) return this.#indexPosition(index, buffer, length, m, e)
241
232
 
242
233
  return m
243
234
  }
@@ -264,21 +255,36 @@ export class Entity {
264
255
  if (i >= 0) {
265
256
 
266
257
  index.splice(i, 1)
258
+ }
267
259
 
268
- if (buf.compare(buffer) > 0) {
260
+ let resutl = buffer.compare(this.#storage.getValue(index[0], length))
269
261
 
270
- e = i - 1
262
+ if (index.length === 0) {
271
263
 
272
- } else {
264
+ i = 0
265
+
266
+ } else if (index.length === 1) {
267
+
268
+ i = resutl < 0 ? 0 : 1
273
269
 
274
- e--
270
+ } else if (resutl <= 0) {
271
+
272
+ i = 0
273
+
274
+ } else {
275
275
 
276
- s = i
276
+ resutl = buffer.compare(this.#storage.getValue(index[e], length))
277
+
278
+ if (resutl >= 0) {
279
+
280
+ i = e + 1
281
+
282
+ } else {
283
+
284
+ i = this.#indexPosition(index, buffer, length, s, e)
277
285
  }
278
286
  }
279
287
 
280
- i = index.length === 0 ? 0 : this.#indexPosition(index, buffer, length, s, e)
281
-
282
288
  index.splice(i, 0, position)
283
289
  }
284
290
  }
@@ -463,9 +469,9 @@ export class Entities extends Array {
463
469
 
464
470
  let i
465
471
 
466
- for (const value of Object.values(this.#index)) {
472
+ for (const [key, value] of Object.entries(this.#index)) {
467
473
 
468
- i = value.indexOf(index)
474
+ i = value.indexOf(index + this.#positionSet[key])
469
475
 
470
476
  if (i >= 0) {
471
477
 
@@ -729,6 +735,15 @@ export class Entities extends Array {
729
735
  return result
730
736
  }
731
737
 
738
+ findByValue(name, value) {
739
+
740
+ const index = this.#index[name]
741
+ const position = this.#positionSet[name]
742
+
743
+ return this.#findByValue(index, value, this.#lengthSet[name], 0, index.length - 1)
744
+ .map(index => this.#getEntity(index - position))
745
+ }
746
+
732
747
  #indexAfterPosition(index, after, length, s, e) {
733
748
 
734
749
  if (s + 1 === e) return after.compare(this.#storage.getValue(index[s], length)) > 0 ? e : s
@@ -800,15 +815,6 @@ export class Entities extends Array {
800
815
  .map(index => this.#getEntity(index - position))
801
816
  }
802
817
 
803
- findByValue(name, value) {
804
-
805
- const index = this.#index[name]
806
- const position = this.#positionSet[name]
807
-
808
- return this.#findByValue(index, value, this.#lengthSet[name], 0, index.length - 1)
809
- .map(index => this.#getEntity(index - position))
810
- }
811
-
812
818
  #findByTime(index, after, before, length, s, e) {
813
819
 
814
820
  if (e < s) return []
@@ -1303,6 +1309,17 @@ export class Storage {
1303
1309
  expired: true,
1304
1310
  needsSave,
1305
1311
  })
1312
+
1313
+ } else {
1314
+
1315
+ try {
1316
+
1317
+ writeSync(this.#fd_data, value, 0, length, position)
1318
+
1319
+ } catch (e) {
1320
+
1321
+ console.error(e)
1322
+ }
1306
1323
  }
1307
1324
 
1308
1325
  return needsSave
@@ -1372,9 +1389,12 @@ export class Storage {
1372
1389
 
1373
1390
  updateValue(value, name, key) {
1374
1391
 
1375
- if (!value) return this.#record.value[name][key] += this.#struct.base[name][key].step
1392
+ if (value === undefined) return this.#record.value[name][key] += this.#struct.base[name][key].step
1393
+
1394
+ if (Number.isNaN(Number.parseFloat(value))) {
1376
1395
 
1377
- value = Number.parseFloat(value) || 1
1396
+ value = 1
1397
+ }
1378
1398
 
1379
1399
  if (value > this.#record.value[name][key]) this.#record.value[name][key] = value
1380
1400
 
package/generator.mjs CHANGED
@@ -1315,7 +1315,7 @@ ${Object.entries(value).map(([k, v]) => {
1315
1315
  return `
1316
1316
  indexBy${n}(${k}, ${k}_2) {
1317
1317
 
1318
- if (${k}_2 === undefined) return super.findByValue($${k}, ${gen.set[v.type]}(${k}, $${k}))
1318
+ if (${k}_2 === undefined || ${k} == ${k}_2) return super.findByValue($${k}, ${gen.set[v.type]}(${k}, $${k}))
1319
1319
 
1320
1320
  return super.findByRange($${k}, ${gen.set[v.type]}(${k}, $${k}), ${gen.set[v.type]}(${k}_2, $${k}))
1321
1321
  }`
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@k3000/store",
3
- "version": "1.5.5",
3
+ "version": "1.6.0",
4
4
  "description": "storage",
5
5
  "main": "generator.mjs",
6
6
  "scripts": {