mirror of
https://github.com/beefytech/Beef.git
synced 2025-06-14 14:24:10 +02:00
Merge pull request #1182 from disarray2077/trygetvaluealt
Add `TryGetValueAlt` and `ContainsAlt` to Dictionary
This commit is contained in:
commit
e0103b7dd7
1 changed files with 25 additions and 0 deletions
|
@ -277,6 +277,19 @@ namespace System.Collections
|
||||||
return false;
|
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)
|
public void CopyTo(Span<KeyValuePair> kvPair)
|
||||||
{
|
{
|
||||||
|
@ -739,6 +752,18 @@ namespace System.Collections
|
||||||
return false;
|
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)
|
public bool TryGet(TKey key, out TKey matchKey, out TValue value)
|
||||||
{
|
{
|
||||||
int_cosize i = (int_cosize)FindEntry(key);
|
int_cosize i = (int_cosize)FindEntry(key);
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue