Path Compression Code
ID find(Object x) {
assert(hTable.contains(x));
ID xID = hTable[x];
ID hold = xID;
while(up[xID] != -1) {
xID = up[xID];
}
while(up[hold] != -1) {
temp = up[hold];
up[hold] = xID;
hold = temp;
}
return xID;
}
typedef ID int;
runtime:
Previous slide
Next slide
Back to first slide
View graphic version