More edge cases
This commit is contained in:
@@ -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>>
|
||||
{
|
||||
|
||||
@@ -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());
|
||||
}
|
||||
@@ -1,3 +0,0 @@
|
||||
namespace Toolkit.Foundation;
|
||||
|
||||
public record EditEventArgs<TValue>(TValue Value);
|
||||
@@ -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);
|
||||
|
||||
@@ -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());
|
||||
}
|
||||
@@ -0,0 +1,3 @@
|
||||
namespace Toolkit.Foundation;
|
||||
|
||||
public record UpdateEventArgs<TValue>(TValue Value);
|
||||
Reference in New Issue
Block a user