Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 7 additions & 4 deletions src/main/java/edu/graal/graphs/types/VertexSubtype.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,9 @@
public enum VertexSubtype implements IVertexSubtype {
LT, GT, LEQ, GEQ, EQ, INEQ, MOD, AND, OR, INCR, DECR, SH_PLUS, SH_MINUS, PRINT, CALL, ADD, SUB, MUL, COMP, LOGICAL;

private static HashMap<Tuple2, Double> penaltyMap = penalty();
private static HashMap<Tuple2, Double> penalty() {
java.util.Map<Tuple2, Double> map = new java.util.HashMap<>();
private static HashMap<Tuple2<? extends IVertexSubtype, ? extends IVertexSubtype>, Double> penaltyMap = penalty();
private static HashMap<Tuple2<? extends IVertexSubtype, ? extends IVertexSubtype>, Double> penalty() {
java.util.Map<Tuple2<? extends IVertexSubtype, ? extends IVertexSubtype>, Double> map = new java.util.HashMap<>();

map.put(Tuple.of(LT, GT), 0.5);
map.put(Tuple.of(LT, LEQ), 0.25);
Expand Down Expand Up @@ -77,7 +77,7 @@ private static HashMap<Tuple2, Double> penalty() {
return HashMap.ofAll(map);
}

public static Double getPenalty(Tuple2 vertexSubtypeTuple) {
public static Double getPenalty(Tuple2<? extends IVertexSubtype, ? extends IVertexSubtype> vertexSubtypeTuple) {
Option<Double> penalty = penaltyMap.get(vertexSubtypeTuple);
if(penalty.isDefined()) {
return penalty.get();
Expand All @@ -87,4 +87,7 @@ public static Double getPenalty(Tuple2 vertexSubtypeTuple) {
}
}

public static void addPenalty(IVertexSubtype v1, IVertexSubtype v2, double value) {
penaltyMap.put(Tuple.of(v1, v2), value);

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@magyargergo Javaslang HashMap is immutable by nature. This will create new instance of penaltyMap everytime addPenalty is called.
if you think this method adds value in future, consider changing penaltyMap type to java.util.HashMap

}
}