Stashbox by Peter Csajtai

<PackageReference Include="Stashbox" Version="3.6.2-preview-635" />

 ExpandableArray<TKey, TItem>

class ExpandableArray<TKey, TItem> : ExpandableArray<KeyValue<TKey, TItem>>
using System.Runtime.CompilerServices; namespace Stashbox.Utils.Data { internal class ExpandableArray<TKey, TItem> : ExpandableArray<KeyValue<TKey, TItem>> { public ExpandableArray() { } public ExpandableArray(ExpandableArray<TKey, TItem> initial) : base((ExpandableArray<KeyValue<TKey, TItem>>)initial) { } [MethodImpl(MethodImplOptions.AggressiveInlining)] public TItem GetOrDefaultByValue(TKey key) { int length = Length; for (int i = 0; i < length; i++) { ref KeyValue<TKey, TItem> reference = ref Repository[i]; if (object.Equals(reference.Key, key)) return reference.Value; } return default(TItem); } [MethodImpl(MethodImplOptions.AggressiveInlining)] public TItem GetOrDefaultByRef(TKey key) { int length = Length; for (int i = 0; i < length; i++) { ref KeyValue<TKey, TItem> reference = ref Repository[i]; if ((object)reference.Key == (object)key) return reference.Value; } return default(TItem); } public void AddOrKeep(TKey item, TItem value) { if (!ContainsReference(item)) { int num = EnsureSize(1); Repository[num] = new KeyValue<TKey, TItem>(item, value); } } public void AddOrUpdate(TKey key, TItem value) { int num = IndexOf(key); if (num >= 0) Repository[num] = new KeyValue<TKey, TItem>(key, value); else { num = EnsureSize(1); Repository[num] = new KeyValue<TKey, TItem>(key, value); } } public int IndexAndValueOf(TKey key, out TItem value) { value = default(TItem); int length = Length; for (int i = 0; i < length; i++) { ref KeyValue<TKey, TItem> reference = ref Repository[i]; if ((object)reference.Key == (object)key) { value = reference.Value; return i; } } return -1; } public int IndexOf(TKey key) { int length = Length; if (length == 1) { if ((object)Repository[0].Key != (object)key) return -1; return 0; } for (int i = 0; i < length; i++) { if ((object)Repository[i].Key == (object)key) return i; } return -1; } public bool ContainsReference(TKey key) { int length = Length; if (length == 1) return (object)Repository[0].Key == (object)key; for (int i = 0; i < length; i++) { if ((object)Repository[i].Key == (object)key) return true; } return false; } } }