Esempio n. 1
0
            public PairComparer(IComparer <TKey> keyComparer, IComparer <TValue> valueComparer)
            {
                keyComparer.ShouldNotBeNull("keyComparer");
                valueComparer.ShouldNotBeNull("valueComparer");

                _keyComparer   = keyComparer;
                _valueComparer = valueComparer;
            }
Esempio n. 2
0
        /// <summary>
        /// Given an IComparer on TKey and TValue, returns an IComparer on
        /// key-value Pairs of TKey and TValue, comparing first keys, then values.
        /// </summary>
        /// <typeparam name="TKey">TKey of the pairs</typeparam>
        /// <typeparam name="TValue">TValue of the apris</typeparam>
        /// <param name="keyComparer">IComparer on TKey</param>
        /// <param name="valueComparer">IComparer on TValue</param>
        /// <returns>IComparer for comparing key-value pairs.</returns>
        public static IComparer <KeyValuePair <TKey, TValue> > ComparerPairFromKeyValueComparers <TKey, TValue>(IComparer <TKey> keyComparer,
                                                                                                                IComparer <TValue>
                                                                                                                valueComparer)
        {
            keyComparer.ShouldNotBeNull("keyComparer");
            valueComparer.ShouldNotBeNull("valueComparer");

            return(new PairComparer <TKey, TValue>(keyComparer, valueComparer));
        }
Esempio n. 3
0
        /// <summary>
        /// Create a new OrderedMultiDictionary. If duplicate values
        /// are allowed, multiple copies of the same value can be associated with the same key. For example, the key "foo"
        /// could have "a", "a", and "b" associated with it. If duplicate values are not allowed, only one copies of a given value can
        /// be associated with the same key, although different keys can have the same value. For example, the key "foo" could
        /// have "a" and "b" associated with it, which key "bar" has values "b" and "c" associated with it.
        /// </summary>
        /// <param name="allowDuplicateValues">Can the same value be associated with a key multiple times?</param>
        /// <param name="keyComparer">An IComparer&lt;TKey&gt; instance that will be used to compare keys.</param>
        /// <param name="valueComparer">An IComparer&lt;TValue&gt; instance that will be used to compare values.</param>
        public OrderedMultiDictionary(bool allowDuplicateValues, IComparer <TKey> keyComparer, IComparer <TValue> valueComparer)
        {
            keyComparer.ShouldNotBeNull("keyComparer");
            valueComparer.ShouldNotBeNull("valueComparer");

            _allowDuplicateValues = allowDuplicateValues;
            _keyComparer          = keyComparer;
            _valueComparer        = valueComparer;
            _comparer             = Comparers.ComparerPairFromKeyValueComparers(keyComparer, valueComparer);
            _tree = new RedBlackTree <KeyValuePair <TKey, TValue> >(_comparer);
        }
Esempio n. 4
0
 /// <summary>
 /// Creates a new OrderedDictionary. The Compare method of the passed comparison object
 /// will be used to compare keys in this dictionary.
 /// </summary>
 /// <remarks>
 /// The GetHashCode and Equals methods of the provided IComparer&lt;TKey&gt; will never
 /// be called, and need not be implemented.</remarks>
 /// <param name="comparer">An instance of IComparer&lt;TKey&gt; that will be used to compare keys.</param>
 public OrderedDictionary(IComparer <TKey> comparer)
     : this(null, comparer, Comparers.ComparerKeyValueFromComparerKey <TKey, TValue>(comparer))
 {
     comparer.ShouldNotBeNull("comparer");
 }
Esempio n. 5
0
 /// <summary>
 /// <para>Creates a new OrderedDictionary. The Compare method of the passed comparison object
 /// will be used to compare keys in this dictionary.</para>
 /// <para>A collection and keys and values (typically another dictionary) is used to initialized the
 /// contents of the dictionary.</para>
 /// </summary>
 /// <remarks>
 /// The GetHashCode and Equals methods of the provided IComparer&lt;TKey&gt; will never
 /// be called, and need not be implemented.</remarks>
 /// <param name="keysAndValues">A collection of keys and values whose contents are used to initialized the dictionary.</param>
 /// <param name="comparer">An instance of IComparer&lt;TKey&gt; that will be used to compare keys.</param>
 public OrderedDictionary(IEnumerable <KeyValuePair <TKey, TValue> > keysAndValues, IComparer <TKey> comparer)
     : this(keysAndValues, comparer, Comparers.ComparerKeyValueFromComparerKey <TKey, TValue>(comparer))
 {
     comparer.ShouldNotBeNull("comparer");
 }
Esempio n. 6
0
 public KeyValueComparer(IComparer <TKey> keyComparer)
 {
     keyComparer.ShouldNotBeNull("keyComparer");
     _keyComparer = keyComparer;
 }
Esempio n. 7
0
        /// <summary>
        /// Given an IComparer on TKey, returns an IComparer on
        /// key-value Pairs.
        /// </summary>
        /// <typeparam name="TKey">TKey of the pairs</typeparam>
        /// <typeparam name="TValue">TValue of the apris</typeparam>
        /// <param name="keyComparer">IComparer on TKey</param>
        /// <returns>IComparer for comparing key-value pairs.</returns>
        public static IComparer <KeyValuePair <TKey, TValue> > ComparerKeyValueFromComparerKey <TKey, TValue>(IComparer <TKey> keyComparer)
        {
            keyComparer.ShouldNotBeNull("keyComparer");

            return(new KeyValueComparer <TKey, TValue>(keyComparer));
        }