fix binary index.
This commit is contained in:
parent
3dddfcf7ea
commit
4d30c9428a
@ -1429,7 +1429,12 @@ BinaryIndex.prototype.insert = function insert(tx) {
|
||||
};
|
||||
|
||||
BinaryIndex.prototype.remove = function remove(tx) {
|
||||
var index = binarySearch(this.data, tx.hash());
|
||||
var ps = new Buffer(4);
|
||||
var index;
|
||||
|
||||
utils.writeU32BE(ps, tx.ps, 0);
|
||||
|
||||
index = binarySearch(this.index, ps);
|
||||
|
||||
if (index !== -1) {
|
||||
this.index.splice(index, 1);
|
||||
@ -1439,12 +1444,12 @@ BinaryIndex.prototype.remove = function remove(tx) {
|
||||
|
||||
BinaryIndex.prototype.range = function range(start, end) {
|
||||
var hashes = [];
|
||||
var s = new Buffer(4);
|
||||
var ts = new Buffer(4);
|
||||
var i, ps;
|
||||
|
||||
utils.writeU32BE(s, start, 0);
|
||||
utils.writeU32BE(ts, start, 0);
|
||||
|
||||
i = binarySearch(this.index, s, true);
|
||||
i = binarySearch(this.index, ts, true);
|
||||
|
||||
for (; i < this.index.length; i++) {
|
||||
ps = utils.readU32BE(this.index[i], 0);
|
||||
@ -1460,14 +1465,17 @@ BinaryIndex.prototype.range = function range(start, end) {
|
||||
* Helpers
|
||||
*/
|
||||
|
||||
function binarySearch(items, key, insert) {
|
||||
function binarySearch(items, key, insert, compare) {
|
||||
var start = 0;
|
||||
var end = items.length - 1;
|
||||
var pos, cmp;
|
||||
|
||||
if (!compare)
|
||||
compare = utils.cmp;
|
||||
|
||||
while (start <= end) {
|
||||
pos = (start + end) >>> 1;
|
||||
cmp = utils.cmp(items[pos], key);
|
||||
cmp = compare(items[pos], key);
|
||||
|
||||
if (cmp === 0)
|
||||
return pos;
|
||||
|
||||
Loading…
Reference in New Issue
Block a user