<commit_before>/* This Source Code Form is subject to the terms of the Mozilla Public
 * License, v. 2.0. If a copy of the MPL was not distributed with this
 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */

package etomica.graph.iterators;

import java.util.NoSuchElementException;

import etomica.graph.model.Permutator;

/*
 * Consider the partition P of a given set S of objects, where each partition
 * Pi consists of |Pi| distinct objects of the same type. The total number of
 * elements in S is the sum of |Pi| for all i.
 *
 * This iterator produces all distinct permutations of these |S| objects, where
 * objects in each partition Pi are treated as equivalents. There are exactly
 *
 *   choose(|S|,|P1|) x choose(|S|-|P1|,|P2|) x ... x choose(|Pn|,|Pn|)
 *
 * permutations in the resulting set of objects.
 *
 * The constructor takes as input int[] psizes. We assume that i = Type(Pi) and
 * that psizes[i] = |Pi|. This means that we map each partition Pi to an integer
 * i and that we assume that the size of the partitions are given by psizes. The
 * iterator produces a vector consisting of |Pi| entries with value i. The client
 * code can map these integer values to any types of objects needed. Note that the
 * sum of sizes of the partitions must fit in a byte.
 *
 * @author <NAME>
 */
public class DefaultPermutator implements Permutator {

  private int size = 0;
  private int[][] groups;
  private int activeGroup = -1;
  private int curPermutation = 0;
  private long maxPermutations = 1;
  private int[] groupSizes;

  public DefaultPermutator(int[] psizes) {

    assert (groupSizes != null);
    /**
     * Copy the partition sizes array into a local array to protect the iterator
     * from external changes to this array.
     */
    groupSizes = new int[psizes.length];
    System.arraycopy(psizes, 0, groupSizes, 0, psizes.length);
    /**
     * Compute the total size of the permutations we will generate.<commit_msg>Remove impossible assert in DefaultPermutor constructor<commit_after>/* This Source Code Form is subject to the terms of the Mozilla Public
 * License, v. 2.0. If a copy of the MPL was not distributed with this
 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */

package etomica.graph.iterators;

import java.util.NoSuchElementException;

import etomica.graph.model.Permutator;

/*
 * Consider the partition P of a given set S of objects, where each partition
 * Pi consists of |Pi| distinct objects of the same type. The total number of
 * elements in S is the sum of |Pi| for all i.
 *
 * This iterator produces all distinct permutations of these |S| objects, where
 * objects in each partition Pi are treated as equivalents. There are exactly
 *
 *   choose(|S|,|P1|) x choose(|S|-|P1|,|P2|) x ... x choose(|Pn|,|Pn|)
 *
 * permutations in the resulting set of objects.
 *
 * The constructor takes as input int[] psizes. We assume that i = Type(Pi) and
 * that psizes[i] = |Pi|. This means that we map each partition Pi to an integer
 * i and that we assume that the size of the partitions are given by psizes. The
 * iterator produces a vector consisting of |Pi| entries with value i. The client
 * code can map these integer values to any types of objects needed. Note that the
 * sum of sizes of the partitions must fit in a byte.
 *
 * @author <NAME>
 */
public class DefaultPermutator implements Permutator {

  private int size = 0;
  private int[][] groups;
  private int activeGroup = -1;
  private int curPermutation = 0;
  private long maxPermutations = 1;
  private int[] groupSizes;

  public DefaultPermutator(int[] psizes) {

    /**
     * Copy the partition sizes array into a local array to protect the iterator
     * from external changes to this array.
     */
    groupSizes = new int[psizes.length];
    System.arraycopy(psizes, 0, groupSizes, 0, psizes.length);
    /**
     * Compute the total size of the permutations we will generate.
{'fraction_non_alphanumeric': 0.08551129155036792, 'fraction_numerical': 0.0065973103273280894, 'mean_word_length': 3.489749430523918, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, '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': '2145772', 'n_tokens_mistral': 1151, 'n_tokens_neox': 1106, 'n_words': 541}