public void Copy() { var keys = new object[245]; var values = new object[245]; for (int i = 0; i < 245; i++) { keys[i] = new object(); values[i] = new object(); } var indexes = new EntryIndex <object> [245]; for (int i = 0; i < 245; i++) { var key = keys[i]; var value = values[i]; FixedSizeDictionary.AddOrReplace(key, value, out var index); indexes[i] = index; Assert.True(FixedSizeDictionary.ContainsKey(index)); Assert.True(FixedSizeDictionary.ContainsKey(key)); Assert.True(FixedSizeDictionary.TryGetValue(key, out var actualValue)); Assert.Equal(value, actualValue); Assert.True(FixedSizeDictionary.TryGetValue(index, out actualValue)); Assert.Equal(value, actualValue); } var destination = new FixedSizeDictionary <object, object, EqualityComparers.ReferenceEqualityComparer <object> >(15, 17, new EqualityComparers.ReferenceEqualityComparer <object>()); FixedSizeDictionary.CopyTo(destination); FixedSizeDictionary.Clear(); for (int i = 0; i < 245; i++) { var key = keys[i]; var value = values[i]; destination.TryGetIndex(key, out var index); Assert.True(destination.ContainsKey(index)); Assert.True(destination.ContainsKey(key)); Assert.True(destination.TryGetValue(key, out var actualValue)); Assert.Equal(value, actualValue); Assert.True(destination.TryGetValue(index, out actualValue)); Assert.Equal(value, actualValue); } }
public async Task QueueTrack(string trackId) { if (downloads.ContainsKey(trackId)) { return; } var helper = downloads[trackId] = CreateHelper(trackId); RunPoller(); await helper.StartDownload(); }
public void AddOrReplace() { var objects = new object[245]; for (int i = 0; i < 245; i++) { objects[i] = new object(); } for (int iteration = 0; iteration < 5; iteration++) { for (int i = 0; i < 245; i++) { var key = objects[i]; var value = new object(); FixedSizeDictionary.AddOrReplace(key, value, out var index); Assert.True(FixedSizeDictionary.ContainsKey(index)); Assert.True(FixedSizeDictionary.ContainsKey(key)); Assert.True(FixedSizeDictionary.TryGetValue(key, out var actualValue)); Assert.Equal(value, actualValue); Assert.True(FixedSizeDictionary.TryGetValue(index, out actualValue)); Assert.Equal(value, actualValue); } } }