mirror of
https://github.com/eclipse-cdt/cdt
synced 2025-07-29 20:05:35 +02:00
Code streamlining.
Change-Id: I773eb373e6397260af6fd3815f1b16815500dabd
This commit is contained in:
parent
4376bec698
commit
2b3ab14082
3 changed files with 45 additions and 50 deletions
|
@ -8,20 +8,17 @@
|
||||||
* Contributors:
|
* Contributors:
|
||||||
* QNX - Initial API and implementation
|
* QNX - Initial API and implementation
|
||||||
*******************************************************************************/
|
*******************************************************************************/
|
||||||
|
|
||||||
package org.eclipse.cdt.core.dom;
|
package org.eclipse.cdt.core.dom;
|
||||||
|
|
||||||
import org.eclipse.core.runtime.CoreException;
|
import org.eclipse.core.runtime.CoreException;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author Doug Schaefer
|
* @author Doug Schaefer
|
||||||
*
|
|
||||||
*/
|
*/
|
||||||
public interface IPDOMVisitor {
|
public interface IPDOMVisitor {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Walk the nodes in a PDOM. Return true to visit the children of
|
* Walks the nodes in a PDOM. Returns true to visit the children of
|
||||||
* this node, or false to skip to the next sibling of this node.
|
* the node, or false to skip to the next sibling of this node.
|
||||||
* Throw CoreException to stop the visit.
|
* Throw CoreException to stop the visit.
|
||||||
*
|
*
|
||||||
* @param node being visited
|
* @param node being visited
|
||||||
|
@ -36,5 +33,4 @@ public interface IPDOMVisitor {
|
||||||
* @throws CoreException
|
* @throws CoreException
|
||||||
*/
|
*/
|
||||||
public void leave(IPDOMNode node) throws CoreException;
|
public void leave(IPDOMNode node) throws CoreException;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -47,7 +47,7 @@ public class BTree {
|
||||||
/**
|
/**
|
||||||
* Constructor.
|
* Constructor.
|
||||||
*
|
*
|
||||||
* @param db the database containing the btree
|
* @param db the database containing the B-tree
|
||||||
* @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) {
|
||||||
|
@ -157,7 +157,7 @@ public class BTree {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Binary search to find the insert point.
|
// Binary search to find the insertion 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) {
|
||||||
|
@ -165,7 +165,7 @@ public class BTree {
|
||||||
}
|
}
|
||||||
|
|
||||||
while (lower < upper) {
|
while (lower < upper) {
|
||||||
int middle= (lower + upper) / 2;
|
int middle= (lower + upper) >>> 1;
|
||||||
long checkRec= getRecord(chunk, node, middle);
|
long checkRec= getRecord(chunk, node, middle);
|
||||||
if (checkRec == 0) {
|
if (checkRec == 0) {
|
||||||
upper= middle;
|
upper= middle;
|
||||||
|
@ -414,7 +414,7 @@ public class BTree {
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Merge node 'src' onto the right side of node 'dst' using node
|
* Merges node 'src' onto the right side of node 'dst' using node
|
||||||
* 'keyProvider' as the source of the median key. Bounds checking is not
|
* 'keyProvider' as the source of the median key. Bounds checking is not
|
||||||
* performed.
|
* performed.
|
||||||
* @param src the key to merge into dst
|
* @param src the key to merge into dst
|
||||||
|
@ -446,7 +446,7 @@ public class BTree {
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Insert the key and (its predecessor) child at the left side of the specified node. Bounds checking
|
* Inserts the key and (its predecessor) child at the left side of the specified node. Bounds checking
|
||||||
* is not performed.
|
* is not performed.
|
||||||
* @param node the node to prepend to
|
* @param node the node to prepend to
|
||||||
* @param key the new leftmost (least) key
|
* @param key the new leftmost (least) key
|
||||||
|
@ -459,7 +459,7 @@ public class BTree {
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Insert the key and (its successor) child at the right side of the specified node. Bounds
|
* Inserts the key and (its successor) child at the right side of the specified node. Bounds
|
||||||
* checking is not performed.
|
* checking is not performed.
|
||||||
* @param node
|
* @param node
|
||||||
* @param key
|
* @param key
|
||||||
|
@ -471,7 +471,7 @@ public class BTree {
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Overwrite a section of the specified node (dst) with the specified section of the source
|
* Overwrites a section of the specified node (dst) with the specified section of the source
|
||||||
* node. Bounds checking is not performed. To allow just copying of the final child (which has
|
* node. Bounds checking is not performed. To allow just copying of the final child (which has
|
||||||
* no corresponding key) the routine behaves as though there were a corresponding key existing
|
* no corresponding key) the routine behaves as though there were a corresponding key existing
|
||||||
* with value zero.<p>
|
* with value zero.<p>
|
||||||
|
@ -500,7 +500,7 @@ public class BTree {
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Delete a section of node content - (key, (predecessor)child) pairs. Bounds checking
|
* Deletes a section of node content - (key, (predecessor)child) pairs. Bounds checking
|
||||||
* is not performed. To allow deletion of the final child (which has no corresponding key)
|
* is not performed. To allow deletion of the final child (which has no corresponding key)
|
||||||
* the routine behaves as though there were a corresponding key existing with value zero.<p>
|
* the routine behaves as though there were a corresponding key existing with value zero.<p>
|
||||||
* Content is deleted and remaining content is moved leftward the appropriate amount.
|
* Content is deleted and remaining content is moved leftward the appropriate amount.
|
||||||
|
@ -522,7 +522,7 @@ public class BTree {
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Visit all nodes beginning when the visitor comparator
|
* Visits all nodes beginning when the visitor comparator
|
||||||
* returns >= 0 until the visitor visit returns falls.
|
* returns >= 0 until the visitor visit returns falls.
|
||||||
*
|
*
|
||||||
* @param visitor
|
* @param visitor
|
||||||
|
@ -539,9 +539,7 @@ public class BTree {
|
||||||
if (node == 0) {
|
if (node == 0) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
if (visitor instanceof IBTreeVisitor2) {
|
visitor.preNode(node);
|
||||||
((IBTreeVisitor2) visitor).preNode(node);
|
|
||||||
}
|
|
||||||
|
|
||||||
try {
|
try {
|
||||||
Chunk chunk = db.getChunk(node);
|
Chunk chunk = db.getChunk(node);
|
||||||
|
@ -553,7 +551,7 @@ public class BTree {
|
||||||
upper--;
|
upper--;
|
||||||
}
|
}
|
||||||
while (lower < upper) {
|
while (lower < upper) {
|
||||||
int middle= (lower + upper) / 2;
|
int middle= (lower + upper) >>> 1;
|
||||||
long checkRec = getRecord(chunk, node, middle);
|
long checkRec = getRecord(chunk, node, middle);
|
||||||
if (checkRec == 0) {
|
if (checkRec == 0) {
|
||||||
upper= middle;
|
upper= middle;
|
||||||
|
@ -587,25 +585,14 @@ public class BTree {
|
||||||
}
|
}
|
||||||
return accept(getChild(chunk, node, i), visitor);
|
return accept(getChild(chunk, node, i), visitor);
|
||||||
} finally {
|
} finally {
|
||||||
if (visitor instanceof IBTreeVisitor2) {
|
visitor.postNode(node);
|
||||||
((IBTreeVisitor2) visitor).postNode(node);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
/*
|
|
||||||
* TODO: It would be good to move these into IBTreeVisitor and eliminate
|
|
||||||
* IBTreeVisitor2 if this is acceptable.
|
|
||||||
*/
|
|
||||||
private interface IBTreeVisitor2 extends IBTreeVisitor {
|
|
||||||
void preNode(long node) throws CoreException;
|
|
||||||
void postNode(long node) throws CoreException;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Debugging method for checking B-tree invariants
|
* Debugging method for checking B-tree invariants.
|
||||||
* @return the empty String if B-tree invariants hold, otherwise
|
*
|
||||||
* a human readable report
|
* @return the empty String if B-tree invariants hold, otherwise a human readable report
|
||||||
* @throws CoreException
|
* @throws CoreException
|
||||||
*/
|
*/
|
||||||
public String getInvariantsErrorReport() throws CoreException {
|
public String getInvariantsErrorReport() throws CoreException {
|
||||||
|
@ -618,7 +605,7 @@ public class BTree {
|
||||||
* A B-tree visitor for checking some B-tree invariants.
|
* A B-tree visitor for checking some B-tree invariants.
|
||||||
* Note ordering invariants are not checked here.
|
* Note ordering invariants are not checked here.
|
||||||
*/
|
*/
|
||||||
private class InvariantsChecker implements IBTreeVisitor2 {
|
private class InvariantsChecker implements IBTreeVisitor {
|
||||||
boolean valid = true;
|
boolean valid = true;
|
||||||
String msg = ""; //$NON-NLS-1$
|
String msg = ""; //$NON-NLS-1$
|
||||||
Integer leafDepth;
|
Integer leafDepth;
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
/*******************************************************************************
|
/*******************************************************************************
|
||||||
* Copyright (c) 2005, 2012 QNX Software Systems and others.
|
* Copyright (c) 2005, 2015 QNX Software Systems and others.
|
||||||
* All rights reserved. This program and the accompanying materials
|
* All rights reserved. This program and the accompanying materials
|
||||||
* are made available under the terms of the Eclipse Public License v1.0
|
* are made available under the terms of the Eclipse Public License v1.0
|
||||||
* which accompanies this distribution, and is available at
|
* which accompanies this distribution, and is available at
|
||||||
|
@ -20,21 +20,33 @@ import org.eclipse.core.runtime.CoreException;
|
||||||
*/
|
*/
|
||||||
public interface IBTreeVisitor {
|
public interface IBTreeVisitor {
|
||||||
/**
|
/**
|
||||||
* Compare the record against an internally held key. The comparison must be
|
* Compares the record against an internally held key. The comparison must be
|
||||||
* compatible with the one used for the btree.
|
* compatible with the one used for the B-tree.
|
||||||
* Used for visiting.
|
* Used for visiting.
|
||||||
*
|
*
|
||||||
* @param record
|
* @param record
|
||||||
* @return -1 if record < key, 0 if record == key, 1 if record > key
|
* @return -1 if record < key, 0 if record == key, 1 if record > key
|
||||||
* @throws CoreException
|
|
||||||
*/
|
*/
|
||||||
public abstract int compare(long record) throws CoreException;
|
public int compare(long record) throws CoreException;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Visit a given record and return whether to continue or not.
|
* Visits a given record and returns whether to continue or not.
|
||||||
|
*
|
||||||
* @return <code>true</code> to continue the visit, <code>false</code> to abort it.
|
* @return {@code true} to continue the visit, {@code false} to abort it.
|
||||||
* @throws CoreException
|
|
||||||
*/
|
*/
|
||||||
public abstract boolean visit(long record) throws CoreException;
|
public boolean visit(long record) throws CoreException;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Called before visiting a node.
|
||||||
|
*
|
||||||
|
* @param record the node being visited
|
||||||
|
*/
|
||||||
|
public default void preNode(long record) throws CoreException {}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Called after visiting a node.
|
||||||
|
*
|
||||||
|
* @param record the node being visited
|
||||||
|
*/
|
||||||
|
public default void postNode(long record) throws CoreException {}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue