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;
00030
00031 import java.io.*;
00032
00033 import org.openmobileis.database.fastobjectdb.db.index.node.Node;
00034
00035
00040 public class FODBIndexTable implements Externalizable {
00041 static final long serialVersionUID = 5521257935120563452L;
00042
00043 private static int DEF_TAB_SIZE = 20;
00044
00045 private int incTabSize;
00046 private int currentSize;
00047
00048 private long[] indexsPos;
00049
00050 public FODBIndexTable() {
00051 incTabSize = DEF_TAB_SIZE;
00052 constructorHelper();
00053 }
00054
00055 public FODBIndexTable(int tSize) {
00056 incTabSize = tSize;
00057 constructorHelper();
00058 }
00059
00060 protected void constructorHelper() {
00061 currentSize = 0;
00062 indexsPos = new long[incTabSize];
00063
00064 for (int i = 0; i < incTabSize; i++) {
00065 indexsPos[i] = Node.NO_NODE;
00066 }
00067 }
00068
00069 public int size() {
00070 return currentSize;
00071 }
00072
00073 public int allocatedSize() {
00074 return indexsPos.length;
00075 }
00076
00077 public synchronized boolean add(long pos) {
00078 int tabSize = indexsPos.length;
00079
00080 if (currentSize < tabSize) {
00081 indexsPos[currentSize] = pos;
00082 currentSize++;
00083 return false;
00084 }
00085 else {
00086 long[] newIndexsPos = new long[tabSize + incTabSize];
00087
00088 System.arraycopy(indexsPos, 0, newIndexsPos, 0, indexsPos.length);
00089
00090 newIndexsPos[currentSize] = pos;
00091
00092 for (int i = currentSize+1; i<newIndexsPos.length; i++) {
00093 newIndexsPos[i] = Node.NO_NODE;
00094 }
00095
00096 indexsPos = newIndexsPos;
00097 currentSize++;
00098 return true;
00099 }
00100
00101 }
00102
00103 public long getPosByPlace(int place) {
00104 if (place >= currentSize || place < 0) {
00105 return Node.NO_NODE;
00106 }
00107 return indexsPos[place];
00108 }
00109
00110 public String toString() {
00111 String result = " FODBIndexTable[" + incTabSize + ", " + currentSize + "]\n";
00112
00113 result = result.concat(" [");
00114 for (int i = 0; i < currentSize; i++) {
00115 result = result.concat("(" + indexsPos[i] + ")");
00116 }
00117 result = result.concat("]\n");
00118
00119 return result;
00120 }
00121
00122 public void writeExternal(ObjectOutput out) throws IOException {
00123 out.writeInt(incTabSize);
00124 out.writeInt(currentSize);
00125 out.writeInt(indexsPos.length);
00126 for (int i = 0; i < indexsPos.length; i++) {
00127 out.writeLong(indexsPos[i]);
00128 }
00129 }
00130
00131 public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException {
00132 incTabSize = in.readInt();
00133 currentSize = in.readInt();
00134 int realTabSize = in.readInt();
00135
00136 indexsPos = new long[realTabSize];
00137
00138 for (int i = 0; i < realTabSize; i++) {
00139 indexsPos[i] = in.readLong();
00140 }
00141 }
00142
00143 }
00144