Exemple #1
0
        private AggregationResult Modify(IFact fact, TKey key, TElement element)
        {
            var group = _groups[key];

            group.Modify(fact, element);
            group.Key = key;
            return(AggregationResult.Modified(group));
        }
Exemple #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) });
 }
Exemple #3
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()) });
 }
Exemple #4
0
        private AggregationResult RemoveElementOnly(IFact fact, TKey key, TElement element)
        {
            var group = _groups[key];

            group.Remove(fact, element);
            if (group.Count == 0)
            {
                return(AggregationResult.Removed(group));
            }
            return(AggregationResult.Modified(group, group, group.Facts));
        }
        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);
        }
Exemple #6
0
        private AggregationResult Remove(TKey key, TElement element)
        {
            var group = _groups[key];

            group.Remove(element);
            if (group.Count == 0)
            {
                _groups.Remove(key);
                return(AggregationResult.Removed(group));
            }
            return(AggregationResult.Modified(group));
        }
        public IEnumerable <AggregationResult> Remove(AggregationContext context, ITuple tuple, IEnumerable <IFact> facts)
        {
            var results = new List <AggregationResult>();

            foreach (var fact in facts)
            {
                var oldValue = _sourceToValue[fact];
                _sourceToValue.Remove(fact);
                results.Add(AggregationResult.Removed(oldValue));
            }
            return(results);
        }
        public IEnumerable <AggregationResult> Modify(ITuple tuple, IEnumerable <IFact> facts)
        {
            var results = new List <AggregationResult>();

            foreach (var fact in facts)
            {
                var value    = _selector.Invoke(tuple, fact);
                var oldValue = (TResult)_sourceToValue[fact];
                _sourceToValue[fact] = value;
                results.Add(AggregationResult.Modified(value, oldValue));
            }
            return(results);
        }
        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);
        }
        public IEnumerable <AggregationResult> Remove(ITuple tuple, IEnumerable <IFact> facts)
        {
            var results = new List <AggregationResult>();

            foreach (var fact in facts)
            {
                var source   = (TSource)fact.Value;
                var oldValue = _sourceToValue[source];
                _sourceToValue.Remove(source);
                results.Add(AggregationResult.Removed(oldValue));
            }
            return(results);
        }
Exemple #11
0
        public IEnumerable <AggregationResult> Modify(ITuple tuple, IEnumerable <IFact> facts)
        {
            var keys         = new List <TKey>();
            var resultLookup = new DefaultKeyMap <TKey, AggregationResult>();

            foreach (var fact in facts)
            {
                var source     = (TSource)fact.Value;
                var key        = (TKey)_keySelector.Invoke(tuple, fact);
                var element    = (TElement)_elementSelector.Invoke(tuple, fact);
                var oldKey     = _sourceToKey[source];
                var oldElement = _sourceToElement[source];
                _sourceToKey[source]     = key;
                _sourceToElement[source] = element;

                if (Equals(key, oldKey))
                {
                    var result = Modify(key, oldElement, element);
                    if (!resultLookup.ContainsKey(key))
                    {
                        keys.Add(key);
                        resultLookup[key] = result;
                    }
                }
                else
                {
                    var result1 = Remove(oldKey, oldElement);
                    if (!resultLookup.ContainsKey(oldKey))
                    {
                        keys.Add(oldKey);
                    }
                    resultLookup[oldKey] = result1;

                    var result2 = Add(key, element);
                    AggregationResult previousResult;
                    if (!resultLookup.TryGetValue(key, out previousResult))
                    {
                        keys.Add(key);
                        resultLookup[key] = result2;
                    }
                    else if (previousResult.Action == AggregationAction.Removed ||
                             result2.Action == AggregationAction.Added)
                    {
                        resultLookup[key] = AggregationResult.Modified(previousResult.Aggregate);
                    }
                }
            }
            var results = GetResults(keys, resultLookup);

            return(results);
        }
Exemple #12
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));
        }
Exemple #13
0
        private AggregationResult Modify(TKey key, TElement oldElement, TElement element)
        {
            var group = _groups[key];

            if (Equals(oldElement, element))
            {
                group.Modify(element);
            }
            else
            {
                group.Remove(oldElement);
                group.Add(element);
            }
            return(AggregationResult.Modified(group));
        }
        public IEnumerable <AggregationResult> Remove(ITuple tuple, IEnumerable <IFact> facts)
        {
            var results = new List <AggregationResult>();

            foreach (var fact in facts)
            {
                var source  = (TSource)fact.Value;
                var oldList = _sourceToList[source];
                _sourceToList.Remove(source);
                foreach (var item in oldList)
                {
                    results.Add(AggregationResult.Removed(item));
                }
            }
            return(results);
        }
Exemple #15
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));
        }
        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);
        }
Exemple #17
0
        public IEnumerable <AggregationResult> Remove(ITuple tuple, IEnumerable <IFact> facts)
        {
            var results = new List <AggregationResult>();

            foreach (var fact in facts)
            {
                var oldList = _sourceToList[fact];
                _sourceToList.Remove(fact);
                foreach (var item in oldList)
                {
                    if (RemoveRef(item) == 0)
                    {
                        results.Add(AggregationResult.Removed(item));
                    }
                }
            }
            return(results);
        }
Exemple #18
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);
        }
Exemple #19
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);
        }
        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);
        }
Exemple #21
0
 public IEnumerable <AggregationResult> Modify(ITuple tuple, IEnumerable <IFact> facts)
 {
     ModifyFacts(facts);
     return(new[] { AggregationResult.Modified(_items) });
 }
Exemple #22
0
 public IEnumerable <AggregationResult> Remove(AggregationContext context, ITuple tuple, IEnumerable <IFact> facts)
 {
     RemoveFacts(context, tuple, facts);
     return(new[] { AggregationResult.Modified(_sortedFactCollection, _sortedFactCollection, _sortedFactCollection.GetFactEnumerable()) });
 }
Exemple #23
0
 public IEnumerable <AggregationResult> Remove(AggregationContext context, ITuple tuple, IEnumerable <IFact> facts)
 {
     RemoveFacts(facts);
     return(new[] { AggregationResult.Modified(_items, _items, _items.Facts) });
 }