|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||
java.lang.Objectorg.eigenbase.util.Permutation
public class Permutation
Represents a mapping which reorders elements in an array.
| Field Summary | |
|---|---|
private int[] |
sources
|
private int[] |
targets
|
| Constructor Summary | |
|---|---|
|
Permutation(int size)
Creates a permutation of a given size. |
|
Permutation(int[] targets)
Creates a permutation from an array. |
private |
Permutation(int[] targets,
int[] sources)
Creates a permuation. |
| Method Summary | |
|---|---|
Object |
clone()
|
boolean |
equals(Object obj)
|
MappingType |
getMappingType()
|
int |
getSource(int target)
Returns the position which maps to target. |
int |
getSourceCount()
Returns the number of sources. |
int |
getSourceOpt(int target)
|
int |
getTarget(int source)
Returns the position that source is mapped to. |
int |
getTargetCount()
Returns the number of targets. |
int |
getTargetOpt(int source)
Returns the target that a source maps to, or -1 if it is not mapped. |
int |
hashCode()
|
void |
identity()
Initializes this permutation to the identity permutation. |
private void |
increment(int x,
int[] zzz)
|
void |
insertSource(int x)
Inserts into the sources. |
void |
insertTarget(int x)
Inserts into the targets. |
Permutation |
inverse()
Returns the inverse permutation. |
boolean |
isIdentity()
Returns whether this is the identity permutation. |
private boolean |
isValid(boolean fail)
Checks whether this permutation is valid. |
Iterator<IntPair> |
iterator()
Returns an iterator over the elements in this mapping. |
Permutation |
product(Permutation permutation)
Returns the product of this Permutation with a given Permutation. |
private void |
resize(int newSize)
|
void |
set(int source,
int target)
Maps source position to target position. |
void |
set(int source,
int target,
boolean allowResize)
Maps source position to target position, automatically resizing if source or target is out of bounds. |
void |
setAll(Mapping mapping)
|
private void |
setInternal(int source,
int target)
|
private void |
shuffleUp(int[] zz,
int x)
|
int |
size()
Returns the number of elements in this permutation. |
String |
toString()
Returns a string representation of this permutation. |
| Methods inherited from class java.lang.Object |
|---|
finalize, getClass, notify, notifyAll, wait, wait, wait |
| Field Detail |
|---|
private int[] targets
private int[] sources
| Constructor Detail |
|---|
public Permutation(int size)
It is intialized to the identity permutation, such as "[0, 1, 2, 3]".
size - Number of elements in the permutationpublic Permutation(int[] targets)
targets - Array of targets
IllegalArgumentException - if elements of array are not unique
ArrayIndexOutOfBoundsException - if elements of array are not
between 0 through targets.length - 1 inclusive
private Permutation(int[] targets,
int[] sources)
| Method Detail |
|---|
public Object clone()
clone in class Objectpublic void identity()
public final int size()
public String toString()
For example, the mapping
| source | target |
|---|---|
| 0 | 2 |
| 1 | 0 |
| 2 | 1 |
| 3 | 3 |
toString in class Object
public void set(int source,
int target)
To preserve the 1:1 nature of the permutation, the previous target of source becomes the new target of the previous source.
For example, given the permutation
[3, 2, 0, 1]suppose we map position 2 to target 1. Position 2 currently has target 0, and the source of position 1 is position 3. We preserve the permutation property by mapping the previous source 3 to the previous target 0. The new permutation is
[3, 2, 1, 0].
Another example. Again starting from
[3, 2, 0, 1]suppose we map position 2 to target 3. We map the previous source 0 to the previous target 0, which gives
[0, 2, 3, 1].
set in interface Mappings.TargetMappingsource - Source positiontarget - Target position
ArrayIndexOutOfBoundsException - if source or target is negative or
greater than or equal to the size of the permuation
public void set(int source,
int target,
boolean allowResize)
To preserve the 1:1 nature of the permutation, the previous target of source becomes the new target of the previous source.
For example, given the permutation
[3, 2, 0, 1]suppose we map position 2 to target 1. Position 2 currently has target 0, and the source of position 1 is position 3. We preserve the permutation property by mapping the previous source 3 to the previous target 0. The new permutation is
[3, 2, 1, 0].
Another example. Again starting from
[3, 2, 0, 1]suppose we map position 2 to target 3. We map the previous source 0 to the previous target 0, which gives
[0, 2, 3, 1].
source - Source positiontarget - Target positionallowResize - Whether to resize the permutation if the source or
target is greater than the current capacity
ArrayIndexOutOfBoundsException - if source or target is negative,
or greater than or equal to the size of the permutation, and
allowResize is falsepublic void insertTarget(int x)
| source | 0 | 1 | 2 | 3 | 4 |
| target | 3 | 0 | 4 | 2 | 1 |
insertTarget(2) every target 2 or higher is
shifted up one.
| source | 0 | 1 | 2 | 3 | 4 | 5 |
| target | 4 | 0 | 5 | 3 | 1 | 2 |
x - public void insertSource(int x)
insertTarget(int).
x -
private void increment(int x,
int[] zzz)
private void shuffleUp(int[] zz,
int x)
private void resize(int newSize)
private void setInternal(int source,
int target)
public Permutation inverse()
inverse in interface Mappings.SourceMappinginverse in interface Mappings.TargetMappingpublic boolean isIdentity()
isIdentity in interface MappingisIdentity in interface Mappings.SourceMappingpublic int getTarget(int source)
source is mapped to.
getTarget in interface Mappings.FunctionMappinggetTarget in interface Mappings.TargetMappingsource - source
public int getSource(int target)
target.
getSource in interface Mappings.SourceMappingprivate boolean isValid(boolean fail)
fail - Whether to assert if invalid
public int hashCode()
hashCode in class Objectpublic boolean equals(Object obj)
equals in class Objectpublic Iterator<IntPair> iterator()
MappingThis method is optional; implementations may throw UnsupportedOperationException.
iterator in interface Iterable<IntPair>iterator in interface Mappingpublic int getSourceCount()
Mapping
getSourceCount in interface MappinggetSourceCount in interface Mappings.FunctionMappinggetSourceCount in interface Mappings.SourceMappinggetSourceCount in interface Mappings.TargetMappingpublic int getTargetCount()
Mapping
getTargetCount in interface MappinggetTargetCount in interface Mappings.SourceMappinggetTargetCount in interface Mappings.TargetMappingpublic MappingType getMappingType()
getMappingType in interface MappinggetMappingType in interface Mappings.FunctionMappinggetMappingType in interface Mappings.SourceMappinggetMappingType in interface Mappings.TargetMappingpublic int getTargetOpt(int source)
Mappings.FunctionMapping
getTargetOpt in interface Mappings.FunctionMappinggetTargetOpt in interface Mappings.SourceMappinggetTargetOpt in interface Mappings.TargetMappingpublic int getSourceOpt(int target)
getSourceOpt in interface Mappings.SourceMappinggetSourceOpt in interface Mappings.TargetMappingpublic void setAll(Mapping mapping)
public Permutation product(Permutation permutation)
permutation.
For example, perm.product(perm.inverse()) yields the identity.
|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||