Esempio n. 1
0
 public IEnumerable <AggregationResult> Add(AggregationContext context, ITuple tuple, IEnumerable <IFact> facts)
 {
     AddFacts(context, tuple, facts);
     if (!_created)
     {
         _created = true;
         return(new[] { AggregationResult.Added(_sortedFactCollection, _sortedFactCollection.GetFactEnumerable()) });
     }
     return(new[] { AggregationResult.Modified(_sortedFactCollection, _sortedFactCollection, _sortedFactCollection.GetFactEnumerable()) });
 }
Esempio n. 2
0
 public IEnumerable <AggregationResult> Add(AggregationContext context, ITuple tuple, IEnumerable <IFact> facts)
 {
     AddFacts(facts);
     if (!_created)
     {
         _created = true;
         return(new[] { AggregationResult.Added(_items, _items.Facts) });
     }
     return(new[] { AggregationResult.Modified(_items, _items, _items.Facts) });
 }
Esempio n. 3
0
        public IEnumerable <AggregationResult> Add(AggregationContext context, ITuple tuple, IEnumerable <IFact> facts)
        {
            var results = new List <AggregationResult>();

            foreach (var fact in facts)
            {
                var value = _selector.Invoke(context, tuple, fact);
                _sourceToValue[fact] = value;
                results.Add(AggregationResult.Added(value, Enumerable.Repeat(fact, 1)));
            }
            return(results);
        }
Esempio n. 4
0
        public IEnumerable <AggregationResult> Add(ITuple tuple, IEnumerable <IFact> facts)
        {
            var results = new List <AggregationResult>();

            foreach (var fact in facts)
            {
                var source = (TSource)fact.Value;
                var value  = _selector.Invoke(tuple, fact);
                _sourceToValue[source] = value;
                results.Add(AggregationResult.Added(value));
            }
            return(results);
        }
Esempio n. 5
0
        private AggregationResult Add(IFact fact, TKey key, TElement element)
        {
            if (!_groups.TryGetValue(key, out var group))
            {
                group        = new Grouping(key);
                _groups[key] = group;

                group.Add(fact, element);
                return(AggregationResult.Added(group));
            }

            group.Add(fact, element);
            group.Key = key;
            return(AggregationResult.Modified(group));
        }
Esempio n. 6
0
        private AggregationResult Add(TKey key, TElement element)
        {
            Grouping group;

            if (!_groups.TryGetValue(key, out group))
            {
                group        = new Grouping(key);
                _groups[key] = group;

                group.Add(element);
                return(AggregationResult.Added(group));
            }

            group.Add(element);
            return(AggregationResult.Modified(group));
        }
Esempio n. 7
0
        public IEnumerable <AggregationResult> Add(ITuple tuple, IEnumerable <IFact> facts)
        {
            var results = new List <AggregationResult>();

            foreach (var fact in facts)
            {
                var source = (TSource)fact.Value;
                var value  = (IEnumerable <TResult>)_selector.Invoke(tuple, fact);
                var list   = new List <TResult>(value);
                _sourceToList[source] = list;
                foreach (var item in list)
                {
                    results.Add(AggregationResult.Added(item));
                }
            }
            return(results);
        }
Esempio n. 8
0
        public IEnumerable <AggregationResult> Add(ITuple tuple, IEnumerable <IFact> facts)
        {
            var results = new List <AggregationResult>();

            foreach (var fact in facts)
            {
                var list = new OrderedHashSet <TResult>();
                _sourceToList[fact] = list;
                var value = (IEnumerable <TResult>)_selector.Invoke(tuple, fact);
                foreach (var item in value)
                {
                    if (list.Add(item) &&
                        AddRef(item) == 1)
                    {
                        results.Add(AggregationResult.Added(item));
                    }
                }
            }
            return(results);
        }
Esempio n. 9
0
        public IEnumerable <AggregationResult> Modify(ITuple tuple, IEnumerable <IFact> facts)
        {
            var results = new List <AggregationResult>();

            foreach (var fact in facts)
            {
                var list    = new OrderedHashSet <TResult>();
                var oldList = _sourceToList[fact];
                _sourceToList[fact] = list;

                var value = (IEnumerable <TResult>)_selector.Invoke(tuple, fact);
                foreach (var item in value)
                {
                    list.Add(item);
                }

                foreach (var item in oldList)
                {
                    if (!list.Contains(item) &&
                        RemoveRef(item) == 0)
                    {
                        results.Add(AggregationResult.Removed(item));
                    }
                }
                foreach (var item in list)
                {
                    if (oldList.Contains(item))
                    {
                        results.Add(AggregationResult.Modified(item));
                    }
                    else if (AddRef(item) == 1)
                    {
                        results.Add(AggregationResult.Added(item));
                    }
                }
            }
            return(results);
        }
Esempio n. 10
0
        public IEnumerable <AggregationResult> Modify(ITuple tuple, IEnumerable <IFact> facts)
        {
            var results = new List <AggregationResult>();

            foreach (var fact in facts)
            {
                var source   = (TSource)fact.Value;
                var value    = _selector.Invoke(tuple, fact);
                var oldValue = (TResult)_sourceToValue[source];
                _sourceToValue[source] = value;

                if (Equals(oldValue, value))
                {
                    results.Add(AggregationResult.Modified(value));
                }
                else
                {
                    results.Add(AggregationResult.Removed(oldValue));
                    results.Add(AggregationResult.Added(value));
                }
            }
            return(results);
        }