protected ProgressiveDictionary(Progressor <KeyValuePair <TKey, TValue> > wrapped, IDictionary <TKey, TValue> cache, IEqualityComparer <TKey> keyComparer, IEqualityComparer <TValue> valueComparer) : base ((out KeyValuePair <TKey, TValue> pair) => { again: if (wrapped.TryTake(out pair)) { if (cache.ContainsKey(pair.Key)) { goto again; } return(true); } else { return(false); } }, cache, new KeyValuePairEqualityComparer <TKey, TValue>(keyComparer, valueComparer)) { _cache = Check.NotNullArgument(cache, "cache"); _keyComparer = keyComparer ?? EqualityComparer <TKey> .Default; _keyComparer = EqualityComparer <TKey> .Default; _valuesReadonly = new ProgressiveSet <TValue>(Progressor <TValue> .CreateConverted(Progressor, input => input.Value), valueComparer); _keysReadonly = new ProgressiveSet <TKey>(Progressor <TKey> .CreateConverted(Progressor, input => input.Key), keyComparer); }
protected ProgressiveDictionary(IEnumerable <KeyValuePair <TKey, TValue> > wrapped, IDictionary <TKey, TValue> cache, IEqualityComparer <TKey> keyComparer, IEqualityComparer <TValue> valueComparer) : this(wrapped.GetEnumerator(), cache, new KeyValuePairEqualityComparer <TKey, TValue>(keyComparer, valueComparer)) { _cache = Check.NotNullArgument(cache, "cache"); _keyComparer = keyComparer ?? EqualityComparer <TKey> .Default; _valuesReadonly = new ProgressiveSet <TValue>(Progressor <TValue> .CreateConverted(Progressor, input => input.Value), valueComparer); _keysReadonly = new ProgressiveSet <TKey>(Progressor <TKey> .CreateConverted(Progressor, input => input.Key), keyComparer); }
protected ProgressiveLookup(TryTake <IGrouping <TKey, T> > tryTake, IDictionary <TKey, IGrouping <TKey, T> > cache, IEqualityComparer <TKey> keyComparer, IEqualityComparer <T> itemComparer) { _cache = Check.NotNullArgument(cache, "cache"); _progressor = new Progressor <IGrouping <TKey, T> >(tryTake, false); // false because the underlaying structure may change _progressor.SubscribeAction(obj => _cache.Add(new KeyValuePair <TKey, IGrouping <TKey, T> >(obj.Key, obj))); _keyComparer = keyComparer ?? EqualityComparer <TKey> .Default; _itemComparer = itemComparer ?? EqualityComparer <T> .Default; _keysReadonly = new ProgressiveSet <TKey>(Progressor <TKey> .CreateConverted(Progressor, input => input.Key), keyComparer); }
protected ProgressiveLookup(Progressor <IGrouping <TKey, T> > wrapped, IDictionary <TKey, IGrouping <TKey, T> > cache, IEqualityComparer <TKey> keyComparer, IEqualityComparer <T> itemComparer) { _cache = Check.NotNullArgument(cache, "cache"); _progressor = new Progressor <IGrouping <TKey, T> >(wrapped); _progressor.SubscribeAction(obj => _cache.Add(new KeyValuePair <TKey, IGrouping <TKey, T> >(obj.Key, obj))); _keyComparer = keyComparer ?? EqualityComparer <TKey> .Default; _itemComparer = itemComparer ?? EqualityComparer <T> .Default; _keysReadonly = new ProgressiveSet <TKey>(Progressor <TKey> .CreateConverted(Progressor, input => input.Key), keyComparer); }