Exemplo n.º 1
0
 protected ProgressiveLookup(Progressor <IGrouping <TKey, T> > progressor, NullAwareDictionary <TKey, IGrouping <TKey, T> > cache, IEqualityComparer <TKey>?keyComparer, IEqualityComparer <T>?itemComparer)
 {
     _cache        = cache ?? throw new ArgumentNullException(nameof(cache));
     Progressor    = progressor ?? throw new ArgumentNullException(nameof(progressor));
     _subscription = Progressor.SubscribeAction(obj => _cache.Add(obj.Key, obj));
     Comparer      = keyComparer ?? EqualityComparer <TKey> .Default;
     ItemComparer  = itemComparer ?? EqualityComparer <T> .Default;
     Keys          = EnumerationList <TKey> .Create(this.ConvertProgressive(input => input.Key));
 }
Exemplo n.º 2
0
 public HashSet(IEnumerable <T> collection)
 {
     if (collection == null)
     {
         throw new ArgumentNullException("collection");
     }
     _wrapped = new NullAwareDictionary <T, object>();
     foreach (var item in collection)
     {
         _wrapped[item] = null;
     }
 }
            public IEnumerator <IGrouping <TKey, TElement> > GetEnumerator()
            {
                var groupings = new NullAwareDictionary <TKey, Tuple <Grouping <TKey, TElement>, List <TElement> > >(_comparer);

                foreach (var item in _source)
                {
                    var key = _keySelector(item);
                    if (!groupings.TryGetValue(key, out var tuple))
                    {
                        var collection = new List <TElement>();
                        tuple = new Tuple <Grouping <TKey, TElement>, List <TElement> >(new Grouping <TKey, TElement>(key, collection), collection);
                        groupings.Add(key, tuple);
                    }
                    tuple.Item2.Add(_elementSelector(item));
                }
                return(Enumerator(groupings));
            }
Exemplo n.º 4
0
            public IEnumerator <TResult> GetEnumerator()
            {
                var groupings = new NullAwareDictionary <TKey, Lookup <TKey, TElement> .Grouping>(_comparer);

                foreach (var item in _source)
                {
                    var key = _keySelector(item);
                    Lookup <TKey, TElement> .Grouping grouping;
                    if (!groupings.TryGetValue(key, out grouping))
                    {
                        grouping = new Lookup <TKey, TElement> .Grouping(key);

                        groupings.Add(key, grouping);
                    }
                    grouping.Items.Add(_elementSelector(item));
                }
                return(Enumerator(groupings));
            }