Skip to content

Instantly share code, notes, and snippets.

@xjia1
Last active December 20, 2015 20:58
Show Gist options
  • Save xjia1/6193740 to your computer and use it in GitHub Desktop.
Save xjia1/6193740 to your computer and use it in GitHub Desktop.
yield in Java
import java.util.Iterator;
import com.google.common.collect.AbstractIterator;
/*
i = 1;
j = n - 2;
while (i <= j) {
e1 = Main.exprOfSize(i);
while (e1.hasNext()) {
_e1 = e1.next();
e2 = Main.exprOfSize(j);
while (e2.hasNext()) {
yield construct(_e1, e2.next());
}
}
i++;
j--;
}
*/
public abstract class BinaryExprOfSize extends AbstractIterator<BvExpr> {
private int i, j;
private Iterator<BvExpr> e1, e2;
private BvExpr _e1;
public BinaryExprOfSize(int n) {
i = 1;
j = n - 2;
e1 = Main.exprOfSize(i);
_e1 = e1.next();
e2 = Main.exprOfSize(j);
}
protected abstract BvExpr construct(BvExpr e1, BvExpr e2);
@Override
protected BvExpr computeNext() {
loop_e2: while (true) {
if (e2.hasNext()) {
return construct(_e1, e2.next());
}
loop_e1: while (true) {
if (e1.hasNext()) {
_e1 = e1.next();
e2 = Main.exprOfSize(j);
continue loop_e2;
}
i++;
j--;
if (i <= j) {
e1 = Main.exprOfSize(i);
continue loop_e1;
}
return endOfData();
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment