private static <A, B> Genotype<EnumGene<Integer>> toEncoding(
		final Map<A, B> mapping,
		final Map<A, Integer> source,
		final Map<B, Integer> target,
		final Map<Integer, EnumGene<Integer>> genes
	) {
		final int[] perm = new int[target.size()];
		source.forEach((key, value) -> {
			final int i = value;
			final int j = target.get(mapping.get(key));
			perm[i%perm.length] = j;
		});

		// If the target size is greater the source size, only the first
		// elements (source size) are filled. The rest of the 'perm' array
		// has to be filled with unique elements.
		if (target.size() > source.size()) {
			final int[] indexes = new int[target.size()];

			// Initialize the index set with all target indexes: O(|t|)
			for (int i = 0; i < target.size(); ++i) {
				indexes[i] = i;
			}

			// Mark existing permutations in the index array: O(|s|*log(|t|))
			for (int i = 0; i < source.size(); ++i) {
				final int si = Arrays.binarySearch(indexes, perm[i]);
				if (si >= 0) {
					indexes[si] = -1;
				}
			}

			// Fill the 'perm' array with the remaining, non-duplicate indexes:
			// O(|t|)
			int j = 0;
			int next;
			for (int i = source.size(); i < target.size(); ++i) {
				while ((next = indexes[j++]) == -1);
				perm[i] = next;
			}
		}

		return  Genotype.of(
			new PermutationChromosome<>(
				IntStream.of(perm)
					.mapToObj(genes::get)
					.collect(ISeq.toISeq())
			)
		);
	}
Create a codec, which creates a mapping from the elements given in the
{@code source} sequence to the elements given in the {@code target}
sequence. The returned mapping can be seen as a function which maps every
element of the {@code target} set to an element of the {@code source} set.
{@snippet lang="java":
final ISeq<Integer> numbers = ISeq.of(1, 2, 3, 4, 5);
final ISeq<String> strings = ISeq.of("1", "2", "3");

final Codec<Map<Integer, String>, EnumGene<Integer>> codec =
    Codecs.ofMapping(numbers, strings, HashMap::new);
}

If {@code source.size() > target.size()}, the created mapping is
<a href="https://en.wikipedia.org/wiki/Surjective_function">surjective</a>,
if {@code source.size() < target.size()}, the mapping is
<a href="https://en.wikipedia.org/wiki/Injective_function">injective</a>
and if both sets have the same size, the returned mapping is
<a href="https://en.wikipedia.org/wiki/Bijection">bijective</a>.

@since 4.3

@param source the source elements. Will be the <em>keys</em> of the
       encoded {@code Map}.
@param target the target elements. Will be the <em>values</em> of the
	      encoded {@code Map}.
@param mapSupplier a function which returns a new, empty Map into which
       the mapping will be inserted
@param <A> the type of the source elements
@param <B> the type of the target elements
@param <M> the type of the encoded Map
@return a new mapping codec
@throws IllegalArgumentException if the {@code target} sequences are empty
@throws NullPointerException if one of the arguments is {@code null}
jenetics/src/main/java/io/jenetics/engine/Codecs.java