Skip to content

Commit 66bf501

Browse files
committed
added PermutationBinaryOperator
1 parent d36c91c commit 66bf501

File tree

2 files changed

+63
-0
lines changed

2 files changed

+63
-0
lines changed

src/main/java/org/cicirello/permutations/Permutation.java

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -216,6 +216,19 @@ public void apply(PermutationUnaryOperator operator) {
216216
operator.apply(permutation);
217217
}
218218

219+
/**
220+
* Applies a custom binary operator on a pair of Permutation objects.
221+
* The raw int array belonging to this is passed as the first array to
222+
* operator.apply() and the raw int array belonging to other is passed
223+
* as the second.
224+
*
225+
* @param operator A binary Permutation operator
226+
* @param other The other Permutation
227+
*/
228+
public void apply(PermutationBinaryOperator operator, Permutation other) {
229+
operator.apply(permutation, other.permutation);
230+
}
231+
219232
/**
220233
* Creates an identical copy of this object.
221234
* @return an identical copy of this object
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
/*
2+
* JavaPermutationTools: A Java library for computation on permutations and sequences
3+
* Copyright 2005-2022 Vincent A. Cicirello, <https://www.cicirello.org/>.
4+
*
5+
* This file is part of JavaPermutationTools (https://jpt.cicirello.org/).
6+
*
7+
* JavaPermutationTools is free software: you can
8+
* redistribute it and/or modify it under the terms of the GNU
9+
* General Public License as published by the Free Software
10+
* Foundation, either version 3 of the License, or (at your
11+
* option) any later version.
12+
*
13+
* JavaPermutationTools is distributed in the hope
14+
* that it will be useful, but WITHOUT ANY WARRANTY; without even
15+
* the implied warranty of MERCHANTABILITY or FITNESS FOR A
16+
* PARTICULAR PURPOSE. See the GNU General Public License for more
17+
* details.
18+
*
19+
* You should have received a copy of the GNU General Public License
20+
* along with JavaPermutationTools. If not, see <http://www.gnu.org/licenses/>.
21+
*/
22+
package org.cicirello.permutations;
23+
24+
/**
25+
* A functional interface for defining custom binary operators on Permutations.
26+
* See the {@link Permutation#apply(PermutationBinaryOperator,Permutation)} method.
27+
*
28+
* @author <a href=https://www.cicirello.org/ target=_top>Vincent A. Cicirello</a>,
29+
* <a href=https://www.cicirello.org/ target=_top>https://www.cicirello.org/</a>
30+
*/
31+
@FunctionalInterface
32+
public interface PermutationBinaryOperator {
33+
34+
/**
35+
* Applies an operator on the raw representations of
36+
* a pair of Permutations. Implementers of this interface are responsible
37+
* for ensuring that the apply method maintains valid
38+
* permutations of the integers in {0, 1, ..., rawPermutation1.length - 1 },
39+
* and likewise for rawPermutation2.
40+
*
41+
* @param rawPermutation1 A reference to the raw array of ints underlying a
42+
* Permutation object. Changes to this array will directly change the Permutation
43+
* object that encapsulates it.
44+
*
45+
* @param rawPermutation2 A reference to the raw array of ints underlying a
46+
* Permutation object. Changes to this array will directly change the Permutation
47+
* object that encapsulates it.
48+
*/
49+
void apply(int[] rawPermutation1, int[] rawPermutation2);
50+
}

0 commit comments

Comments
 (0)