/// /// Copyright © 2003-2008 JetBrains s.r.o. /// You may distribute under the terms of the GNU General Public License, as published by the Free Software Foundation, version 2 (see License.txt in the repository root folder). /// using System.Collection.Generic; using System.Collections; using System.Collections.Generic; namespace JetBrains.Omea.Containers { /// /// A prototype implementation for a one-to-set map. /// public class OneToSetMap : IEnumerable>> { #region Data private readonly Dictionary> _map; #endregion #region Init public OneToSetMap() { _map = new Dictionary>(); } #endregion #region Attributes public ICollection this[TKey key] { get { ICollection value; value = !_map.TryGetValue(key, out value) ? new TValue[] {} : value; return value; } } #endregion #region Operations public void Add(TKey key, TValue value) { ICollection values = TryGetValues(key); if(values == null) { values = new HashSet(); _map[key] = values; } values.Add(value); } public bool ContainsKey(TKey key) { return _map.ContainsKey(key); } #endregion #region Implementation private ICollection TryGetValues(TKey key) { ICollection value; return _map.TryGetValue(key, out value) ? value : null; } #endregion #region IEnumerable>> Members public IEnumerator>> GetEnumerator() { return _map.GetEnumerator(); } IEnumerator IEnumerable.GetEnumerator() { return _map.GetEnumerator(); } #endregion } }