mirror of
https://github.com/tornadocash/fixed-merkle-tree.git
synced 2024-11-22 01:37:09 +01:00
implementing getTreeSlices
This commit is contained in:
parent
8e2b0a2dbc
commit
ad634a6b3a
@ -195,17 +195,21 @@ export default class MerkleTree {
|
|||||||
return { edgePath, edgeElement, edgeIndex }
|
return { edgePath, edgeElement, edgeIndex }
|
||||||
}
|
}
|
||||||
|
|
||||||
getTreeSlices(count: number): { edge: TreeEdge, elements: Element[] }[] {
|
/**
|
||||||
|
* 🪓
|
||||||
|
* @param count
|
||||||
|
*/
|
||||||
|
getTreeSlices(count = 4): { edge: TreeEdge, elements: Element[] }[] {
|
||||||
const length = this._layers[0].length
|
const length = this._layers[0].length
|
||||||
let size = Math.ceil(length / count)
|
let size = Math.ceil(length / count)
|
||||||
size % 2 && size++
|
size % 2 && size++
|
||||||
const indexes = []
|
const slices = []
|
||||||
for (let i = length - size - 1; i > -size; i -= size) {
|
for (let i = length - size - 1; i > -size; i -= size) {
|
||||||
const edgeLeft = i >= 0 ? i : 0
|
const edgeLeft = i >= 0 ? i : 0
|
||||||
const edgeRight = i + size
|
const edgeRight = i + size
|
||||||
indexes.push({ edge: this.getTreeEdge(edgeLeft), elements: this.elements.slice(edgeLeft, edgeRight) })
|
slices.push({ edge: this.getTreeEdge(edgeLeft), elements: this.elements.slice(edgeLeft, edgeRight) })
|
||||||
}
|
}
|
||||||
return indexes
|
return slices.reverse()
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
Loading…
Reference in New Issue
Block a user