// (c) Copyright Microsoft Corporation. // This source is subject to the Microsoft Public License (Ms-PL). // Please see http://go.microsoft.com/fwlink/?LinkID=131993 for details. // All other rights reserved. using System.Collections; using System.Collections.Generic; using System.Diagnostics; using System.Diagnostics.CodeAnalysis; using System.Linq; namespace System.Windows.Controls.DataVisualization.Collections { /// /// Implements a dictionary that can store multiple values for the same key and sorts the values. /// /// Type for keys. /// Type for values. internal class OrderedMultipleDictionary : MultipleDictionary, IEnumerable where TKey : IComparable { /// /// Initializes a new instance of the MultipleDictionary class. /// /// The parameter is not used. /// Key comparison class. /// Value comparison class. [SuppressMessage("Microsoft.Usage", "CA1801:ReviewUnusedParameters", MessageId = "allowDuplicateValues", Justification = "Unused parameter exists for API compatibility.")] public OrderedMultipleDictionary(bool allowDuplicateValues, Comparison keyComparison, Comparison valueComparison) { Debug.Assert(null != keyComparison, "keyComparison must not be null."); Debug.Assert(null != valueComparison, "valueComparison must not be null."); BinaryTree = new LeftLeaningRedBlackTree(keyComparison, valueComparison); } /// /// Gets a Range corresponding to the keys in the dictionary. /// /// Range of keys. public Range GetKeyRange() { if (0 < BinaryTree.Count) { return new Range(BinaryTree.MinimumKey, BinaryTree.MaximumKey); } else { return new Range(); } } /// /// Gets the largest and smallest key's extreme values from the dictionary. /// /// Tuple of the largest and smallest values. public Tuple GetLargestAndSmallestValues() { if (0 < BinaryTree.Count) { return new Tuple(BinaryTree.MinimumValue, BinaryTree.MaximumValue); } else { return null; } } /// /// Gets an enumerator for the values in the dictionary. /// /// Enumerator for values. public IEnumerator GetEnumerator() { return BinaryTree.GetValuesForAllKeys().GetEnumerator(); } /// /// Gets an enumerator for the values in the dictionary. /// /// Enumerator for the values. IEnumerator IEnumerable.GetEnumerator() { return BinaryTree.GetValuesForAllKeys().GetEnumerator(); } } }