serializable-bptree 1.0.0 → 1.0.2

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/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2023 izure
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md CHANGED
@@ -1,6 +1,6 @@
1
1
  # serializable-bptree
2
2
 
3
- [![](https://data.jsdelivr.com/v1/package/npm/serializable-bptree/badge)](https://www.jsdelivr.com/package/npm/serialiable-bptree)
3
+ [![](https://data.jsdelivr.com/v1/package/npm/serializable-bptree/badge)](https://www.jsdelivr.com/package/npm/serializable-bptree)
4
4
  ![Node.js workflow](https://github.com/izure1/serializable-bptree/actions/workflows/node.js.yml/badge.svg)
5
5
 
6
6
  This is a B+tree that's totally okay with duplicate values. If you need to keep track of the B+ tree's state, don't just leave it in memory - make sure you write it down.
@@ -41,7 +41,7 @@ class FileStoreStrategy extends SerializeStrategy<K, V> {
41
41
 
42
42
  const order = 5
43
43
  const tree = new BPTree(
44
- new SerializeStrategy(order),
44
+ new FileStoreStrategy(order),
45
45
  new NumericComparator()
46
46
  )
47
47
 
@@ -81,7 +81,7 @@ import { BPTree } from 'serializable-bptree'
81
81
  </script>
82
82
  ```
83
83
 
84
- ## conceptualization
84
+ ## Conceptualization
85
85
 
86
86
  ### Value comparator
87
87
 
@@ -190,7 +190,7 @@ This kind of delay writing should ideally occur within a few milliseconds. If th
190
190
 
191
191
  #### readHead(): `SerializeStrategyHead`|`null`
192
192
 
193
- This method is called only once when the tree is created. It's a method to restore the saved tree information. If it's the first tree creation and there are no saved tree information, return `null`.
193
+ This method is called only once when the tree is created. It's a method to restore the saved tree information. If it is the initial creation and there is no stored root node, it should return `null`.
194
194
 
195
195
  This method should return the value stored in the `writeHead` method.
196
196
 
@@ -200,7 +200,6 @@ This method is called whenever the head information of the tree changes, typical
200
200
 
201
201
  As a parameter, it receives the header information of the tree. This value should be serialized and stored. Later, the `readHead` method should convert this serialized value into a json format and return it.
202
202
 
203
-
204
203
  ### The Default `ValueComparator` and `SerializeStrategy`
205
204
 
206
205
  To utilize `serializable-bptree`, you need to implement certain functions. However, a few basic helper classes are provided by default.
package/dist/cjs/index.js CHANGED
@@ -494,7 +494,8 @@ var BPTree = class {
494
494
  */
495
495
  delete(key, value) {
496
496
  const node = this._insertableNode(value);
497
- for (let i = 0, len = node.values.length; i < len; i++) {
497
+ let i = node.values.length;
498
+ while (i--) {
498
499
  const nValue = node.values[i];
499
500
  if (this.comparator.isSame(value, nValue)) {
500
501
  const keys = node.keys[i];
@@ -724,7 +725,7 @@ var InMemoryStoreStrategy = class extends SerializeStrategy {
724
725
  return Math.ceil(Math.random() * Number.MAX_SAFE_INTEGER - 1);
725
726
  }
726
727
  read(id) {
727
- if (Object.prototype.hasOwnProperty.call(this.data, id)) {
728
+ if (!Object.prototype.hasOwnProperty.call(this.data.node, id)) {
728
729
  throw new Error(`The tree attempted to reference node '${id}', but couldn't find the corresponding node.`);
729
730
  }
730
731
  return this.data.node[id];
package/dist/esm/index.js CHANGED
@@ -463,7 +463,8 @@ var BPTree = class {
463
463
  */
464
464
  delete(key, value) {
465
465
  const node = this._insertableNode(value);
466
- for (let i = 0, len = node.values.length; i < len; i++) {
466
+ let i = node.values.length;
467
+ while (i--) {
467
468
  const nValue = node.values[i];
468
469
  if (this.comparator.isSame(value, nValue)) {
469
470
  const keys = node.keys[i];
@@ -693,7 +694,7 @@ var InMemoryStoreStrategy = class extends SerializeStrategy {
693
694
  return Math.ceil(Math.random() * Number.MAX_SAFE_INTEGER - 1);
694
695
  }
695
696
  read(id) {
696
- if (Object.prototype.hasOwnProperty.call(this.data, id)) {
697
+ if (!Object.prototype.hasOwnProperty.call(this.data.node, id)) {
697
698
  throw new Error(`The tree attempted to reference node '${id}', but couldn't find the corresponding node.`);
698
699
  }
699
700
  return this.data.node[id];
@@ -30,7 +30,7 @@ export declare abstract class SerializeStrategy<K, V> {
30
30
  * It is called when a tree instance is created.
31
31
  * This method should return the information needed to initialize the tree. This information refers to the values stored in the `writeHead` method.
32
32
  *
33
- * If it's the first creation and there are no saved root nodes, return `null`.
33
+ * If it is the initial creation and there is no stored head, it should return `null`.
34
34
  * In this case, the tree is created based on the order specified in the strategy instance constructor parameters.
35
35
  */
36
36
  abstract readHead(): SerializeStrategyHead | null;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "serializable-bptree",
3
- "version": "1.0.0",
3
+ "version": "1.0.2",
4
4
  "description": "Store the B+tree flexibly, not only in-memory.",
5
5
  "main": "dist/cjs/index.js",
6
6
  "module": "dist/esm/index.js",