/// <summary> /// Evaluate a predicate Expression and determine a key range which /// contains all items matched by the predicate. /// </summary> /// <param name="expression">The expression to evaluate.</param> /// <returns> /// A KeyRange that contains all items matched by the predicate. If no /// range can be determined the range will include all items. /// </returns> public static KeyRange <TKey> GetKeyRange(Expression <Predicate <KeyValuePair <TKey, TValue> > > expression) { if (null == expression) { throw new ArgumentNullException("expression"); } return(KeyExpressionEvaluator <TKey> .GetKeyRange(expression.Body, KeyMemberInfo)); }
/// <summary> /// Returns an enumerator that iterates through the collection. /// </summary> /// <returns> /// A <see cref="T:System.Collections.Generic.IEnumerator`1"/> that can be used to iterate through the collection. /// </returns> public IEnumerator <TKey> GetEnumerator() { // Consider: we could get the enumeration of key ranges, sort them and union overlapping ranges. // Enumerating the data as several different ranges would be more efficient when the expression // specifies an OR and the ranges are highly disjoint. KeyRange <TKey> range = KeyExpressionEvaluator <TKey> .GetKeyRange(this.expression); this.dictionary.TraceWhere(range, this.isReversed); if (this.isReversed) { return(new PersistentDictionaryReverseEnumerator <TKey, TValue, TKey>( this.dictionary, range, c => c.RetrieveCurrentKey(), this.predicate)); } return(new PersistentDictionaryEnumerator <TKey, TValue, TKey>( this.dictionary, range, c => c.RetrieveCurrentKey(), this.predicate)); }