/// <summary> /// Gets the hash code /// </summary> /// <returns>Hash code</returns> public override int GetHashCode() { unchecked // Overflow is fine, just wrap { var hashCode = 41; // Suitable nullity checks etc, of course :) if (CpuCores != null) { hashCode = hashCode * 59 + CpuCores.GetHashCode(); } if (Preemptible != null) { hashCode = hashCode * 59 + Preemptible.GetHashCode(); } if (RamGb != null) { hashCode = hashCode * 59 + RamGb.GetHashCode(); } if (DiskGb != null) { hashCode = hashCode * 59 + DiskGb.GetHashCode(); } if (Zones != null) { hashCode = hashCode * 59 + Zones.GetHashCode(); } return(hashCode); } }
/// <summary> /// Subtracts another resource spec from this one. /// </summary> /// <param name="other">The other resource spec to subtract.</param> /// <returns>The subtracted resource spec.</returns> public ResourceSpec Subtract(ResourceSpec other) { Preconditions.CheckNotNull(other, "Cannot subtract null resources"); if (Equals(Unknown) || other.Equals(Unknown)) { return(Unknown); } Preconditions.CheckArgument(other.LessThanOrEqual(this), "Cannot subtract a larger ResourceSpec from this one."); var target = new ResourceSpec( CpuCores.Merge(other.CpuCores), TaskHeapMemory.Subtract(other.TaskHeapMemory), TaskOffHeapMemory.Subtract(other.TaskOffHeapMemory), OnHeapManagedMemory.Subtract(other.OnHeapManagedMemory), OffHeapManagedMemory.Subtract(other.OffHeapManagedMemory)); foreach (var(key, value) in ExtendedResources) { target.ExtendedResources.Add(key, value); } foreach (var resource in other.ExtendedResources.Values) { var temp = target.ExtendedResources[resource.Name]; var subtracted = temp.Subtract(resource); target.ExtendedResources.Add(temp.Name, subtracted); } return(target); }
/// <summary> /// Used by system internally to merge the other resources of chained operators when generating the job graph. /// </summary> /// <param name="other">Reference to resource to merge in.</param> /// <returns>The new resource with merged values.</returns> public ResourceSpec Merge(ResourceSpec other) { Preconditions.CheckNotNull(other, "Cannot merge with null resources"); if (Equals(Unknown) || other.Equals(Unknown)) { return(Unknown); } var target = new ResourceSpec( CpuCores.Merge(other.CpuCores), TaskHeapMemory.Add(other.TaskHeapMemory), TaskOffHeapMemory.Add(other.TaskOffHeapMemory), OnHeapManagedMemory.Add(other.OnHeapManagedMemory), OffHeapManagedMemory.Add(other.OffHeapManagedMemory)); foreach (var(key, value) in ExtendedResources) { target.ExtendedResources.Add(key, value); } foreach (var resource in other.ExtendedResources.Values) { var temp = target.ExtendedResources[resource.Name]; var merged = temp.Merge(resource); target.ExtendedResources.Add(temp.Name, merged); } return(target); }
public override int GetHashCode() { unchecked { var hashCode = (CpuCores != null ? CpuCores.GetHashCode() : 0); hashCode = (hashCode * 397) ^ (TaskHeapMemory != null ? TaskHeapMemory.GetHashCode() : 0); hashCode = (hashCode * 397) ^ (TaskOffHeapMemory != null ? TaskOffHeapMemory.GetHashCode() : 0); hashCode = (hashCode * 397) ^ (OnHeapManagedMemory != null ? OnHeapManagedMemory.GetHashCode() : 0); hashCode = (hashCode * 397) ^ (OffHeapManagedMemory != null ? OffHeapManagedMemory.GetHashCode() : 0); hashCode = (hashCode * 397) ^ (ExtendedResources != null ? ExtendedResources.GetHashCode() : 0); return(hashCode); } }
/// <summary> /// Returns true if TesResources instances are equal /// </summary> /// <param name="other">Instance of TesResources to be compared</param> /// <returns>Boolean</returns> public bool Equals(TesResources other) { if (other is null) { return(false); } if (ReferenceEquals(this, other)) { return(true); } return (( CpuCores == other.CpuCores || CpuCores != null && CpuCores.Equals(other.CpuCores) ) && ( Preemptible == other.Preemptible || Preemptible != null && Preemptible.Equals(other.Preemptible) ) && ( RamGb == other.RamGb || RamGb != null && RamGb.Equals(other.RamGb) ) && ( DiskGb == other.DiskGb || DiskGb != null && DiskGb.Equals(other.DiskGb) ) && ( Zones == other.Zones || Zones != null && Zones.SequenceEqual(other.Zones) )); }