From a26b44b2cc4929b3d25e00fd378fdbb9feb36baf Mon Sep 17 00:00:00 2001 From: John Colvin Date: Wed, 3 Apr 2019 20:19:57 -0500 Subject: [PATCH] SetMap implements IReadOnlyDictionary (was only a few methods short) --- src/client/spark/core/Collections/SetMap.cs | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/src/client/spark/core/Collections/SetMap.cs b/src/client/spark/core/Collections/SetMap.cs index ae2cbd18a..85ab812d0 100644 --- a/src/client/spark/core/Collections/SetMap.cs +++ b/src/client/spark/core/Collections/SetMap.cs @@ -6,7 +6,7 @@ using System.Linq; namespace mbts.collections { interface IGroupingSet : IGrouping, ISet { } - class SetMap : IEnumerable>, ICollection { + class SetMap : IEnumerable>, ICollection, IReadOnlyDictionary> { readonly IEqualityComparer _key_comparer; readonly IEqualityComparer _element_comparer; readonly Dictionary _dictionary; @@ -30,6 +30,10 @@ namespace mbts.collections { public object SyncRoot => null; public bool IsSynchronized => false; public IEnumerable Keys => _dictionary.Keys; + + public IEnumerable> Values => _dictionary.Values; + IEnumerable IReadOnlyDictionary>.this[TKey key] => _dictionary[key]; + public ISet this[TKey key] => _dictionary[key]; public void CopyTo(Array array, int index) => @@ -103,6 +107,19 @@ namespace mbts.collections { kv => new InternalGroupSet(kv.Key, kv.Value, _element_comparer) ), _key_comparer, _element_comparer); + public bool ContainsKey(TKey key) => _dictionary.ContainsKey(key); + public bool TryGetValue(TKey key, out IEnumerable value) { + if (_dictionary.TryGetValue(key, out InternalGroupSet igs)) { + value = igs; + return true; + } + value = null; + return false; + } + IEnumerator>> IEnumerable>>.GetEnumerator() { + foreach (var kv in _dictionary) + yield return new KeyValuePair>(kv.Key, kv.Value); + } class InternalGroupSet : HashSet, IGroupingSet { public InternalGroupSet(TKey key, IEqualityComparer comparer)