/**
  * Applies a mapping to a BitSet.
  *
  * <p>If the mapping does not affect the bit set, returns the original. Never changes the
  * original.
  *
  * @param mapping Mapping
  * @param bitSet Bit set
  * @return Bit set with mapping applied
  */
 public static BitSet apply(Mapping mapping, BitSet bitSet) {
   final BitSet newBitSet = new BitSet();
   for (int source : BitSets.toIter(bitSet)) {
     final int target = mapping.getTarget(source);
     newBitSet.set(target);
   }
   if (newBitSet.equals(bitSet)) {
     return bitSet;
   }
   return newBitSet;
 }
 /**
  * Divides one mapping by another.
  *
  * <p>{@code divide(A, B)} returns a mapping C such that B . C (the mapping B followed by the
  * mapping C) is equivalent to A.
  *
  * @param mapping1 First mapping
  * @param mapping2 Second mapping
  * @return Mapping mapping3 such that mapping1 = mapping2 . mapping3
  */
 public static Mapping divide(Mapping mapping1, Mapping mapping2) {
   if (mapping1.getSourceCount() != mapping2.getSourceCount()) {
     throw new IllegalArgumentException();
   }
   Mapping remaining =
       create(
           MappingType.INVERSE_SURJECTION, mapping2.getTargetCount(), mapping1.getTargetCount());
   for (int target = 0; target < mapping1.getTargetCount(); ++target) {
     int source = mapping1.getSourceOpt(target);
     if (source >= 0) {
       int x = mapping2.getTarget(source);
       remaining.set(x, target);
     }
   }
   return remaining;
 }
 /**
  * Multiplies one mapping by another.
  *
  * <p>{@code divide(A, B)} returns a mapping C such that B . C (the mapping B followed by the
  * mapping C) is equivalent to A.
  *
  * @param mapping1 First mapping
  * @param mapping2 Second mapping
  * @return Mapping mapping3 such that mapping1 = mapping2 . mapping3
  */
 public static Mapping multiply(Mapping mapping1, Mapping mapping2) {
   if (mapping1.getTargetCount() != mapping2.getSourceCount()) {
     throw new IllegalArgumentException();
   }
   Mapping product =
       create(
           MappingType.INVERSE_SURJECTION, mapping1.getSourceCount(), mapping2.getTargetCount());
   for (int source = 0; source < mapping1.getSourceCount(); ++source) {
     int x = mapping1.getTargetOpt(source);
     if (x >= 0) {
       int target = mapping2.getTarget(x);
       product.set(source, target);
     }
   }
   return product;
 }
 public int getSource(int target) {
   return parent.getTarget(target);
 }