java.lang.Object
dev.civl.mc.util.IF.Transmuter
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic int[]inverse(int[] map) Given a bijection from a subset S of {0,...,n-1} to {0,...,m-1}, returns the inverse of that bijection.static int[]inverse(int[] map, int m) Given a bijection from a subset S of {0,...,n-1} to {0,...,m-1}, returns the inverse of that bijection.static <T> ArrayList<T> Returns a new array list obtained from given one by reordering elements according to a specified map.static <T> voidtransmuteInPlace(int[] map, int[] inverseMap, ArrayList<T> a) Permutes in-place the elements of an array list.static voidtransmuteInPlaceMultiple(int[] map, int[] inverseMap, ArrayList<Object>[] a)
-
Constructor Details
-
Transmuter
public Transmuter()
-
-
Method Details
-
inverse
public static int[] inverse(int[] map, int m) Given a bijection from a subset S of {0,...,n-1} to {0,...,m-1}, returns the inverse of that bijection. The given map must have length n and for each i (0invalid input: '<'=iinvalid input: '<'n), either map[i]=-1, indicating i is not in S, or map[i] is in {0,...,m-1}. The result will be an array of length m satisfying result[map[i]]==i, for all i in S.- Parameters:
map- array of ints of length n specifying bijection from a subset of 0..n-1 to 0..m-1.m- cardinality of S- Returns:
- inverse of map
-
inverse
public static int[] inverse(int[] map) Given a bijection from a subset S of {0,...,n-1} to {0,...,m-1}, returns the inverse of that bijection. This method will determine m by scanning map and counting the number of elements that are nonnegative. The given map must have length n and for each i (0invalid input: '<'=iinvalid input: '<'n), either map[i]=-1, indicating i is not in S, or map[i] is in {0,...,m-1}. The result will be an array of length m satisfying result[map[i]]==i, for all i in S.- Parameters:
map- array of ints of length n specifying bijection from a subset of 0..n-1 to 0..m-1.m- cardinality of S- Returns:
- inverse of map
-
transmute
Returns a new array list obtained from given one by reordering elements according to a specified map. Let n be the size of a. The map specifies (1) a subset S of {0,1,...,n-1} and (2) a bijection from S to {0,1,...,m-1}, where m is the cardinality of S. The elements of a at positions not in S will not be copied to the new array list b. The other elements will be copied and reordered. Specifically, for each i in S, we will have b[map[i]] == a[i] where b is the array list returned by this method. Furthermore, b.size()==m. The map is an array of ints of length n. For 0invalid input: '<'=iinvalid input: '<'n, map[i] is either -1 (indicating i is not in S, i.e., the element a[i] is to be discarded) or a nonnegative integer giving the new index of the element. Neither map nor a is modified by this method.- Parameters:
map- array of ints of length n giving bijection from a subset of {0,...,n-1} to {0,...,m-1}a- array list of length n- Returns:
- array list of length m satisfying b[map[i]] == a[i]
-
transmuteInPlace
Permutes in-place the elements of an array list. Let n be the size of a. The map specifies (1) a subset S of {0,1,...,n-1} and (2) a bijection from S to {0,1,...,m-1}, where m is the cardinality of S. The elements of a at positions not in S are to be discarded. The other elements are to be reordered. Specifically, for each i in S, we will have a'[map[i]] == a[i] where a' is the array list after this method completes. Furthermore, a'.size()==m. The map is an array of ints of length n. For 0invalid input: '<'=iinvalid input: '<'n, map[i] is either -1 (indicating i is not in S, i.e., the element a[i] is to be discarded) or a nonnegative integer giving the new index of the element. The inverseMap is the inverse of map and is completely determined by map. It specifies a function from {0,1,...,m-1} to S. Its length is m and it satisfies inverseMap[map[i]]==i for i in S map[inverseMap[j]]==j for j in {0,1,...,m-1}. The method may modify inverseMap.- Parameters:
map- array of length n specifying bijection from subset of 0..n-1 to 0..m-1.inverseMap- inverse of mapa- an array list of length n to be transmuted
-
transmuteInPlaceMultiple
-