Merge branch 'main' into iouescrow

This commit is contained in:
Denis Angell
2023-02-09 11:20:36 -05:00
committed by GitHub
239 changed files with 8410 additions and 4616 deletions

View File

@@ -80,6 +80,7 @@ module.exports = {
'jsdoc/require-description-complete-sentence': 'off',
'jsdoc/require-jsdoc': 'off',
'jsdoc/check-tag-names': 'off',
'jsdoc/check-examples': 'off', // Not implemented in eslint 8
'jsdoc/require-returns': 'off',
'jsdoc/require-hyphen-before-param-description': 'off',
'jsdoc/require-description': 'off',

View File

@@ -159,20 +159,22 @@ class ShaMapInner extends ShaMapNode {
*/
addItem(index?: Hash256, item?: ShaMapNode, leaf?: ShaMapLeaf): void {
assert.ok(index !== undefined)
const nibble = index.nibblet(this.depth)
const existing = this.branches[nibble]
if (index !== undefined) {
const nibble = index.nibblet(this.depth)
const existing = this.branches[nibble]
if (existing === undefined) {
this.setBranch(nibble, leaf || new ShaMapLeaf(index, item))
} else if (existing instanceof ShaMapLeaf) {
const newInner = new ShaMapInner(this.depth + 1)
newInner.addItem(existing.index, undefined, existing)
newInner.addItem(index, item, leaf)
this.setBranch(nibble, newInner)
} else if (existing instanceof ShaMapInner) {
existing.addItem(index, item, leaf)
} else {
throw new Error('invalid ShaMap.addItem call')
if (existing === undefined) {
this.setBranch(nibble, leaf || new ShaMapLeaf(index, item))
} else if (existing instanceof ShaMapLeaf) {
const newInner = new ShaMapInner(this.depth + 1)
newInner.addItem(existing.index, undefined, existing)
newInner.addItem(index, item, leaf)
this.setBranch(nibble, newInner)
} else if (existing instanceof ShaMapInner) {
existing.addItem(index, item, leaf)
} else {
throw new Error('invalid ShaMap.addItem call')
}
}
}
}