i already had a DefaultDictionary.cs!!
This commit is contained in:
parent
754489dfe7
commit
0dc2c05312
|
@ -1,16 +0,0 @@
|
|||
namespace AOC.Common;
|
||||
|
||||
public class DefaultDictionary<TKey, TValue> : Dictionary<TKey, TValue> where TValue : new() where TKey : notnull
|
||||
{
|
||||
public new TValue this[TKey key]
|
||||
{
|
||||
get
|
||||
{
|
||||
if (TryGetValue(key, out var val)) return val;
|
||||
val = new();
|
||||
Add(key, val);
|
||||
return val;
|
||||
}
|
||||
set => base[key] = value;
|
||||
}
|
||||
}
|
|
@ -1,6 +1,6 @@
|
|||
namespace AOC.Common;
|
||||
|
||||
public class DefaultDict<TKey, TValue> : Dictionary<TKey, TValue> where TKey : notnull
|
||||
public class DefaultDictionary<TKey, TValue> : Dictionary<TKey, TValue> where TKey : notnull
|
||||
{
|
||||
public TValue? DefaultValue;
|
||||
|
||||
|
@ -81,7 +81,7 @@ public class Dijkstra<TCell, TMid> where TCell : notnull
|
|||
public int ComputeFind(TCell start, TCell target, Func<TCell, bool>? valid = null)
|
||||
{
|
||||
valid ??= _ => true;
|
||||
var dist = new DefaultDict<TCell, int> { DefaultValue = int.MaxValue, [start] = 0 };
|
||||
var dist = new DefaultDictionary<TCell, int> { DefaultValue = int.MaxValue, [start] = 0 };
|
||||
var seen = new HashSet<TCell>();
|
||||
var queue = new PriorityQueue<TCell, int>();
|
||||
queue.Enqueue(start, 0);
|
||||
|
|
Loading…
Reference in New Issue