2 Commits

Author SHA1 Message Date
poma
3e31a2f875 efficient bulk insert
(cherry picked from commit c83a4a4dc0)
2021-09-15 20:02:06 +03:00
poma
c775fc35f4 minor refactor 2021-09-15 20:01:17 +03:00

View File

@@ -22,13 +22,13 @@ class MerkleTree {
* @param {hashFunction} [options.hashFunction] Function used to hash 2 leaves
* @param [options.zeroElement] Value for non-existent leaves
*/
constructor(levels, elements = [], { hashFunction = defaultHash, zeroElement = DEFAULT_ZERO } = {}) {
constructor(levels, elements = [], { hashFunction, zeroElement = DEFAULT_ZERO } = {}) {
this.levels = levels
this.capacity = 2 ** levels
if (elements.length > this.capacity) {
throw new Error('Tree is full')
}
this._hash = hashFunction
this._hash = hashFunction || defaultHash
this.zeroElement = zeroElement
this._zeros = []
this._zeros[0] = zeroElement