Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix #159 - Use LinkedHashSet to store sets #161

Open
wants to merge 23 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 22 commits
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
bbcd122
fix issue #159, also modified BoaJava.stg, passed all tests
CheShianHung Oct 11, 2017
970890b
Fixes #159 type updated
CheShianHung Oct 12, 2017
b3f0fb4
Fixed #159, change types to general set as much as possible
CheShianHung Oct 12, 2017
207cdc8
fix issue #159, change most LinkedHashSet to Set, change codegen
CheShianHung Jan 19, 2018
b263206
fix issue #159, toInterdaceJavaType and toParameterJavaType methods a…
CheShianHung Jan 22, 2018
081e731
fix #159, simplify setType and stackType in codegen
CheShianHung Jan 22, 2018
668fe6b
Merge branch 'master' of github.com:boalang/compiler into issue159
psybers Jan 22, 2018
1316b9e
fix #159, inhattr stack type added
CheShianHung Jan 22, 2018
1a582b6
fix #159, Map field type fixed
CheShianHung Jan 22, 2018
7521adb
fix #159, spacing and template fixed
CheShianHung Jan 22, 2018
6ecdbe6
merge master
psybers Aug 13, 2019
e3b1449
remove unneeded type templates
psybers Aug 13, 2019
af992b8
convert more HashSet to LinkedHashSet
psybers Aug 13, 2019
e6ec701
fix test errors and simplify some code
psybers Aug 15, 2019
683c817
code cleanup
psybers Aug 15, 2019
bf3e47e
Merge branch 'master' into issue159
psybers Aug 31, 2019
1c8a28a
Merge branch 'master' into issue159
psybers Sep 1, 2023
9961c74
fix bad merge that lost types2
psybers Sep 3, 2023
b73f2d8
fix compile error with template
psybers Sep 3, 2023
a240174
fix boxing issue with arrays
psybers Sep 3, 2023
6a2ccf9
make sure set aggregator sorts output
psybers Sep 3, 2023
e63b9b3
the set aggregator does not need to be a linked set, since we sort it
psybers Sep 3, 2023
cfe85ab
Merge branch 'master' into issue159
psybers Sep 5, 2023
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
2 changes: 1 addition & 1 deletion src/java/boa/aggregators/GraphAggregator.java
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ public abstract class GraphAggregator extends Aggregator {
public void start(final EmitKey key) {
super.start(key);

this.neighbors = new HashSet<String>();
this.neighbors = new LinkedHashSet<String>();
this.weights = new HashMap<String, String>();
}

Expand Down
18 changes: 9 additions & 9 deletions src/java/boa/aggregators/PreconditionAggregator.java
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
import java.util.Collections;
import java.util.Comparator;
import java.util.HashMap;
import java.util.HashSet;
import java.util.LinkedHashSet;
import java.util.List;
import java.util.Map;
import java.util.Set;
Expand All @@ -43,7 +43,7 @@ public class PreconditionAggregator extends Aggregator {
private final double sigma;
private int args = 0;

private final Set<Expression> preconds = new HashSet<Expression>();
private final Set<Expression> preconds = new LinkedHashSet<Expression>();
private final Map<Expression, Set<String>> omega = new HashMap<Expression, Set<String>>(); // preconditions: set of methods

/**
Expand Down Expand Up @@ -79,7 +79,7 @@ public void aggregate(final String data, final String metadata) throws IOExcepti
final Expression precondition = parseexpression(precond);

if (!omega.containsKey(precondition)) {
omega.put(precondition, new HashSet<String>());
omega.put(precondition, new LinkedHashSet<String>());
preconds.add(precondition);
}

Expand All @@ -106,7 +106,7 @@ public void finish() throws IOException, InterruptedException {
* @return map of all preconditions which include inferred preconditions
*/
private void inferNonStrictInequalities() {
final Set<Expression> added = new HashSet<Expression>();
final Set<Expression> added = new LinkedHashSet<Expression>();

for (final Expression p : preconds) {
if (p.getKind() == ExpressionKind.EQ) {
Expand All @@ -123,7 +123,7 @@ private void inferNonStrictInequalities() {
final Expression t = builder.build();

if (!preconds.contains(t)) {
omega.put(t, new HashSet<String>());
omega.put(t, new LinkedHashSet<String>());
added.add(t);
}

Expand Down Expand Up @@ -186,7 +186,7 @@ private Map<String, Double> doFiltering() {
// generate psi from omega
final Map<Expression, Set<String>> psi = new HashMap<Expression, Set<String>>();
for (final Expression e : preconds) {
psi.put(e, new HashSet<String>());
psi.put(e, new LinkedHashSet<String>());

for (final String s : omega.get(e)) {
psi.get(e).add(s.split(":", 2)[0]);
Expand All @@ -213,7 +213,7 @@ private Map<String, Double> doFiltering() {
private Map<Expression, Double> calcConfidence(final Map<Expression, Set<String>> precondMP) {
final Map<Expression, Double> precondConf = new HashMap<Expression, Double>();

final Set<String> totalCalls = new HashSet<String>();
final Set<String> totalCalls = new LinkedHashSet<String>();
for (final Expression precond : preconds)
totalCalls.addAll(precondMP.get(precond));

Expand Down Expand Up @@ -267,7 +267,7 @@ private List<Map.Entry<String, Double>> doRanking(final Map<String, Double> filt
* @return set of all combinations of arguments
*/
private Set<SortedSet<String>> generateCombinations() {
final Set<SortedSet<String>> comb = new HashSet<SortedSet<String>>();
final Set<SortedSet<String>> comb = new LinkedHashSet<SortedSet<String>>();
final List<String> argList = new ArrayList<String>();
comb.add(new TreeSet<String>(Collections.singletonList("$RECEIVER$")));
argList.add("$RECEIVER$");
Expand All @@ -278,7 +278,7 @@ private Set<SortedSet<String>> generateCombinations() {
}

for (final String arg : argList) {
final Set<SortedSet<String>> tempComb = new HashSet<SortedSet<String>>(comb);
final Set<SortedSet<String>> tempComb = new LinkedHashSet<SortedSet<String>>(comb);
for (final SortedSet<String> s : tempComb) {
final SortedSet<String> t = new TreeSet<String>(s);
t.add(arg);
Expand Down
10 changes: 8 additions & 2 deletions src/java/boa/aggregators/SetAggregator.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,11 @@
package boa.aggregators;

import java.io.IOException;
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashSet;
import java.util.List;
import java.util.Set;

import boa.io.EmitKey;

Expand All @@ -28,7 +32,7 @@
*/
@AggregatorSpec(name = "set", canCombine = true)
public class SetAggregator extends Aggregator {
private HashSet<String> set;
private Set<String> set;
private final long max;

/**
Expand Down Expand Up @@ -75,7 +79,9 @@ public void aggregate(final String data, final String metadata) throws IOExcepti
/** {@inheritDoc} */
@Override
public void finish() throws IOException, InterruptedException {
for (final String s : this.set)
final List<String> list = new ArrayList<String>(this.set);
Collections.sort(list);
for (final String s : list)
this.collect(s);
}
}
13 changes: 11 additions & 2 deletions src/java/boa/compiler/SymbolTable.java
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ public class SymbolTable {
private Operand operand;
private Stack<BoaType> operandType = new Stack<BoaType>();
private boolean needsBoxing;
private boolean needsCast;
private Stack<Boolean> isVisitor = new Stack<Boolean>();
private Stack<VisitStatement> lastVisit = new Stack<VisitStatement>();
private boolean isTraverse = false;
Expand Down Expand Up @@ -207,7 +208,7 @@ public class SymbolTable {

// clone functions
globalFunctions.addFunction("clone", new BoaFunction(new BoaMap(new BoaTypeVar("K"), new BoaTypeVar("V")), new BoaType[] {new BoaMap(new BoaTypeVar("K"), new BoaTypeVar("V"))}, "(java.util.HashMap)${0}.clone()"));
globalFunctions.addFunction("clone", new BoaFunction(new BoaSet(new BoaTypeVar("V")), new BoaType[] {new BoaSet(new BoaTypeVar("V"))}, "(java.util.HashSet)${0}.clone()"));
globalFunctions.addFunction("clone", new BoaFunction(new BoaSet(new BoaTypeVar("V")), new BoaType[] {new BoaSet(new BoaTypeVar("V"))}, "(java.util.LinkedHashSet)${0}.clone()"));
globalFunctions.addFunction("clone", new BoaFunction(new BoaString(), new BoaType[] {new BoaString()}, "new String(${0})"));

// visitors
Expand Down Expand Up @@ -250,7 +251,7 @@ public class SymbolTable {
globalFunctions.addFunction("remove", new BoaFunction(new BoaAny(), new BoaType[] { new BoaSet(new BoaTypeVar("V")), new BoaTypeVar("V") }, "${0}.remove(${1})"));
globalFunctions.addFunction("clear", new BoaFunction(new BoaAny(), new BoaType[] { new BoaSet(new BoaTypeVar("V")) }, "${0}.clear()"));
globalFunctions.addFunction("values", new BoaFunction(new BoaArray(new BoaTypeVar("V")), new BoaType[] { new BoaSet(new BoaTypeVar("V")) }, "boa.functions.BoaIntrinsics.basic_array(${0}.toArray(new ${V}[0]))"));
globalFunctions.addFunction("values", new BoaFunction(new BoaArray(new BoaSet(new BoaString())), new BoaType[] { new BoaSet(new BoaSet(new BoaString())) }, "boa.functions.BoaIntrinsics.basic_array(${0}.toArray(new java.util.HashSet[0]))"));
globalFunctions.addFunction("values", new BoaFunction(new BoaArray(new BoaSet(new BoaString())), new BoaType[] { new BoaSet(new BoaSet(new BoaString())) }, "boa.functions.BoaIntrinsics.basic_array(${0}.toArray(new java.util.LinkedHashSet[0]))"));

globalFunctions.addFunction("union", new BoaFunction(new BoaSet(new BoaTypeVar("V")), new BoaType[] { new BoaSet(new BoaTypeVar("V")), new BoaSet(new BoaTypeVar("V")) }, "boa.functions.BoaIntrinsics.set_union(${0}, ${1})"));
globalFunctions.addFunction("intersect", new BoaFunction(new BoaSet(new BoaTypeVar("V")), new BoaType[] { new BoaSet(new BoaTypeVar("V")), new BoaSet(new BoaTypeVar("V")) }, "boa.functions.BoaIntrinsics.set_intersect(${0}, ${1})"));
Expand Down Expand Up @@ -701,6 +702,14 @@ public boolean getNeedsBoxing() {
return this.needsBoxing;
}

public void setNeedsCast(final boolean needsCast) {
this.needsCast = needsCast;
}

public boolean getNeedsCast() {
return this.needsCast;
}

public void setIsTraverse(final boolean isTraverse) {
this.isTraverse = isTraverse;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@

import java.util.ArrayList;
import java.util.HashMap;
import java.util.HashSet;
import java.util.LinkedHashSet;
import java.util.List;
import java.util.Map;
import java.util.Set;
Expand Down Expand Up @@ -104,7 +104,7 @@ public void visit(final VisitorExpression n) {
* mapping from each type T found to a list of all uses in current(T).
*/
private class FindCurrentInVisitors extends AbstractVisitorNoArgNoRet{
protected final Set<BoaTuple> currents = new HashSet<BoaTuple>();
protected final Set<BoaTuple> currents = new LinkedHashSet<BoaTuple>();
protected final Map<BoaTuple, List<Factor>> factorMap = new HashMap<BoaTuple, List<Factor>>();

/** @{inheritDoc} */
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
*/
package boa.compiler.transforms;

import java.util.HashSet;
import java.util.LinkedHashSet;
import java.util.Set;
import java.util.Stack;

Expand All @@ -41,8 +41,8 @@
* @author rdyer
*/
public class VisitorOptimizingTransformer extends AbstractVisitorNoArgNoRet {
protected final static Set<Class<? extends BoaType>> astTypes = new HashSet<Class<? extends BoaType>>();
protected final static Set<Class<? extends BoaType>> revTypes = new HashSet<Class<? extends BoaType>>();
protected final static Set<Class<? extends BoaType>> astTypes = new LinkedHashSet<Class<? extends BoaType>>();
protected final static Set<Class<? extends BoaType>> revTypes = new LinkedHashSet<Class<? extends BoaType>>();

static {
astTypes.addAll(new ASTRootProtoTuple().reachableTypes());
Expand Down Expand Up @@ -70,7 +70,7 @@ public class VisitorOptimizingTransformer extends AbstractVisitorNoArgNoRet {
/** {@inheritDoc} */
@Override
protected void initialize() {
types = new HashSet<Class<? extends BoaType>>();
types = new LinkedHashSet<Class<? extends BoaType>>();
beforeChangedFile = afterChangedFile = null;
beforeCodeRepository = afterCodeRepository = null;

Expand All @@ -90,15 +90,15 @@ public void visit(final VisitorExpression n) {
beforeCodeRepositoryStack.push(beforeCodeRepository);
afterCodeRepositoryStack.push(afterCodeRepository);

types = new HashSet<Class<? extends BoaType>>();
types = new LinkedHashSet<Class<? extends BoaType>>();
beforeChangedFile = afterChangedFile = null;

n.getBody().accept(this);

// if the visitor doesnt use an AST type, we can enforce
// a stop at the lowest level visited
final Set<Class<? extends BoaType>> hasAst = new HashSet<Class<? extends BoaType>>(types);
final Set<Class<? extends BoaType>> hasRevision = new HashSet<Class<? extends BoaType>>(types);
final Set<Class<? extends BoaType>> hasAst = new LinkedHashSet<Class<? extends BoaType>>(types);
final Set<Class<? extends BoaType>> hasRevision = new LinkedHashSet<Class<? extends BoaType>>(types);
hasAst.retainAll(astTypes);
hasRevision.retainAll(revTypes);
if (hasRevision.isEmpty()) {
Expand Down
Loading