TreeIndex.prototype.digest = function (index) { if (this.get(index)) return 1 var digest = 0 var next = flat.sibling(index) var max = this.bitfield.buffer.length * 8 var bit = 2 var depth = flat.depth(index) var parent = flat.parent(next, depth++) while (flat.rightSpan(next) < max || flat.leftSpan(parent) > 0) { if (this.get(next)) { digest |= bit } if (this.get(parent)) { digest |= (2 * bit + 1) if (digest + 1 === 4 * bit) return 1 return digest } next = flat.sibling(parent) parent = flat.parent(next, depth++) bit *= 2 } return digest }
TreeIndex.prototype.verifiedBy = function (index, nodes) { var hasIndex = this.get(index) if (!hasIndex) return 0 // find root of current tree var depth = flat.depth(index) var top = index var parent = flat.parent(top, depth++) while (this.get(parent) && this.get(flat.sibling(top))) { top = parent parent = flat.parent(top, depth++) } // expand right down depth-- while (depth) { top = flat.leftChild(flat.index(depth, flat.offset(top, depth) + 1), depth) depth-- while (!this.get(top) && depth) top = flat.leftChild(top, depth--) if (nodes && this.get(top)) nodes.push(top) } return this.get(top) ? top + 2 : top }