public static <T> InvertibleCodec<ISeq<T>, BitGene>
	ofSubSet(final ISeq<? extends T> basicSet) {
		requireNonNull(basicSet);
		Requires.positive(basicSet.length());

		return InvertibleCodec.of(
			Genotype.of(BitChromosome.of(basicSet.length())),
			gt -> gt.chromosome()
				.as(BitChromosome.class).ones()
				.<T>mapToObj(basicSet)
				.collect(ISeq.toISeq()),
			values -> {
				final byte[] bits = Bits.newArray(basicSet.size());

				int i = 0;
				for (T v : values) {
					while (i < basicSet.size() && !Objects.equals(basicSet.get(i), v)) {
						++i;
					}
					if (i >= basicSet.size()) {
						throw new IllegalArgumentException(
							"Invalid subset; input values were not created by " +
								"'decode' method."
						);
					}

					Bits.set(bits, i);
				}

				return Genotype.of(new BitChromosome(bits, 0, basicSet.size()));
			}
		);
	}
The subset {@link InvertibleCodec} can be used for problems where it is
required to find the best <b>variable-sized</b> subset from a given basic
set. A typical usage example of the returned {@code Codec} is the
Knapsack problem.
<p>
The following code snippet shows a simplified variation of the Knapsack
problem.
{@snippet lang="java":
public final class Main {
     // The basic set from where to choose an 'optimal' subset.
     private final static ISeq<Integer> SET =
         ISeq.of(1, 2, 3, 4, 5, 6, 7, 8, 9, 10);

     // Fitness function directly takes an 'int' value.
     private static int fitness(final ISeq<Integer> subset) {
         assert(subset.size() <= SET.size());
         final int size = subset.stream()
            .mapToInt(Integer::intValue)
            .sum();
         return size <= 20 ? size : 0;
     }

     public static void main(final String[] args) {
         final Engine<BitGene, Double> engine = Engine
             .builder(Main::fitness, codec.ofSubSet(SET))
             .build();
         // ...
     }
 }
}

@param <T> the element type of the basic set
@param basicSet the basic set, from where to choose the <i>optimal</i>
       subset.
@return a new codec which can be used for modelling <i>subset</i>
        problems.
@throws NullPointerException if the given {@code basicSet} is
        {@code null}; {@code null} elements are allowed.
@throws IllegalArgumentException if the {@code basicSet} size is smaller
        than one.
jenetics/src/main/java/io/jenetics/engine/Codecs.java