コード例 #1
0
 /**
  * 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;
 }
コード例 #2
0
 /**
  * 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;
 }
コード例 #3
0
 /**
  * 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;
 }
コード例 #4
0
 public int getSource(int target) {
   return parent.getTarget(target);
 }