01: /*
02: * Node.java
03: *
04: * Created on 09 May 2003, 15:08
05: */
06:
07: package com.jofti.btree;
08:
09: import com.jofti.oswego.concurrent.FIFOReadWriteLock;
10: import com.jofti.oswego.concurrent.ReadWriteLock;
11:
12: /**
13: * <p>Base class for Node providing the {@link ReadWriteLock} used in each Node to provide locking semantics.</p>
14: *
15: * @author steve Woodcock
16: * @version 1.15
17: *
18: */
19: abstract public class Node implements INode {
20:
21: public final ReadWriteLock nodeLock = new FIFOReadWriteLock();
22:
23: protected int entryNumber = 0;
24:
25: protected Object[] split(Object[] tempEntries, int entryNumber) {
26: // first insert the entry
27: Object[] entriesList = new Object[2];
28:
29: // redistribute over old and new node
30:
31: int splitPoint = (entryNumber / 2);
32:
33: Object[] newSplitValues = new Object[BTree.getMaxNodeSize()];
34:
35: int endPoint = entryNumber - splitPoint;
36: // copies the split values into the new array
37: System.arraycopy(tempEntries, splitPoint, newSplitValues, 0,
38: endPoint);
39:
40: EntrySplitWrapper splitWrapper = new EntrySplitWrapper();
41: splitWrapper.size = endPoint;
42: splitWrapper.entries = newSplitValues;
43:
44: // remove the higher ones
45: for (int i = splitPoint; i < entryNumber; i++) {
46: tempEntries[i] = null;
47: }
48:
49: EntrySplitWrapper replacementWrapper = new EntrySplitWrapper();
50: replacementWrapper.size = splitPoint;
51: replacementWrapper.entries = tempEntries;
52:
53: entriesList[0] = replacementWrapper;
54: entriesList[1] = splitWrapper;
55: return entriesList;
56:
57: }
58:
59: /* (non-Javadoc)
60: * @see com.jofti.btree.INode#getNodeLock()
61: */
62: public ReadWriteLock getNodeLock() {
63: return nodeLock;
64: }
65:
66: /* (non-Javadoc)
67: * @see com.jofti.btree.INode#isLeaf()
68: */
69: public boolean isLeaf() {
70: return false;
71: }
72:
73: }
|