@chainsafe/ssz
Advanced tools
Comparing version
@@ -6,2 +6,17 @@ # Change Log | ||
## [0.16.0](https://github.com/ChainSafe/ssz/compare/ssz-v0.15.1...ssz-v0.16.0) (2024-05-02) | ||
### Features | ||
* add `sliceFrom` to `ListCompositeTreeViewDU` ([#366](https://github.com/ChainSafe/ssz/issues/366)) ([b3fa4f1](https://github.com/ChainSafe/ssz/commit/b3fa4f1335e893f514afdf735b0da34b50b15b6f)) | ||
### Dependencies | ||
* The following workspace dependencies were updated | ||
* dependencies | ||
* @chainsafe/as-sha256 bumped to 0.4.2 | ||
* @chainsafe/persistent-merkle-tree bumped to 0.7.2 | ||
## [0.15.1](https://github.com/ChainSafe/ssz/compare/ssz-v0.15.0...ssz-v0.15.1) (2024-03-15) | ||
@@ -8,0 +23,0 @@ |
@@ -51,9 +51,6 @@ /** | ||
/** | ||
* Return the position of a single bit set. If no bit set or more than 1 bit set, throws. | ||
* Return the position of a single bit set. | ||
* @returns | ||
* - number: if there's a single bit set, the number it the single bit set position | ||
* - null: if ERROR_MORE_THAN_ONE_BIT_SET or ERROR_NO_BIT_SET | ||
* @throws | ||
* - ERROR_MORE_THAN_ONE_BIT_SET | ||
* - ERROR_NO_BIT_SET | ||
*/ | ||
@@ -60,0 +57,0 @@ getSingleTrueBit(): number | null; |
@@ -163,9 +163,6 @@ "use strict"; | ||
/** | ||
* Return the position of a single bit set. If no bit set or more than 1 bit set, throws. | ||
* Return the position of a single bit set. | ||
* @returns | ||
* - number: if there's a single bit set, the number it the single bit set position | ||
* - null: if ERROR_MORE_THAN_ONE_BIT_SET or ERROR_NO_BIT_SET | ||
* @throws | ||
* - ERROR_MORE_THAN_ONE_BIT_SET | ||
* - ERROR_NO_BIT_SET | ||
*/ | ||
@@ -172,0 +169,0 @@ getSingleTrueBit() { |
@@ -29,2 +29,14 @@ import { Node } from "@chainsafe/persistent-merkle-tree"; | ||
/** | ||
* Returns a new ListCompositeTreeViewDU instance with the values from `index` to the end of list | ||
* | ||
* ```ts | ||
* const nodes = getChunkNodes() | ||
* return listFromChunkNodes(node.slice(index)) | ||
* ``` | ||
* | ||
* Note: If index === n, returns an empty list of length 0 | ||
* | ||
*/ | ||
sliceFrom(index: number): this; | ||
/** | ||
* Same method to `type/listComposite.ts` leveraging cached nodes. | ||
@@ -31,0 +43,0 @@ */ |
@@ -57,2 +57,38 @@ "use strict"; | ||
/** | ||
* Returns a new ListCompositeTreeViewDU instance with the values from `index` to the end of list | ||
* | ||
* ```ts | ||
* const nodes = getChunkNodes() | ||
* return listFromChunkNodes(node.slice(index)) | ||
* ``` | ||
* | ||
* Note: If index === n, returns an empty list of length 0 | ||
* | ||
*/ | ||
sliceFrom(index) { | ||
// Commit before getting rootNode to ensure all pending data is in the rootNode | ||
this.commit(); | ||
// If negative index, try to make it positive long as |index| < length | ||
if (index < 0) { | ||
index += this.nodes.length; | ||
} | ||
// If slicing from 0 or neg index, no slicing is necesary | ||
if (index <= 0) { | ||
return this; | ||
} | ||
let newChunksNode; | ||
let newLength; | ||
if (index >= this.nodes.length) { | ||
newChunksNode = persistent_merkle_tree_1.zeroNode(this.type.chunkDepth); | ||
newLength = 0; | ||
} | ||
else { | ||
const nodes = this.nodes.slice(index); | ||
newChunksNode = persistent_merkle_tree_1.subtreeFillToContents(nodes, this.type.chunkDepth); | ||
newLength = nodes.length; | ||
} | ||
const newRootNode = this.type.tree_setChunksNode(this._rootNode, newChunksNode, newLength); | ||
return this.type.getViewDU(newRootNode); | ||
} | ||
/** | ||
* Same method to `type/listComposite.ts` leveraging cached nodes. | ||
@@ -59,0 +95,0 @@ */ |
@@ -7,3 +7,3 @@ { | ||
"homepage": "https://github.com/chainsafe/ssz", | ||
"version": "0.15.1", | ||
"version": "0.16.0", | ||
"main": "lib/index.js", | ||
@@ -39,4 +39,4 @@ "files": [ | ||
"dependencies": { | ||
"@chainsafe/as-sha256": "^0.4.1", | ||
"@chainsafe/persistent-merkle-tree": "^0.7.1" | ||
"@chainsafe/as-sha256": "^0.4.2", | ||
"@chainsafe/persistent-merkle-tree": "^0.7.2" | ||
}, | ||
@@ -43,0 +43,0 @@ "devDependencies": { |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
512181
0.53%7529
0.56%