public Pfs Add(int n) { var builder = Values.ToBuilder(); if (builder.TryGetValue(n, out int val)) { val++; } else { val = 1; } builder[n] = val; var pfs = new Pfs(builder.ToImmutable()); return(pfs); }
public static Pfs operator +(Pfs lhs, Pfs rhs) { var tot = lhs.Values.Keys.Concat(rhs.Values.Keys).Distinct() .Select(k => { if (!lhs.Values.TryGetValue(k, out int val)) { val = 0; } if (rhs.Values.TryGetValue(k, out int rval)) { val += rval; } return(new KeyValuePair <int, int>(k, val)); }).ToImmutableDictionary(); var result = new Pfs(tot, lhs.Total * rhs.Total); return(result); }