예제 #1
0
 public Sorter(SortOptimisations optimisations,
               IComparer <TObject> comparer = null,
               int resetThreshold           = -1)
 {
     _optimisations  = optimisations;
     _resetThreshold = resetThreshold;
     _updater        = new IntermediateUpdater <TObject, TKey>(_cache);
     _comparer       = new KeyValueComparer <TObject, TKey>(comparer);
 }
예제 #2
0
 public DynamicCombiner([NotNull] IObservableList <IObservable <IChangeSet <TObject, TKey> > > source, CombineOperator type)
 {
     if (source == null)
     {
         throw new ArgumentNullException(nameof(source));
     }
     _source  = source;
     _type    = type;
     _updater = new IntermediateUpdater <TObject, TKey>(_resultCache);
 }
 public void Initialise()
 {
     _cache = new Cache<Person, String>();
     _updater = new IntermediateUpdater<Person, string>(_cache);
 }
예제 #4
0
        private IChangeSet <TObject, TKey> UpdateCombined(IChangeSet <TObject, TKey> updates)
        {
            //child caches have been updated before we reached this point.
            var updater = new IntermediateUpdater <TObject, TKey>(_combinedCache);

            foreach (var update in updates)
            {
                TKey key = update.Key;
                switch (update.Reason)
                {
                case ChangeReason.Add:
                case ChangeReason.Update:

                {
                    // get the current key.
                    //check whether the item should belong to the cache
                    Optional <TObject> cached = updater.Lookup(key);
                    bool contained            = cached.HasValue;

                    bool match = MatchesConstraint(key);

                    if (match)
                    {
                        if (contained)
                        {
                            if (!ReferenceEquals(update.Current, cached.Value))
                            {
                                updater.AddOrUpdate(update.Current, key);
                            }
                        }
                        else
                        {
                            updater.AddOrUpdate(update.Current, key);
                        }
                    }
                    else
                    {
                        if (contained)
                        {
                            updater.Remove(key);
                        }
                    }
                }
                break;

                case ChangeReason.Remove:
                {
                    var  cached           = updater.Lookup(key);
                    var  contained        = cached.HasValue;
                    bool shouldBeIncluded = MatchesConstraint(key);

                    if (shouldBeIncluded)
                    {
                        var firstOne = _sourceCaches.Select(s => s.Lookup(key))
                                       .SelectValues()
                                       .First();

                        if (!cached.HasValue)
                        {
                            updater.AddOrUpdate(firstOne, key);
                        }
                        else if (!ReferenceEquals(firstOne, cached.Value))
                        {
                            updater.AddOrUpdate(firstOne, key);
                        }
                    }
                    else
                    {
                        if (contained)
                        {
                            updater.Remove(key);
                        }
                    }
                }


                break;

                case ChangeReason.Evaluate:
                {
                    updater.Evaluate(key);
                }

                break;
                }
            }
            return(updater.AsChangeSet());

            // }
            // return up
        }
예제 #5
0
 public void Initialise()
 {
     _cache   = new Cache <Person, String>();
     _updater = new IntermediateUpdater <Person, string>(_cache);
 }