| 1 |
package ukmer; |
| 2 |
|
| 3 |
import java.util.Arrays; |
| 4 |
import java.util.concurrent.atomic.AtomicIntegerArray; |
| 5 |
import java.util.concurrent.atomic.AtomicLong; |
| 6 |
import java.util.concurrent.locks.Lock; |
| 7 |
import java.util.concurrent.locks.ReentrantLock; |
| 8 |
|
| 9 |
import fileIO.ByteStreamWriter; |
| 10 |
import fileIO.TextStreamWriter; |
| 11 |
import shared.Primes; |
| 12 |
import shared.Tools; |
| 13 |
import structures.ByteBuilder; |
| 14 |
import structures.SuperLongList; |
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
|
| 20 |
|
| 21 |
|
| 22 |
public abstract class HashArrayU extends AbstractKmerTableU { |
| 23 |
|
| 24 |
|
| 25 |
|
| 26 |
|
| 27 |
|
| 28 |
HashArrayU(int[] schedule_, int k_, int kbig_, boolean twod_){ |
| 29 |
schedule=schedule_; |
| 30 |
autoResize=schedule.length>1; |
| 31 |
prime=schedule[0]; |
| 32 |
|
| 33 |
sizeLimit=(long)((schedule.length==1 ? maxLoadFactorFinal : maxLoadFactor)*prime); |
| 34 |
k=k_; |
| 35 |
kbig=kbig_; |
| 36 |
mult=kbig/k; |
| 37 |
arrays=new long[mult][]; |
| 38 |
for(int i=0; i<mult; i++){ |
| 39 |
arrays[i]=allocLong1D(prime+extra); |
| 40 |
Arrays.fill(arrays[i], NOT_PRESENT); |
| 41 |
} |
| 42 |
victims=new HashForestU(Tools.max(10, prime/victimRatio), k, autoResize, twod_); |
| 43 |
TWOD=twod_; |
| 44 |
} |
| 45 |
|
| 46 |
|
| 47 |
|
| 48 |
|
| 49 |
|
| 50 |
|
| 51 |
|
| 52 |
|
| 53 |
|
| 54 |
|
| 55 |
|
| 56 |
|
| 57 |
|
| 58 |
|
| 59 |
|
| 60 |
|
| 61 |
|
| 62 |
|
| 63 |
|
| 64 |
|
| 65 |
|
| 66 |
|
| 67 |
|
| 68 |
|
| 69 |
|
| 70 |
|
| 71 |
|
| 72 |
|
| 73 |
|
| 74 |
|
| 75 |
|
| 76 |
|
| 77 |
|
| 78 |
|
| 79 |
|
| 80 |
|
| 81 |
|
| 82 |
|
| 83 |
|
| 84 |
|
| 85 |
|
| 86 |
|
| 87 |
|
| 88 |
|
| 89 |
|
| 90 |
|
| 91 |
|
| 92 |
|
| 93 |
|
| 94 |
|
| 95 |
|
| 96 |
|
| 97 |
|
| 98 |
|
| 99 |
|
| 100 |
|
| 101 |
|
| 102 |
|
| 103 |
|
| 104 |
|
| 105 |
|
| 106 |
|
| 107 |
|
| 108 |
|
| 109 |
|
| 110 |
|
| 111 |
|
| 112 |
|
| 113 |
|
| 114 |
|
| 115 |
|
| 116 |
|
| 117 |
|
| 118 |
|
| 119 |
|
| 120 |
|
| 121 |
|
| 122 |
|
| 123 |
|
| 124 |
|
| 125 |
|
| 126 |
|
| 127 |
|
| 128 |
|
| 129 |
|
| 130 |
|
| 131 |
|
| 132 |
|
| 133 |
|
| 134 |
|
| 135 |
|
| 136 |
|
| 137 |
public final int kmerToCell(Kmer kmer){ |
| 138 |
int cell=(int)(kmer.xor()%prime); |
| 139 |
return cell; |
| 140 |
} |
| 141 |
|
| 142 |
@Override |
| 143 |
public final int set(Kmer kmer, final int[] v){ |
| 144 |
final int cell=findKmerOrEmpty(kmer); |
| 145 |
|
| 146 |
if(cell==HASH_COLLISION){ |
| 147 |
if(verbose){System.err.println("C2: Adding "+kmer+", "+v+", "+cell);} |
| 148 |
final int x=victims.set(kmer, v); |
| 149 |
if(autoResize && size+victims.size>sizeLimit){resize();} |
| 150 |
if(verbose){System.err.println("C2: getValues("+kmer+") = "+Arrays.toString(getValues(kmer, new int[1])));} |
| 151 |
return x; |
| 152 |
} |
| 153 |
final long[] key=kmer.key(); |
| 154 |
|
| 155 |
assert(cell>=0); |
| 156 |
|
| 157 |
final boolean notpresent=(arrays[0][cell]==NOT_PRESENT); |
| 158 |
if(notpresent){ |
| 159 |
if(verbose){System.err.println("B2: Setting cell "+cell+" to kmer "+kmer);} |
| 160 |
setKmer(kmer.key(), cell); |
| 161 |
} |
| 162 |
|
| 163 |
if(verbose){System.err.println("A2: Adding "+kmer+", "+Arrays.toString(v)+", "+cell);} |
| 164 |
insertValue(key, v, cell); |
| 165 |
if(verbose){System.err.println("A2: getValues("+kmer+") = "+Arrays.toString(getValues(kmer, new int[1])));} |
| 166 |
|
| 167 |
if(notpresent){ |
| 168 |
size++; |
| 169 |
if(autoResize && size+victims.size>sizeLimit){resize();} |
| 170 |
return 1; |
| 171 |
}else{ |
| 172 |
return 0; |
| 173 |
} |
| 174 |
} |
| 175 |
|
| 176 |
public final void setKmer(long[] key, int cell){ |
| 177 |
if(verbose){System.err.println();} |
| 178 |
for(int i=0; i<mult; i++){ |
| 179 |
arrays[i][cell]=key[i]; |
| 180 |
} |
| 181 |
} |
| 182 |
|
| 183 |
@Override |
| 184 |
public final int set(final Kmer kmer, final int v){ |
| 185 |
assert(kmer.mult==mult && kmer.len>=kmer.kbig); |
| 186 |
final int cell=findKmerOrEmpty(kmer); |
| 187 |
|
| 188 |
|
| 189 |
if(cell==HASH_COLLISION){ |
| 190 |
if(verbose){System.err.println("C2: Adding "+kmer+", "+v+", "+cell);} |
| 191 |
final int x=victims.set(kmer, v); |
| 192 |
if(autoResize && size+victims.size>sizeLimit){resize();} |
| 193 |
if(verbose){System.err.println("C2: getValues("+kmer+") = "+Arrays.toString(getValues(kmer, new int[1])));} |
| 194 |
return x; |
| 195 |
} |
| 196 |
assert(cell>=0); |
| 197 |
final long[] key=kmer.key(); |
| 198 |
|
| 199 |
final boolean notpresent=(arrays[0][cell]==NOT_PRESENT); |
| 200 |
if(notpresent){ |
| 201 |
if(verbose){System.err.println("B2: Setting cell "+cell+" to kmer "+kmer);} |
| 202 |
setKmer(key, cell); |
| 203 |
} |
| 204 |
|
| 205 |
if(verbose){System.err.println("A2: Adding "+kmer+", "+v+", "+cell);} |
| 206 |
insertValue(key, v, cell); |
| 207 |
if(verbose){System.err.println("A2: getValues("+kmer+") = "+Arrays.toString(getValues(kmer, new int[1])));} |
| 208 |
|
| 209 |
if(notpresent){ |
| 210 |
size++; |
| 211 |
if(autoResize && size+victims.size>sizeLimit){resize();} |
| 212 |
return 1; |
| 213 |
}else{ |
| 214 |
return 0; |
| 215 |
} |
| 216 |
} |
| 217 |
|
| 218 |
|
| 219 |
|
| 220 |
|
| 221 |
|
| 222 |
@Override |
| 223 |
public final int setIfNotPresent(Kmer kmer, int value){ |
| 224 |
final int cell=findKmerOrEmpty(kmer); |
| 225 |
|
| 226 |
if(cell==HASH_COLLISION){ |
| 227 |
int x=victims.setIfNotPresent(kmer, value); |
| 228 |
if(autoResize && size+victims.size>sizeLimit){resize();} |
| 229 |
return x; |
| 230 |
} |
| 231 |
assert(cell>=0); |
| 232 |
final long[] key=kmer.key(); |
| 233 |
|
| 234 |
if(cell==NOT_PRESENT){ |
| 235 |
setKmer(key, cell); |
| 236 |
insertValue(key, value, cell); |
| 237 |
size++; |
| 238 |
if(autoResize && size+victims.size>sizeLimit){resize();} |
| 239 |
return 1; |
| 240 |
}else{ |
| 241 |
return 0; |
| 242 |
} |
| 243 |
} |
| 244 |
|
| 245 |
@Override |
| 246 |
public final int getValue(Kmer kmer){ |
| 247 |
int cell=findKmer(kmer); |
| 248 |
if(cell==NOT_PRESENT){return NOT_PRESENT;} |
| 249 |
if(cell==HASH_COLLISION){return victims.getValue(kmer);} |
| 250 |
return readCellValue(cell); |
| 251 |
} |
| 252 |
|
| 253 |
public final int getValue(Kmer kmer, int startCell){ |
| 254 |
int cell=findKmer(kmer, startCell); |
| 255 |
if(cell==NOT_PRESENT){return NOT_PRESENT;} |
| 256 |
if(cell==HASH_COLLISION){return victims.getValue(kmer);} |
| 257 |
return readCellValue(cell); |
| 258 |
} |
| 259 |
|
| 260 |
public final int getCount(Kmer kmer){ |
| 261 |
return getValue(kmer); |
| 262 |
} |
| 263 |
|
| 264 |
|
| 265 |
|
| 266 |
|
| 267 |
@Override |
| 268 |
public int getValue(long[] key, long xor) { |
| 269 |
throw new RuntimeException("Unimplemented"); |
| 270 |
} |
| 271 |
|
| 272 |
protected final long[] fillKey(int cell, long[] temp) { |
| 273 |
return fillKey(cell, temp, arrays); |
| 274 |
} |
| 275 |
|
| 276 |
public final Kmer fillKmer(int cell, Kmer kmer) { |
| 277 |
return fillKmer(cell, kmer, arrays); |
| 278 |
} |
| 279 |
|
| 280 |
public final Kmer fillKmer(int cell, Kmer kmer, long[][] matrix) { |
| 281 |
long[] x=fillKey(cell, kmer.array1(), matrix); |
| 282 |
|
| 283 |
if(x==null){return null;} |
| 284 |
kmer.fillArray2(); |
| 285 |
if(verbose){System.err.println("Filled kmer "+kmer+": a1="+Arrays.toString(kmer.array1())+", a2="+Arrays.toString(kmer.array2())+", key="+Arrays.toString(kmer.key()));} |
| 286 |
return kmer; |
| 287 |
} |
| 288 |
|
| 289 |
protected final long[] fillKey(int cell, long[] temp, long[][] matrix) { |
| 290 |
assert(temp.length==mult); |
| 291 |
if(matrix[0][cell]<0){ |
| 292 |
|
| 293 |
return null; |
| 294 |
} |
| 295 |
for(int i=0; i<temp.length; i++){ |
| 296 |
temp[i]=matrix[i][cell]; |
| 297 |
} |
| 298 |
if(verbose){System.err.println("cell="+cell+", matrix[0][cell]="+matrix[0][cell]+", temp="+Arrays.toString(temp)+"\nmatrix[0]="+Arrays.toString(matrix[0]));} |
| 299 |
return temp; |
| 300 |
} |
| 301 |
|
| 302 |
@Override |
| 303 |
public final int[] getValues(Kmer kmer, int[] singleton){ |
| 304 |
int cell=findKmer(kmer); |
| 305 |
if(cell==NOT_PRESENT){ |
| 306 |
singleton[0]=NOT_PRESENT; |
| 307 |
return singleton; |
| 308 |
} |
| 309 |
if(cell==HASH_COLLISION){return victims.getValues(kmer, singleton);} |
| 310 |
return readCellValues(cell, singleton); |
| 311 |
} |
| 312 |
|
| 313 |
@Override |
| 314 |
public final boolean contains(Kmer kmer){ |
| 315 |
int cell=findKmer(kmer); |
| 316 |
if(cell==NOT_PRESENT){return false;} |
| 317 |
if(cell==HASH_COLLISION){return victims.contains(kmer);} |
| 318 |
return true; |
| 319 |
} |
| 320 |
|
| 321 |
|
| 322 |
|
| 323 |
|
| 324 |
|
| 325 |
@Override |
| 326 |
public final void initializeOwnership(){ |
| 327 |
assert(owners==null); |
| 328 |
owners=allocAtomicInt(arrays[0].length); |
| 329 |
for(int i=0; i<arrays[0].length; i++){ |
| 330 |
owners.set(i, NO_OWNER); |
| 331 |
} |
| 332 |
victims.initializeOwnership(); |
| 333 |
} |
| 334 |
|
| 335 |
@Override |
| 336 |
public final void clearOwnership(){ |
| 337 |
owners=null; |
| 338 |
victims.clearOwnership(); |
| 339 |
} |
| 340 |
|
| 341 |
@Override |
| 342 |
public final int setOwner(final Kmer kmer, final int newOwner){ |
| 343 |
final int cell=findKmer(kmer); |
| 344 |
assert(cell!=NOT_PRESENT); |
| 345 |
if(cell==HASH_COLLISION){return victims.setOwner(kmer, newOwner);} |
| 346 |
return setOwner(kmer, newOwner, cell); |
| 347 |
} |
| 348 |
|
| 349 |
public final int setOwner(final Kmer kmer, final int newOwner, final int cell){ |
| 350 |
|
| 351 |
assert(matches(kmer.key(), cell)) : "cell="+cell+", key="+Arrays.toString(kmer.key())+", row="+Arrays.toString(cellToArray(cell))+"\n" + |
| 352 |
"kmer="+kmer+", array1="+Arrays.toString(kmer.array1())+", array2="+Arrays.toString(kmer.array2())+", row="+AbstractKmerTableU.toText(cellToArray(cell), kmer.k); |
| 353 |
final int original=owners.get(cell); |
| 354 |
int current=original; |
| 355 |
while(current<newOwner){ |
| 356 |
boolean success=owners.compareAndSet(cell, current, newOwner); |
| 357 |
if(!success){current=owners.get(cell);} |
| 358 |
else{current=newOwner;} |
| 359 |
} |
| 360 |
assert(current>=original) : "original="+original+", current="+current+", newOwner="+newOwner+", re-read="+owners.get(cell); |
| 361 |
return current; |
| 362 |
} |
| 363 |
|
| 364 |
@Override |
| 365 |
public final boolean clearOwner(final Kmer kmer, final int owner){ |
| 366 |
final int cell=findKmer(kmer); |
| 367 |
assert(cell!=NOT_PRESENT); |
| 368 |
if(cell==HASH_COLLISION){return victims.clearOwner(kmer, owner);} |
| 369 |
return clearOwner(kmer, owner, cell); |
| 370 |
} |
| 371 |
|
| 372 |
public final boolean clearOwner(final Kmer kmer, final int owner, final int cell){ |
| 373 |
assert(matches(kmer.key(), cell)); |
| 374 |
boolean success=owners.compareAndSet(cell, owner, NO_OWNER); |
| 375 |
return success; |
| 376 |
} |
| 377 |
|
| 378 |
@Override |
| 379 |
public final int getOwner(final Kmer kmer){ |
| 380 |
final int cell=findKmer(kmer); |
| 381 |
assert(cell!=NOT_PRESENT); |
| 382 |
if(cell==HASH_COLLISION){return victims.getOwner(kmer);} |
| 383 |
return getCellOwner(cell); |
| 384 |
} |
| 385 |
|
| 386 |
public final int getCellOwner(final int cell){ |
| 387 |
return owners.get(cell); |
| 388 |
} |
| 389 |
|
| 390 |
|
| 391 |
|
| 392 |
|
| 393 |
|
| 394 |
protected abstract void insertValue(final long[] kmer, final int v, final int cell); |
| 395 |
|
| 396 |
protected abstract void insertValue(final long[] kmer, final int[] vals, final int cell); |
| 397 |
|
| 398 |
protected abstract int readCellValue(int cell); |
| 399 |
protected abstract int[] readCellValues(int cell, int[] singleton); |
| 400 |
|
| 401 |
@Override |
| 402 |
final Object get(long[] kmer){ |
| 403 |
throw new RuntimeException("Unimplemented."); |
| 404 |
} |
| 405 |
|
| 406 |
final int findKmer(Kmer kmer){ |
| 407 |
return findKmer(kmer.key(), (int)(kmer.xor()%prime)); |
| 408 |
} |
| 409 |
|
| 410 |
final int findKmer(Kmer kmer, int startCell){ |
| 411 |
return findKmer(kmer.key(), startCell); |
| 412 |
} |
| 413 |
|
| 414 |
|
| 415 |
|
| 416 |
|
| 417 |
|
| 418 |
|
| 419 |
|
| 420 |
|
| 421 |
|
| 422 |
|
| 423 |
|
| 424 |
|
| 425 |
|
| 426 |
|
| 427 |
|
| 428 |
|
| 429 |
|
| 430 |
|
| 431 |
|
| 432 |
|
| 433 |
final int findKmer(final long[] key, final int startCell){ |
| 434 |
int cell=startCell; |
| 435 |
|
| 436 |
final long[] array0=arrays[0]; |
| 437 |
final long key0=key[0]; |
| 438 |
for(final int max=cell+extra; cell<max; cell++){ |
| 439 |
final long n=array0[cell]; |
| 440 |
if(n==key0){ |
| 441 |
boolean success=true; |
| 442 |
for(int i=1; i<mult && success; i++){ |
| 443 |
if(key[i]!=arrays[i][cell]){success=false;} |
| 444 |
} |
| 445 |
if(success){return cell;} |
| 446 |
}else if(n==NOT_PRESENT){return NOT_PRESENT;} |
| 447 |
} |
| 448 |
return HASH_COLLISION; |
| 449 |
} |
| 450 |
|
| 451 |
final int findKmerOrEmpty(Kmer kmer){ |
| 452 |
int cell=kmerToCell(kmer); |
| 453 |
if(verbose){System.err.println("Started at cell "+cell+" for "+kmer);} |
| 454 |
|
| 455 |
final long[] key=kmer.key(); |
| 456 |
final long[] array0=arrays[0]; |
| 457 |
final long key0=key[0]; |
| 458 |
for(final int max=cell+extra; cell<max; cell++){ |
| 459 |
final long n=array0[cell]; |
| 460 |
if(n==NOT_PRESENT){ |
| 461 |
if(verbose){System.err.println("Chose empty cell "+cell+" for "+kmer);} |
| 462 |
return cell; |
| 463 |
}else if(n==key0){ |
| 464 |
boolean success=true; |
| 465 |
for(int i=1; i<mult && success; i++){ |
| 466 |
if(key[i]!=arrays[i][cell]){success=false;} |
| 467 |
} |
| 468 |
if(success){ |
| 469 |
if(verbose){System.err.println("Found cell "+cell+" containing "+kmer);} |
| 470 |
return cell; |
| 471 |
} |
| 472 |
} |
| 473 |
} |
| 474 |
return HASH_COLLISION; |
| 475 |
} |
| 476 |
|
| 477 |
final boolean matches(long[] key, int cell){ |
| 478 |
assert(cell>=0); |
| 479 |
for(int i=0; i<mult; i++){ |
| 480 |
if(key[i]!=arrays[i][cell]){return false;} |
| 481 |
} |
| 482 |
return true; |
| 483 |
} |
| 484 |
|
| 485 |
|
| 486 |
|
| 487 |
|
| 488 |
|
| 489 |
@Override |
| 490 |
final boolean canResize() {return true;} |
| 491 |
|
| 492 |
@Override |
| 493 |
final public long size() {return size;} |
| 494 |
|
| 495 |
@Override |
| 496 |
final public int arrayLength() {return arrays[0].length;} |
| 497 |
|
| 498 |
@Override |
| 499 |
protected abstract void resize(); |
| 500 |
|
| 501 |
|
| 502 |
|
| 503 |
|
| 504 |
|
| 505 |
protected long[] cellToArray(int cell){throw new RuntimeException("Unimplemented");} |
| 506 |
|
| 507 |
@Override |
| 508 |
public final boolean dumpKmersAsText(TextStreamWriter tsw, int k, int mincount, int maxcount){ |
| 509 |
final long[] key=new long[mult]; |
| 510 |
final int alen=arrays[0].length; |
| 511 |
if(TWOD){ |
| 512 |
final int[] singleton=new int[1]; |
| 513 |
for(int i=0; i<alen; i++){ |
| 514 |
long[] temp=fillKey(i, key); |
| 515 |
if(temp!=null){ |
| 516 |
tsw.print(toText(temp, readCellValues(i, singleton), k).append('\n')); |
| 517 |
} |
| 518 |
} |
| 519 |
}else{ |
| 520 |
for(int i=0; i<alen; i++){ |
| 521 |
long[] temp=fillKey(i, key); |
| 522 |
if(temp!=null && readCellValue(i)>=mincount){ |
| 523 |
tsw.print(toText(temp, readCellValue(i), k).append('\n')); |
| 524 |
} |
| 525 |
} |
| 526 |
} |
| 527 |
if(victims!=null){ |
| 528 |
victims.dumpKmersAsText(tsw, k, mincount, maxcount); |
| 529 |
} |
| 530 |
return true; |
| 531 |
} |
| 532 |
|
| 533 |
@Override |
| 534 |
public final boolean dumpKmersAsBytes(ByteStreamWriter bsw, int k, int mincount, int maxcount, AtomicLong remaining){ |
| 535 |
final long[] key=new long[mult]; |
| 536 |
final int alen=arrays[0].length; |
| 537 |
if(TWOD){ |
| 538 |
final int[] singleton=new int[1]; |
| 539 |
for(int i=0; i<alen; i++){ |
| 540 |
long[] temp=fillKey(i, key); |
| 541 |
if(temp!=null){ |
| 542 |
if(remaining!=null && remaining.decrementAndGet()<0){return true;} |
| 543 |
bsw.printlnKmer(temp, readCellValues(i, singleton), k); |
| 544 |
} |
| 545 |
} |
| 546 |
}else{ |
| 547 |
for(int i=0; i<alen; i++){ |
| 548 |
long[] temp=fillKey(i, key); |
| 549 |
if(temp!=null && readCellValue(i)>=mincount){ |
| 550 |
if(remaining!=null && remaining.decrementAndGet()<0){return true;} |
| 551 |
bsw.printlnKmer(temp, readCellValue(i), k); |
| 552 |
} |
| 553 |
} |
| 554 |
} |
| 555 |
if(victims!=null){ |
| 556 |
victims.dumpKmersAsBytes(bsw, k, mincount, maxcount, remaining); |
| 557 |
} |
| 558 |
return true; |
| 559 |
} |
| 560 |
|
| 561 |
@Override |
| 562 |
public final boolean dumpKmersAsBytes_MT(final ByteStreamWriter bsw, final ByteBuilder bb, final int k, final int mincount, final int maxcount, AtomicLong remaining){ |
| 563 |
final long[] key=new long[mult]; |
| 564 |
final int alen=arrays[0].length; |
| 565 |
if(TWOD){ |
| 566 |
final int[] singleton=new int[1]; |
| 567 |
for(int i=0; i<alen; i++){ |
| 568 |
long[] temp=fillKey(i, key); |
| 569 |
if(temp!=null){ |
| 570 |
if(remaining!=null && remaining.decrementAndGet()<0){return true;} |
| 571 |
toBytes(temp, readCellValues(i, singleton), k, bb); |
| 572 |
bb.nl(); |
| 573 |
if(bb.length()>=16000){ |
| 574 |
ByteBuilder bb2=new ByteBuilder(bb); |
| 575 |
synchronized(bsw){bsw.addJob(bb2);} |
| 576 |
bb.clear(); |
| 577 |
} |
| 578 |
} |
| 579 |
} |
| 580 |
}else{ |
| 581 |
for(int i=0; i<alen; i++){ |
| 582 |
long[] temp=fillKey(i, key); |
| 583 |
if(temp!=null && readCellValue(i)>=mincount){ |
| 584 |
if(remaining!=null && remaining.decrementAndGet()<0){return true;} |
| 585 |
toBytes(temp, readCellValue(i), k, bb); |
| 586 |
bb.nl(); |
| 587 |
if(bb.length()>=16000){ |
| 588 |
ByteBuilder bb2=new ByteBuilder(bb); |
| 589 |
synchronized(bsw){bsw.addJob(bb2);} |
| 590 |
bb.clear(); |
| 591 |
} |
| 592 |
} |
| 593 |
} |
| 594 |
} |
| 595 |
if(victims!=null){ |
| 596 |
victims.dumpKmersAsBytes_MT(bsw, bb, k, mincount, maxcount, remaining); |
| 597 |
} |
| 598 |
return true; |
| 599 |
} |
| 600 |
|
| 601 |
@Override |
| 602 |
public final void fillHistogram(long[] ca, int max){ |
| 603 |
final int alen=arrays[0].length; |
| 604 |
final long[] array0=arrays[0]; |
| 605 |
for(int i=0; i<alen; i++){ |
| 606 |
long kmer=array0[i]; |
| 607 |
if(kmer!=NOT_PRESENT){ |
| 608 |
int count=Tools.min(readCellValue(i), max); |
| 609 |
ca[count]++; |
| 610 |
} |
| 611 |
} |
| 612 |
if(victims!=null){ |
| 613 |
victims.fillHistogram(ca, max); |
| 614 |
} |
| 615 |
} |
| 616 |
|
| 617 |
@Override |
| 618 |
public void fillHistogram(SuperLongList sll){ |
| 619 |
final int alen=arrays[0].length; |
| 620 |
final long[] array0=arrays[0]; |
| 621 |
for(int i=0; i<alen; i++){ |
| 622 |
long kmer=array0[i]; |
| 623 |
if(kmer!=NOT_PRESENT){ |
| 624 |
int count=readCellValue(i); |
| 625 |
sll.add(count); |
| 626 |
} |
| 627 |
} |
| 628 |
if(victims!=null){ |
| 629 |
victims.fillHistogram(sll); |
| 630 |
} |
| 631 |
} |
| 632 |
|
| 633 |
@Override |
| 634 |
public final void countGC(long[] gcCounts, int max){ |
| 635 |
final int alen0=arrays.length; |
| 636 |
final int alen=arrays[0].length; |
| 637 |
for(int i=0; i<alen; i++){ |
| 638 |
long kmer0=arrays[0][i]; |
| 639 |
if(kmer0!=NOT_PRESENT){ |
| 640 |
int count=Tools.min(readCellValue(i), max); |
| 641 |
for(int j=0; j<alen0; j++){ |
| 642 |
gcCounts[count]+=gc(arrays[j][i]); |
| 643 |
} |
| 644 |
} |
| 645 |
} |
| 646 |
if(victims!=null){ |
| 647 |
victims.countGC(gcCounts, max); |
| 648 |
} |
| 649 |
} |
| 650 |
|
| 651 |
public HashForestU victims(){ |
| 652 |
return victims; |
| 653 |
} |
| 654 |
|
| 655 |
|
| 656 |
|
| 657 |
|
| 658 |
|
| 659 |
AtomicIntegerArray owners; |
| 660 |
long[][] arrays; |
| 661 |
int prime; |
| 662 |
long size=0; |
| 663 |
long sizeLimit; |
| 664 |
final HashForestU victims; |
| 665 |
final boolean autoResize; |
| 666 |
final int k; |
| 667 |
final int kbig; |
| 668 |
final int mult; |
| 669 |
public final boolean TWOD; |
| 670 |
private final Lock lock=new ReentrantLock(); |
| 671 |
|
| 672 |
public AtomicIntegerArray owners() {return owners;} |
| 673 |
|
| 674 |
protected int nextScheduleSize(){ |
| 675 |
if(schedulePos<schedule.length-1){schedulePos++;} |
| 676 |
return schedule[schedulePos]; |
| 677 |
} |
| 678 |
|
| 679 |
protected boolean atMaxSize(){ |
| 680 |
return schedulePos>=schedule.length-1; |
| 681 |
} |
| 682 |
|
| 683 |
protected final int[] schedule; |
| 684 |
private int schedulePos=0; |
| 685 |
|
| 686 |
@Override |
| 687 |
final Lock getLock(){return lock;} |
| 688 |
|
| 689 |
|
| 690 |
|
| 691 |
|
| 692 |
|
| 693 |
final static int victimRatio=16; |
| 694 |
final static int extra=60; |
| 695 |
final static int maxPrime=Primes.primeAtMost(Integer.MAX_VALUE-extra-20); |
| 696 |
final static float resizeMult=2f; |
| 697 |
final static float minLoadFactor=0.58f; |
| 698 |
final static float maxLoadFactor=0.88f; |
| 699 |
final static float maxLoadFactorFinal=0.95f; |
| 700 |
final static float minLoadMult=1/minLoadFactor; |
| 701 |
final static float maxLoadMult=1/maxLoadFactor; |
| 702 |
|
| 703 |
} |