00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029 package org.openmobileis.database.fastobjectdb.db.index.node;
00030
00031 import java.io.*;
00032
00039 public abstract class Node implements Externalizable {
00040
00041 static final long serialVersionUID = 5521257935120563452L;
00042 public final static long NO_NODE = -1;
00043
00044
00045
00046
00047 public long filePtr = Node.NO_NODE;
00048 public long parentPtr = Node.NO_NODE;
00049 public long[] ptr;
00050 public long[] branchs;
00051 public int nbKey;
00052
00053
00054
00055
00056 public Node() {
00057 nbKey = 0;
00058 }
00059
00060 public Node(int order) {
00061 this();
00062 ptr = new long[order - 1];
00063 branchs = new long[order];
00064
00065
00066 for (int n = 0; n < branchs.length; ++n)
00067 branchs[n] = Node.NO_NODE;
00068 }
00069
00070 public long getNodePtrAtPos(int pos) {
00071 return this.ptr[pos];
00072 }
00073
00074 public int getMaxNbKey() {
00075 return ptr.length;
00076 }
00077
00078
00079
00080
00081 public void writeExternal(ObjectOutput out) throws IOException {
00082
00083 out.writeLong(filePtr);
00084 out.writeLong(parentPtr);
00085
00086
00087 this.serializeLongArray(out,ptr);
00088 this.serializeLongArray(out,branchs);
00089 out.writeInt(nbKey);
00090 }
00091
00092 protected void serializeLongArray(ObjectOutput out, long[] array) throws IOException {
00093 int size=array.length;
00094 out.writeInt(size);
00095 for (int i=0; i<size; i++) {
00096 out.writeLong(array[i]);
00097 }
00098
00099 }
00100
00101 protected long[] unserializeLongArray(ObjectInput in) throws IOException {
00102 int size=in.readInt();
00103 long[] ret = new long[size];
00104 for (int i=0; i<size; i++) {
00105 ret[i] = in.readLong();
00106 }
00107 return ret;
00108 }
00109
00110 protected void serializeInArray(ObjectOutput out, int[] array) throws IOException {
00111 int size=array.length;
00112 out.writeInt(size);
00113 for (int i=0; i<size; i++) {
00114 out.writeInt(array[i]);
00115 }
00116
00117 }
00118
00119 protected int[] unserializeInArray(ObjectInput in) throws IOException {
00120 int size=in.readInt();
00121 int[] ret = new int[size];
00122 for (int i=0; i<size; i++) {
00123 ret[i] = in.readInt();
00124 }
00125 return ret;
00126 }
00127
00128 public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException {
00129 filePtr = in.readLong();
00130 parentPtr = in.readLong();
00131 ptr = this.unserializeLongArray(in);
00132 branchs = this.unserializeLongArray(in);
00133 nbKey = in.readInt();
00134 }
00135
00136 }