using System; using Microsoft.Ccr.Core; namespace Roblox; public class ParallelDictionary : IAsyncDictionary where TValue : new() { private readonly AsyncDictionary[] dictionaries = new AsyncDictionary[64]; public ParallelDictionary() { for (int i = 0; i < dictionaries.Length; i++) { dictionaries[i] = new AsyncDictionary(); } } private AsyncDictionary GetDictionary(TKey key) { uint hashCode = (uint)key.GetHashCode(); checked { return dictionaries[(int)(IntPtr)(long)unchecked((ulong)hashCode % (ulong)dictionaries.Length)]; } } public void Add(TKey key, TValue value, Port result) { GetDictionary(key).Add(key, value, result); } public void ContainsKey(TKey key, Port result) { GetDictionary(key).ContainsKey(key, result); } public void Remove(TKey key, Port result) { GetDictionary(key).Remove(key, result); } public void TryGetValue(TKey key, PortSet result) { GetDictionary(key).TryGetValue(key, result); } public void GetOrCreate(TKey key, Port result) { GetDictionary(key).GetOrCreate(key, result); } }