public void writePayload(BTreeNode<Key,Value> node, DataOutput os) throws IOException { // Write the keys short count = (short)node.keys.length; // cast may truncate value... if( count != node.keys.length ) { throw new IOException("Too many keys"); } os.writeShort(count); for (int i = 0; i < node.keys.length; i++) { index.getKeyMarshaller().writePayload(node.keys[i], os); } if( node.isBranch() ) { // If this is a branch... os.writeBoolean(true); for (int i = 0; i < count+1; i++) { os.writeLong(node.children[i]); } } else { // If this is a leaf os.writeBoolean(false); for (int i = 0; i < count; i++) { index.getValueMarshaller().writePayload(node.values[i], os); } os.writeLong(node.next); } }
@SuppressWarnings("unchecked") public BTreeNode<Key,Value> readPayload(DataInput is) throws IOException { BTreeNode<Key,Value> node = new BTreeNode<Key,Value>(index); int count = is.readShort(); node.keys = (Key[])new Object[count]; for (int i = 0; i < count; i++) { node.keys[i] = index.getKeyMarshaller().readPayload(is); } if( is.readBoolean() ) { node.children = new long[count+1]; for (int i = 0; i < count+1; i++) { node.children[i] = is.readLong(); } } else { node.values = (Value[])new Object[count]; for (int i = 0; i < count; i++) { node.values[i] = index.getValueMarshaller().readPayload(is); } node.next = is.readLong(); } return node; } }
public void writePayload(BTreeNode<Key,Value> node, DataOutput os) throws IOException { // Write the keys short count = (short)node.keys.length; // cast may truncate value... if( count != node.keys.length ) { throw new IOException("Too many keys"); } os.writeShort(count); for (int i = 0; i < node.keys.length; i++) { index.getKeyMarshaller().writePayload(node.keys[i], os); } if( node.isBranch() ) { // If this is a branch... os.writeBoolean(true); for (int i = 0; i < count+1; i++) { os.writeLong(node.children[i]); } } else { // If this is a leaf os.writeBoolean(false); for (int i = 0; i < count; i++) { index.getValueMarshaller().writePayload(node.values[i], os); } os.writeLong(node.next); } }
public void writePayload(BTreeNode<Key,Value> node, DataOutput os) throws IOException { // Write the keys short count = (short)node.keys.length; // cast may truncate value... if( count != node.keys.length ) { throw new IOException("Too many keys"); } os.writeShort(count); for (int i = 0; i < node.keys.length; i++) { index.getKeyMarshaller().writePayload(node.keys[i], os); } if( node.isBranch() ) { // If this is a branch... os.writeBoolean(true); for (int i = 0; i < count+1; i++) { os.writeLong(node.children[i]); } } else { // If this is a leaf os.writeBoolean(false); for (int i = 0; i < count; i++) { index.getValueMarshaller().writePayload(node.values[i], os); } os.writeLong(node.next); } }
public void writePayload(BTreeNode<Key,Value> node, DataOutput os) throws IOException { // Write the keys short count = (short)node.keys.length; // cast may truncate value... if( count != node.keys.length ) { throw new IOException("Too many keys"); } os.writeShort(count); for (int i = 0; i < node.keys.length; i++) { index.getKeyMarshaller().writePayload(node.keys[i], os); } if( node.isBranch() ) { // If this is a branch... os.writeBoolean(true); for (int i = 0; i < count+1; i++) { os.writeLong(node.children[i]); } } else { // If this is a leaf os.writeBoolean(false); for (int i = 0; i < count; i++) { index.getValueMarshaller().writePayload(node.values[i], os); } os.writeLong(node.next); } }
@SuppressWarnings("unchecked") public BTreeNode<Key,Value> readPayload(DataInput is) throws IOException { BTreeNode<Key,Value> node = new BTreeNode<Key,Value>(index); int count = is.readShort(); node.keys = (Key[])new Object[count]; for (int i = 0; i < count; i++) { node.keys[i] = index.getKeyMarshaller().readPayload(is); } if( is.readBoolean() ) { node.children = new long[count+1]; for (int i = 0; i < count+1; i++) { node.children[i] = is.readLong(); } } else { node.values = (Value[])new Object[count]; for (int i = 0; i < count; i++) { node.values[i] = index.getValueMarshaller().readPayload(is); } node.next = is.readLong(); } return node; } }
@SuppressWarnings("unchecked") public BTreeNode<Key,Value> readPayload(DataInput is) throws IOException { BTreeNode<Key,Value> node = new BTreeNode<Key,Value>(index); int count = is.readShort(); node.keys = (Key[])new Object[count]; for (int i = 0; i < count; i++) { node.keys[i] = index.getKeyMarshaller().readPayload(is); } if( is.readBoolean() ) { node.children = new long[count+1]; for (int i = 0; i < count+1; i++) { node.children[i] = is.readLong(); } } else { node.values = (Value[])new Object[count]; for (int i = 0; i < count; i++) { node.values[i] = index.getValueMarshaller().readPayload(is); } node.next = is.readLong(); } return node; } }
@SuppressWarnings("unchecked") public BTreeNode<Key,Value> readPayload(DataInput is) throws IOException { BTreeNode<Key,Value> node = new BTreeNode<Key,Value>(index); int count = is.readShort(); node.keys = (Key[])new Object[count]; for (int i = 0; i < count; i++) { node.keys[i] = index.getKeyMarshaller().readPayload(is); } if( is.readBoolean() ) { node.children = new long[count+1]; for (int i = 0; i < count+1; i++) { node.children[i] = is.readLong(); } } else { node.values = (Value[])new Object[count]; for (int i = 0; i < count; i++) { node.values[i] = index.getValueMarshaller().readPayload(is); } node.next = is.readLong(); } return node; } }