📄 charnode.java
字号:
/* * Created on Aug 1, 2004 * * TODO To change the template for this generated file go to * Window - Preferences - Java - Code Style - Code Templates */package com.nay0648.ds.bplustree;import java.nio.*;import java.util.*;/** * Description:<br> * @abstract * @keywords * @author nay0648 * @version last modified:Jun 6, 2004 */class CharNode extends BPlusTreeNode{ public CharNode() { super(); } /** * get a new empty char node instance * @param addr * file pointer point to this node * @return */ public BPlusTreeNode getInstance(long addr) { BPlusTreeNode node; node=new CharNode(); node.setAddr(addr); return node; } /** * rebuild the char node instance from byte array * @param addr * file pointer point to this node * @param node * byte array contain this node's information * @return */ public BPlusTreeNode getInstance(long addr,byte[] node) { int i,j,valid; byte[] key; ByteBuffer buff; CharNode cnode; List keyword,pointer; //check argument size if(node.length!=CharNode.nodelength) throw new IllegalArgumentException("byte array's length mismatch. array length: "+node.length+" required: "+CharNode.nodelength); //construct buffer buff=ByteBuffer.wrap(node); //prepare to read data from buffer buff.position(0); buff.limit(buff.capacity()); cnode=new CharNode();//build a new empty node cnode.setAddr(addr);//set file pointer //read data in order if(buff.get()==CharNode.TRUE) cnode.isLeaf(true);else cnode.isLeaf(false); valid=buff.getInt(); //keyword and pointer list keyword=new ArrayList(); pointer=new ArrayList(); key=new byte[CharNode.keywordlength]; /* * if this is a empty node,it still contain one pointer */ for(i=0;i<valid;i++) { pointer.add(new Long(buff.getLong())); buff.get(key); keyword.add(new CharKeyword(key,CharNode.keywordlength));//here use the keyword's Keyword form } //read the last pointer pointer.add(new Long(buff.getLong())); //set keyword and pointer list cnode.setKeywordList(keyword); cnode.setPointerList(pointer); return cnode; } /** * get the node's binary byte array,used to save node into file * @return */ public byte[] getBytes() { int i; ByteBuffer buff; buff=ByteBuffer.allocate(CharNode.nodelength); //write data into buffer in order if(this.isLeaf()) buff.put(IntNode.TRUE);else buff.put(IntNode.FALSE); buff.putInt(this.getValid());//valid keyword number for(i=0;i<this.getValid();i++) { buff.putLong(this.getPointer(i)); buff.put(((CharKeyword)this.getKeyword(i)).getBytes()); } /* * if this is a empty node,it still contain one pointer */ buff.putLong(this.getLast());//the last pointer return buff.array(); } /** * convert a keyword from Object form to Keyword form * @param o * the keyword's Object form */ public Keyword buildKeyword(Object o) { return new CharKeyword((String)o,CharNode.keywordlength); } /** * this is used to convert a kwyword's byte array form to the * Keyword form,it is used when keyword is received from remote * host * @param key * keyword's byte array form * @return * keyword's Keyword form */ public Keyword buildKeyword(byte[] key) { return new CharKeyword(key,CharNode.keywordlength); }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -