<commit_before>package org.clafer.choco.constraint.propagator;

import gnu.trove.set.TIntSet;
import org.chocosolver.solver.ICause;
import org.chocosolver.solver.exception.ContradictionException;
import org.chocosolver.solver.variables.IntVar;
import org.chocosolver.solver.variables.SetVar;
import org.chocosolver.solver.variables.delta.IIntDeltaMonitor;
import org.chocosolver.solver.variables.delta.ISetDeltaMonitor;
import org.chocosolver.util.objects.setDataStructures.ISet;
import org.chocosolver.util.objects.setDataStructures.ISetIterator;

/**
 * Various static utility functions for writing Choco propagators.
 *
 * @author jimmy
 */
public class PropUtil {

    private PropUtil() {
    }

    /**
     * Monitor the deltas for all the variables.
     *
     * @param vars the variables
     * @param propagator the propagator
     * @return the variables delta monitors
     */
    public static IIntDeltaMonitor[] monitorDeltas(IntVar[] vars, ICause propagator) {
        IIntDeltaMonitor[] deltas = new IIntDeltaMonitor[vars.length];
        for (int i = 0; i < vars.length; i++) {
            deltas[i] = vars[i].monitorDelta(propagator);
        }
        return deltas;
    }

    /**
     * Monitor the deltas for all the variables.
     *
     * @param vars the variables
     * @param propagator the propagator
     * @return the variables delta monitors
     */
    public static ISetDeltaMonitor[] monitorDeltas(SetVar[] vars, ICause propagator) {
        ISetDeltaMonitor[] deltas = new ISetDeltaMonitor[vars.length];
        for (int i = 0; i < vars.length; i++) {
            deltas[i] = vars[i].monitorDelta(propagator);
        }
        return deltas;
    }

    public static boolean equals(ISet a, ISet b) {
        if (a.size() != b.size()) {
            return false;
        }
        ISetIterator aIter = a.iterator();
        ISetIterator bIter = b.iterator();
        while (aIter.hasNext()) {
            assert bIter.hasNext();
            if (aIter.nextInt() != bIter.nextInt()) {
                return false;
            }
        }
        assert !bIter.hasNext();
        return true;
    }

    /**
     * Enumerate the domain of a integer variable.
     *
     * @param ivar the integer variable
     * @return {@code dom(int)}
     */
    public static int[] iterateDom(IntVar ivar) {
        int[] iterate = new int[ivar.getDomainSize()];
        int count = 0;
        int ub = ivar.getUB();
        for (int i = ivar.getLB(); i <= ub; i = ivar.nextValue(i)) {
            iterate[count++] = i;
        }
        assert count == iterate.length;
        return iterate;
    }

    /**
     * Enumerate the envelope of a set variable.
     *
     * @param set the set variable
     * @return {@code env(set)}
     */
    public static int[] iterateEnv(SetVar set) {
        int[] iterate = new int[set.getUB().size()];
        int count = 0;
        ISetIterator iter = set.getUB().iterator();
        while (iter.hasNext()) {
            iterate[count++] = iter.nextInt();
        }
        assert count == iterate.length;
        return iterate;
    }

    /**
     * Enumerate the kernel of a set variable.
     *
     * @param set the set variable
     * @return {@code ker(set)}
     */
    public static int[] iterateKer(SetVar set) {
        int[] iterate = new int[set.getLB().size()];
        int count = 0;
        ISetIterator iter = set.getLB().iterator();
        while (iter.hasNext()) {
            iterate[count++] = iter.nextInt();
        }
        assert count == iterate.length;
        return iterate;
    }

    public static int getEnv(SetVar set, int index) {
        ISetIterator iter = set.getUB().iterator();
        for (int i = 0; i < index && iter.hasNext(); i++) {
            iter.nextInt();
        }
        if (iter.hasNext()) {
            return iter.nextInt();
        }
        throw new IllegalArgumentException();
    }

    /**
     * Checks if at least one of the integer's domain contains a value.
     *
     * @param union the integers
     * @param value the value
     * @return {@code true} if {@code value ∈ dom(union[i]) for some i},
     * {@code false} otherwise
     */
    public static boolean domsContain(IntVar[] union, int value) {
        for (IntVar var : union) {
            if (var.contains(value)) {
                return true;
            }
        }
        return false;<commit_msg>Add message to exception in getEnv.<commit_after>package org.clafer.choco.constraint.propagator;

import gnu.trove.set.TIntSet;
import org.chocosolver.solver.ICause;
import org.chocosolver.solver.exception.ContradictionException;
import org.chocosolver.solver.variables.IntVar;
import org.chocosolver.solver.variables.SetVar;
import org.chocosolver.solver.variables.delta.IIntDeltaMonitor;
import org.chocosolver.solver.variables.delta.ISetDeltaMonitor;
import org.chocosolver.util.objects.setDataStructures.ISet;
import org.chocosolver.util.objects.setDataStructures.ISetIterator;

/**
 * Various static utility functions for writing Choco propagators.
 *
 * @author jimmy
 */
public class PropUtil {

    private PropUtil() {
    }

    /**
     * Monitor the deltas for all the variables.
     *
     * @param vars the variables
     * @param propagator the propagator
     * @return the variables delta monitors
     */
    public static IIntDeltaMonitor[] monitorDeltas(IntVar[] vars, ICause propagator) {
        IIntDeltaMonitor[] deltas = new IIntDeltaMonitor[vars.length];
        for (int i = 0; i < vars.length; i++) {
            deltas[i] = vars[i].monitorDelta(propagator);
        }
        return deltas;
    }

    /**
     * Monitor the deltas for all the variables.
     *
     * @param vars the variables
     * @param propagator the propagator
     * @return the variables delta monitors
     */
    public static ISetDeltaMonitor[] monitorDeltas(SetVar[] vars, ICause propagator) {
        ISetDeltaMonitor[] deltas = new ISetDeltaMonitor[vars.length];
        for (int i = 0; i < vars.length; i++) {
            deltas[i] = vars[i].monitorDelta(propagator);
        }
        return deltas;
    }

    public static boolean equals(ISet a, ISet b) {
        if (a.size() != b.size()) {
            return false;
        }
        ISetIterator aIter = a.iterator();
        ISetIterator bIter = b.iterator();
        while (aIter.hasNext()) {
            assert bIter.hasNext();
            if (aIter.nextInt() != bIter.nextInt()) {
                return false;
            }
        }
        assert !bIter.hasNext();
        return true;
    }

    /**
     * Enumerate the domain of a integer variable.
     *
     * @param ivar the integer variable
     * @return {@code dom(int)}
     */
    public static int[] iterateDom(IntVar ivar) {
        int[] iterate = new int[ivar.getDomainSize()];
        int count = 0;
        int ub = ivar.getUB();
        for (int i = ivar.getLB(); i <= ub; i = ivar.nextValue(i)) {
            iterate[count++] = i;
        }
        assert count == iterate.length;
        return iterate;
    }

    /**
     * Enumerate the envelope of a set variable.
     *
     * @param set the set variable
     * @return {@code env(set)}
     */
    public static int[] iterateEnv(SetVar set) {
        int[] iterate = new int[set.getUB().size()];
        int count = 0;
        ISetIterator iter = set.getUB().iterator();
        while (iter.hasNext()) {
            iterate[count++] = iter.nextInt();
        }
        assert count == iterate.length;
        return iterate;
    }

    /**
     * Enumerate the kernel of a set variable.
     *
     * @param set the set variable
     * @return {@code ker(set)}
     */
    public static int[] iterateKer(SetVar set) {
        int[] iterate = new int[set.getLB().size()];
        int count = 0;
        ISetIterator iter = set.getLB().iterator();
        while (iter.hasNext()) {
            iterate[count++] = iter.nextInt();
        }
        assert count == iterate.length;
        return iterate;
    }

    public static int getEnv(SetVar set, int index) {
        ISetIterator iter = set.getUB().iterator();
        for (int i = 0; i < index && iter.hasNext(); i++) {
            iter.nextInt();
        }
        if (iter.hasNext()) {
            return iter.nextInt();
        }
        throw new IllegalArgumentException("Cannot retrieve element " + index + " in " + set);
    }

    /**
     * Checks if at least one of the integer's domain contains a value.
     *
     * @param union the integers
     * @param value the value
     * @return {@code true} if {@code value ∈ dom(union[i]) for some i},
     * {@code false} otherwise
     */
    public static boolean domsContain(IntVar[] union, int value) {
        for (IntVar var : union) {
            if (var.contains(value)) {
                return true;
            }
        }
        return false;
{'fraction_non_alphanumeric': 0.11934574168076706, 'fraction_numerical': 0.0013536379018612521, 'mean_word_length': 2.128440366972477, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5396265', 'n_tokens_mistral': 2706, 'n_tokens_neox': 2600, 'n_words': 709}