Class Permute<T>

java.lang.Object
org.ddogleg.combinatorics.Permute<T>
Type Parameters:
T -

public class Permute<T> extends Object

Exhaustively computes all the permutations of a set, without recursion. Designed to be memory and speed efficient.

Example for the set "0123".

 
 0123
 0132
 0213
 0231
 0321
 0312
 1023
 1032
 1203
 1230
 1320
 1302
 2103
 2130
 2013
 2031
 2301
 2310
 3120
 3102
 3210
 3201
 3021
 3012
 
 
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    protected List<T>
     
  • Constructor Summary

    Constructors
    Constructor
    Description
    Permute(List<T> list)
    Permute the elements in the list provided
  • Method Summary

    Modifier and Type
    Method
    Description
    get(int i)
    Returns element 'i' in the current permutation
    getPermutation(@Nullable List<T> storage)
    Returns a list containing the current permutation.
    int
    Returns the total number of permutations
    static void
    main(String[] args)
     
    boolean
    This will permute the list once
    boolean
    This will undo a permutation.
    int
    Returns the size of the list being premuted

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Field Details

    • list

      protected List<T> list
  • Constructor Details

    • Permute

      public Permute(List<T> list)
      Permute the elements in the list provided
  • Method Details

    • getTotalPermutations

      public int getTotalPermutations()
      Returns the total number of permutations
    • next

      public boolean next()
      This will permute the list once
    • previous

      public boolean previous()
      This will undo a permutation.
    • size

      public int size()
      Returns the size of the list being premuted
      Returns:
      list size
    • get

      public T get(int i)
      Returns element 'i' in the current permutation
      Parameters:
      i - index
      Returns:
      element in permuted list
    • getPermutation

      public List<T> getPermutation(@Nullable @Nullable List<T> storage)
      Returns a list containing the current permutation.
      Parameters:
      storage - Optional storage. If null a new list will be declared.
      Returns:
      Current permutation
    • main

      public static void main(String[] args)