ben
/
aoc
1
0
Fork 0

i already had a DefaultDictionary.cs!!

This commit is contained in:
Ben Harris 2022-12-09 11:59:13 -05:00
parent 754489dfe7
commit 0dc2c05312
2 changed files with 2 additions and 18 deletions

View File

@ -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;
}
}

View File

@ -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);