1
0
Fork 0
mirror of https://github.com/eclipse-cdt/cdt synced 2025-06-09 10:46:02 +02:00

Cosmetics.

This commit is contained in:
Sergey Prigogin 2012-03-17 21:53:29 -07:00
parent d3b2a6305b
commit 0496018fad
5 changed files with 101 additions and 107 deletions

View file

@ -447,14 +447,14 @@ public class TranslationUnit extends Openable implements ITranslationUnit {
Map<ICElement, CElementInfo> newElements, IResource underlyingResource) throws CModelException { Map<ICElement, CElementInfo> newElements, IResource underlyingResource) throws CModelException {
TranslationUnitInfo unitInfo = (TranslationUnitInfo) info; TranslationUnitInfo unitInfo = (TranslationUnitInfo) info;
// generate structure // Generate structure
this.parse(newElements, pm); this.parse(newElements, pm);
// ///////////////////////////////////////////////////////////// // /////////////////////////////////////////////////////////////
if (isWorkingCopy()) { if (isWorkingCopy()) {
ITranslationUnit original = ((IWorkingCopy)this).getOriginalElement(); ITranslationUnit original = ((IWorkingCopy)this).getOriginalElement();
// might be IResource.NULL_STAMP if original does not exist // Might be IResource.NULL_STAMP if original does not exist
IResource r = original.getResource(); IResource r = original.getResource();
if (r != null && r instanceof IFile) { if (r != null && r instanceof IFile) {
unitInfo.fTimestamp = ((IFile) r).getModificationStamp(); unitInfo.fTimestamp = ((IFile) r).getModificationStamp();
@ -499,7 +499,7 @@ public class TranslationUnit extends Openable implements ITranslationUnit {
} else { } else {
workingCopy= new WorkingCopy(getParent(), getLocationURI(), getContentTypeId(), factory); workingCopy= new WorkingCopy(getParent(), getLocationURI(), getContentTypeId(), factory);
} }
// open the working copy now to ensure contents are that of the current state of this element // Open the working copy now to ensure contents are that of the current state of this element
workingCopy.open(monitor); workingCopy.open(monitor);
return workingCopy; return workingCopy;
} }
@ -541,7 +541,7 @@ public class TranslationUnit extends Openable implements ITranslationUnit {
return null; return null;
} }
// create a new info and make it the current info // Create a new info and make it the current info
// (this will remove the info and its children just before storing the new infos) // (this will remove the info and its children just before storing the new infos)
CModelManager manager = CModelManager.getDefault(); CModelManager manager = CModelManager.getDefault();
boolean hadTemporaryCache = manager.hasTemporaryCache(); boolean hadTemporaryCache = manager.hasTemporaryCache();
@ -555,7 +555,7 @@ public class TranslationUnit extends Openable implements ITranslationUnit {
Map<ICElement, CElementInfo> newElements = manager.getTemporaryCache(); Map<ICElement, CElementInfo> newElements = manager.getTemporaryCache();
openWhenClosed(info, monitor); openWhenClosed(info, monitor);
if (newElements.get(this) == null) { if (newElements.get(this) == null) {
// close any buffer that was opened for the new elements // Close any buffer that was opened for the new elements
Iterator<ICElement> iterator = newElements.keySet().iterator(); Iterator<ICElement> iterator = newElements.keySet().iterator();
while (iterator.hasNext()) { while (iterator.hasNext()) {
ICElement element = iterator.next(); ICElement element = iterator.next();
@ -593,13 +593,13 @@ public class TranslationUnit extends Openable implements ITranslationUnit {
@Override @Override
protected IBuffer openBuffer(IProgressMonitor pm) throws CModelException { protected IBuffer openBuffer(IProgressMonitor pm) throws CModelException {
// create buffer - translation units only use default buffer factory // Create buffer - translation units only use default buffer factory
BufferManager bufManager = getBufferManager(); BufferManager bufManager = getBufferManager();
IBuffer buffer = getBufferFactory().createBuffer(this); IBuffer buffer = getBufferFactory().createBuffer(this);
if (buffer == null) if (buffer == null)
return null; return null;
// set the buffer source // Set the buffer source
if (buffer.getCharacters() == null) { if (buffer.getCharacters() == null) {
IResource resource = this.getResource(); IResource resource = this.getResource();
if (resource != null && resource.getType() == IResource.FILE) { if (resource != null && resource.getType() == IResource.FILE) {
@ -620,10 +620,10 @@ public class TranslationUnit extends Openable implements ITranslationUnit {
} }
} }
// add buffer to buffer cache // Add buffer to buffer cache
bufManager.addBuffer(buffer); bufManager.addBuffer(buffer);
// listen to buffer changes // Listen to buffer changes
buffer.addBufferChangedListener(this); buffer.addBufferChangedListener(this);
return buffer; return buffer;
@ -889,6 +889,7 @@ public class TranslationUnit extends Openable implements ITranslationUnit {
} }
private static final int[] CTX_LINKAGES= { ILinkage.CPP_LINKAGE_ID, ILinkage.C_LINKAGE_ID }; private static final int[] CTX_LINKAGES= { ILinkage.CPP_LINKAGE_ID, ILinkage.C_LINKAGE_ID };
public IIndexFile[] getContextToHeader(IIndex index, int style) { public IIndexFile[] getContextToHeader(IIndex index, int style) {
if (index != null && (style & AST_CONFIGURE_USING_SOURCE_CONTEXT) != 0) { if (index != null && (style & AST_CONFIGURE_USING_SOURCE_CONTEXT) != 0) {
try { try {

View file

@ -2125,7 +2125,7 @@ public class CPPVisitor extends ASTQueries {
} }
IType type = expr.getExpressionType(); IType type = expr.getExpressionType();
if (spec.getType() == IASTSimpleDeclSpecifier.t_decltype) { if (spec.getType() == IASTSimpleDeclSpecifier.t_decltype) {
switch((expr).getValueCategory()) { switch (expr.getValueCategory()) {
case XVALUE: case XVALUE:
type= new CPPReferenceType(type, true); type= new CPPReferenceType(type, true);
break; break;

View file

@ -102,7 +102,7 @@ public class CIndex implements IIndex {
public IIndexBinding[] findBindings(Pattern[] patterns, boolean isFullyQualified, IndexFilter filter, public IIndexBinding[] findBindings(Pattern[] patterns, boolean isFullyQualified, IndexFilter filter,
IProgressMonitor monitor) throws CoreException { IProgressMonitor monitor) throws CoreException {
if (SPECIALCASE_SINGLES && fFragments.length == 1) { if (SPECIALCASE_SINGLES && fFragments.length == 1) {
return fFragments[0].findBindings(patterns, isFullyQualified, filter, monitor); return fFragments[0].findBindings(patterns, isFullyQualified, filter, monitor);
} else { } else {
List<IIndexBinding[]> result = new ArrayList<IIndexBinding[]>(); List<IIndexBinding[]> result = new ArrayList<IIndexBinding[]>();
ILinkage[] linkages = Linkage.getIndexerLinkages(); ILinkage[] linkages = Linkage.getIndexerLinkages();

View file

@ -469,6 +469,7 @@ public class PDOM extends PlatformObject implements IPDOM {
public int compare(long record) throws CoreException { public int compare(long record) throws CoreException {
return 0; return 0;
} }
@Override @Override
public boolean visit(long record) throws CoreException { public boolean visit(long record) throws CoreException {
PDOMFile file = PDOMFile.recreateFile(PDOM.this, record); PDOMFile file = PDOMFile.recreateFile(PDOM.this, record);

View file

@ -10,19 +10,17 @@
* Andrew Ferguson (Symbian) - Provide B-tree deletion routine * Andrew Ferguson (Symbian) - Provide B-tree deletion routine
* Markus Schorn (Wind River Systems) * Markus Schorn (Wind River Systems)
*******************************************************************************/ *******************************************************************************/
package org.eclipse.cdt.internal.core.pdom.db; package org.eclipse.cdt.internal.core.pdom.db;
import com.ibm.icu.text.MessageFormat;
import org.eclipse.cdt.core.CCorePlugin; import org.eclipse.cdt.core.CCorePlugin;
import org.eclipse.core.runtime.CoreException; import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IStatus; import org.eclipse.core.runtime.IStatus;
import org.eclipse.core.runtime.Status; import org.eclipse.core.runtime.Status;
import com.ibm.icu.text.MessageFormat;
/** /**
* @author Doug Schaefer * @author Doug Schaefer
*
*/ */
public class BTree { public class BTree {
// Constants for internal deletion routine (see deleteImp doc) // Constants for internal deletion routine (see deleteImp doc)
@ -53,7 +51,7 @@ public class BTree {
* @param rootPointer offset into database of the pointer to the root node * @param rootPointer offset into database of the pointer to the root node
*/ */
public BTree(Database db, long rootPointer, int degree, IBTreeComparator cmp) { public BTree(Database db, long rootPointer, int degree, IBTreeComparator cmp) {
if(degree<2) if (degree < 2)
throw new IllegalArgumentException(Messages.getString("BTree.IllegalDegree")); //$NON-NLS-1$ throw new IllegalArgumentException(Messages.getString("BTree.IllegalDegree")); //$NON-NLS-1$
this.db = db; this.db = db;
@ -113,10 +111,10 @@ public class BTree {
// if this node is full (last record isn't null), split it // if this node is full (last record isn't null), split it
if (getRecord(chunk, node, MAX_RECORDS - 1) != 0) { if (getRecord(chunk, node, MAX_RECORDS - 1) != 0) {
long median = getRecord(chunk, node, MEDIAN_RECORD); long median = getRecord(chunk, node, MEDIAN_RECORD);
if (median == record) if (median == record) {
// found it, never mind // found it, never mind
return median; return median;
else { } else {
// split it // split it
// create the new node and move the larger records over // create the new node and move the larger records over
long newnode = allocateNode(); long newnode = allocateNode();
@ -161,8 +159,8 @@ public class BTree {
// binary search to find the insert point // binary search to find the insert point
int lower= 0; int lower= 0;
int upper= MAX_RECORDS-1; int upper= MAX_RECORDS - 1;
while (lower < upper && getRecord(chunk, node, upper-1) == 0) { while (lower < upper && getRecord(chunk, node, upper - 1) == 0) {
upper--; upper--;
} }
@ -171,16 +169,13 @@ public class BTree {
long checkRec= getRecord(chunk, node, middle); long checkRec= getRecord(chunk, node, middle);
if (checkRec == 0) { if (checkRec == 0) {
upper= middle; upper= middle;
} } else {
else {
int compare= cmp.compare(checkRec, record); int compare= cmp.compare(checkRec, record);
if (compare > 0) { if (compare > 0) {
upper= middle; upper= middle;
} } else if (compare < 0) {
else if (compare < 0) { lower= middle + 1;
lower= middle+1; } else {
}
else {
// found it, no insert, just return the record // found it, no insert, just return the record
return record; return record;
} }
@ -256,16 +251,16 @@ public class BTree {
BTNode(long node) throws CoreException { BTNode(long node) throws CoreException {
this.node = node; this.node = node;
this.chunk = db.getChunk(node); this.chunk = db.getChunk(node);
int i=0; int i= 0;
while(i<MAX_RECORDS && getRecord(chunk, node, i)!=0) while (i < MAX_RECORDS && getRecord(chunk, node, i) != 0)
i++; i++;
keyCount = i; keyCount = i;
} }
private BTNode getChild(int index) throws CoreException { private BTNode getChild(int index) throws CoreException {
if(0<=index && index<MAX_CHILDREN) { if (0 <= index && index < MAX_CHILDREN) {
long child = BTree.this.getChild(chunk, node, index); long child = BTree.this.getChild(chunk, node, index);
if(child!=0) if (child != 0)
return new BTNode(child); return new BTNode(child);
} }
return null; return null;
@ -295,38 +290,38 @@ public class BTree {
// Determine index of key in current node, or -1 if its not in this node // Determine index of key in current node, or -1 if its not in this node
int keyIndexInNode = -1; int keyIndexInNode = -1;
if(mode==DELMODE_NORMAL) if (mode == DELMODE_NORMAL)
for(int i=0; i<node.keyCount; i++) for (int i= 0; i < node.keyCount; i++)
if(getRecord(node.chunk, node.node, i) == key) { if (getRecord(node.chunk, node.node, i) == key) {
keyIndexInNode = i; keyIndexInNode = i;
break; break;
} }
if(getChild(node.chunk, node.node, 0)==0) { if (getChild(node.chunk, node.node, 0) == 0) {
/* Case 1: leaf node containing the key (by method precondition) */ /* Case 1: leaf node containing the key (by method precondition) */
if(keyIndexInNode!=-1) { if (keyIndexInNode != -1) {
nodeContentDelete(node, keyIndexInNode, 1); nodeContentDelete(node, keyIndexInNode, 1);
return key; return key;
} else { } else {
if(mode==DELMODE_DELETE_MINIMUM) { if (mode == DELMODE_DELETE_MINIMUM) {
long subst = getRecord(node.chunk, node.node, 0); long subst = getRecord(node.chunk, node.node, 0);
nodeContentDelete(node, 0, 1); nodeContentDelete(node, 0, 1);
return subst; return subst;
} else if(mode==DELMODE_DELETE_MAXIMUM) { } else if (mode == DELMODE_DELETE_MAXIMUM) {
long subst = getRecord(node.chunk, node.node, node.keyCount-1); long subst = getRecord(node.chunk, node.node, node.keyCount - 1);
nodeContentDelete(node, node.keyCount-1, 1); nodeContentDelete(node, node.keyCount - 1, 1);
return subst; return subst;
} }
throw new BTreeKeyNotFoundException( throw new BTreeKeyNotFoundException(
MessageFormat.format(Messages.getString("BTree.DeletionOnAbsentKey"), //$NON-NLS-1$ MessageFormat.format(Messages.getString("BTree.DeletionOnAbsentKey"), //$NON-NLS-1$
new Object[]{new Long(key), new Integer(mode)})); new Object[] { new Long(key), new Integer(mode) }));
} }
} else { } else {
if(keyIndexInNode != -1) { if (keyIndexInNode != -1) {
/* Case 2: non-leaf node which contains the key itself */ /* Case 2: non-leaf node which contains the key itself */
BTNode succ = node.getChild(keyIndexInNode+1); BTNode succ = node.getChild(keyIndexInNode + 1);
if(succ!=null && succ.keyCount > MIN_RECORDS) { if (succ != null && succ.keyCount > MIN_RECORDS) {
/* Case 2a: Delete key by overwriting it with its successor (which occurs in a leaf node) */ /* Case 2a: Delete key by overwriting it with its successor (which occurs in a leaf node) */
long subst = deleteImp(-1, succ.node, DELMODE_DELETE_MINIMUM); long subst = deleteImp(-1, succ.node, DELMODE_DELETE_MINIMUM);
putRecord(node.chunk, node.node, keyIndexInNode, subst); putRecord(node.chunk, node.node, keyIndexInNode, subst);
@ -334,7 +329,7 @@ public class BTree {
} }
BTNode pred = node.getChild(keyIndexInNode); BTNode pred = node.getChild(keyIndexInNode);
if(pred!=null && pred.keyCount > MIN_RECORDS) { if (pred != null && pred.keyCount > MIN_RECORDS) {
/* Case 2b: Delete key by overwriting it with its predecessor (which occurs in a leaf node) */ /* Case 2b: Delete key by overwriting it with its predecessor (which occurs in a leaf node) */
long subst = deleteImp(-1, pred.node, DELMODE_DELETE_MAXIMUM); long subst = deleteImp(-1, pred.node, DELMODE_DELETE_MAXIMUM);
putRecord(node.chunk, node.node, keyIndexInNode, subst); putRecord(node.chunk, node.node, keyIndexInNode, subst);
@ -342,7 +337,7 @@ public class BTree {
} }
/* Case 2c: Merge successor and predecessor */ /* Case 2c: Merge successor and predecessor */
// assert(pred!=null && succ!=null); // assert(pred != null && succ != null);
if (pred != null) { if (pred != null) {
mergeNodes(succ, node, keyIndexInNode, pred); mergeNodes(succ, node, keyIndexInNode, pred);
return deleteImp(key, pred.node, mode); return deleteImp(key, pred.node, mode);
@ -356,8 +351,8 @@ public class BTree {
switch(mode) { switch(mode) {
case DELMODE_NORMAL: case DELMODE_NORMAL:
subtreeIndex = node.keyCount; subtreeIndex = node.keyCount;
for(int i=0; i<node.keyCount; i++) for (int i= 0; i < node.keyCount; i++)
if(cmp.compare(getRecord(node.chunk, node.node, i), key)>0) { if (cmp.compare(getRecord(node.chunk, node.node, i), key)>0) {
subtreeIndex = i; subtreeIndex = i;
break; break;
} }
@ -368,15 +363,15 @@ public class BTree {
} }
BTNode child = node.getChild(subtreeIndex); BTNode child = node.getChild(subtreeIndex);
if(child==null) { if (child == null) {
throw new CoreException(new Status(IStatus.ERROR, CCorePlugin.PLUGIN_ID, IStatus.OK, Messages.getString("BTree.IntegrityError"), null)); //$NON-NLS-1$ throw new CoreException(new Status(IStatus.ERROR, CCorePlugin.PLUGIN_ID, IStatus.OK, Messages.getString("BTree.IntegrityError"), null)); //$NON-NLS-1$
} }
if(child.keyCount > MIN_RECORDS) { if (child.keyCount > MIN_RECORDS) {
return deleteImp(key, child.node, mode); return deleteImp(key, child.node, mode);
} else { } else {
BTNode sibR = node.getChild(subtreeIndex+1); BTNode sibR = node.getChild(subtreeIndex + 1);
if(sibR!=null && sibR.keyCount > MIN_RECORDS) { if (sibR != null && sibR.keyCount > MIN_RECORDS) {
/* Case 3a (i): child will underflow upon deletion, take a key from rightSibling */ /* Case 3a (i): child will underflow upon deletion, take a key from rightSibling */
long rightKey = getRecord(node.chunk, node.node, subtreeIndex); long rightKey = getRecord(node.chunk, node.node, subtreeIndex);
long leftmostRightSiblingKey = getRecord(sibR.chunk, sibR.node, 0); long leftmostRightSiblingKey = getRecord(sibR.chunk, sibR.node, 0);
@ -386,26 +381,26 @@ public class BTree {
return deleteImp(key, child.node, mode); return deleteImp(key, child.node, mode);
} }
BTNode sibL = node.getChild(subtreeIndex-1); BTNode sibL = node.getChild(subtreeIndex - 1);
if(sibL!=null && sibL.keyCount > MIN_RECORDS) { if (sibL != null && sibL.keyCount > MIN_RECORDS) {
/* Case 3a (ii): child will underflow upon deletion, take a key from leftSibling */ /* Case 3a (ii): child will underflow upon deletion, take a key from leftSibling */
long leftKey = getRecord(node.chunk, node.node, subtreeIndex-1); long leftKey = getRecord(node.chunk, node.node, subtreeIndex - 1);
prepend(child, leftKey, getChild(sibL.chunk, sibL.node, sibL.keyCount)); prepend(child, leftKey, getChild(sibL.chunk, sibL.node, sibL.keyCount));
long rightmostLeftSiblingKey = getRecord(sibL.chunk, sibL.node, sibL.keyCount-1); long rightmostLeftSiblingKey = getRecord(sibL.chunk, sibL.node, sibL.keyCount - 1);
putRecord(sibL.chunk, sibL.node, sibL.keyCount-1, 0); putRecord(sibL.chunk, sibL.node, sibL.keyCount - 1, 0);
putChild(sibL.chunk, sibL.node, sibL.keyCount, 0); putChild(sibL.chunk, sibL.node, sibL.keyCount, 0);
putRecord(node.chunk, node.node, subtreeIndex-1, rightmostLeftSiblingKey); putRecord(node.chunk, node.node, subtreeIndex - 1, rightmostLeftSiblingKey);
return deleteImp(key, child.node, mode); return deleteImp(key, child.node, mode);
} }
/* Case 3b (i,ii): leftSibling, child, rightSibling all have minimum number of keys */ /* Case 3b (i,ii): leftSibling, child, rightSibling all have minimum number of keys */
if(sibL!=null) { // merge child into leftSibling if (sibL != null) { // merge child into leftSibling
mergeNodes(child, node, subtreeIndex-1, sibL); mergeNodes(child, node, subtreeIndex - 1, sibL);
return deleteImp(key, sibL.node, mode); return deleteImp(key, sibL.node, mode);
} }
if(sibR!=null) { // merge rightSibling into child if (sibR != null) { // merge rightSibling into child
mergeNodes(sibR, node, subtreeIndex, child); mergeNodes(sibR, node, subtreeIndex, child);
return deleteImp(key, child.node, mode); return deleteImp(key, child.node, mode);
} }
@ -429,21 +424,21 @@ public class BTree {
*/ */
public void mergeNodes(BTNode src, BTNode keyProvider, int kIndex, BTNode dst) public void mergeNodes(BTNode src, BTNode keyProvider, int kIndex, BTNode dst)
throws CoreException { throws CoreException {
nodeContentCopy(src, 0, dst, dst.keyCount+1, src.keyCount+1); nodeContentCopy(src, 0, dst, dst.keyCount + 1, src.keyCount + 1);
long midKey = getRecord(keyProvider.chunk, keyProvider.node, kIndex); long midKey = getRecord(keyProvider.chunk, keyProvider.node, kIndex);
putRecord(dst.chunk, dst.node, dst.keyCount, midKey); putRecord(dst.chunk, dst.node, dst.keyCount, midKey);
long keySucc = kIndex+1 == MAX_RECORDS ? 0 : getRecord(keyProvider.chunk, keyProvider.node, kIndex+1); long keySucc = kIndex + 1 == MAX_RECORDS ? 0 : getRecord(keyProvider.chunk, keyProvider.node, kIndex + 1);
db.free(getChild(keyProvider.chunk, keyProvider.node, kIndex+1)); db.free(getChild(keyProvider.chunk, keyProvider.node, kIndex + 1));
nodeContentDelete(keyProvider, kIndex+1, 1); nodeContentDelete(keyProvider, kIndex + 1, 1);
putRecord(keyProvider.chunk, keyProvider.node, kIndex, keySucc); putRecord(keyProvider.chunk, keyProvider.node, kIndex, keySucc);
if(kIndex == 0 && keySucc == 0) { if (kIndex == 0 && keySucc == 0) {
/* /*
* The root node is excused from the property that a node must have a least MIN keys * The root node is excused from the property that a node must have a least MIN keys
* This means we must special case it at the point when its had all of its keys deleted * This means we must special case it at the point when its had all of its keys deleted
* entirely during merge operations (which push one of its keys down as a pivot) * entirely during merge operations (which push one of its keys down as a pivot)
*/ */
long rootNode = getRoot(); long rootNode = getRoot();
if(rootNode == keyProvider.node) { if (rootNode == keyProvider.node) {
db.putRecPtr(rootPointer, dst.node); db.putRecPtr(rootPointer, dst.node);
db.free(rootNode); db.free(rootNode);
} }
@ -458,7 +453,7 @@ public class BTree {
* @param child the new leftmost (least) subtree root * @param child the new leftmost (least) subtree root
*/ */
private void prepend(BTNode node, long key, long child) { private void prepend(BTNode node, long key, long child) {
nodeContentCopy(node, 0, node, 1, node.keyCount+1); nodeContentCopy(node, 0, node, 1, node.keyCount + 1);
putRecord(node.chunk, node.node, 0, key); putRecord(node.chunk, node.node, 0, key);
putChild(node.chunk, node.node, 0, child); putChild(node.chunk, node.node, 0, child);
} }
@ -487,15 +482,15 @@ public class BTree {
* @param length the number of (key,(predecessor)child) nodes to write * @param length the number of (key,(predecessor)child) nodes to write
*/ */
private void nodeContentCopy(BTNode src, int srcPos, BTNode dst, int dstPos, int length) { private void nodeContentCopy(BTNode src, int srcPos, BTNode dst, int dstPos, int length) {
for(int i=length-1; i>=0; i--) { // this order is important when src==dst! for (int i=length - 1; i >= 0; i--) { // this order is important when src == dst!
int srcIndex = srcPos + i; int srcIndex = srcPos + i;
int dstIndex = dstPos + i; int dstIndex = dstPos + i;
if(srcIndex<src.keyCount+1) { if (srcIndex < src.keyCount + 1) {
long srcChild = getChild(src.chunk, src.node, srcIndex); long srcChild = getChild(src.chunk, src.node, srcIndex);
putChild(dst.chunk, dst.node, dstIndex, srcChild); putChild(dst.chunk, dst.node, dstIndex, srcChild);
if(srcIndex<src.keyCount) { if (srcIndex < src.keyCount) {
long srcKey = getRecord(src.chunk, src.node, srcIndex); long srcKey = getRecord(src.chunk, src.node, srcIndex);
putRecord(dst.chunk, dst.node, dstIndex, srcKey); putRecord(dst.chunk, dst.node, dstIndex, srcKey);
} }
@ -513,13 +508,13 @@ public class BTree {
* @param length the length of the sequence to delete * @param length the length of the sequence to delete
*/ */
private void nodeContentDelete(BTNode node, int i, int length) { private void nodeContentDelete(BTNode node, int i, int length) {
for(int index=i; index<=MAX_RECORDS; index++) { for (int index= i; index <= MAX_RECORDS; index++) {
long newKey = (index+length) < node.keyCount ? getRecord(node.chunk, node.node, index+length) : 0; long newKey = (index + length) < node.keyCount ? getRecord(node.chunk, node.node, index + length) : 0;
long newChild = (index+length) < node.keyCount+1 ? getChild(node.chunk, node.node, index+length) : 0; long newChild = (index + length) < node.keyCount + 1 ? getChild(node.chunk, node.node, index + length) : 0;
if(index<MAX_RECORDS) { if (index < MAX_RECORDS) {
putRecord(node.chunk, node.node, index, newKey); putRecord(node.chunk, node.node, index, newKey);
} }
if(index<MAX_CHILDREN) { if (index < MAX_CHILDREN) {
putChild(node.chunk, node.node, index, newChild); putChild(node.chunk, node.node, index, newChild);
} }
} }
@ -543,8 +538,8 @@ public class BTree {
if (node == 0) { if (node == 0) {
return true; return true;
} }
if(visitor instanceof IBTreeVisitor2) { if (visitor instanceof IBTreeVisitor2) {
((IBTreeVisitor2)visitor).preNode(node); ((IBTreeVisitor2) visitor).preNode(node);
} }
try { try {
@ -552,23 +547,21 @@ public class BTree {
// binary search to find first record greater or equal // binary search to find first record greater or equal
int lower= 0; int lower= 0;
int upper= MAX_RECORDS-1; int upper= MAX_RECORDS - 1;
while (lower < upper && getRecord(chunk, node, upper-1) == 0) { while (lower < upper && getRecord(chunk, node, upper - 1) == 0) {
upper--; upper--;
} }
while (lower < upper) { while (lower < upper) {
int middle= (lower+upper)/2; int middle= (lower + upper) / 2;
long checkRec = getRecord(chunk, node, middle); long checkRec = getRecord(chunk, node, middle);
if (checkRec == 0) { if (checkRec == 0) {
upper= middle; upper= middle;
} } else {
else {
int compare= visitor.compare(checkRec); int compare= visitor.compare(checkRec);
if (compare >= 0) { if (compare >= 0) {
upper= middle; upper= middle;
} } else {
else { lower= middle + 1;
lower= middle+1;
} }
} }
} }
@ -584,8 +577,7 @@ public class BTree {
if (compare > 0) { if (compare > 0) {
// start point is to the left // start point is to the left
return accept(getChild(chunk, node, i), visitor); return accept(getChild(chunk, node, i), visitor);
} } else if (compare == 0) {
else if (compare == 0) {
if (!accept(getChild(chunk, node, i), visitor)) if (!accept(getChild(chunk, node, i), visitor))
return false; return false;
if (!visitor.visit(record)) if (!visitor.visit(record))
@ -594,8 +586,8 @@ public class BTree {
} }
return accept(getChild(chunk, node, i), visitor); return accept(getChild(chunk, node, i), visitor);
} finally { } finally {
if(visitor instanceof IBTreeVisitor2) { if (visitor instanceof IBTreeVisitor2) {
((IBTreeVisitor2)visitor).postNode(node); ((IBTreeVisitor2) visitor).postNode(node);
} }
} }
} }
@ -648,56 +640,56 @@ public class BTree {
int keyCount = 0; int keyCount = 0;
int indexFirstBlankKey = MAX_RECORDS; int indexFirstBlankKey = MAX_RECORDS;
int indexLastNonBlankKey = 0; int indexLastNonBlankKey = 0;
for(int i=0; i<MAX_RECORDS; i++) { for (int i= 0; i < MAX_RECORDS; i++) {
if(getRecord(db.getChunk(node), node, i)!=0) { if (getRecord(db.getChunk(node), node, i) != 0) {
keyCount++; keyCount++;
indexLastNonBlankKey = i; indexLastNonBlankKey = i;
} else if(indexFirstBlankKey== MAX_RECORDS){ } else if (indexFirstBlankKey == MAX_RECORDS) {
indexFirstBlankKey = i; indexFirstBlankKey = i;
} }
} }
int childCount = 0; int childCount = 0;
for(int i=0; i<MAX_CHILDREN; i++) { for (int i= 0; i < MAX_CHILDREN; i++) {
if(getChild(db.getChunk(node), node, i)!=0) { if (getChild(db.getChunk(node), node, i) != 0) {
childCount++; childCount++;
} }
} }
// check that non-blank keys are contiguous and blank key terminated // check that non-blank keys are contiguous and blank key terminated
if(indexFirstBlankKey != indexLastNonBlankKey+1) { if (indexFirstBlankKey != indexLastNonBlankKey + 1) {
boolean full = indexFirstBlankKey == MAX_RECORDS && indexLastNonBlankKey == MAX_RECORDS-1; boolean full = indexFirstBlankKey == MAX_RECORDS && indexLastNonBlankKey == MAX_RECORDS - 1;
boolean empty = indexFirstBlankKey == 0 && indexLastNonBlankKey == 0; boolean empty = indexFirstBlankKey == 0 && indexLastNonBlankKey == 0;
if(!full && !empty){ if (!full && !empty) {
valid = false; valid = false;
msg += MessageFormat.format(Messages.getString("BTree.IntegrityErrorA"), //$NON-NLS-1$ msg += MessageFormat.format(Messages.getString("BTree.IntegrityErrorA"), //$NON-NLS-1$
new Object[]{new Long(node), new Integer(indexFirstBlankKey), new Integer(indexLastNonBlankKey)}); new Object[] { new Long(node), new Integer(indexFirstBlankKey), new Integer(indexLastNonBlankKey) });
} }
} }
// Check: Key number constrains child numbers // Check: Key number constrains child numbers
if(childCount!=0 && childCount!=keyCount+1) { if (childCount != 0 && childCount != keyCount + 1) {
valid = false; valid = false;
msg += MessageFormat.format(Messages.getString("BTree.IntegrityErrorB"), new Object[]{new Long(node)}); //$NON-NLS-1$ msg += MessageFormat.format(Messages.getString("BTree.IntegrityErrorB"), new Object[] { new Long(node) }); //$NON-NLS-1$
} }
// the root node is excused from the remaining node constraints // the root node is excused from the remaining node constraints
if(node == db.getRecPtr(rootPointer)) { if (node == db.getRecPtr(rootPointer)) {
return; return;
} }
// Check: Non-root nodes must have a keyCount within a certain range // Check: Non-root nodes must have a keyCount within a certain range
if(keyCount < MIN_RECORDS || keyCount > MAX_RECORDS) { if (keyCount < MIN_RECORDS || keyCount > MAX_RECORDS) {
valid = false; valid = false;
msg += MessageFormat.format(Messages.getString("BTree.IntegrityErrorC"), new Object[]{new Long(node)}); //$NON-NLS-1$ msg += MessageFormat.format(Messages.getString("BTree.IntegrityErrorC"), new Object[] { new Long(node) }); //$NON-NLS-1$
} }
// Check: All leaf nodes are at the same depth // Check: All leaf nodes are at the same depth
if(childCount==0) { if (childCount == 0) {
if(leafDepth==null) { if (leafDepth == null) {
leafDepth = new Integer(depth); leafDepth = new Integer(depth);
} }
if(depth!=leafDepth.intValue()) { if (depth != leafDepth.intValue()) {
valid = false; valid = false;
msg += Messages.getString("BTree.IntegrityErrorD"); //$NON-NLS-1$ msg += Messages.getString("BTree.IntegrityErrorD"); //$NON-NLS-1$
} }