1
0
Fork 0
mirror of https://github.com/eclipse-cdt/cdt synced 2025-04-29 19:45:01 +02:00

Compiler warnings.

This commit is contained in:
Sergey Prigogin 2008-04-27 06:43:57 +00:00
parent a602cd1826
commit d6d86766bb
2 changed files with 25 additions and 30 deletions

View file

@ -16,8 +16,7 @@ import java.util.Comparator;
/** /**
* @author ddaoust * @author ddaoust
*/ */
public class HashTable implements Cloneable{ public class HashTable implements Cloneable {
protected static final int minHashSize = 2; protected static final int minHashSize = 2;
protected int currEntry = -1; protected int currEntry = -1;
@ -40,8 +39,7 @@ public class HashTable implements Cloneable{
if (size > minHashSize) { if (size > minHashSize) {
hashTable = new int[size * 2]; hashTable = new int[size * 2];
nextTable = new int[size]; nextTable = new int[size];
} } else {
else {
hashTable = null; hashTable = null;
nextTable = null; nextTable = null;
} }
@ -81,8 +79,8 @@ public class HashTable implements Cloneable{
return; return;
for (int i = 0; i < capacity(); i++) { for (int i = 0; i < capacity(); i++) {
hashTable[2*i] = 0; hashTable[2 * i] = 0;
hashTable[2*i+1] = 0; hashTable[2 * i + 1] = 0;
nextTable[i] = 0; nextTable[i] = 0;
} }
} }
@ -92,8 +90,8 @@ public class HashTable implements Cloneable{
// clear the table (don't call clear() or else the subclasses stuff will be cleared too) // clear the table (don't call clear() or else the subclasses stuff will be cleared too)
for (int i = 0; i < capacity(); i++) { for (int i = 0; i < capacity(); i++) {
hashTable[2*i] = 0; hashTable[2 * i] = 0;
hashTable[2*i+1] = 0; hashTable[2 * i + 1] = 0;
nextTable[i] = 0; nextTable[i] = 0;
} }
// Need to rehash everything // Need to rehash everything
@ -103,7 +101,6 @@ public class HashTable implements Cloneable{
} }
protected void resize(int size) { protected void resize(int size) {
if (size > minHashSize) { if (size > minHashSize) {
hashTable = new int[size * 2]; hashTable = new int[size * 2];
nextTable = new int[size]; nextTable = new int[size];

View file

@ -23,7 +23,7 @@ import java.util.List;
/** /**
* @author aniefer * @author aniefer
*/ */
public abstract class ObjectTable<T> extends HashTable implements Cloneable{ public abstract class ObjectTable<T> extends HashTable {
protected T[] keyTable; protected T[] keyTable;
@SuppressWarnings("unchecked") @SuppressWarnings("unchecked")
@ -47,14 +47,14 @@ public abstract class ObjectTable<T> extends HashTable implements Cloneable{
public List<T> toList(){ public List<T> toList(){
List<T> list = new ArrayList<T>(size()); List<T> list = new ArrayList<T>(size());
int size = size(); int size = size();
for( int i = 0; i < size; i++ ){ for (int i = 0; i < size; i++){
list.add( keyAt( i ) ); list.add(keyAt(i));
} }
return list; return list;
} }
public T keyAt(int i){ public T keyAt(int i) {
if(i<0 || i>currEntry) if (i < 0 || i > currEntry)
return null; return null;
return keyTable[i]; return keyTable[i];
@ -63,12 +63,12 @@ public abstract class ObjectTable<T> extends HashTable implements Cloneable{
@Override @Override
public void clear(){ public void clear(){
super.clear(); super.clear();
for( int i = 0; i < keyTable.length; i++ ) for (int i = 0; i < keyTable.length; i++)
keyTable[i] = null; keyTable[i] = null;
} }
@Override @Override
protected final int hash( int pos ){ protected final int hash(int pos){
return hash(keyTable[pos]); return hash(keyTable[pos]);
} }
@ -90,7 +90,7 @@ public abstract class ObjectTable<T> extends HashTable implements Cloneable{
if (pos != -1) if (pos != -1)
return pos; return pos;
if ( (currEntry + 1) >= capacity()) { if ((currEntry + 1) >= capacity()) {
resize(); resize();
} }
currEntry++; currEntry++;
@ -101,7 +101,6 @@ public abstract class ObjectTable<T> extends HashTable implements Cloneable{
protected void removeEntry(int i) { protected void removeEntry(int i) {
// Remove the entry from the keyTable, shifting everything over if necessary // Remove the entry from the keyTable, shifting everything over if necessary
int hash = hash(keyTable[i]); int hash = hash(keyTable[i]);
if (i < currEntry) if (i < currEntry)
System.arraycopy(keyTable, i + 1, keyTable, i, currEntry - i); System.arraycopy(keyTable, i + 1, keyTable, i, currEntry - i);
@ -110,11 +109,9 @@ public abstract class ObjectTable<T> extends HashTable implements Cloneable{
// Make sure you remove the value before calling super where currEntry will change // Make sure you remove the value before calling super where currEntry will change
removeEntry(i, hash); removeEntry(i, hash);
} }
protected final int lookup(Object buffer ){ protected final int lookup(Object buffer){
if (hashTable != null) { if (hashTable != null) {
int hash = hash(buffer); int hash = hash(buffer);
@ -122,18 +119,19 @@ public abstract class ObjectTable<T> extends HashTable implements Cloneable{
return -1; return -1;
int i = hashTable[hash] - 1; int i = hashTable[hash] - 1;
if (buffer.equals( keyTable[i] ) ) if (buffer.equals(keyTable[i]))
return i; return i;
// Follow the next chain // Follow the next chain
for (i = nextTable[i] - 1; i >= 0 && nextTable[i] != i + 1; i = nextTable[i] - 1) for (i = nextTable[i] - 1; i >= 0 && nextTable[i] != i + 1; i = nextTable[i] - 1) {
if ( buffer.equals( keyTable[i] )) if (buffer.equals(keyTable[i]))
return i; return i;
}
return -1; return -1;
} }
for (int i = 0; i <= currEntry; i++) { for (int i = 0; i <= currEntry; i++) {
if (buffer.equals( keyTable[i] ) ) if (buffer.equals(keyTable[i]))
return i; return i;
} }
return -1; return -1;
@ -143,16 +141,16 @@ public abstract class ObjectTable<T> extends HashTable implements Cloneable{
return lookup(key) != -1; return lookup(key) != -1;
} }
public Object [] keyArray(){ public Object[] keyArray(){
Object [] keys = new Object[ size() ]; Object[] keys = new Object[size()];
System.arraycopy( keyTable, 0, keys, 0, keys.length ); System.arraycopy(keyTable, 0, keys, 0, keys.length);
return keys; return keys;
} }
@SuppressWarnings("unchecked") @SuppressWarnings("unchecked")
public <X> X[] keyArray(Class<X> c) { public <X> X[] keyArray(Class<X> c) {
X[] keys = (X[]) Array.newInstance( c, size() ); X[] keys = (X[]) Array.newInstance(c, size());
System.arraycopy( keyTable, 0, keys, 0, keys.length ); System.arraycopy(keyTable, 0, keys, 0, keys.length);
return keys; return keys;
} }
} }