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