Exemplo n.º 1
0
        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);
        }
Exemplo n.º 2
0
        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);
        }