<commit_before>Permutations
============

A super-simple Java class that calculates all permutations for a given set, list, or array. It returns an Iterator of all of the permutations, allowing the class to be used in a for loop.

Permutations are calculated on-demand, as the iteration is traversed. This allows the memory requirements to be constant (or O(N)) and the execution time to be linear (or O(N)), and certainly usable even for relatively large input sets.

Taken from my Shipping Packer project, which is hosted on Bitbucket.

Performance
-----------

Performance (on my modest machine):

	4-item set: Calculates the 24 permutations (or 4!) in 1 millisecond
	10-item set: Calculates the 3,628,800 permutations (or 10!) in ~3.5 seconds
	25-item set: Calculates the first 3,628,800 permutations in ~10.5 seconds (out of 15,511,210,043,330,985,984,000,000 possible permutations)


Example usage
-------------


    set.add("apple");
    set.add("banana");
    set.add("canteloupe");

    Permutations<String> permutations = new Permutations<String>( set );
    for ( List<String> permutation : permutations ) { 
        System.out.println( permutation.get( 0 ) + ", " + permutation.get( 1 ) + ", " + permutation.get( 2 ) );
    }


Todo
----

Still very raw. Minimal input-checking or handling of corner cases. Minimal unit tests.<commit_msg>Updated the README to reflect the differences of the BigInteger implementation (performance, and compatibility with large sets).<commit_after>Permutations
============

A super-simple Java class that calculates all permutations for a given set, list, or array. It returns an Iterator of all of the permutations, allowing the class to be used in a for loop.

Permutations are calculated on-demand, as the iteration is traversed. This allows the memory requirements to be constant (or O(1)).

Calculating the number of permutations of a given set size has O(n!) time complexity. However, by keeping memory complexity constant, the Permutations class can handle relatively large input sets.

Taken from my Shipping Packer project, which is hosted on Bitbucket.

Performance
-----------

The Permutations class has two implementations of the algorithm, one of which uses long variables and the other uses BigIntegers. The class automatically chooses the BigInteger implementation if the given set size requires it. This incurs a big hit to execution time, but it allows larger sets (> 20 items) to be processed.

Performance (on my modest machine):

* 4-item set: Calculates the 24 permutations (or 4!) in 1 millisecond
* 10-item set: Calculates the 3,628,800 permutations (or 10!) in ~3.5 seconds
* 50-item set: Calculates the first 40,320 permutations in ~150 milliseconds (out of 3e+64 possible permutations)

The latter example uses the BigInteger implementation, which is much slower. It's only feasible to calculate a sub-set of all permutations, because the total number is so large. Calculating all permutations for a 50-item set would take roughly 2.39e+52 years to process on my machine.

Example usage
-------------


    set.add("apple");
    set.add("banana");
    set.add("canteloupe");

    Permutations<String> permutations = new Permutations<String>( set );
    for ( List<String> permutation : permutations ) { 
        System.out.println( permutation.get( 0 ) + ", " + permutation.get( 1 ) + ", " + permutation.get( 2 ) );
    }


Todo
----

Still very raw. Minimal input-checking or handling of corner cases. Minimal unit tests.
{'fraction_non_alphanumeric': 0.0955650929899857, 'fraction_numerical': 0.029470672389127324, 'mean_word_length': 3.930888575458392, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 10, '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': '276571', 'n_tokens_mistral': 1063, 'n_tokens_neox': 887, 'n_words': 445}