[prev] 25 [next]

Relation Copying (cont)

In terms of file operations:

File inf,outf;   // input/output file handles
int ip,op;       // input/output page numbers
int i;           // tuple number in input buf
Tuple t;         // current tuple
Buffer buf,obuf; // input/output file buffers

inf = openFile(fileName("S"), READ);
outf = openFile(fileName("T"), CREATE);
clear(obuf);
for (ip = op = 0; ip < nPages(inf); ip++) {
    buf = readPage(inf, ip);
    for (i = 0; i < nTuples(buf); i++) {
        t = getTuple(i, buf);
        addTuple(t, obuf);
        if (isFull(obuf)) {
            writePage(outf, op++, obuf);
            clear(obuf);
}   }   }
if (nTuples(obuf) > 0) writePage(outf, op, obuf);