Remove `Bag<K, V>`
This commit is contained in:
parent
ba4c406a36
commit
633216be14
|
@ -1,42 +1,12 @@
|
||||||
using System.Collections;
|
using System.Collections;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Diagnostics.CodeAnalysis;
|
using System.Diagnostics.CodeAnalysis;
|
||||||
using System.Linq;
|
|
||||||
using System.Runtime.Serialization;
|
using System.Runtime.Serialization;
|
||||||
|
|
||||||
using BizHawk.Common.CollectionExtensions;
|
using BizHawk.Common.CollectionExtensions;
|
||||||
|
|
||||||
namespace BizHawk.Common
|
namespace BizHawk.Common
|
||||||
{
|
{
|
||||||
/// <summary>Wrapper over <see cref="WorkingDictionary{TKey, TValue}">WorkingDictionary</see><<typeparamref name="TKey"/>, <see cref="List{T}">List</see><<typeparamref name="TValue"/>>>.</summary>
|
|
||||||
[Serializable]
|
|
||||||
public class Bag<TKey, TValue> : IEnumerable<TValue> where TKey : notnull
|
|
||||||
{
|
|
||||||
private readonly WorkingDictionary<TKey, List<TValue>> dictionary = new WorkingDictionary<TKey, List<TValue>>();
|
|
||||||
|
|
||||||
public IList<TKey> Keys => dictionary.Keys.ToList();
|
|
||||||
|
|
||||||
public List<TValue> this[TKey key]
|
|
||||||
{
|
|
||||||
#pragma warning disable CS8603 // the only call to the index setter of `dictionary` is this index setter, which only takes non-null `List<TValue>`s
|
|
||||||
get => dictionary[key];
|
|
||||||
#pragma warning restore CS8603
|
|
||||||
set => dictionary[key] = value;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void Add(TKey key, IEnumerable<TValue> val) => this[key].AddRange(val);
|
|
||||||
|
|
||||||
public void Add(TKey key, TValue val) => this[key].Add(val);
|
|
||||||
|
|
||||||
public bool ContainsKey(TKey key) => dictionary.ContainsKey(key);
|
|
||||||
|
|
||||||
IEnumerator IEnumerable.GetEnumerator() => GetEnumerator();
|
|
||||||
|
|
||||||
public IEnumerator<TValue> GetEnumerator() => dictionary.Values.SelectMany(lv => lv).GetEnumerator();
|
|
||||||
|
|
||||||
public IEnumerator<KeyValuePair<TKey, List<TValue>>> GetKVPEnumerator() => dictionary.GetEnumerator();
|
|
||||||
}
|
|
||||||
|
|
||||||
public class SortedList<T> : ICollection<T>
|
public class SortedList<T> : ICollection<T>
|
||||||
where T : IComparable<T>
|
where T : IComparable<T>
|
||||||
{
|
{
|
||||||
|
|
|
@ -4,6 +4,7 @@ using System.IO;
|
||||||
using System.Xml;
|
using System.Xml;
|
||||||
using System.Threading;
|
using System.Threading;
|
||||||
using BizHawk.Common;
|
using BizHawk.Common;
|
||||||
|
using BizHawk.Common.CollectionExtensions;
|
||||||
using BizHawk.Common.StringExtensions;
|
using BizHawk.Common.StringExtensions;
|
||||||
|
|
||||||
namespace BizHawk.Emulation.Cores.Nintendo.NES
|
namespace BizHawk.Emulation.Cores.Nintendo.NES
|
||||||
|
@ -17,7 +18,7 @@ namespace BizHawk.Emulation.Cores.Nintendo.NES
|
||||||
|
|
||||||
private readonly bool validate = true;
|
private readonly bool validate = true;
|
||||||
|
|
||||||
private readonly Bag<string, CartInfo> _sha1Table = new Bag<string, CartInfo>();
|
private readonly Dictionary<string, List<CartInfo>> _sha1Table = new();
|
||||||
|
|
||||||
private static BootGodDb instance;
|
private static BootGodDb instance;
|
||||||
|
|
||||||
|
@ -124,7 +125,7 @@ namespace BizHawk.Emulation.Cores.Nintendo.NES
|
||||||
case 4:
|
case 4:
|
||||||
if (xmlReader.NodeType == XmlNodeType.EndElement && xmlReader.Name == "cartridge")
|
if (xmlReader.NodeType == XmlNodeType.EndElement && xmlReader.Name == "cartridge")
|
||||||
{
|
{
|
||||||
_sha1Table[currCart.Sha1].Add(currCart);
|
_sha1Table.GetValueOrPutNew(currCart.Sha1).Add(currCart);
|
||||||
currCart = null;
|
currCart = null;
|
||||||
state = 5;
|
state = 5;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue