?? btpageformatter.java
字號(hào):
package simpledb.index.btree;
import static simpledb.file.Page.*;
import static simpledb.sql.Types.INTEGER;
import simpledb.file.Page;
import simpledb.buffer.PageFormatter;
import simpledb.record.TableInfo;
/**
* An object that can format a page to look like an
* empty B-tree block.
* @author Edward Sciore
*/
public class BTPageFormatter implements PageFormatter {
private TableInfo md;
private int flag;
/**
* Creates a formatter for a new page of the
* specified B-tree index.
* @param md the index's metadata
* @param flag the page's initial flag value
*/
public BTPageFormatter(TableInfo md, int flag) {
this.md = md;
this.flag = flag;
}
/**
* Formats the page by initializing as many index-record slots
* as possible to have default values.
* Each integer field is given a value of 0, and
* each string field is given a value of "".
* The location that indicates the number of records
* in the page is also set to 0.
* @see simpledb.buffer.PageFormatter#format(simpledb.file.Page)
*/
public void format(Page page) {
page.setInt(0, flag);
page.setInt(INT_SIZE, 0); // #records = 0
int recsize = md.recordLength();
for (int pos=2*INT_SIZE; pos+recsize<BLOCK_SIZE; pos += recsize)
makeDefaultRecord(page, pos);
}
private void makeDefaultRecord(Page page, int pos) {
for (String fldname : md.schema().fields()) {
int offset = md.offset(fldname);
if (md.schema().type(fldname) == INTEGER)
page.setInt(pos + INT_SIZE + offset, 0);
else
page.setString(pos + INT_SIZE + offset, "");
}
}
}
?? 快捷鍵說明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號(hào)
Ctrl + =
減小字號(hào)
Ctrl + -