(int dirShift, long recid, Store store, int level, long indexStart)
| 523 | } |
| 524 | } |
| 525 | public static long[] treeIter(int dirShift, long recid, Store store, int level, long indexStart){ |
| 526 | if(CC.ASSERT && level<0) |
| 527 | throw new DBException.DataCorruption("level too low"); |
| 528 | if(CC.ASSERT && indexStart<0) |
| 529 | throw new AssertionError(); |
| 530 | if(CC.ASSERT && (dirShift<0||dirShift>maxDirShift)) |
| 531 | throw new AssertionError(); |
| 532 | |
| 533 | |
| 534 | long[] dir = store.get(recid, dirSer); |
| 535 | |
| 536 | boolean first = true; |
| 537 | final int slot = treePos(dirShift, level, indexStart); |
| 538 | int pos = dirOffsetFromSlot(dir,slot); |
| 539 | if(pos<0) |
| 540 | pos = -pos; |
| 541 | posLoop: |
| 542 | for(; |
| 543 | pos<dir.length; |
| 544 | pos+=2) |
| 545 | { |
| 546 | long oldVal = dir[pos]; |
| 547 | long oldIndex = dir[pos + 1]-1; |
| 548 | |
| 549 | if (oldIndex == -1) { |
| 550 | if(oldVal == 0){ |
| 551 | first = false; |
| 552 | //nothing here continue |
| 553 | continue posLoop; |
| 554 | } |
| 555 | |
| 556 | //calculate corresponding index from our pos |
| 557 | long index = first? indexStart : ( |
| 558 | //upper part of level, strip out part for pos |
| 559 | indexStart & (full << ((level+1)*dirShift)) | |
| 560 | //part with current pos |
| 561 | ((long)slot)<<(dirShift*level) |
| 562 | ); |
| 563 | // recid here, dive deeper |
| 564 | long[] ret = treeIter(dirShift, oldVal, store, level-1, index); |
| 565 | if (ret != null) |
| 566 | return ret; |
| 567 | //nothing in this dir, continue |
| 568 | |
| 569 | //TODO PERF: add another type of iteration |
| 570 | // this place should not be reached if we collapse nodes on delete, or delete is forbidden |
| 571 | // in that case we do not have to use recursion, and `dir` variable can be reused |
| 572 | } else { |
| 573 | if(oldIndex>=indexStart) { |
| 574 | //there is value here, return it |
| 575 | return new long[]{oldIndex, oldVal}; |
| 576 | } |
| 577 | //this position is occupied by smaller index |
| 578 | } |
| 579 | first = false; |
| 580 | } |
| 581 | //reached end of this dir, nothing found |
| 582 | return null; |
nothing calls this directly
no test coverage detected