Class CoreSubsets
- All Implemented Interfaces:
Iterable<CoreLocation>
,MappableIterable<CoreLocation>
public final class CoreSubsets extends Object implements MappableIterable<CoreLocation>
CoreLocation
s organised by chip. Each chip
location conceptually has a subset of cores that are members of this overall
CoreSubsets
.- Author:
- Christian-B
- See Also:
- Python Version
-
Constructor Summary
Constructors Constructor Description CoreSubsets()
Bases constructor which creates an empty set of CoreSubset(s).CoreSubsets(Iterable<CoreLocation> locations)
Constructor which adds the locations.CoreSubsets(HasCoreLocation location)
Constructor which adds a single location. -
Method Summary
Modifier and Type Method Description void
addCore(int x, int y, int p)
Adds the core location, creating a new subset if required.void
addCore(ChipLocation chip, int p)
Adds the processor for this chip, creating a new subset if required.void
addCore(CoreLocation core)
Adds the core Location.void
addCores(int x, int y, Iterable<Integer> processors)
Adds the processors for this chip, creating a new subset if required.void
addCores(Iterable<CoreLocation> locations)
Adds the locations into this one.void
addCores(ChipLocation chip, Iterable<Integer> processors)
Adds the processors for this chip, creating a new subset if required.Collection<CoreLocation>
coreByChip(ChipLocation chip)
Provides theCoreLocation
s for just a single chip.boolean
equals(Object obj)
Indicates whether some other object is "equal to" this one.Set<ChipLocation>
getChips()
Returns theChipLocation
s for which there is at least oneCoreLocation
in the subsets.int
hashCode()
Generate a hash-code for these subsets.CoreSubsets
intersection(CoreSubsets other)
Returns a newCoreSubsets
which is an intersect of this and the other.boolean
isChip(ChipLocation chip)
Determine if the chip with coordinates (x, y) is in the subset.boolean
isCore(CoreLocation core)
Determine if there is a chip with coordinates (x, y) in the subset, which has a core with the given ID in the subset.boolean
isEmpty()
Whether there are any processors in these core subsets.Iterator<CoreLocation>
iterator()
Set<Integer>
pByChip(ChipLocation chip)
Provides the processor identifiers for just a single chip.int
size()
The total number of processors that are in these core subsets.String
toString()
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
Methods inherited from interface uk.ac.manchester.spinnaker.utils.MappableIterable
filter, first, first, map, nth, toCollectingMap, toCollectingMap, toCollectingMap, toCollectingMap, toList, toList, toMap, toMap, toSet, toSet
-
Constructor Details
-
CoreSubsets
public CoreSubsets()Bases constructor which creates an empty set of CoreSubset(s). -
CoreSubsets
Constructor which adds a single location.- Parameters:
location
- The location of the processor to add.
-
CoreSubsets
Constructor which adds the locations.- Parameters:
locations
- The location of all processors to add.
-
-
Method Details
-
addCore
Adds the core Location.This method uses set semantics so attempts to add a core/processor that is already in the subset are silently ignored.
- Parameters:
core
- Location (x, y, p) to add.- Throws:
IllegalStateException
- If the subsets have been set immutable. For example because a hash-code has been generated,
-
addCore
public void addCore(int x, int y, int p)Adds the core location, creating a new subset if required.This method uses set semantics so attempts to add a core/processor that is already in the subset are silently ignored.
- Parameters:
x
- X coordinate of chipy
- Y coordinate of chipp
- P coordinate/ processor ID- Throws:
IllegalStateException
- If the subsets have been set immutable. For example because a hash-code has been generated,
-
addCore
Adds the processor for this chip, creating a new subset if required.This method uses set semantics so attempts to add a core/processor that is already in the subset are silently ignored.
- Parameters:
chip
- Chip key of CoreSubset to add to.p
- P coordinate/ processor ID.- Throws:
IllegalStateException
- If the subsets have been set immutable. For example because a hashcode has been generated,
-
addCores
Adds the processors for this chip, creating a new subset if required.This method uses set semantics so attempts to add a core/processor that is already in the subset are silently ignored.
- Parameters:
chip
- Chip key of CoreSubset to add to.processors
- p coordinates/ processor IDs.- Throws:
IllegalStateException
- If the subsets have been set immutable. For example because a hash-code has been generated,
-
addCores
Adds the processors for this chip, creating a new subset if required.This method uses set semantics so attempts to add a core/processor that is already in the subset are silently ignored.
- Parameters:
x
- x coordinate of chipy
- y coordinate of chipprocessors
- p coordinates/ processor IDs.- Throws:
IllegalStateException
- If the subsets have been set immutable. For example because a hash-code has been generated,
-
addCores
Adds the locations into this one.This method uses set semantics so attempts to add a core/processor that is already in the subset are silently ignored.
- Parameters:
locations
- the locations to add.
-
size
public int size()The total number of processors that are in these core subsets.- Returns:
- The sum of the individual subset sizes.
-
isEmpty
public boolean isEmpty()Whether there are any processors in these core subsets.- Returns:
true
when all the subsets are empty.
-
isChip
Determine if the chip with coordinates (x, y) is in the subset.Note: An empty subset mapped to the chip is ignored.
- Parameters:
chip
- Coordinates to check- Returns:
- True if and only if there is a none empty Subset for this Chip.
-
isCore
Determine if there is a chip with coordinates (x, y) in the subset, which has a core with the given ID in the subset.- Parameters:
core
- x, y and p coordinates- Returns:
- True if and only if there is a core with these coordinates
-
hashCode
public int hashCode()Generate a hash-code for these subsets.Two
CoreSubsets
that have the same subsets (and are therefore considered equals) will generate the same hash-code.To guarantee consistency over time, once a hash-code is requested the
CoreSubsets
and all its subsets will be made immutable and any further add calls will raise an exception. -
equals
Indicates whether some other object is "equal to" this one. It is reflexive, symmetric and transitive. It is consistent provided no core or subset has been added.Unlike
hashCode()
, a call to equals does not effect mutability. -
toString
-
intersection
Returns a newCoreSubsets
which is an intersect of this and the other.- Parameters:
other
- A secondCoreSubsets
with possibly overlapping cores.- Returns:
- A new
CoreSubsets
object with only the cores present in both. Therefore the result may be empty.
-
getChips
Returns theChipLocation
s for which there is at least oneCoreLocation
in the subsets.The order of the locations is guaranteed to be the natural order.
- Returns:
- An ordered set of chips.
-
iterator
- Specified by:
iterator
in interfaceIterable<CoreLocation>
-
coreByChip
Provides theCoreLocation
s for just a single chip.This will be an empty list when
isChip(ChipLocation)
returnsfalse
.- Parameters:
chip
- coordinates of the chip- Returns:
- Unmodifiable (possibly empty) collection of CoreLocation
-
pByChip
Provides the processor identifiers for just a single chip.This will be an empty list when
isChip(ChipLocation)
returnsfalse
.- Parameters:
chip
- coordinates of the chip- Returns:
- Unmodifiable (possibly empty) collection of processor identifiers
-