コード例 #1
0
        public static IDisposable connect_sorted_distinct_mux <T, TResult>(IList <T> source_list, INotifyCollectionChanged source_notifier, IList <TResult> target, Func <T, IEnumerable <TResult> > selector, IComparer <TResult> comparer, IEqualityComparer <TResult> eq_comparer)
        {
            var ref_count = new RefCountMap <TResult>(eq_comparer);

            if (target.Count > 0)
            {
                target.Clear();
            }
            foreach (var v in source_list)
            {
                var r = selector(v);
                target.InsertSortedDistinct(r, comparer);
            }
            return(source_notifier.Subscribe(on_collection_changed));

            void on_collection_changed(object sender, NotifyCollectionChangedEventArgs e)
            {
                switch (e.Action)
                {
                case NotifyCollectionChangedAction.Add:
                    target.InsertSorted(e.NewItems.Cast <T>().SelectMany(selector).Where(ref_count.increment_adds_key), comparer);
                    break;

                case NotifyCollectionChangedAction.Remove:
                    target.RemoveSorted(e.OldItems.Cast <T>().SelectMany(selector).Where(ref_count.decrement_removes_key), comparer);
                    break;

                case NotifyCollectionChangedAction.Replace:
                    target.RemoveSorted(e.OldItems.Cast <T>().SelectMany(selector).Where(ref_count.decrement_removes_key), comparer);
                    target.InsertSorted(e.NewItems.Cast <T>().SelectMany(selector).Where(ref_count.increment_adds_key), comparer);
                    break;

                case NotifyCollectionChangedAction.Reset:
                    target.Clear();
                    ref_count.Clear();
                    target.InsertSorted(source_list.SelectMany(selector).Where(ref_count.increment_adds_key), comparer);
                    break;
                }
            }
        }
コード例 #2
0
 public void Clear()
 {
     StrokeMap.Clear();
     RefCountMap.Clear();
     TotalStrokeCount = 0;
 }