Created
October 31, 2022 13:21
-
-
Save NikitaChizhov/0e9cb6277ace5e4cfa4dc385d1a7d568 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public static class Extensions | |
{ | |
public static TValue GetOrNew<TKey, TValue>(this Dictionary<TKey, TValue> dict, TKey key) | |
where TKey : notnull | |
where TValue : new() | |
{ | |
if (!dict.TryGetValue(key, out var value)) | |
{ | |
dict[key] = value = new(); | |
} | |
return value; | |
} | |
public static void AddOrUpdateDot<TActorId>(this List<Dot<TActorId>> dots, TActorId actorId, int newVersion) | |
where TActorId : IEquatable<TActorId> | |
{ | |
var index = -1; | |
for (var i = 0; i < dots.Count; ++i) | |
{ | |
if (dots[i].Actor.Equals(actorId)) | |
{ | |
index = i; | |
break; | |
} | |
} | |
if (index < 0) | |
{ | |
dots.Add(new Dot<TActorId>(actorId, newVersion)); | |
} | |
else | |
{ | |
dots[index] = new Dot<TActorId>(actorId, newVersion); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment