biojava/biojava · PermutationGroup.java
java logo
public static List<Integer> combine(List<Integer> permutation1, List<Integer> permutation2) {
		List<Integer> intermediate = new ArrayList<Integer>(permutation1.size());
		for (int i = 0, n = permutation1.size(); i < n; i++) {
			intermediate.add(permutation2.get(permutation1.get(i)));
		}
		return intermediate;
	}
Similar code snippets
1.
biojava/biojava · PermutationGroup.java
Match rating: 76.06% · See similar code snippets
java logo
public static int getOrder(List<Integer> permutation) {
		List<Integer> copy = new ArrayList<Integer>(permutation);
		for (int i = 0, n = permutation.size(); i < n; i++) {
			copy = combine(copy, permutation);
			if (copy.equals(permutation)) {
				return i + 1;
			}
		}
		return 0;
	}
2.
Match rating: 76.02% · See similar code snippets
java logo
@Override
  public int[] next() {
    if (numLeft == 0) {
      throw new NoSuchElementException();
    }

    if (numLeft == total) {
      numLeft--;
      return ArrayUtils.copyOf(permutation, permutation.length);
    }

    // Find largest index j with a[j] < a[j+1]
    int j = permutation.length - 2;
    while (permutation[j] > permutation[j + 1]) {
      j--;
    }

    // Find index k such that a[k] is smallest integer
    // greater than a[j] to the right of a[j]
    int k = permutation.length - 1;
    while (permutation[j] > permutation[k]) {
      k--;
    }

    // Interchange a[j] and a[k]
    int temp = permutation[k];
    permutation[k] = permutation[j];
    permutation[j] = temp;

    // Put tail end of permutation after jth position in increasing order
    int r = permutation.length - 1;
    int s = j + 1;

    while (r > s) {
      temp = permutation[s];
      permutation[s] = permutation[r];
      permutation[r] = temp;
      r--;
      s++;
    }

    numLeft--;
    return ArrayUtils.copyOf(permutation, permutation.length);
  }
3.
Match rating: 75.34% · See similar code snippets
java logo
public int test(Permutation permutation) {
        for (int i = 0; i < size; i++) {
            int x = permutation.get(base.get(i));
            Permutation h = permutations[i][x];
            if (h == null) {
                return i;
            } else {
                permutation.setTo(h.invert().multiply(permutation));
            }
        }
        return size;
    }
4.
apache/groovy · fannkuch.java
Match rating: 74.7% · See similar code snippets
java logo
private static final void next_perm(final int[] permutation, int position)
    {
        int perm0 = permutation[0];

        for (int i = 0; i < position; ++i)
            permutation[i] = permutation[i + 1];
        permutation[position] = perm0;
    }
5.
dwdyer/uncommons-maths · PermutationGenerator.java
Match rating: 74.61% · See similar code snippets
java logo
public List<T> nextPermutationAsList()
    {
        List<T> permutation = new ArrayList<T>(elements.length);
        return nextPermutationAsList(permutation);
    }
6.
biojava/biojava · RotationSolver.java
Match rating: 72.97% · See similar code snippets
java logo
private Rotation isValidPermutation(List<Integer> permutation) {
		if (permutation.size() == 0) {
			return null;
		}

		// cached value
		if (evaluatedPermutations.containsKey(permutation)) {
			return evaluatedPermutations.get(permutation);
		}

		// check if permutation is allowed
		if (! isAllowedPermutation(permutation)) {
			evaluatedPermutations.put(permutation, null);
			return null;
		}

		// check if superimposes
		Rotation rot = superimposePermutation(permutation);
		return rot;
	}
7.
cdk/cdk · Partition.java
Match rating: 72.89% · See similar code snippets
java logo
public Permutation toPermutation() {
        Permutation p = new Permutation(this.size());
        for (int i = 0; i < this.size(); i++) {
            p.set(i, this.cells.get(i).first());
        }
        return p;
    }
8.
javadev/underscore-java · U.java
Match rating: 72.68% · See similar code snippets
java logo
public List<List<T>> createPermutationWithRepetition(final int permutationLength) {
        return createPermutationWithRepetition((List<T>) value(), permutationLength);
    }
9.
Match rating: 71.99% · See similar code snippets
java logo
public List<Permutation> all() {
        final List<Permutation> permutations = new ArrayList<Permutation>();
        Backtracker counter = new Backtracker() {

            @Override
            public void applyTo(Permutation p) {
                permutations.add(p);
            }

            @Override
            public boolean isFinished() {
                return false;
            }
        };
        this.apply(counter);
        return permutations;
    }
10.
blacklocus/metrics-cloudwatch · DemuxedKey.java
Match rating: 71.8% · See similar code snippets
java logo
@Override
    public Iterator<Iterable<T>> iterator() {
        return new Iterator<Iterable<T>>() {

            int permutation = permutable ? 2 : 1;
            Iterator<Iterable<T>> nextSegmentIt = nextSegment == null ? null : nextSegment.iterator();

            @Override
            public boolean hasNext() {
                boolean isTail = nextSegmentIt == null;
                if (isTail) {
                    return permutation > 0;
                } else {
                    return permutation > 0 && nextSegmentIt != null && nextSegmentIt.hasNext();
                }
            }

            @Override
            public Iterable<T> next() {
                assert permutation > 0 && permutation <= 2;
                boolean isTail = nextSegmentIt == null;
                if (isTail) {
                    if (permutation == 2) {
                        permutation = 1;
                        return Collections.emptyList();
                    } else {
                        assert permutation == 1;
                        permutation = 0;
                        return ImmutableList.of(token);
                    }
                } else {
                    if (permutation == 2) {
                        Iterable<T> next = nextSegmentIt.next();
                        if (!nextSegmentIt.hasNext()) {
                            permutation = 1;
                            nextSegmentIt = nextSegment.iterator();
                        }
                        return next;
                    } else {
                        assert permutation == 1;
                        Iterable<T> next = Iterables.concat(ImmutableList.of(token), nextSegmentIt.next());
                        if (!nextSegmentIt.hasNext()) {
                            permutation = 0;
                            nextSegmentIt = null;
                        }
                        return next;
                    }
                }
            }

            @Override
            public void remove() {
                throw new UnsupportedOperationException("Nope.");
            }
        };
    }