-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPoolTable.java
More file actions
28 lines (24 loc) · 915 Bytes
/
Copy pathPoolTable.java
File metadata and controls
28 lines (24 loc) · 915 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
import java.util.HashMap;
class PoolTable {
// id (serial number) mapped to PoolTableEntry
public HashMap<Integer, PoolTableEntry> table = new HashMap<>();
@Override
public String toString() {
StringBuilder buffer = new StringBuilder();
buffer.append("Pool Table:\n");
buffer.append(String.format("%-4s %-8s %-11s\n", "ID", "Lit. ID", "Pool Length"));
for (int key : table.keySet()) {
PoolTableEntry entry = table.get(key);
buffer.append(String.format("%-4d %-8d %-11d\n", key, entry.literalId, entry.poolLength));
}
return buffer.toString();
}
}
class PoolTableEntry {
int literalId; // literal id in the literal table
int poolLength; // number of literals in the pool
public PoolTableEntry(int literalId, int poolLength) {
this.literalId = literalId;
this.poolLength = poolLength;
}
}