Search in sources :

Example 1 with IntIntPair

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);
    }
}
Also used : TODO(jcog.TODO) PrediTerm(nars.term.pred.PrediTerm) FasterList(jcog.list.FasterList) PeekableIntIterator(org.roaringbitmap.PeekableIntIterator) PrediTerm(nars.term.pred.PrediTerm) Term(nars.term.Term) Util(jcog.Util) NotNull(org.jetbrains.annotations.NotNull) NotNull(org.jetbrains.annotations.NotNull) RoaringBitmap(org.roaringbitmap.RoaringBitmap) IntIntPair(org.eclipse.collections.api.tuple.primitive.IntIntPair)

Example 2 with IntIntPair

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();
}
Also used : IntIterator(org.eclipse.collections.api.iterator.IntIterator) IntIntPair(org.eclipse.collections.api.tuple.primitive.IntIntPair)

Example 3 with IntIntPair

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();
}
Also used : IntIterator(org.eclipse.collections.api.iterator.IntIterator) IntIntPair(org.eclipse.collections.api.tuple.primitive.IntIntPair)

Example 4 with IntIntPair

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();
}
Also used : IntIterator(org.eclipse.collections.api.iterator.IntIterator) IntIntPair(org.eclipse.collections.api.tuple.primitive.IntIntPair)

Aggregations

IntIntPair (org.eclipse.collections.api.tuple.primitive.IntIntPair)4 IntIterator (org.eclipse.collections.api.iterator.IntIterator)3 TODO (jcog.TODO)1 Util (jcog.Util)1 FasterList (jcog.list.FasterList)1 Term (nars.term.Term)1 PrediTerm (nars.term.pred.PrediTerm)1 NotNull (org.jetbrains.annotations.NotNull)1 PeekableIntIterator (org.roaringbitmap.PeekableIntIterator)1 RoaringBitmap (org.roaringbitmap.RoaringBitmap)1