@optimystic/db-core 1.18.0 → 1.19.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/README.md +2 -1
- package/dist/src/blocks/helpers.d.ts +7 -0
- package/dist/src/blocks/helpers.d.ts.map +1 -1
- package/dist/src/blocks/helpers.js +7 -1
- package/dist/src/blocks/helpers.js.map +1 -1
- package/dist/src/btree/btree.d.ts +100 -4
- package/dist/src/btree/btree.d.ts.map +1 -1
- package/dist/src/btree/btree.js +252 -90
- package/dist/src/btree/btree.js.map +1 -1
- package/dist/src/btree/node-division.d.ts +37 -0
- package/dist/src/btree/node-division.d.ts.map +1 -0
- package/dist/src/btree/node-division.js +133 -0
- package/dist/src/btree/node-division.js.map +1 -0
- package/dist/src/chain/chain.d.ts +23 -0
- package/dist/src/chain/chain.d.ts.map +1 -1
- package/dist/src/chain/chain.js +43 -6
- package/dist/src/chain/chain.js.map +1 -1
- package/dist/src/collection/collection.d.ts +38 -5
- package/dist/src/collection/collection.d.ts.map +1 -1
- package/dist/src/collection/collection.js +126 -11
- package/dist/src/collection/collection.js.map +1 -1
- package/dist/src/collection/struct.d.ts +20 -0
- package/dist/src/collection/struct.d.ts.map +1 -1
- package/dist/src/collection/struct.js.map +1 -1
- package/dist/src/collections/tree/tree.d.ts.map +1 -1
- package/dist/src/collections/tree/tree.js +5 -3
- package/dist/src/collections/tree/tree.js.map +1 -1
- package/dist/src/log/log.d.ts +5 -1
- package/dist/src/log/log.d.ts.map +1 -1
- package/dist/src/log/log.js +7 -1
- package/dist/src/log/log.js.map +1 -1
- package/dist/src/network/block-size.d.ts +67 -0
- package/dist/src/network/block-size.d.ts.map +1 -0
- package/dist/src/network/block-size.js +82 -0
- package/dist/src/network/block-size.js.map +1 -0
- package/dist/src/network/index.d.ts +2 -0
- package/dist/src/network/index.d.ts.map +1 -1
- package/dist/src/network/index.js +2 -0
- package/dist/src/network/index.js.map +1 -1
- package/dist/src/network/struct.d.ts +13 -11
- package/dist/src/network/struct.d.ts.map +1 -1
- package/dist/src/network/struct.js.map +1 -1
- package/dist/src/network/transaction-size.d.ts +59 -0
- package/dist/src/network/transaction-size.d.ts.map +1 -0
- package/dist/src/network/transaction-size.js +74 -0
- package/dist/src/network/transaction-size.js.map +1 -0
- package/dist/src/reactivity/config.d.ts +8 -4
- package/dist/src/reactivity/config.d.ts.map +1 -1
- package/dist/src/reactivity/config.js +7 -3
- package/dist/src/reactivity/config.js.map +1 -1
- package/dist/src/reactivity/rotation.d.ts +9 -3
- package/dist/src/reactivity/rotation.d.ts.map +1 -1
- package/dist/src/reactivity/rotation.js +8 -2
- package/dist/src/reactivity/rotation.js.map +1 -1
- package/dist/src/testing/test-transactor.d.ts +2 -0
- package/dist/src/testing/test-transactor.d.ts.map +1 -1
- package/dist/src/testing/test-transactor.js +10 -0
- package/dist/src/testing/test-transactor.js.map +1 -1
- package/dist/src/transaction/coordinator.d.ts +72 -3
- package/dist/src/transaction/coordinator.d.ts.map +1 -1
- package/dist/src/transaction/coordinator.js +320 -146
- package/dist/src/transaction/coordinator.js.map +1 -1
- package/dist/src/transactor/change-notifier.d.ts +13 -4
- package/dist/src/transactor/change-notifier.d.ts.map +1 -1
- package/dist/src/transactor/change-notifier.js.map +1 -1
- package/dist/src/transactor/network-transactor.d.ts +57 -8
- package/dist/src/transactor/network-transactor.d.ts.map +1 -1
- package/dist/src/transactor/network-transactor.js +185 -24
- package/dist/src/transactor/network-transactor.js.map +1 -1
- package/dist/src/transactor/transactor.d.ts +14 -0
- package/dist/src/transactor/transactor.d.ts.map +1 -1
- package/dist/src/transform/digest.d.ts +20 -0
- package/dist/src/transform/digest.d.ts.map +1 -1
- package/dist/src/transform/digest.js +23 -3
- package/dist/src/transform/digest.js.map +1 -1
- package/package.json +1 -1
- package/src/blocks/helpers.ts +8 -1
- package/src/btree/btree.ts +266 -88
- package/src/btree/node-division.ts +155 -0
- package/src/chain/chain.ts +55 -6
- package/src/collection/collection.ts +135 -13
- package/src/collection/struct.ts +18 -0
- package/src/collections/tree/tree.ts +4 -2
- package/src/log/log.ts +7 -1
- package/src/network/block-size.ts +81 -0
- package/src/network/index.ts +2 -0
- package/src/network/struct.ts +15 -13
- package/src/network/transaction-size.ts +73 -0
- package/src/reactivity/config.ts +8 -4
- package/src/reactivity/rotation.ts +9 -3
- package/src/testing/test-transactor.ts +12 -0
- package/src/transaction/coordinator.ts +383 -154
- package/src/transactor/change-notifier.ts +13 -4
- package/src/transactor/network-transactor.ts +192 -29
- package/src/transactor/transactor.ts +16 -0
- package/src/transform/digest.ts +36 -3
package/README.md
CHANGED
|
@@ -95,7 +95,7 @@ Linked block primitives that can function as stacks, queues, or logs:
|
|
|
95
95
|
|
|
96
96
|
- **Flexible access patterns**: LIFO (stack), FIFO (queue), or sequential (log)
|
|
97
97
|
- **Efficient traversal**: Forward and backward iteration with precise navigation
|
|
98
|
-
- **Block efficiency**: 32 entries per block
|
|
98
|
+
- **Block efficiency**: at most 32 entries per block, and a log block rolls over at `BLOCK_TARGET_BYTES` (1 MiB) as well, so every block stays small enough to copy between machines
|
|
99
99
|
- **Distributed ready**: Lazy loading and efficient network operations
|
|
100
100
|
|
|
101
101
|
```typescript
|
|
@@ -115,6 +115,7 @@ B+tree implementation providing efficient sorted access to data:
|
|
|
115
115
|
- **Sorted access**: Keys maintained in order for efficient range queries
|
|
116
116
|
- **Path-based navigation**: Cursor-like traversal through the tree
|
|
117
117
|
- **Automatic rebalancing**: Splits, merges, and borrowing maintain optimal structure
|
|
118
|
+
- **Bounded node size**: a tree collection's nodes split by size as well as by count, so a table of large rows never builds a block too large to copy between machines (see [Node size](docs/btree.md#node-size))
|
|
118
119
|
- **Type-safe**: Generic implementation supporting custom key/entry types
|
|
119
120
|
|
|
120
121
|
```typescript
|
|
@@ -6,4 +6,11 @@ export declare function apply<T extends IBlock>(store: BlockStore<T>, block: IBl
|
|
|
6
6
|
* content-agreement (db-p2p `selectQuorumBlock` candidates) and commit content digests. Keep ONE
|
|
7
7
|
* implementation: a drifted copy reports honest content as forged. */
|
|
8
8
|
export declare function canonicalBlockHash(block: IBlock): Promise<string>;
|
|
9
|
+
/** {@link canonicalBlockHash}, together with how many bytes it hashed. That count is the block's
|
|
10
|
+
* `jsonEncodedBytes`: canonical JSON is `JSON.stringify` with object keys reordered, which changes no
|
|
11
|
+
* length, so one serialization both declares a block's content and measures it. */
|
|
12
|
+
export declare function canonicalBlockHashAndBytes(block: IBlock): Promise<{
|
|
13
|
+
hash: string;
|
|
14
|
+
bytes: number;
|
|
15
|
+
}>;
|
|
9
16
|
//# sourceMappingURL=helpers.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"helpers.d.ts","sourceRoot":"","sources":["../../../src/blocks/helpers.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,EAAE,OAAO,EAAE,UAAU,EAAE,WAAW,EAAE,MAAM,aAAa,CAAC;AAI5F,wBAAsB,GAAG,CAAC,CAAC,SAAS,MAAM,EAAE,KAAK,EAAE,UAAU,CAAC,CAAC,CAAC,EAAE,EAAE,EAAE,OAAO,EAAE,OAAO,CAAC,EAAE,WAAW,GAAG,OAAO,CAAC,CAAC,CAAC,CAIhH;AAED,wBAAgB,KAAK,CAAC,CAAC,SAAS,MAAM,EAAE,KAAK,EAAE,UAAU,CAAC,CAAC,CAAC,EAAE,KAAK,EAAE,MAAM,EAAE,EAAE,EAAE,cAAc,QAG9F;AAED;;;sEAGsE;AACtE,wBAAsB,kBAAkB,CAAC,KAAK,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC,
|
|
1
|
+
{"version":3,"file":"helpers.d.ts","sourceRoot":"","sources":["../../../src/blocks/helpers.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,EAAE,OAAO,EAAE,UAAU,EAAE,WAAW,EAAE,MAAM,aAAa,CAAC;AAI5F,wBAAsB,GAAG,CAAC,CAAC,SAAS,MAAM,EAAE,KAAK,EAAE,UAAU,CAAC,CAAC,CAAC,EAAE,EAAE,EAAE,OAAO,EAAE,OAAO,CAAC,EAAE,WAAW,GAAG,OAAO,CAAC,CAAC,CAAC,CAIhH;AAED,wBAAgB,KAAK,CAAC,CAAC,SAAS,MAAM,EAAE,KAAK,EAAE,UAAU,CAAC,CAAC,CAAC,EAAE,KAAK,EAAE,MAAM,EAAE,EAAE,EAAE,cAAc,QAG9F;AAED;;;sEAGsE;AACtE,wBAAsB,kBAAkB,CAAC,KAAK,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC,CAEvE;AAED;;mFAEmF;AACnF,wBAAsB,0BAA0B,CAAC,KAAK,EAAE,MAAM,GAAG,OAAO,CAAC;IAAE,IAAI,EAAE,MAAM,CAAC;IAAC,KAAK,EAAE,MAAM,CAAA;CAAE,CAAC,CAIxG"}
|
|
@@ -17,8 +17,14 @@ export function apply(store, block, op) {
|
|
|
17
17
|
* content-agreement (db-p2p `selectQuorumBlock` candidates) and commit content digests. Keep ONE
|
|
18
18
|
* implementation: a drifted copy reports honest content as forged. */
|
|
19
19
|
export async function canonicalBlockHash(block) {
|
|
20
|
+
return (await canonicalBlockHashAndBytes(block)).hash;
|
|
21
|
+
}
|
|
22
|
+
/** {@link canonicalBlockHash}, together with how many bytes it hashed. That count is the block's
|
|
23
|
+
* `jsonEncodedBytes`: canonical JSON is `JSON.stringify` with object keys reordered, which changes no
|
|
24
|
+
* length, so one serialization both declares a block's content and measures it. */
|
|
25
|
+
export async function canonicalBlockHashAndBytes(block) {
|
|
20
26
|
const bytes = new TextEncoder().encode(canonicalJson(block));
|
|
21
27
|
const digest = await sha256.digest(bytes);
|
|
22
|
-
return uint8ArrayToString(digest.digest, 'base64url');
|
|
28
|
+
return { hash: uint8ArrayToString(digest.digest, 'base64url'), bytes: bytes.byteLength };
|
|
23
29
|
}
|
|
24
30
|
//# sourceMappingURL=helpers.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"helpers.js","sourceRoot":"","sources":["../../../src/blocks/helpers.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,0BAA0B,CAAC;AAClD,OAAO,EAAE,QAAQ,IAAI,kBAAkB,EAAE,MAAM,aAAa,CAAC;AAE7D,OAAO,EAAE,cAAc,EAAE,MAAM,yBAAyB,CAAC;AACzD,OAAO,EAAE,aAAa,EAAE,MAAM,8BAA8B,CAAC;AAE7D,MAAM,CAAC,KAAK,UAAU,GAAG,CAAmB,KAAoB,EAAE,EAAW,EAAE,OAAqB;IACnG,MAAM,KAAK,GAAG,MAAM,KAAK,CAAC,MAAM,CAAC,EAAE,EAAE,OAAO,CAAC,CAAC;IAC9C,IAAI,CAAC,KAAK;QAAE,MAAM,KAAK,CAAC,kBAAkB,EAAE,GAAG,CAAC,CAAC;IACjD,OAAO,KAAK,CAAC;AACd,CAAC;AAED,MAAM,UAAU,KAAK,CAAmB,KAAoB,EAAE,KAAa,EAAE,EAAkB;IAC9F,cAAc,CAAC,KAAK,EAAE,EAAE,CAAC,CAAC;IAC1B,KAAK,CAAC,MAAM,CAAC,KAAK,CAAC,MAAM,CAAC,EAAE,EAAE,EAAE,CAAC,CAAC;AACnC,CAAC;AAED;;;sEAGsE;AACtE,MAAM,CAAC,KAAK,UAAU,kBAAkB,CAAC,KAAa;IACrD,MAAM,KAAK,GAAG,IAAI,WAAW,EAAE,CAAC,MAAM,CAAC,aAAa,CAAC,KAAK,CAAC,CAAC,CAAC;IAC7D,MAAM,MAAM,GAAG,MAAM,MAAM,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC;IAC1C,OAAO,kBAAkB,CAAC,MAAM,CAAC,MAAM,EAAE,WAAW,CAAC,CAAC;
|
|
1
|
+
{"version":3,"file":"helpers.js","sourceRoot":"","sources":["../../../src/blocks/helpers.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,0BAA0B,CAAC;AAClD,OAAO,EAAE,QAAQ,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Entry: (entry: TEntry) => TKey;
|
|
18
18
|
readonly compare: (a: TKey, b: TKey) => number;
|
|
19
19
|
readonly nodeCapacity: number;
|
|
20
|
+
/** When set, a node also splits once its JSON (`jsonEncodedBytes`) would pass this many bytes, and
|
|
21
|
+
* a borrow or merge that would take a node past it is refused. A node may exceed it only while
|
|
22
|
+
* holding the least a node holds — one entry for a leaf, two children for a branch — so a leaf is
|
|
23
|
+
* never larger than the entry that was written into it. Absent, nodes split by count alone and
|
|
24
|
+
* are never serialized to be measured. The tree collection sets it to `BLOCK_TARGET_BYTES`; see
|
|
25
|
+
* "Node size" in `docs/btree.md`. */
|
|
26
|
+
readonly nodeTargetBytes?: number | undefined;
|
|
20
27
|
protected _version: number;
|
|
21
28
|
private _proxy?;
|
|
22
29
|
/**
|
|
23
30
|
* @param [compare=(a: TKey, b: TKey) => a < b ? -1 : a > b ? 1 : 0] a comparison function for keys. The default uses < and > operators.
|
|
24
31
|
* @param [keyFromEntry=(entry: TEntry) => entry as unknown as TKey] a function to extract the key from an entry. The default assumes the key is the entry itself.
|
|
25
32
|
*/
|
|
26
|
-
constructor(store: BlockStore<ITreeNode>, trunk: ITreeTrunk, keyFromEntry?: (entry: TEntry) => TKey, compare?: (a: TKey, b: TKey) => number, nodeCapacity?: number
|
|
33
|
+
constructor(store: BlockStore<ITreeNode>, trunk: ITreeTrunk, keyFromEntry?: (entry: TEntry) => TKey, compare?: (a: TKey, b: TKey) => number, nodeCapacity?: number,
|
|
34
|
+
/** When set, a node also splits once its JSON (`jsonEncodedBytes`) would pass this many bytes, and
|
|
35
|
+
* a borrow or merge that would take a node past it is refused. A node may exceed it only while
|
|
36
|
+
* holding the least a node holds — one entry for a leaf, two children for a branch — so a leaf is
|
|
37
|
+
* never larger than the entry that was written into it. Absent, nodes split by count alone and
|
|
38
|
+
* are never serialized to be measured. The tree collection sets it to `BLOCK_TARGET_BYTES`; see
|
|
39
|
+
* "Node size" in `docs/btree.md`. */
|
|
40
|
+
nodeTargetBytes?: number | undefined);
|
|
27
41
|
private atomic;
|
|
28
42
|
static createRoot(store: BlockStore<ITreeNode>): LeafNode<never>;
|
|
29
|
-
static create<TKey, TEntry>(store: BlockStore<ITreeNode | TreeBlock>, createTrunk: getTrunkFunc, keyFromEntry?: (entry: TEntry) => TKey, compare?: (a: TKey, b: TKey) => number, nodeCapacity?: number, newId?: BlockId
|
|
43
|
+
static create<TKey, TEntry>(store: BlockStore<ITreeNode | TreeBlock>, createTrunk: getTrunkFunc, keyFromEntry?: (entry: TEntry) => TKey, compare?: (a: TKey, b: TKey) => number, nodeCapacity?: number, newId?: BlockId,
|
|
44
|
+
/** See the constructor's `nodeTargetBytes`. */
|
|
45
|
+
nodeTargetBytes?: number): BTree<TKey, TEntry>;
|
|
30
46
|
/** @returns a path to the first entry (on = false if no entries) */
|
|
31
47
|
first(): Promise<Path<TKey, TEntry>>;
|
|
32
48
|
/** @returns a path to the last entry (on = false if no entries) */
|
|
@@ -135,6 +151,16 @@ export declare class BTree<TKey, TEntry> {
|
|
|
135
151
|
protected internalDelete(path: Path<TKey, TEntry>): Promise<boolean>;
|
|
136
152
|
private internalInsert;
|
|
137
153
|
private internalInsertAt;
|
|
154
|
+
/** Apply `edit` to the path's leaf and absorb whatever splits it causes up the path: each parent
|
|
155
|
+
* that cannot take the new children splits in turn, and a split that reaches the root grows the
|
|
156
|
+
* tree by a level. The path follows the edited entry throughout. */
|
|
157
|
+
private applyLeafEdit;
|
|
158
|
+
/** Put a new root over the old one and the nodes `overflow` left to its right. Written whole when it
|
|
159
|
+
* fits one node, as a root of two children always does. Otherwise — more new nodes than a branch
|
|
160
|
+
* holds, or keys so large that two of them pass the byte target — the root starts as the old root
|
|
161
|
+
* alone and absorbs the rest through {@link branchInsert}, which divides it and may hand back an
|
|
162
|
+
* overflow for the caller to grow another level over. */
|
|
163
|
+
private growRoot;
|
|
138
164
|
/** Starting from the given node, recursively working down to the leaf, build onto the path based on the beginning-most entry. */
|
|
139
165
|
private moveToFirst;
|
|
140
166
|
/** Starting from the given node, recursively working down to the leaf, build onto the path based on the end-most entry. */
|
|
@@ -143,17 +169,87 @@ export declare class BTree<TKey, TEntry> {
|
|
|
143
169
|
private getFirst;
|
|
144
170
|
/** Construct a path based on the last-most edge of the given node */
|
|
145
171
|
private getLast;
|
|
146
|
-
|
|
172
|
+
/** Apply `edit` to the path's leaf, dividing the leaf when the result would not fit one node (see
|
|
173
|
+
* {@link leafRuns}). The first run of entries stays in the leaf and each further run becomes a new
|
|
174
|
+
* leaf to its right; the edit's entry is placed directly into whichever leaf it falls in rather
|
|
175
|
+
* than logged as an operation on it, so a new leaf is one insert and the old leaf one or two small
|
|
176
|
+
* operations. The path moves to the new leaf when its entry went there.
|
|
177
|
+
* @returns the overflow for the parent to absorb, or `undefined` when the leaf took the edit whole. */
|
|
178
|
+
private leafEdit;
|
|
179
|
+
/** How `entries` — the path's leaf as it would stand after an edit at index `at` — divide into leaves,
|
|
180
|
+
* or `undefined` when they fit one: at most `nodeCapacity` entries and, when the tree has a byte
|
|
181
|
+
* target and the leaf would hold more than one entry, no more than the target's bytes. See
|
|
182
|
+
* {@link divideItems} for the division, a pure function of the leaf's content and the edit, so a
|
|
183
|
+
* replayed or retried action produces the same transforms. */
|
|
184
|
+
private leafRuns;
|
|
185
|
+
/** Absorb a child's overflow into the branch at `branchIndex` of the path: the new children go after
|
|
186
|
+
* the one that split, each under its key. When the branch cannot hold them all ({@link branchRuns})
|
|
187
|
+
* it divides: the first run of children stays with the keys between them, each further run becomes
|
|
188
|
+
* a new branch to the right, and the key before a run's first child is promoted as that branch's
|
|
189
|
+
* key. As in {@link leafEdit}, a new child is placed directly into whichever branch it falls in.
|
|
190
|
+
* @returns the overflow for the next branch up, or `undefined` when this one took the children whole. */
|
|
147
191
|
private branchInsert;
|
|
192
|
+
/** How a branch's children — `partitions` and `nodes` as the branch would stand with new children
|
|
193
|
+
* absorbed, the path following child `at` — divide into branches, or `undefined` when they fit one;
|
|
194
|
+
* the counterpart of {@link leafRuns}. A branch's bytes are its keys and child ids, so only large
|
|
195
|
+
* keys ever make bytes the reason, and a branch of two children (one key) always counts as fitting:
|
|
196
|
+
* nothing smaller routes. */
|
|
197
|
+
private branchRuns;
|
|
198
|
+
/** After a delete, fill the path's leaf back up when it is under-full ({@link leafUnderfull}):
|
|
199
|
+
* borrow one entry from a sibling with more than half the count, else merge with a sibling. With
|
|
200
|
+
* a byte target a borrow or merge that would take a leaf past it is refused, so a leaf of a few
|
|
201
|
+
* large entries can stay under half the count for good; see "Node size" in `docs/btree.md`.
|
|
202
|
+
*
|
|
203
|
+
* NOTE: a leaf that is under-full by both measures and whose siblings refuse it by bytes reads
|
|
204
|
+
* both siblings on every delete from it and writes nothing — one delete of its last entry ends
|
|
205
|
+
* that, since an empty leaf always merges. If such reads ever show up, remember the refusal on
|
|
206
|
+
* the path for the rest of the action. */
|
|
148
207
|
protected rebalanceLeaf(path: Path<TKey, TEntry>, depth: number): Promise<ITreeNode | undefined>;
|
|
208
|
+
/** The branch counterpart of {@link rebalanceLeaf}, with the same rules: a branch under-full by
|
|
209
|
+
* count and (with a byte target) by bytes borrows a child from a sibling with more than half the
|
|
210
|
+
* count, else merges with a sibling, and neither may take a branch past the byte target. The key
|
|
211
|
+
* that separates the two in the parent comes down with the borrowed child or the merge. */
|
|
149
212
|
protected rebalanceBranch(path: Path<TKey, TEntry>, depth: number): Promise<ITreeNode | undefined>;
|
|
150
213
|
protected updatePartition(nodeIndex: number, path: Path<TKey, TEntry>, depth: number, newKey: TKey): void;
|
|
151
214
|
protected insertPartition(branch: BranchNode<TKey>, index: number, key: TKey, node: BlockId, nodeOffset?: number): void;
|
|
215
|
+
/** Insert children after the child at `index`, each under its key: `keys` go in at `index` and
|
|
216
|
+
* `nodes` at `index + 1`, one operation each. */
|
|
217
|
+
private insertChildren;
|
|
218
|
+
/** Drop the items of `node`'s `entity` array (now `length` long) from `keep` on. Nothing is
|
|
219
|
+
* recorded when there is nothing to drop: a zero-length splice would still mark the block updated
|
|
220
|
+
* and have it written again. */
|
|
221
|
+
private cutTail;
|
|
152
222
|
protected deletePartition(branch: BranchNode<TKey>, index: number, nodeOffset?: number): void;
|
|
153
223
|
private validatePath;
|
|
154
224
|
/** Iterates every node ID below and including the given node. */
|
|
155
225
|
private nodeIds;
|
|
156
226
|
protected getEntry(path: Path<TKey, TEntry>): TEntry;
|
|
157
|
-
|
|
227
|
+
/** Replace the entry at the path in place. A larger entry can take the leaf past the byte target
|
|
228
|
+
* with no insert, so this goes through the same split an insert does ({@link leafEdit}); the path
|
|
229
|
+
* follows the entry when it moves to a new leaf. */
|
|
230
|
+
protected updateEntry(path: Path<TKey, TEntry>, entry: TEntry): Promise<void>;
|
|
231
|
+
/** A node's bytes against the byte target, or `undefined` when the tree has none. */
|
|
232
|
+
private measure;
|
|
233
|
+
/** A leaf below half the count AND, with a byte target, below half the target — one that a borrow
|
|
234
|
+
* or merge could usefully fill. A leaf of a few large entries is under half the count for good but
|
|
235
|
+
* is a healthy block, so it is left alone and a delete from it reads no sibling. */
|
|
236
|
+
private leafUnderfull;
|
|
237
|
+
/** Whether `leaf` may take one more `entry` from a sibling without passing the byte target. */
|
|
238
|
+
private leafTakes;
|
|
239
|
+
/** Whether `leaf` and a sibling may become one: within the count, and within the byte target unless
|
|
240
|
+
* one of them is empty — removing an empty leaf adds nothing to the other, so that is never refused
|
|
241
|
+
* and no empty leaf outlives the delete that emptied it. Whichever of the two survives, the merged
|
|
242
|
+
* leaf is one fixed part plus both sets of entries and the comma that joins them. */
|
|
243
|
+
private leavesMerge;
|
|
244
|
+
/** {@link leafUnderfull} for a branch, by its children. */
|
|
245
|
+
private branchUnderfull;
|
|
246
|
+
/** Whether the measured branch may take one more child, `node`, under `key` — the parent's key
|
|
247
|
+
* that comes down with it — without passing the byte target: the key and the id, a comma before each. */
|
|
248
|
+
private branchTakes;
|
|
249
|
+
/** Whether `branch` and a sibling may become one under `key`, the parent's key between them: within
|
|
250
|
+
* the count and, with a byte target, within it — the sibling's keys and ids, the key that comes down,
|
|
251
|
+
* and the three commas that join them (one before the key, one before each of the two lists). A
|
|
252
|
+
* branch is never empty, so there is no exemption. */
|
|
253
|
+
private branchesMerge;
|
|
158
254
|
}
|
|
159
255
|
//# sourceMappingURL=btree.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"btree.d.ts","sourceRoot":"","sources":["../../../src/btree/btree.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,IAAI,EAAc,MAAM,WAAW,CAAC;AAC7C,OAAO,KAAK,EAAE,UAAU,EAAE,QAAQ,EAAE,YAAY,EAAE,MAAM,YAAY,CAAC;AACrE,OAAO,KAAK,EAAE,OAAO,
|
|
1
|
+
{"version":3,"file":"btree.d.ts","sourceRoot":"","sources":["../../../src/btree/btree.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,IAAI,EAAc,MAAM,WAAW,CAAC;AAC7C,OAAO,KAAK,EAAE,UAAU,EAAE,QAAQ,EAAE,YAAY,EAAE,MAAM,YAAY,CAAC;AACrE,OAAO,KAAK,EAAE,OAAO,EAAkB,UAAU,EAAE,MAAM,oBAAoB,CAAC;AAG9E,OAAO,KAAK,EAAE,UAAU,EAAE,SAAS,EAAE,QAAQ,EAAE,MAAM,YAAY,CAAC;AAClE,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAC;AACjD,OAAO,EAAe,KAAK,WAAW,EAAE,MAAM,8BAA8B,CAAC;AAI7E,eAAO,MAAM,YAAY,KAAK,CAAC;AAM/B;;;;;GAKG;AACH,qBAAa,KAAK,CAAC,IAAI,EAAE,MAAM;aASb,KAAK,EAAE,UAAU,CAAC,SAAS,CAAC;aAC5B,KAAK,EAAE,UAAU;aACjB,YAAY,GAAI,OAAO,MAAM,KAAyB,IAAI;aAC1D,OAAO,GAAI,GAAG,IAAI,EAAE,GAAG,IAAI;aAC3B,YAAY;IAC5B;;;;;0CAKsC;aACtB,eAAe,CAAC,EAAE,MAAM;IAnBzC,SAAS,C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