@chainsafe/persistent-merkle-tree
Advanced tools
Comparing version 0.6.1 to 0.7.1
@@ -6,2 +6,16 @@ # Change Log | ||
## [0.7.1](https://github.com/ChainSafe/ssz/compare/persistent-merkle-tree-v0.7.0...persistent-merkle-tree-v0.7.1) (2024-03-15) | ||
### Bug Fixes | ||
* export ListUintNum64Type ([#353](https://github.com/ChainSafe/ssz/issues/353)) ([30e3deb](https://github.com/ChainSafe/ssz/commit/30e3debbaf7346711eb201740c072aab645d3b14)) | ||
## [0.7.0](https://github.com/ChainSafe/ssz/compare/persistent-merkle-tree-v0.6.1...persistent-merkle-tree-v0.7.0) (2024-03-12) | ||
### Features | ||
* new type for list of uint64 ([#352](https://github.com/ChainSafe/ssz/issues/352)) ([e131b5a](https://github.com/ChainSafe/ssz/commit/e131b5a9080f8719d624df97d8a4462081a65807)) | ||
## [0.6.1](https://github.com/ChainSafe/ssz/compare/persistent-merkle-tree-v0.6.0...persistent-merkle-tree-v0.6.1) (2023-04-21) | ||
@@ -8,0 +22,0 @@ |
@@ -1,4 +0,16 @@ | ||
import { Node } from "./node"; | ||
import { Node, LeafNode } from "./node"; | ||
export declare function packedRootsBytesToNode(depth: number, dataView: DataView, start: number, end: number): Node; | ||
/** | ||
* Pack a list of uint64 numbers into a list of LeafNodes. | ||
* Each value is UintNum64, which is 8 bytes long, which is 2 h values. | ||
* Each 4 of them forms a LeafNode. | ||
* | ||
* v0 v1 v2 v3 | ||
* |-------------|-------------|-------------|-------------| | ||
* | ||
* h0 h1 h2 h3 h4 h5 h6 h7 | ||
* |------|------|------|------|------|------|------|------| | ||
*/ | ||
export declare function packedUintNum64sToLeafNodes(values: number[]): LeafNode[]; | ||
/** | ||
* Optimized deserialization of linear bytes to consecutive leaf nodes | ||
@@ -5,0 +17,0 @@ */ |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.packedNodeRootsToBytes = exports.packedRootsBytesToLeafNodes = exports.packedRootsBytesToNode = void 0; | ||
exports.packedNodeRootsToBytes = exports.packedRootsBytesToLeafNodes = exports.packedUintNum64sToLeafNodes = exports.packedRootsBytesToNode = void 0; | ||
const subtree_1 = require("./subtree"); | ||
const node_1 = require("./node"); | ||
const NUMBER_2_POW_32 = 2 ** 32; | ||
function packedRootsBytesToNode(depth, dataView, start, end) { | ||
@@ -12,2 +13,35 @@ const leafNodes = packedRootsBytesToLeafNodes(dataView, start, end); | ||
/** | ||
* Pack a list of uint64 numbers into a list of LeafNodes. | ||
* Each value is UintNum64, which is 8 bytes long, which is 2 h values. | ||
* Each 4 of them forms a LeafNode. | ||
* | ||
* v0 v1 v2 v3 | ||
* |-------------|-------------|-------------|-------------| | ||
* | ||
* h0 h1 h2 h3 h4 h5 h6 h7 | ||
* |------|------|------|------|------|------|------|------| | ||
*/ | ||
function packedUintNum64sToLeafNodes(values) { | ||
const leafNodes = new Array(Math.ceil(values.length / 4)); | ||
for (let i = 0; i < values.length; i++) { | ||
const nodeIndex = Math.floor(i / 4); | ||
const leafNode = leafNodes[nodeIndex] ?? new node_1.LeafNode(0, 0, 0, 0, 0, 0, 0, 0); | ||
const vIndex = i % 4; | ||
const hIndex = 2 * vIndex; | ||
const value = values[i]; | ||
// same logic to UintNumberType.value_serializeToBytes() for 8 bytes | ||
if (value === Infinity) { | ||
node_1.setNodeH(leafNode, hIndex, 0xffffffff); | ||
node_1.setNodeH(leafNode, hIndex + 1, 0xffffffff); | ||
} | ||
else { | ||
node_1.setNodeH(leafNode, hIndex, value & 0xffffffff); | ||
node_1.setNodeH(leafNode, hIndex + 1, (value / NUMBER_2_POW_32) & 0xffffffff); | ||
} | ||
leafNodes[nodeIndex] = leafNode; | ||
} | ||
return leafNodes; | ||
} | ||
exports.packedUintNum64sToLeafNodes = packedUintNum64sToLeafNodes; | ||
/** | ||
* Optimized deserialization of linear bytes to consecutive leaf nodes | ||
@@ -14,0 +48,0 @@ */ |
{ | ||
"name": "@chainsafe/persistent-merkle-tree", | ||
"version": "0.6.1", | ||
"version": "0.7.1", | ||
"description": "Merkle tree implemented as a persistent datastructure", | ||
@@ -5,0 +5,0 @@ "main": "lib/index.js", |
@@ -24,3 +24,4 @@ # Persistent Merkle Tree | ||
const r: Uint8Array = branch.root; // == hash(leaf.root, otherLeaf.root)); | ||
// this is equal to `hash(leaf.root, otherLeaf.root));` | ||
const r: Uint8Array = branch.root; | ||
@@ -27,0 +28,0 @@ // The `isLeaf` method returns true if the Node is a LeafNode |
125141
2732
170