Skip to content

Commit

Permalink
Use 64 bit math
Browse files Browse the repository at this point in the history
  • Loading branch information
cmdcolin committed Jul 1, 2018
1 parent b081b1c commit 17cc6e5
Showing 1 changed file with 18 additions and 6 deletions.
24 changes: 18 additions & 6 deletions src/JBrowse/Model/CSIIndex.js
Expand Up @@ -12,7 +12,12 @@ define([
TabixIndex,
VirtualOffset
) {

function lshift(num, bits) {
return num * Math.pow(2, bits);
}
function rshift(num, bits) {
return Math.floor(num / Math.pow(2,bits));
}
// inner class representing a chunk
var Chunk = Util.fastDeclare({
constructor: function(minv,maxv,bin) {
Expand Down Expand Up @@ -197,12 +202,19 @@ return declare( TabixIndex, {
}
return 0;
},
_reg2bins: function(beg, end, min_shift, depth) {


_reg2bins: function(beg, end, min_shift, n_lvls) {
let l, t, s = min_shift + lshift(n_lvls,1) + n_lvls, nt = 0;
let bins = [];
let l, t, n, s = min_shift + depth*3;
for (--end, l = n = t = 0; l <= depth; s -= 3, t += 1<<l*3, ++l) {
let b = t + (beg>>s), e = t + (end>>s), i;
for (i = b; i <= e; ++i) bins[n++] = i;
for (--end, l = 0, t = 0; l <= n_lvls; s -= 3, t += lshift(1,lshift(l,1)+l), ++l) {
let b, e, n, i;
b = t + rshift(beg,s);
e = t + rshift(end,s);
n = e - b + 1;
for (i = b; i <= e; ++i) {
bins[nt++]=i;
}
}
return bins;
}
Expand Down

0 comments on commit 17cc6e5

Please sign in to comment.