mirror of
https://github.com/tornadocash/fixed-merkle-tree.git
synced 2024-11-22 09:47:15 +01:00
add comparator for indexOf
This commit is contained in:
parent
bb55160b17
commit
523094bdc8
@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "fixed-merkle-tree",
|
||||
"version": "0.3.1",
|
||||
"version": "0.3.2",
|
||||
"description": "Fixed depth merkle tree implementation with sequential inserts",
|
||||
"main": "src/merkleTree.js",
|
||||
"scripts": {
|
||||
|
@ -134,11 +134,17 @@ class MerkleTree {
|
||||
/**
|
||||
* Find an element in the tree
|
||||
* @param element An element to find
|
||||
* @param comparator A function that checks leaf value equality
|
||||
* @returns {number} Index if element is found, otherwise -1
|
||||
*/
|
||||
indexOf(element) {
|
||||
indexOf(element, comparator) {
|
||||
if (comparator) {
|
||||
const result = this._layers[0].findIndex((el) => comparator(element, el))
|
||||
return result === undefined ? -1 : result
|
||||
} else {
|
||||
return this._layers[0].indexOf(element)
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a copy of non-zero tree elements
|
||||
|
Loading…
Reference in New Issue
Block a user