mirror of
https://github.com/eclipse-cdt/cdt
synced 2025-04-29 19:45:01 +02:00
Added toString method and generics.
This commit is contained in:
parent
d64fdf7905
commit
8111176e94
2 changed files with 77 additions and 49 deletions
|
@ -150,9 +150,9 @@ public class HashTable implements Cloneable{
|
||||||
}
|
}
|
||||||
|
|
||||||
// Remove the hash entry
|
// Remove the hash entry
|
||||||
if (hashTable[hash] == i + 1)
|
if (hashTable[hash] == i + 1) {
|
||||||
hashTable[hash] = nextTable[i];
|
hashTable[hash] = nextTable[i];
|
||||||
else {
|
} else {
|
||||||
// find entry pointing to me
|
// find entry pointing to me
|
||||||
int j = hashTable[hash] - 1;
|
int j = hashTable[hash] - 1;
|
||||||
while (nextTable[j] != 0 && nextTable[j] != i + 1)
|
while (nextTable[j] != 0 && nextTable[j] != i + 1)
|
||||||
|
@ -165,27 +165,29 @@ public class HashTable implements Cloneable{
|
||||||
System.arraycopy(nextTable, i + 1, nextTable, i, currEntry - i);
|
System.arraycopy(nextTable, i + 1, nextTable, i, currEntry - i);
|
||||||
|
|
||||||
// adjust hash and next entries for things that moved
|
// adjust hash and next entries for things that moved
|
||||||
for (int j = 0; j < hashTable.length; ++j)
|
for (int j = 0; j < hashTable.length; ++j) {
|
||||||
if (hashTable[j] > i + 1)
|
if (hashTable[j] > i + 1)
|
||||||
--hashTable[j];
|
--hashTable[j];
|
||||||
|
}
|
||||||
|
|
||||||
for (int j = 0; j < nextTable.length; ++j)
|
for (int j = 0; j < nextTable.length; ++j) {
|
||||||
if (nextTable[j] > i + 1)
|
if (nextTable[j] > i + 1)
|
||||||
--nextTable[j];
|
--nextTable[j];
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// last entry is now free
|
// last entry is now free
|
||||||
nextTable[currEntry] = 0;
|
nextTable[currEntry] = 0;
|
||||||
--currEntry;
|
--currEntry;
|
||||||
}
|
}
|
||||||
|
|
||||||
final public void sort( Comparator c ) {
|
final public void sort(Comparator<Object> c) {
|
||||||
if (size() > 1) {
|
if (size() > 1) {
|
||||||
quickSort(c, 0, size() - 1);
|
quickSort(c, 0, size() - 1);
|
||||||
rehash();
|
rehash();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
final private void quickSort( Comparator c, int p, int r ){
|
final private void quickSort(Comparator<Object> c, int p, int r) {
|
||||||
if (p < r) {
|
if (p < r) {
|
||||||
int q = partition(c, p, r);
|
int q = partition(c, p, r);
|
||||||
if (p < q) quickSort(c, p, q);
|
if (p < q) quickSort(c, p, q);
|
||||||
|
@ -193,7 +195,7 @@ public class HashTable implements Cloneable{
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
protected int partition( Comparator c, int p, int r ) {
|
protected int partition(Comparator<Object> c, int p, int r) {
|
||||||
throw new UnsupportedOperationException();
|
throw new UnsupportedOperationException();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -25,7 +25,7 @@ import java.util.List;
|
||||||
public class ObjectMap extends ObjectTable {
|
public class ObjectMap extends ObjectTable {
|
||||||
public static final ObjectMap EMPTY_MAP = new ObjectMap(0) {
|
public static final ObjectMap EMPTY_MAP = new ObjectMap(0) {
|
||||||
public Object clone() { return this; }
|
public Object clone() { return this; }
|
||||||
public List toList() { return Collections.EMPTY_LIST; }
|
public List<Object> toList() { return Collections.emptyList(); }
|
||||||
public Object put(Object key, Object value) { throw new UnsupportedOperationException(); }
|
public Object put(Object key, Object value) { throw new UnsupportedOperationException(); }
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -101,16 +101,22 @@ public class ObjectMap extends ObjectTable {
|
||||||
super.removeEntry(i);
|
super.removeEntry(i);
|
||||||
}
|
}
|
||||||
|
|
||||||
protected int partition( Comparator c, int p, int r ){
|
@Override
|
||||||
|
protected int partition(Comparator<Object> c, int p, int r) {
|
||||||
Object x = keyTable[p];
|
Object x = keyTable[p];
|
||||||
Object temp = null;
|
Object temp = null;
|
||||||
int i = p;
|
int i = p;
|
||||||
int j = r;
|
int j = r;
|
||||||
|
|
||||||
while (true) {
|
while (true) {
|
||||||
while( c.compare( keyTable[ j ], x ) > 0 ){ j--; }
|
while (c.compare(keyTable[j], x) > 0) {
|
||||||
if( i < j )
|
j--;
|
||||||
while( c.compare( keyTable[ i ], x ) < 0 ){ i++; }
|
}
|
||||||
|
if (i < j) {
|
||||||
|
while (c.compare(keyTable[i], x) < 0) {
|
||||||
|
i++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if (i < j) {
|
if (i < j) {
|
||||||
temp = keyTable[j];
|
temp = keyTable[j];
|
||||||
|
@ -131,4 +137,24 @@ public class ObjectMap extends ObjectTable {
|
||||||
System.arraycopy(valueTable, 0, vals, 0, vals.length);
|
System.arraycopy(valueTable, 0, vals, 0, vals.length);
|
||||||
return vals;
|
return vals;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public String toString() {
|
||||||
|
StringBuilder sb = new StringBuilder();
|
||||||
|
for (int i = 0; i < size(); i++) {
|
||||||
|
Object key = keyAt(i);
|
||||||
|
if (key != null) {
|
||||||
|
if (sb.length() == 0) {
|
||||||
|
sb.append("{");
|
||||||
|
} else {
|
||||||
|
sb.append(", ");
|
||||||
|
}
|
||||||
|
Object value = valueTable[i];
|
||||||
|
sb.append(String.valueOf(key));
|
||||||
|
sb.append(": ");
|
||||||
|
sb.append(String.valueOf(value));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
sb.append("}");
|
||||||
|
return sb.toString();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue