Skip to content

Instantly share code, notes, and snippets.

@ice1000
Created May 8, 2021 10:05
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ice1000/d3e1d13a48949d62d914504c402617f3 to your computer and use it in GitHub Desktop.
Save ice1000/d3e1d13a48949d62d914504c402617f3 to your computer and use it in GitHub Desktop.
Random graph theory problem
import java.util.List;
import java.util.Map;
public class Main {
interface Level {
// Pattern matcher
interface Visitor<P, R> {
R visitConst(Const c, P p);
R visitInfinity(P p);
R visitRef(Reference r, P p);
}
<P, R> R accept(Visitor<P, R> visitor, P p);
}
record Const(int constant) implements Level {
@Override public <P, R> R accept(Visitor<P, R> visitor, P p) {
return visitor.visitConst(this, p);
}
}
record Infinity() implements Level {
@Override public <P, R> R accept(Visitor<P, R> visitor, P p) {
return visitor.visitInfinity(p);
}
}
record Reference(Var ref, int lift) implements Level {
@Override public <P, R> R accept(Visitor<P, R> visitor, P p) {
return visitor.visitRef(this, p);
}
}
// free means need to be 'solved'
record Var(boolean canBeInf, int defaultValue, boolean free) {
}
record Max(List<Level> levels) {
}
enum Ord {
// <=, >=, ==
Lt, Gt, Eq
}
record Equation(Ord ord, Max lhs, Max rhs) {
}
// in the returned map, all keys are 'free', and the Var in the values' are not 'free'
static Map<Var, Level> solve(List<Equation> equations) {
// implement
throw new UnsupportedOperationException();
}
public static void main(String... args) {
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment