MCPcopy Create free account
hub / github.com/1345414527/MIT6.830 / readNext

Method readNext

src/java/simpledb/index/BTreeFile.java:1437–1473  ·  view source on GitHub ↗

Read the next tuple either from the current page if it has more tuples matching the predicate or from the next page by following the right sibling pointer. @return the next tuple matching the predicate, or null if none exists

()

Source from the content-addressed store, hash-verified

1435 * @return the next tuple matching the predicate, or null if none exists
1436 */
1437 @Override
1438 protected Tuple readNext() throws TransactionAbortedException, DbException,
1439 NoSuchElementException {
1440 while (it != null) {
1441
1442 while (it.hasNext()) {
1443 Tuple t = it.next();
1444 if (t.getField(f.keyField()).compare(ipred.getOp(), ipred.getField())) {
1445 return t;
1446 }
1447 else if(ipred.getOp() == Op.LESS_THAN || ipred.getOp() == Op.LESS_THAN_OR_EQ) {
1448 // if the predicate was not satisfied and the operation is less than, we have
1449 // hit the end
1450 return null;
1451 }
1452 else if(ipred.getOp() == Op.EQUALS &&
1453 t.getField(f.keyField()).compare(Op.GREATER_THAN, ipred.getField())) {
1454 // if the tuple is now greater than the field passed in and the operation
1455 // is equals, we have reached the end
1456 return null;
1457 }
1458 }
1459
1460 BTreePageId nextp = curp.getRightSiblingId();
1461 // if there are no more pages to the right, end the iteration
1462 if(nextp == null) {
1463 return null;
1464 }
1465 else {
1466 curp = (BTreeLeafPage) Database.getBufferPool().getPage(tid,
1467 nextp, Permissions.READ_ONLY);
1468 it = curp.iterator();
1469 }
1470 }
1471
1472 return null;
1473 }
1474
1475 /**
1476 * rewind this iterator back to the beginning of the tuples

Callers

nothing calls this directly

Calls 10

getFieldMethod · 0.95
getBufferPoolMethod · 0.95
keyFieldMethod · 0.80
hasNextMethod · 0.65
nextMethod · 0.65
compareMethod · 0.65
iteratorMethod · 0.65
getOpMethod · 0.45
getRightSiblingIdMethod · 0.45
getPageMethod · 0.45

Tested by

no test coverage detected