serializable-bptree 1.0.0 → 1.0.1
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 +21 -0
- package/README.md +3 -4
- package/dist/cjs/index.js +1 -1
- package/dist/esm/index.js +1 -1
- package/dist/typings/SerializeStrategy.d.ts +1 -1
- package/package.json +1 -1
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://www.jsdelivr.com/package/npm/
|
|
3
|
+
[](https://www.jsdelivr.com/package/npm/serializable-bptree)
|
|
4
4
|

|
|
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.
|
|
@@ -81,7 +81,7 @@ import { BPTree } from 'serializable-bptree'
|
|
|
81
81
|
</script>
|
|
82
82
|
```
|
|
83
83
|
|
|
84
|
-
##
|
|
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
|
|
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
|
@@ -724,7 +724,7 @@ var InMemoryStoreStrategy = class extends SerializeStrategy {
|
|
|
724
724
|
return Math.ceil(Math.random() * Number.MAX_SAFE_INTEGER - 1);
|
|
725
725
|
}
|
|
726
726
|
read(id) {
|
|
727
|
-
if (Object.prototype.hasOwnProperty.call(this.data, id)) {
|
|
727
|
+
if (!Object.prototype.hasOwnProperty.call(this.data.node, id)) {
|
|
728
728
|
throw new Error(`The tree attempted to reference node '${id}', but couldn't find the corresponding node.`);
|
|
729
729
|
}
|
|
730
730
|
return this.data.node[id];
|
package/dist/esm/index.js
CHANGED
|
@@ -693,7 +693,7 @@ var InMemoryStoreStrategy = class extends SerializeStrategy {
|
|
|
693
693
|
return Math.ceil(Math.random() * Number.MAX_SAFE_INTEGER - 1);
|
|
694
694
|
}
|
|
695
695
|
read(id) {
|
|
696
|
-
if (Object.prototype.hasOwnProperty.call(this.data, id)) {
|
|
696
|
+
if (!Object.prototype.hasOwnProperty.call(this.data.node, id)) {
|
|
697
697
|
throw new Error(`The tree attempted to reference node '${id}', but couldn't find the corresponding node.`);
|
|
698
698
|
}
|
|
699
699
|
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
|
|
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;
|