org.eigenbase.util.mapping
Class Mappings.PartialMapping

java.lang.Object
  extended by org.eigenbase.util.mapping.Mappings.AbstractMapping
      extended by org.eigenbase.util.mapping.Mappings.FiniteAbstractMapping
          extended by org.eigenbase.util.mapping.Mappings.PartialMapping
All Implemented Interfaces:
Iterable<IntPair>, Mapping, Mappings.FunctionMapping, Mappings.SourceMapping, Mappings.TargetMapping
Direct Known Subclasses:
Mappings.SurjectionWithInverse
Enclosing class:
Mappings

public static class Mappings.PartialMapping
extends Mappings.FiniteAbstractMapping
implements Mapping, Mappings.FunctionMapping, Mappings.TargetMapping

A mapping where a source at most one target, and every target has at most one source.


Nested Class Summary
private  class Mappings.PartialMapping.MappingItr
           
 
Field Summary
private  MappingType mappingType
           
protected  int[] sources
           
protected  int[] targets
           
 
Constructor Summary
private Mappings.PartialMapping(int[] sources, int[] targets, MappingType mappingType)
           
  Mappings.PartialMapping(int sourceCount, int targetCount, MappingType mappingType)
          Creates a partial mapping.
  Mappings.PartialMapping(List<Integer> sourceList, int sourceCount, MappingType mappingType)
          Creates a partial mapping from a list.
 
Method Summary
private static void assertPartialValid(int[] sources, int[] targets)
           
 MappingType getMappingType()
           
 int getSourceCount()
          Returns the number of sources.
 int getSourceOpt(int target)
           
 int getTarget(int source)
          Returns the target that a source maps 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.
 Mapping inverse()
           
 boolean isIdentity()
          Returns whether this mapping is the identity.
protected  boolean isValid()
           
 Iterator<IntPair> iterator()
          Returns an iterator over the elements in this mapping.
 void set(int source, int target)
           
 
Methods inherited from class org.eigenbase.util.mapping.Mappings.FiniteAbstractMapping
equals, hashCode, toString
 
Methods inherited from class org.eigenbase.util.mapping.Mappings.AbstractMapping
getSource
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface org.eigenbase.util.mapping.Mappings.SourceMapping
getSource
 

Field Detail

sources

protected final int[] sources

targets

protected final int[] targets

mappingType

private final MappingType mappingType
Constructor Detail

Mappings.PartialMapping

public Mappings.PartialMapping(int sourceCount,
                               int targetCount,
                               MappingType mappingType)
Creates a partial mapping.

Initially, no element is mapped to any other:

source 0 1 2
target -1 -1 -1
target 0 1 2 3
source -1 -1 -1 -1

Parameters:
sourceCount - Number of source elements
targetCount - Number of target elements
mappingType - Mapping type; must not allow multiple sources per target or multiple targets per source

Mappings.PartialMapping

public Mappings.PartialMapping(List<Integer> sourceList,
                               int sourceCount,
                               MappingType mappingType)
Creates a partial mapping from a list. For example, PartialMapping({1, 2, 4}, 6) creates the mapping
source 0 1 2 3 4 5
target -1 0 1 -1 2 -1

Parameters:
sourceList - List whose i'th element is the source of target #i
sourceCount - Number of elements in the source domain
mappingType - Mapping type, must be MappingType.PartialSurjection or stronger.

Mappings.PartialMapping

private Mappings.PartialMapping(int[] sources,
                                int[] targets,
                                MappingType mappingType)
Method Detail

getMappingType

public MappingType getMappingType()
Specified by:
getMappingType in interface Mapping
Specified by:
getMappingType in interface Mappings.FunctionMapping
Specified by:
getMappingType in interface Mappings.SourceMapping
Specified by:
getMappingType in interface Mappings.TargetMapping

getSourceCount

public int getSourceCount()
Description copied from interface: Mapping
Returns the number of sources. Valid sources will be in the range 0 .. sourceCount.

Specified by:
getSourceCount in interface Mapping
Specified by:
getSourceCount in interface Mappings.FunctionMapping
Specified by:
getSourceCount in interface Mappings.SourceMapping
Specified by:
getSourceCount in interface Mappings.TargetMapping
Overrides:
getSourceCount in class Mappings.AbstractMapping

getTargetCount

public int getTargetCount()
Description copied from interface: Mapping
Returns the number of targets. Valid targets will be in the range 0 .. targetCount.

Specified by:
getTargetCount in interface Mapping
Specified by:
getTargetCount in interface Mappings.SourceMapping
Specified by:
getTargetCount in interface Mappings.TargetMapping
Overrides:
getTargetCount in class Mappings.AbstractMapping

inverse

public Mapping inverse()
Specified by:
inverse in interface Mappings.SourceMapping
Specified by:
inverse in interface Mappings.TargetMapping

iterator

public Iterator<IntPair> iterator()
Description copied from interface: Mapping
Returns an iterator over the elements in this mapping.

This method is optional; implementations may throw UnsupportedOperationException.

Specified by:
iterator in interface Iterable<IntPair>
Specified by:
iterator in interface Mapping
Overrides:
iterator in class Mappings.FiniteAbstractMapping

isValid

protected boolean isValid()

assertPartialValid

private static void assertPartialValid(int[] sources,
                                       int[] targets)

set

public void set(int source,
                int target)
Specified by:
set in interface Mappings.TargetMapping
Overrides:
set in class Mappings.AbstractMapping

getSourceOpt

public int getSourceOpt(int target)
Specified by:
getSourceOpt in interface Mappings.SourceMapping
Specified by:
getSourceOpt in interface Mappings.TargetMapping
Overrides:
getSourceOpt in class Mappings.AbstractMapping

getTargetOpt

public int getTargetOpt(int source)
Description copied from interface: Mappings.FunctionMapping
Returns the target that a source maps to, or -1 if it is not mapped.

Specified by:
getTargetOpt in interface Mappings.FunctionMapping
Specified by:
getTargetOpt in interface Mappings.SourceMapping
Specified by:
getTargetOpt in interface Mappings.TargetMapping
Overrides:
getTargetOpt in class Mappings.AbstractMapping

getTarget

public int getTarget(int source)
Description copied from interface: Mappings.FunctionMapping
Returns the target that a source maps to.

Specified by:
getTarget in interface Mappings.FunctionMapping
Specified by:
getTarget in interface Mappings.TargetMapping
Overrides:
getTarget in class Mappings.AbstractMapping
Parameters:
source - source
Returns:
target

isIdentity

public boolean isIdentity()
Description copied from interface: Mapping
Returns whether this mapping is the identity.

Specified by:
isIdentity in interface Mapping
Specified by:
isIdentity in interface Mappings.SourceMapping
Overrides:
isIdentity in class Mappings.AbstractMapping