2 Commits

Author SHA1 Message Date
poma
c83a4a4dc0 efficient bulk insert 2021-09-15 19:55:13 +03:00
poma
2b6b5c481d minor refactor 2021-09-15 19:54:57 +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, zeroElement = DEFAULT_ZERO } = {}) {
constructor(levels, elements = [], { hashFunction = defaultHash, zeroElement = DEFAULT_ZERO } = {}) {
this.levels = levels
this.capacity = 2 ** levels
if (elements.length > this.capacity) {
throw new Error('Tree is full')
}
this._hash = hashFunction || defaultHash
this._hash = hashFunction
this.zeroElement = zeroElement
this._zeros = []
this._zeros[0] = zeroElement