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
00030 package org.openmobileis.database.fastobjectdb.db.index.node;
00031
00032 import java.io.*;
00033
00034 import org.openmobileis.database.fastobjectdb.db.index.SearchResult;
00035
00042 public class LongNode extends Node {
00043
00044 static final long serialVersionUID = 5521257935120563452L;
00045
00046
00047
00048
00049 private long[] keys;
00050
00051
00052
00053
00054 public LongNode() {
00055 super();
00056 }
00057
00058 public LongNode(int order) {
00059 super(order);
00060
00061 keys = new long[order - 1];
00062 }
00063
00064 public long getKeyAtPos(int pos) {
00065 return this.keys[pos];
00066 }
00067
00068 public void setKeyPtrAtPos(long key, long ptr, int pos) {
00069 this.keys[pos] = key;
00070 super.ptr[pos] = ptr;
00071 }
00072
00073 public SearchResult searchNode(long key, SearchResult search) {
00074 search.node = this;
00075 if (key < this.getKeyAtPos(0)) {
00076 search.pos = 0;
00077 search.found = false;
00078 } else {
00079 int i;
00080 for (i = nbKey - 1; i >= 0 && key < this.getKeyAtPos(i); i--);
00081 search.found = (key == this.getKeyAtPos(i));
00082 if (search.found)
00083 search.pos = i;
00084 else
00085 search.pos = i + 1;
00086 }
00087 return search;
00088 }
00089
00090 public boolean pushInLeaf(long key, int pos, long newPtr) {
00091 this.branchs[this.nbKey + 1] = Node.NO_NODE;
00092 for (int j = this.nbKey - 1; j >= pos; j--) {
00093 this.setKeyPtrAtPos(this.getKeyAtPos(j), this.getNodePtrAtPos(j), j + 1);
00094 }
00095 this.setKeyPtrAtPos(key, newPtr, pos);
00096 this.nbKey++;
00097 return this.nbKey >= this.getMaxNbKey();
00098 }
00099
00100 public boolean promote(long newkey, long keyptr, int pos, long nodePtr) {
00101 for (int j = this.nbKey; j >= pos + 1; j--) {
00102 this.setKeyPtrAtPos(keys[j - 1], this.getNodePtrAtPos(j - 1), j);
00103 this.branchs[j + 1] = this.branchs[j];
00104 }
00105 this.branchs[pos + 1] = nodePtr;
00106 this.setKeyPtrAtPos(newkey, keyptr, pos);
00107 this.nbKey++;
00108 return this.nbKey >= this.getMaxNbKey();
00109 }
00110
00111 public void removeKeyAtPpos(int pos) {
00112 for (int j = pos + 1; j < this.nbKey; j++) {
00113 this.setKeyPtrAtPos(this.getKeyAtPos(j), this.getNodePtrAtPos(j), j - 1);
00114 this.branchs[j] = this.branchs[j + 1];
00115 }
00116 this.branchs[this.nbKey] = Node.NO_NODE;
00117
00118 this.nbKey--;
00119 }
00120
00121
00122
00123
00124 public void writeExternal(ObjectOutput out) throws IOException {
00125 super.writeExternal(out);
00126
00127 super.serializeLongArray(out, keys);
00128 }
00129
00130 public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException {
00131 super.readExternal(in);
00132 keys = super.unserializeLongArray(in);
00133 }
00134 }