More edge cases

This commit is contained in:
TheXamlGuy
2024-05-26 14:51:25 +01:00
parent 6a2708c111
commit 2bd7b54fa0
6 changed files with 40 additions and 14 deletions
+22
View File
@@ -44,6 +44,17 @@ public class Cache<TValue>(IComparer<TValue>? comparer = default) :
return false;
}
public bool Contains(TValue key)
{
int index = items.BinarySearch(key, comparer);
if (index >= 0)
{
return true;
}
return false;
}
public bool TryGetValue(TValue key, out TValue? item)
{
int index = items.BinarySearch(key, comparer);
@@ -147,6 +158,17 @@ public class Cache<TKey, TValue>(IComparer<TKey> comparer) :
return false;
}
public bool Contains(TKey key)
{
int index = items.FindIndex(kvp => comparer.Compare(kvp.Key, key) == 0);
if (index >= 0)
{
items.RemoveAt(index);
return true;
}
return false;
}
private class KeyValuePairComparer<TK, TV>(IComparer<TK> comparer) :
IComparer<KeyValuePair<TK, TV>>
{
-10
View File
@@ -1,10 +0,0 @@
namespace Toolkit.Foundation;
public record Edit
{
public static EditEventArgs<TValue> As<TValue>(TValue value) =>
new(value);
public static EditEventArgs<TValue> As<TValue>() where TValue : new() =>
new(new TValue());
}
-3
View File
@@ -1,3 +0,0 @@
namespace Toolkit.Foundation;
public record EditEventArgs<TValue>(TValue Value);
+5 -1
View File
@@ -7,11 +7,13 @@ public interface ICache<TValue> :
void Clear();
bool TryGetValue(TValue key, out TValue? item);
bool Contains(TValue key);
int IndexOf(TValue value);
bool Remove(TValue value);
bool TryGetValue(TValue key, out TValue? item);
}
public interface ICache<TKey, TValue> :
@@ -25,6 +27,8 @@ public interface ICache<TKey, TValue> :
void Clear();
bool Contains(TKey key);
int IndexOf(TKey key);
bool Remove(TKey key);
+10
View File
@@ -0,0 +1,10 @@
namespace Toolkit.Foundation;
public record Update
{
public static UpdateEventArgs<TValue> As<TValue>(TValue value) =>
new(value);
public static UpdateEventArgs<TValue> As<TValue>() where TValue : new() =>
new(new TValue());
}
+3
View File
@@ -0,0 +1,3 @@
namespace Toolkit.Foundation;
public record UpdateEventArgs<TValue>(TValue Value);