diff --git a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/internal/pdom/tests/BTreeTests.java b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/internal/pdom/tests/BTreeTests.java
index c489e58a2f7..66286c420f4 100644
--- a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/internal/pdom/tests/BTreeTests.java
+++ b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/internal/pdom/tests/BTreeTests.java
@@ -172,7 +172,7 @@ public class BTreeTests extends BaseTestCase {
btree.accept(new IBTreeVisitor(){
int k;
public int compare(int record) throws CoreException {
- return 1;
+ return 0;
}
public boolean visit(int record) throws CoreException {
if(record!=0) {
diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/db/BTree.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/db/BTree.java
index 545d65dff87..cb35bb7f6af 100644
--- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/db/BTree.java
+++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/db/BTree.java
@@ -8,6 +8,7 @@
* Contributors:
* QNX - Initial API and implementation
* Andrew Ferguson (Symbian) - Provide B-tree deletion routine
+ * Markus Schorn (Wind River Systems)
*******************************************************************************/
package org.eclipse.cdt.internal.core.pdom.db;
@@ -520,16 +521,17 @@ public class BTree {
* @param visitor
*/
public void accept(IBTreeVisitor visitor) throws CoreException {
- accept(db.getInt(rootPointer), visitor, false);
+ accept(db.getInt(rootPointer), visitor);
}
- private boolean accept(int node, IBTreeVisitor visitor, boolean found) throws CoreException {
+ private boolean accept(int node, IBTreeVisitor visitor) throws CoreException {
// if found is false, we are still in search mode
// once found is true visit everything
// return false when ready to quit
- if (node == 0)
- return visitor.visit(0);
+ if (node == 0) {
+ return true;
+ }
if(visitor instanceof IBTreeVisitor2) {
((IBTreeVisitor2)visitor).preNode(node);
}
@@ -537,49 +539,25 @@ public class BTree {
try {
Chunk chunk = db.getChunk(node);
- if (found) {
- int child = getChild(chunk, node, 0);
- if (child != 0)
- if (!accept(child, visitor, true))
- return false;
- }
-
- int i;
- for (i = 0; i < MAX_RECORDS; ++i) {
+ int i= 0;
+ for (; i < MAX_RECORDS; ++i) {
int record = getRecord(chunk, node, i);
- if (record == 0)
+ if (record == 0)
break;
- if (found) {
+ int compare = visitor.compare(record);
+ if (compare > 0) {
+ // start point is to the left
+ return accept(getChild(chunk, node, i), visitor);
+ }
+ else if (compare == 0) {
+ if (!accept(getChild(chunk, node, i), visitor))
+ return false;
if (!visitor.visit(record))
return false;
- if (!accept(getChild(chunk, node, i + 1), visitor, true))
- return false;
- } else {
- int compare = visitor.compare(record);
- if (compare > 0) {
- // start point is to the left
- if (!accept(getChild(chunk, node, i), visitor, false))
- return false;
- if (!visitor.visit(record))
- return false;
- if (!accept(getChild(chunk, node, i + 1), visitor, true))
- return false;
- found = true;
- } else if (compare == 0) {
- if (!visitor.visit(record))
- return false;
- if (!accept(getChild(chunk, node, i + 1), visitor, true))
- return false;
- found = true;
- }
}
}
-
- if (!found)
- return accept(getChild(chunk, node, i), visitor, false);
-
- return true;
+ return accept(getChild(chunk, node, i), visitor);
} finally {
if(visitor instanceof IBTreeVisitor2) {
((IBTreeVisitor2)visitor).postNode(node);
@@ -621,7 +599,7 @@ public class BTree {
public String getMsg() { return msg; }
public boolean isValid() { return valid; }
public void postNode(int node) throws CoreException { depth--; }
- public int compare(int record) throws CoreException { return 1; }
+ public int compare(int record) throws CoreException { return 0; }
public boolean visit(int record) throws CoreException { return true; }
public void preNode(int node) throws CoreException {
diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/db/IBTreeVisitor.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/db/IBTreeVisitor.java
index 035601fef27..636ddd89eab 100644
--- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/db/IBTreeVisitor.java
+++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/db/IBTreeVisitor.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2005 QNX Software Systems and others.
+ * Copyright (c) 2005, 2006 QNX Software Systems and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
@@ -7,6 +7,7 @@
*
* Contributors:
* QNX - Initial API and implementation
+ * Markus Schorn (Wind River Systems)
*******************************************************************************/
package org.eclipse.cdt.internal.core.pdom.db;
@@ -15,16 +16,13 @@ import org.eclipse.core.runtime.CoreException;
/**
* @author Doug Schaefer
*
- * The visitor walks through the tree until the compare returns
- * >= 0, i.e. we reach the first record that meets the criteria.
- *
- * It then continues until the visit returns false.
- *
+ * The visitor visits all records where compare returns 0.
*/
public interface IBTreeVisitor {
/**
- * Compare the record against an internally held key.
+ * Compare the record against an internally held key. The comparison must be
+ * compatible with the one used for the btree.
* Used for visiting.
*
* @param record
@@ -35,9 +33,8 @@ public interface IBTreeVisitor {
/**
* Visit a given record and return whether to continue or not.
- *
- * @param record
- * @return
+
+ * @return true
to continue the visit, false
to abort it.
* @throws IOException
*/
public abstract boolean visit(int record) throws CoreException;
diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/dom/PDOMLinkage.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/dom/PDOMLinkage.java
index 27fd71cd875..94b3c5013b9 100644
--- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/dom/PDOMLinkage.java
+++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/dom/PDOMLinkage.java
@@ -108,7 +108,7 @@ public abstract class PDOMLinkage extends PDOMNamedNode implements IBindingIdent
super.accept(visitor);
getIndex().accept(new IBTreeVisitor() {
public int compare(int record) throws CoreException {
- return 1;
+ return 0;
}
public boolean visit(int record) throws CoreException {
PDOMBinding binding = pdom.getBinding(record);
diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/dom/cpp/PDOMCPPNamespace.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/dom/cpp/PDOMCPPNamespace.java
index a6de331aeeb..c9a91072075 100644
--- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/dom/cpp/PDOMCPPNamespace.java
+++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/dom/cpp/PDOMCPPNamespace.java
@@ -74,7 +74,7 @@ implements ICPPNamespace, ICPPNamespaceScope {
super.accept(visitor);
getIndex().accept(new IBTreeVisitor() {
public int compare(int record) throws CoreException {
- return 1;
+ return 0;
}
public boolean visit(int record) throws CoreException {
PDOMBinding binding = pdom.getBinding(record);
diff --git a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/indexview/CountNodeAction.java b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/indexview/CountNodeAction.java
index 57463c21c61..b63750e181d 100644
--- a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/indexview/CountNodeAction.java
+++ b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/indexview/CountNodeAction.java
@@ -76,7 +76,7 @@ public class CountNodeAction extends IndexAction {
pdom.getFileIndex().accept(new IBTreeVisitor() {
public int compare(int record) throws CoreException {
- return 1;
+ return 0;
}
public boolean visit(int record) throws CoreException {
if (record != 0) {