Class CoreSubsets

java.lang.Object
uk.ac.manchester.spinnaker.machine.CoreSubsets
All Implemented Interfaces:
Iterable<CoreLocation>, MappableIterable<CoreLocation>

public final class CoreSubsets
extends Object
implements MappableIterable<CoreLocation>
Represents a set of of CoreLocations 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 Details

    • CoreSubsets

      public CoreSubsets()
      Bases constructor which creates an empty set of CoreSubset(s).
    • CoreSubsets

      public CoreSubsets​(HasCoreLocation location)
      Constructor which adds a single location.
      Parameters:
      location - The location of the processor to add.
    • CoreSubsets

      public CoreSubsets​(Iterable<CoreLocation> locations)
      Constructor which adds the locations.
      Parameters:
      locations - The location of all processors to add.
  • Method Details

    • addCore

      public void addCore​(CoreLocation core)
      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 chip
      y - Y coordinate of chip
      p - P coordinate/ processor ID
      Throws:
      IllegalStateException - If the subsets have been set immutable. For example because a hash-code has been generated,
    • addCore

      public void addCore​(ChipLocation chip, int p)
      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

      public void addCores​(ChipLocation chip, Iterable<Integer> processors)
      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

      public void addCores​(int x, int y, Iterable<Integer> processors)
      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 chip
      y - y coordinate of chip
      processors - p coordinates/ processor IDs.
      Throws:
      IllegalStateException - If the subsets have been set immutable. For example because a hash-code has been generated,
    • addCores

      public void addCores​(Iterable<CoreLocation> locations)
      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

      public boolean isChip​(ChipLocation chip)
      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

      public 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.
      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.

      Overrides:
      hashCode in class Object
      Returns:
      integer to use as the hash-code.
    • equals

      public boolean equals​(Object obj)
      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.

      Overrides:
      equals in class Object
      Parameters:
      obj - Other object to compare to.
      Returns:
      True if and only if obj is another CoreSubsets with exactly the same subsets.
    • toString

      public String toString()
      Overrides:
      toString in class Object
    • intersection

      public CoreSubsets intersection​(CoreSubsets other)
      Returns a new CoreSubsets which is an intersect of this and the other.
      Parameters:
      other - A second CoreSubsets with possibly overlapping cores.
      Returns:
      A new CoreSubsets object with only the cores present in both. Therefore the result may be empty.
    • getChips

      public Set<ChipLocation> getChips()
      Returns the ChipLocations for which there is at least one CoreLocation in the subsets.

      The order of the locations is guaranteed to be the natural order.

      Returns:
      An ordered set of chips.
    • iterator

      public Iterator<CoreLocation> iterator()
      Specified by:
      iterator in interface Iterable<CoreLocation>
    • coreByChip

      public Collection<CoreLocation> coreByChip​(ChipLocation chip)
      Provides the CoreLocations for just a single chip.

      This will be an empty list when isChip(ChipLocation) returns false.

      Parameters:
      chip - coordinates of the chip
      Returns:
      Unmodifiable (possibly empty) collection of CoreLocation
    • pByChip

      public Set<Integer> pByChip​(ChipLocation chip)
      Provides the processor identifiers for just a single chip.

      This will be an empty list when isChip(ChipLocation) returns false.

      Parameters:
      chip - coordinates of the chip
      Returns:
      Unmodifiable (possibly empty) collection of processor identifiers