org.incava.diff.LCSTable Maven / Gradle / Ivy
package org.incava.diff;
import java.util.Map;
import java.util.HashMap;
import java.util.TreeMap;
/**
* The links as used in the Diff/LCS code.
*/
public class LCSTable {
private final Map links;
public LCSTable() {
links = new HashMap();
}
/**
* Updates the value for the key k
.
*/
public void update(Integer i, Integer j, Integer k) {
Object value = k > 0 ? links.get(k - 1) : null;
links.put(k, new Object[] { value, i, j });
}
/**
* Returns the links starting from key
.
*/
public Map getChain(Integer key) {
Map chain = new HashMap();
Object[] link = links.get(key);
while (link != null) {
Integer x = (Integer)link[1];
Integer y = (Integer)link[2];
chain.put(x, y);
link = (Object[])link[0];
}
return chain;
}
}