Package org.apache.calcite.util.mapping
Class Mappings.PartialMapping
- java.lang.Object
-
- org.apache.calcite.util.mapping.Mappings.AbstractMapping
-
- org.apache.calcite.util.mapping.Mappings.FiniteAbstractMapping
-
- org.apache.calcite.util.mapping.Mappings.PartialMapping
-
- All Implemented Interfaces:
java.lang.Iterable<IntPair>
,Mapping
,Mappings.CoreMapping
,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 has at most one target, and every target has at most one source.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description private class
Mappings.PartialMapping.MappingItr
Mapping iterator.
-
Field Summary
Fields Modifier and Type Field Description private MappingType
mappingType
protected int[]
sources
protected int[]
targets
-
Constructor Summary
Constructors Modifier Constructor Description private
PartialMapping(int[] sources, int[] targets, MappingType mappingType)
PartialMapping(int sourceCount, int targetCount, MappingType mappingType)
Creates a partial mapping.PartialMapping(java.util.List<java.lang.Integer> sourceList, int sourceCount, MappingType mappingType)
Creates a partial mapping from a list.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description private static void
assertPartialValid(int[] sources, int[] targets)
void
clear()
Removes all elements in the mapping.MappingType
getMappingType()
Returns the mapping type.int
getSourceCount()
Returns the number of sources.int
getSourceOpt(int target)
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()
java.util.Iterator<IntPair>
iterator()
Returns an iterator over the elements in this mapping.void
set(int source, int target)
int
size()
Returns the number of elements in the mapping.-
Methods inherited from class org.apache.calcite.util.mapping.Mappings.FiniteAbstractMapping
equals, hashCode
-
Methods inherited from class org.apache.calcite.util.mapping.Mappings.AbstractMapping
getSource, getTarget, toString
-
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
-
Methods inherited from interface org.apache.calcite.util.mapping.Mappings.SourceMapping
getSource
-
Methods inherited from interface org.apache.calcite.util.mapping.Mappings.TargetMapping
getTarget
-
-
-
-
Field Detail
-
sources
protected final int[] sources
-
targets
protected final int[] targets
-
mappingType
private final MappingType mappingType
-
-
Constructor Detail
-
PartialMapping
public PartialMapping(int sourceCount, int targetCount, MappingType mappingType)
Creates a partial mapping.Initially, no element is mapped to any other:
Example source 0 1 2 target -1 -1 -1 Example target 0 1 2 3 source -1 -1 -1 -1 - Parameters:
sourceCount
- Number of source elementstargetCount
- Number of target elementsmappingType
- Mapping type; must not allow multiple sources per target or multiple targets per source
-
PartialMapping
public PartialMapping(java.util.List<java.lang.Integer> sourceList, int sourceCount, MappingType mappingType)
Creates a partial mapping from a list. For example,PartialMapping({1, 2, 4}, 6)
creates the mappingExample 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 #isourceCount
- Number of elements in the source domainmappingType
- Mapping type, must beMappingType.PARTIAL_SURJECTION
or stronger.
-
PartialMapping
private PartialMapping(int[] sources, int[] targets, MappingType mappingType)
-
-
Method Detail
-
getMappingType
public MappingType getMappingType()
Description copied from interface:Mappings.CoreMapping
Returns the mapping type.- Specified by:
getMappingType
in interfaceMapping
- Specified by:
getMappingType
in interfaceMappings.CoreMapping
- Specified by:
getMappingType
in interfaceMappings.FunctionMapping
- Specified by:
getMappingType
in interfaceMappings.SourceMapping
- Returns:
- Mapping type
-
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 interfaceMapping
- Specified by:
getSourceCount
in interfaceMappings.FunctionMapping
- Specified by:
getSourceCount
in interfaceMappings.SourceMapping
- Specified by:
getSourceCount
in interfaceMappings.TargetMapping
- Overrides:
getSourceCount
in classMappings.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 interfaceMapping
- Specified by:
getTargetCount
in interfaceMappings.SourceMapping
- Specified by:
getTargetCount
in interfaceMappings.TargetMapping
- Overrides:
getTargetCount
in classMappings.AbstractMapping
-
clear
public void clear()
Description copied from interface:Mapping
Removes all elements in the mapping.
-
size
public int size()
Description copied from interface:Mapping
Returns the number of elements in the mapping.- Specified by:
size
in interfaceMapping
- Specified by:
size
in interfaceMappings.CoreMapping
-
inverse
public Mapping inverse()
- Specified by:
inverse
in interfaceMappings.SourceMapping
- Specified by:
inverse
in interfaceMappings.TargetMapping
-
iterator
public java.util.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 interfacejava.lang.Iterable<IntPair>
- Specified by:
iterator
in interfaceMapping
- Overrides:
iterator
in classMappings.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 interfaceMappings.TargetMapping
- Overrides:
set
in classMappings.AbstractMapping
-
getSourceOpt
public int getSourceOpt(int target)
- Specified by:
getSourceOpt
in interfaceMappings.SourceMapping
- Specified by:
getSourceOpt
in interfaceMappings.TargetMapping
- Overrides:
getSourceOpt
in classMappings.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 interfaceMappings.FunctionMapping
- Specified by:
getTargetOpt
in interfaceMappings.SourceMapping
- Specified by:
getTargetOpt
in interfaceMappings.TargetMapping
- Overrides:
getTargetOpt
in classMappings.AbstractMapping
-
isIdentity
public boolean isIdentity()
Description copied from interface:Mapping
Returns whether this mapping is the identity.- Specified by:
isIdentity
in interfaceMapping
- Specified by:
isIdentity
in interfaceMappings.SourceMapping
- Overrides:
isIdentity
in classMappings.AbstractMapping
-
-