projects
/
sbp.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
fix major bug: create YieldSet2 which does not consider needs/hates
[sbp.git]
/
src
/
edu
/
berkeley
/
sbp
/
Sequence.java
diff --git
a/src/edu/berkeley/sbp/Sequence.java
b/src/edu/berkeley/sbp/Sequence.java
index
84a2dc6
..
d3d8d8a
100644
(file)
--- a/
src/edu/berkeley/sbp/Sequence.java
+++ b/
src/edu/berkeley/sbp/Sequence.java
@@
-1,3
+1,5
@@
+// Copyright 2006 all rights reserved; see LICENSE file for BSD-style license
+
package edu.berkeley.sbp;
import edu.berkeley.sbp.util.*;
import edu.berkeley.sbp.*;
package edu.berkeley.sbp;
import edu.berkeley.sbp.util.*;
import edu.berkeley.sbp.*;
@@
-12,6
+14,8
@@
public abstract class Sequence implements Iterable<Element>, SequenceOrElement {
protected final Element[] elements;
protected final Element[] elements;
+ public boolean needed_or_hated = false;
+
final HashSet<Sequence> hated = new HashSet<Sequence>();
final HashSet<Sequence> needs = new HashSet<Sequence>();
final HashSet<Sequence> hated = new HashSet<Sequence>();
final HashSet<Sequence> needs = new HashSet<Sequence>();
@@
-63,14
+67,20
@@
public abstract class Sequence implements Iterable<Element>, SequenceOrElement {
////////////////////////////////////////////////////////////////////////////////
/** return a new sequence identical to this one, but with a positive conjunct <tt>s</tt> */
////////////////////////////////////////////////////////////////////////////////
/** return a new sequence identical to this one, but with a positive conjunct <tt>s</tt> */
- public Sequence and(Sequence s) { Sequence ret = dup(); ret.needs.add(s); return ret; }
+ public Sequence and(Sequence s) { Sequence ret = dup(); ret.needs.add(s); s.needed_or_hated=true; return ret; }
/** return a new sequence identical to this one, but with a negative conjunct <tt>s</tt> */
/** return a new sequence identical to this one, but with a negative conjunct <tt>s</tt> */
- public Sequence andnot(Sequence s) { Sequence ret = dup(); ret.hates.add(s); s.hated.add(ret); return ret; }
+ public Sequence andnot(Sequence s) { Sequence ret = dup(); ret.hates.add(s); s.hated.add(ret); s.needed_or_hated=true; return ret; }
/** return a new sequence identical to this one, but with a follow-set restricted to <tt>a</tt> */
public Sequence followedBy(Atom a) { Sequence ret = dup(); ret.follow = a; return ret; }
/** return a new sequence identical to this one, but with a follow-set restricted to <tt>a</tt> */
public Sequence followedBy(Atom a) { Sequence ret = dup(); ret.follow = a; return ret; }
+ boolean hatesAny(Iterable<Sequence> it) {
+ if (hates.isEmpty()) return false;
+ for(Sequence s : it) if (hates.contains(s)) return true;
+ return false;
+ }
+
Iterable<Sequence> needs() { return needs; }
Iterable<Sequence> hates() { return hates; }
Iterable<Sequence> needs() { return needs; }
Iterable<Sequence> hates() { return hates; }