/** * 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; }
public int getTargetOpt(int source) { return parent.getSourceOpt(source); }