1
0
Fork 0
mirror of https://github.com/eclipse-cdt/cdt synced 2025-06-07 17:56:01 +02:00

Cosmetics.

This commit is contained in:
Sergey Prigogin 2012-05-02 21:16:32 -07:00
parent 88415fb2a1
commit 981cdfcee6
4 changed files with 80 additions and 70 deletions

View file

@ -260,9 +260,9 @@ public class PDOM extends PlatformObject implements IPDOM {
public static class ChangeEvent { public static class ChangeEvent {
public Set<IIndexFileLocation> fClearedFiles= new HashSet<IIndexFileLocation>(); public Set<IIndexFileLocation> fClearedFiles= new HashSet<IIndexFileLocation>();
public Set<IIndexFileLocation> fFilesWritten= new HashSet<IIndexFileLocation>(); public Set<IIndexFileLocation> fFilesWritten= new HashSet<IIndexFileLocation>();
private boolean fCleared= false; private boolean fCleared;
private boolean fReloaded= false; private boolean fReloaded;
private boolean fNewFiles= false; private boolean fNewFiles;
private void setCleared() { private void setCleared() {
fCleared= true; fCleared= true;
@ -294,7 +294,8 @@ public class PDOM extends PlatformObject implements IPDOM {
} }
public boolean isTrivial() { public boolean isTrivial() {
return !fCleared && !fReloaded && !fNewFiles && fClearedFiles.isEmpty() && fFilesWritten.isEmpty(); return !fCleared && !fReloaded && !fNewFiles && fClearedFiles.isEmpty() &&
fFilesWritten.isEmpty();
} }
} }
@ -313,11 +314,13 @@ public class PDOM extends PlatformObject implements IPDOM {
private List<IListener> listeners; private List<IListener> listeners;
protected ChangeEvent fEvent= new ChangeEvent(); protected ChangeEvent fEvent= new ChangeEvent();
public PDOM(File dbPath, IIndexLocationConverter locationConverter, Map<String, IPDOMLinkageFactory> linkageFactoryMappings) throws CoreException { public PDOM(File dbPath, IIndexLocationConverter locationConverter,
Map<String, IPDOMLinkageFactory> linkageFactoryMappings) throws CoreException {
this(dbPath, locationConverter, ChunkCache.getSharedInstance(), linkageFactoryMappings); this(dbPath, locationConverter, ChunkCache.getSharedInstance(), linkageFactoryMappings);
} }
public PDOM(File dbPath, IIndexLocationConverter locationConverter, ChunkCache cache, Map<String, IPDOMLinkageFactory> linkageFactoryMappings) throws CoreException { public PDOM(File dbPath, IIndexLocationConverter locationConverter, ChunkCache cache,
Map<String, IPDOMLinkageFactory> linkageFactoryMappings) throws CoreException {
fPDOMLinkageFactoryCache = linkageFactoryMappings; fPDOMLinkageFactoryCache = linkageFactoryMappings;
loadDatabase(dbPath, cache); loadDatabase(dbPath, cache);
this.locationConverter = locationConverter; this.locationConverter = locationConverter;

View file

@ -23,7 +23,7 @@ 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).
private static final int DELMODE_NORMAL = 0; private static final int DELMODE_NORMAL = 0;
private static final int DELMODE_DELETE_MINIMUM = 1; private static final int DELMODE_DELETE_MINIMUM = 1;
private static final int DELMODE_DELETE_MAXIMUM = 2; private static final int DELMODE_DELETE_MAXIMUM = 2;
@ -87,16 +87,16 @@ public class BTree {
} }
/** /**
* Inserts the record into the b-tree. We don't insert if the * Inserts the record into the b-tree. We don't insert if the key was already there,
* key was already there, in which case we return the record * in which case we return the record that matched. In other cases, we just return
* that matched. In other cases, we just return the record back. * the record back.
* *
* @param record offset of the record * @param record offset of the record
*/ */
public long insert(long record) throws CoreException { public long insert(long record) throws CoreException {
long root = getRoot(); long root = getRoot();
// is this our first time in // Is this our first time in.
if (root == 0) { if (root == 0) {
firstInsert(record); firstInsert(record);
return record; return record;
@ -108,15 +108,15 @@ public class BTree {
private long insert(Chunk pChunk, long parent, int iParent, long node, long record) throws CoreException { private long insert(Chunk pChunk, long parent, int iParent, long node, long record) throws CoreException {
Chunk chunk = db.getChunk(node); Chunk chunk = db.getChunk(node);
// 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();
Chunk newchunk = db.getChunk(newnode); Chunk newchunk = db.getChunk(newnode);
for (int i = 0; i < MEDIAN_RECORD; ++i) { for (int i = 0; i < MEDIAN_RECORD; ++i) {
@ -129,13 +129,13 @@ public class BTree {
putChild(chunk, node, MAX_RECORDS, 0); putChild(chunk, node, MAX_RECORDS, 0);
if (parent == 0) { if (parent == 0) {
// create a new root // Create a new root
parent = allocateNode(); parent = allocateNode();
pChunk = db.getChunk(parent); pChunk = db.getChunk(parent);
db.putRecPtr(rootPointer, parent); db.putRecPtr(rootPointer, parent);
putChild(pChunk, parent, 0, node); putChild(pChunk, parent, 0, node);
} else { } else {
// insert the median into the parent // Insert the median into the parent.
for (int i = MAX_RECORDS - 2; i >= iParent; --i) { for (int i = MAX_RECORDS - 2; i >= iParent; --i) {
long r = getRecord(pChunk, parent, i); long r = getRecord(pChunk, parent, i);
if (r != 0) { if (r != 0) {
@ -149,7 +149,7 @@ public class BTree {
putRecord(chunk, node, MEDIAN_RECORD, 0); putRecord(chunk, node, MEDIAN_RECORD, 0);
// set the node to the correct one to follow // Set the node to the correct one to follow.
if (cmp.compare(record, median) > 0) { if (cmp.compare(record, median) > 0) {
node = newnode; node = newnode;
chunk = newchunk; chunk = newchunk;
@ -157,7 +157,7 @@ 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) {
@ -165,7 +165,7 @@ public class BTree {
} }
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;
@ -176,19 +176,19 @@ public class BTree {
} 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;
} }
} }
} }
final int i= lower; final int i= lower;
long child = getChild(chunk, node, i); long child = getChild(chunk, node, i);
if (child != 0) { if (child != 0) {
// visit the children // Visit the children.
return insert(chunk, node, i, child, record); return insert(chunk, node, i, child, record);
} else { } else {
// were at the leaf, add us in. // We are at the leaf, add us in.
// first copy everything after over one // First copy everything after over one.
for (int j = MAX_RECORDS - 2; j >= i; --j) { for (int j = MAX_RECORDS - 2; j >= i; --j) {
long r = getRecord(chunk, node, j); long r = getRecord(chunk, node, j);
if (r != 0) if (r != 0)
@ -200,10 +200,10 @@ public class BTree {
} }
private void firstInsert(long record) throws CoreException { private void firstInsert(long record) throws CoreException {
// create the node and save it as root // Create the node and save it as root.
long root = allocateNode(); long root = allocateNode();
db.putRecPtr(rootPointer, root); db.putRecPtr(rootPointer, root);
// put the record in the first slot of the node // Put the record in the first slot of the node.
putRecord(db.getChunk(root), root, 0, record); putRecord(db.getChunk(root), root, 0, record);
} }
@ -228,8 +228,8 @@ public class BTree {
public void delete(long record) throws CoreException { public void delete(long record) throws CoreException {
try { try {
deleteImp(record, getRoot(), DELMODE_NORMAL); deleteImp(record, getRoot(), DELMODE_NORMAL);
} catch(BTreeKeyNotFoundException e) { } catch (BTreeKeyNotFoundException e) {
// contract of this method is to NO-OP upon this event // Contract of this method is to NO-OP upon this event.
} }
} }
@ -288,7 +288,7 @@ public class BTree {
throws CoreException, BTreeKeyNotFoundException { throws CoreException, BTreeKeyNotFoundException {
BTNode node = new BTNode(nodeRecord); BTNode node = new BTNode(nodeRecord);
// 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++)
@ -459,8 +459,8 @@ public class BTree {
} }
/** /**
* Insert the key and (its successor) child at the right side of the specified node. Bounds checking * Insert the key and (its successor) child at the right side of the specified node. Bounds
* is not performed. * checking is not performed.
* @param node * @param node
* @param key * @param key
* @param child * @param child
@ -471,9 +471,10 @@ public class BTree {
} }
/** /**
* Overwrite a section of the specified node (dst) with the specified section of the source node. Bounds checking * Overwrite a section of the specified node (dst) with the specified section of the source
* is not performed. To allow just copying of the final child (which has no corresponding key) the routine * node. Bounds checking is not performed. To allow just copying of the final child (which has
* behaves as though there were a corresponding key existing with value zero.<p> * no corresponding key) the routine behaves as though there were a corresponding key existing
* with value zero.<p>
* Copying from a node to itself is permitted. * Copying from a node to itself is permitted.
* @param src the node to read from * @param src the node to read from
* @param srcPos the initial index to read from (inclusive) * @param srcPos the initial index to read from (inclusive)
@ -500,8 +501,8 @@ public class BTree {
/** /**
* Delete a section of node content - (key, (predecessor)child) pairs. Bounds checking * Delete 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) the routine * is not performed. To allow deletion of the final child (which has no corresponding key)
* 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.
* @param node the node to delete content from * @param node the node to delete content from
* @param i the start index (inclusive) to delete from * @param i the start index (inclusive) to delete from
@ -531,9 +532,9 @@ public class BTree {
} }
private boolean accept(long node, IBTreeVisitor visitor) throws CoreException { private boolean accept(long node, IBTreeVisitor visitor) throws CoreException {
// if found is false, we are still in search mode // If found is false, we are still in search mode.
// once found is true visit everything // Once found is true visit everything.
// return false when ready to quit // Return false when ready to quit.
if (node == 0) { if (node == 0) {
return true; return true;
@ -545,7 +546,7 @@ public class BTree {
try { try {
Chunk chunk = db.getChunk(node); Chunk chunk = db.getChunk(node);
// 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) {
@ -566,7 +567,7 @@ public class BTree {
} }
} }
// start with first record greater or equal, reuse comparison results. // Start with first record greater or equal, reuse comparison results.
int i= lower; int i= lower;
for (; i < MAX_RECORDS; ++i) { for (; i < MAX_RECORDS; ++i) {
long record = getRecord(chunk, node, i); long record = getRecord(chunk, node, i);
@ -575,7 +576,7 @@ public class BTree {
int compare= visitor.compare(record); int compare= visitor.compare(record);
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))
@ -636,7 +637,7 @@ public class BTree {
public void preNode(long node) throws CoreException { public void preNode(long node) throws CoreException {
depth++; depth++;
// collect information for checking // Collect information for checking.
int keyCount = 0; int keyCount = 0;
int indexFirstBlankKey = MAX_RECORDS; int indexFirstBlankKey = MAX_RECORDS;
int indexLastNonBlankKey = 0; int indexLastNonBlankKey = 0;
@ -656,7 +657,7 @@ public class BTree {
} }
} }
// 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;
@ -673,7 +674,7 @@ public class BTree {
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;
} }

View file

@ -6,7 +6,7 @@
* http://www.eclipse.org/legal/epl-v10.html * http://www.eclipse.org/legal/epl-v10.html
* *
* Contributors: * Contributors:
* Andrew Ferguson (Symbian) - Initial implementation * Andrew Ferguson (Symbian) - Initial implementation
*******************************************************************************/ *******************************************************************************/
package org.eclipse.cdt.internal.core.pdom.db; package org.eclipse.cdt.internal.core.pdom.db;
@ -39,7 +39,8 @@ public class DBProperties {
} }
/** /**
* Creates an object for accessing an existing DBProperties record at the specified location of the specified database * Creates an object for accessing an existing DBProperties record at the specified location
* of the specified database.
* @param db * @param db
* @param record * @param record
* @throws CoreException * @throws CoreException
@ -51,15 +52,16 @@ public class DBProperties {
} }
/** /**
* Read the named property from this properties storage * Reads the named property from this properties storage.
* @param key a case-sensitive identifier for a property, or null * @param key a case-sensitive identifier for a property, or null
* @return the value associated with the key, or null if either no such property is set, or the specified key was null * @return the value associated with the key, or null if either no such property is set,
* or the specified key was null
* @throws CoreException * @throws CoreException
*/ */
public String getProperty(String key) throws CoreException { public String getProperty(String key) throws CoreException {
if(key!=null) { if (key != null) {
DBProperty existing= DBProperty.search(db, index, key); DBProperty existing= DBProperty.search(db, index, key);
if(existing!=null) { if (existing != null) {
return existing.getValue().getString(); return existing.getValue().getString();
} }
} }
@ -67,11 +69,12 @@ public class DBProperties {
} }
/** /**
* Read the named property from this properties storage, returning the default value if there is no such property * Reads the named property from this properties storage, returning the default value if there
* is no such property.
* @param key a case-sensitive identifier for a property, or null * @param key a case-sensitive identifier for a property, or null
* @param defaultValue a value to return in case the specified key was null * @param defaultValue a value to return in case the specified key was null
* @return the value associated with the key, or the specified default value if either no such property is set, or * @return the value associated with the key, or the specified default value if either no such
* the specified key was null * property is set, or the specified key was null
* @throws CoreException * @throws CoreException
*/ */
public String getProperty(String key, String defaultValue) throws CoreException { public String getProperty(String key, String defaultValue) throws CoreException {
@ -89,7 +92,7 @@ public class DBProperties {
} }
/** /**
* Write the key, value mapping to the properties. If a mapping for the * Writes the key, value mapping to the properties. If a mapping for the
* same key already exists, it is overwritten. * same key already exists, it is overwritten.
* @param key a non-null property name * @param key a non-null property name
* @param value a value to associate with the key. may not be null. * @param value a value to associate with the key. may not be null.
@ -103,15 +106,16 @@ public class DBProperties {
} }
/** /**
* Deletes a property from this DBProperties object * Deletes a property from this DBProperties object.
* @param key * @param key
* @return whether a property with matching key existed and was removed, or false if the key was null * @return whether a property with matching key existed and was removed, or false if the key
* was null
* @throws CoreException * @throws CoreException
*/ */
public boolean removeProperty(String key) throws CoreException { public boolean removeProperty(String key) throws CoreException {
if(key!=null) { if (key != null) {
DBProperty existing= DBProperty.search(db, index, key); DBProperty existing= DBProperty.search(db, index, key);
if(existing != null) { if (existing != null) {
index.delete(existing.getRecord()); index.delete(existing.getRecord());
existing.delete(); existing.delete();
return true; return true;
@ -121,8 +125,8 @@ public class DBProperties {
} }
/** /**
* Deletes all properties, does not delete the record associated with the object itself - that is * Deletes all properties, does not delete the record associated with the object itself
* it can be re-populated. * - that is it can be re-populated.
* @throws CoreException * @throws CoreException
*/ */
public void clear() throws CoreException { public void clear() throws CoreException {
@ -140,7 +144,8 @@ public class DBProperties {
} }
/** /**
* Deletes all properties stored in this object and the record associated with this object itself. * Deletes all properties stored in this object and the record associated with this object
* itself.
* <br><br> * <br><br>
* <b>The behaviour of objects of this class after calling this method is undefined</b> * <b>The behaviour of objects of this class after calling this method is undefined</b>
* @throws CoreException * @throws CoreException
@ -175,8 +180,8 @@ public class DBProperties {
* @throws CoreException * @throws CoreException
*/ */
DBProperty(Database db, String key, String value) throws CoreException { DBProperty(Database db, String key, String value) throws CoreException {
assert key!=null; assert key != null;
assert value!=null; assert value != null;
IString dbkey= db.newString(key); IString dbkey= db.newString(key);
IString dbvalue= db.newString(value); IString dbvalue= db.newString(value);
this.record= db.malloc(RECORD_SIZE); this.record= db.malloc(RECORD_SIZE);
@ -186,8 +191,8 @@ public class DBProperties {
} }
/** /**
* Returns an object for accessing an existing DBProperty record at the specified location in the * Returns an object for accessing an existing DBProperty record at the specified location
* specified database * in the specified database.
* @param db * @param db
* @param record * @param record
*/ */
@ -222,10 +227,11 @@ public class DBProperties {
public int compare(long record) throws CoreException { public int compare(long record) throws CoreException {
return db.getString(db.getRecPtr(record + KEY)).compare(key, true); return db.getString(db.getRecPtr(record + KEY)).compare(key, true);
} }
@Override @Override
public boolean visit(long record) throws CoreException { public boolean visit(long record) throws CoreException {
result[0] = new DBProperty(db, record); result[0] = new DBProperty(db, record);
return false; // there should never be duplicates return false; // There should never be duplicates.
} }
}); });
return result[0]; return result[0];
@ -238,10 +244,11 @@ public class DBProperties {
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 {
result.add(new DBProperty(db, record).getKey().getString()); result.add(new DBProperty(db, record).getKey().getString());
return true; // there should never be duplicates return true; // There should never be duplicates.
} }
}); });
return result; return result;

View file

@ -16,7 +16,6 @@ import org.eclipse.core.runtime.CoreException;
/** /**
* This is a list item. It contains a next and prev pointer * This is a list item. It contains a next and prev pointer
* as well as a pointer to the item. * as well as a pointer to the item.
* block.
* *
* @author Doug Schaefer * @author Doug Schaefer
*/ */