public bool Leq(VcStamp aOther) { HashSet<string> keys = new HashSet<string>(iContents.Keys); keys.UnionWith(aOther.iContents.Keys); foreach (string key in keys) { long valueThis, valueOther; // If TryGetValue fails, it sets the output value to default(long), // i.e. 0, which is what we want. iContents.TryGetValue(key, out valueThis); aOther.iContents.TryGetValue(key, out valueOther); if (valueThis > valueOther) return false; } return true; }
static void UpdateDictionary(VcStamp aOther, Dictionary<string, long> aContents) { foreach (var kvp in aOther.iContents) { long valueThis; if (aContents.TryGetValue(kvp.Key, out valueThis)) { aContents[kvp.Key] = Math.Max(kvp.Value, valueThis); } else { aContents[kvp.Key] = kvp.Value; } } }
public void UpdateInPlace(VcStamp aOther) { UpdateDictionary(aOther, iContents); }
public VcStamp Update(VcStamp aOther) { var newStamp = Clone(); newStamp.UpdateInPlace(aOther); return newStamp; }