mirror of
https://github.com/tornadocash/fixed-merkle-tree.git
synced 2024-12-28 15:47:57 +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,10 +134,16 @@ 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) {
|
||||
return this._layers[0].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)
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
Loading…
Reference in New Issue
Block a user