📄 intnode.java
字号:
/* * Created on Jun 6, 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.io.*;import java.nio.*;import java.util.*;/** * Description:<br> * @abstract * @keywords * @author nay0648 * @version last modified:Jun 6, 2004 */class IntNode extends BPlusTreeNode{ public IntNode() { super(); } /** * get a new empty int node instance * @param addr * file pointer point to this node * @return */ public BPlusTreeNode getInstance(long addr) { BPlusTreeNode node; node=new IntNode(); node.setAddr(addr); return node; } /** * rebuild the int 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,valid; ByteBuffer buff; IntNode inode; List keyword,pointer; //check argument size if(node.length!=IntNode.nodelength) throw new IllegalArgumentException("byte array's length mismatch. array length: "+node.length+" required: "+IntNode.nodelength); //construct buffer buff=ByteBuffer.wrap(node); //prepare to read data from buffer buff.position(0); buff.limit(buff.capacity()); inode=new IntNode();//build a new empty node inode.setAddr(addr);//set file pointer //read data in order if(buff.get()==IntNode.TRUE) inode.isLeaf(true);else inode.isLeaf(false); valid=buff.getInt(); //keyword and pointer list keyword=new ArrayList(); pointer=new ArrayList(); /* * if this is a empty node,it still contain one pointer */ for(i=0;i<valid;i++) { pointer.add(new Long(buff.getLong())); keyword.add(new IntKeyword(buff.getInt()));//here use the keyword's Keyword form } //read the last pointer pointer.add(new Long(buff.getLong())); //set keyword and pointer list inode.setKeywordList(keyword); inode.setPointerList(pointer); return inode; } /** * get the node's binary byte array,used to save node into file * @return */ public byte[] getBytes() { int i; ByteBuffer buff; buff=ByteBuffer.allocate(IntNode.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.putInt(((IntKeyword)this.getKeyword(i)).getValue()); } /* * 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 IntKeyword(((Integer)o).intValue()); } /** * 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) { Keyword res=null; DataInputStream in=null; if(key.length!=IntNode.keywordlength) throw new IllegalArgumentException("keyword length not match. length: "+key.length+" required: "+IntNode.keywordlength); try { in=new DataInputStream(new ByteArrayInputStream(key)); res=new IntKeyword(in.readInt()); } catch(IOException exc) { exc.printStackTrace(); } finally { try { if(in!=null) in.close(); } catch(IOException exc2) {} } return res; }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -