From 5b02c68372e334430cf77fcffd0283524a697f07 Mon Sep 17 00:00:00 2001 From: disarray2077 <86157825+disarray2077@users.noreply.github.com> Date: Wed, 27 Oct 2021 23:29:03 -0300 Subject: [PATCH 1/2] Add TryGetValueAlt to Dictionary --- BeefLibs/corlib/src/Collections/Dictionary.bf | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/BeefLibs/corlib/src/Collections/Dictionary.bf b/BeefLibs/corlib/src/Collections/Dictionary.bf index 03135d23..7d0bf19e 100644 --- a/BeefLibs/corlib/src/Collections/Dictionary.bf +++ b/BeefLibs/corlib/src/Collections/Dictionary.bf @@ -739,6 +739,18 @@ namespace System.Collections return false; } + public bool TryGetValueAlt(TAltKey key, out TValue value) where TAltKey : IHashable where bool : operator TKey == TAltKey + { + int_cosize i = (int_cosize)FindEntryAlt(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); From 5b2801cbae8cc88a3b753ab5b0366ee30c867756 Mon Sep 17 00:00:00 2001 From: disarray2077 <86157825+disarray2077@users.noreply.github.com> Date: Wed, 27 Oct 2021 23:37:09 -0300 Subject: [PATCH 2/2] Add ContainsAlt to Dictionary --- BeefLibs/corlib/src/Collections/Dictionary.bf | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/BeefLibs/corlib/src/Collections/Dictionary.bf b/BeefLibs/corlib/src/Collections/Dictionary.bf index 7d0bf19e..493a3309 100644 --- a/BeefLibs/corlib/src/Collections/Dictionary.bf +++ b/BeefLibs/corlib/src/Collections/Dictionary.bf @@ -277,6 +277,19 @@ namespace System.Collections return false; } } + + public bool ContainsAlt((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 kvPair) {