use of org.eclipse.collections.api.tuple.primitive.IntIntPair in project narchy by automenta.
the class MatchConstraint method combineConstraints.
public static PrediTerm<Derivation> combineConstraints(AndCondition a) {
RoaringBitmap constraints = new RoaringBitmap();
@NotNull PrediTerm[] cond1 = a.cond;
for (int i = 0, cl = cond1.length; i < cl; i++) {
Term x = cond1[i];
if (x instanceof MatchConstraint) {
constraints.add(i);
}
}
if (constraints.getCardinality() < 2) {
return a;
} else {
// identify contiguous runs of constraints
// inclusive
List<IntIntPair> ranges = new FasterList<>(1);
int start = -1, end = -1;
PeekableIntIterator ii = constraints.getIntIterator();
while (ii.hasNext()) {
int next = ii.next();
if (start == -1) {
start = end = next;
} else {
if (next == end + 1) {
end++;
} else {
if (end - start >= 1) {
// compile that range
ranges.add(pair(start, end));
}
// broken
start = -1;
}
}
}
if (end - start >= 1)
ranges.add(pair(start, end));
if (ranges.size() > 1)
throw new TODO();
IntIntPair rr = ranges.get(0);
List<PrediTerm<Derivation>> l = new FasterList();
int i;
for (i = 0; i < start; i++) {
l.add(a.cond[i]);
}
CompoundConstraint.the(Util.map(MatchConstraint.class::cast, MatchConstraint[]::new, ArrayUtils.subarray(a.cond, rr.getOne(), rr.getTwo() + 1))).forEach(l::add);
i = end + 1;
for (; i < a.cond.length; i++) {
l.add(a.cond[i]);
}
return AndCondition.the((List) l);
}
}
use of org.eclipse.collections.api.tuple.primitive.IntIntPair in project eclipse-collections by eclipse.
the class CodePointAdapter method zipInt.
/**
* @since 9.1.
*/
@Override
public ImmutableList<IntIntPair> zipInt(IntIterable iterable) {
int size = this.size();
int othersize = iterable.size();
MutableList<IntIntPair> target = Lists.mutable.withInitialCapacity(Math.min(size, othersize));
IntIterator iterator = iterable.intIterator();
for (int i = 0; i < size && i < othersize; i++) {
target.add(PrimitiveTuples.pair(this.get(i), iterator.next()));
}
return target.toImmutable();
}
use of org.eclipse.collections.api.tuple.primitive.IntIntPair in project eclipse-collections by eclipse.
the class CodePointList method zipInt.
/**
* @since 9.1.
*/
@Override
public ImmutableList<IntIntPair> zipInt(IntIterable iterable) {
int size = this.size();
int othersize = iterable.size();
MutableList<IntIntPair> target = Lists.mutable.withInitialCapacity(Math.min(size, othersize));
IntIterator iterator = iterable.intIterator();
for (int i = 0; i < size && i < othersize; i++) {
target.add(PrimitiveTuples.pair(this.get(i), iterator.next()));
}
return target.toImmutable();
}
use of org.eclipse.collections.api.tuple.primitive.IntIntPair in project eclipse-collections by eclipse.
the class IntInterval method zipInt.
@Override
public ImmutableList<IntIntPair> zipInt(IntIterable iterable) {
int size = this.size();
int othersize = iterable.size();
MutableList<IntIntPair> target = Lists.mutable.withInitialCapacity(Math.min(size, othersize));
IntIterator iterator = this.intIterator();
IntIterator otherIterator = iterable.intIterator();
for (int i = 0; i < size && otherIterator.hasNext(); i++) {
target.add(PrimitiveTuples.pair(iterator.next(), otherIterator.next()));
}
return target.toImmutable();
}
Aggregations