1
0
Fork 0
mirror of https://github.com/beefytech/Beef.git synced 2025-06-10 12:32:20 +02:00

Merge pull request #1182 from disarray2077/trygetvaluealt

Add `TryGetValueAlt` and `ContainsAlt` to Dictionary
This commit is contained in:
Brian Fiete 2021-10-30 06:37:10 -07:00 committed by GitHub
commit e0103b7dd7
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -277,6 +277,19 @@ namespace System.Collections
return false;
}
}
public bool ContainsAlt<TAltKey>((TAltKey key, TValue value) kvPair) where TAltKey : IHashable where bool : operator TKey == TAltKey
{
TValue value;
if (TryGetValueAlt(kvPair.key, out value))
{
return value == kvPair.value;
}
else
{
return false;
}
}
public void CopyTo(Span<KeyValuePair> kvPair)
{
@ -739,6 +752,18 @@ namespace System.Collections
return false;
}
public bool TryGetValueAlt<TAltKey>(TAltKey key, out TValue value) where TAltKey : IHashable where bool : operator TKey == TAltKey
{
int_cosize i = (int_cosize)FindEntryAlt<TAltKey>(key);
if (i >= 0)
{
value = mEntries[i].mValue;
return true;
}
value = default(TValue);
return false;
}
public bool TryGet(TKey key, out TKey matchKey, out TValue value)
{
int_cosize i = (int_cosize)FindEntry(key);