public void Should_shrink_after_removing_a_lot_of_elements() { var itemsCount = 150 * 1000; dic = new StripedDictionary <Guid, string, FastGuidComparer>(itemsCount); var capacityBefore = dic.Capacity; var segmentsCountBefore = dic.SegmentsCount; Console.Out.WriteLine($"Capacity before = {capacityBefore}"); Console.Out.WriteLine($"Segments before = {segmentsCountBefore}"); for (int i = 0; i < itemsCount; i++) { dic.Add(Guid.NewGuid(), string.Empty); } var capacityAfterFilling = dic.Capacity; var segmentsCountAfterFilling = dic.SegmentsCount; Console.Out.WriteLine($"Capacity after filling = {capacityAfterFilling}"); Console.Out.WriteLine($"Segments after filling = {segmentsCountAfterFilling}"); foreach (var pair in dic) { dic.Remove(pair.Key); } Console.Out.WriteLine($"Capacity after cleaning = {dic.Capacity}"); Console.Out.WriteLine($"Segments after cleaning = {dic.SegmentsCount}"); dic.Capacity.Should().BeLessThan(capacityAfterFilling); dic.SegmentsCount.Should().BeLessThan(segmentsCountAfterFilling); dic.HasArraysInLOH.Should().BeFalse(); }
public void Should_initialize_with_given_capacity_so_that_no_further_resize_is_needed() { var itemsCount = 150 * 1000; dic = new StripedDictionary <Guid, string, FastGuidComparer>(itemsCount); var capacityBefore = dic.Capacity; var segmentsCountBefore = dic.SegmentsCount; Console.Out.WriteLine($"Capacity before = {capacityBefore}"); Console.Out.WriteLine($"Segments before = {segmentsCountBefore}"); for (int i = 0; i < itemsCount; i++) { dic.Add(Guid.NewGuid(), string.Empty); } Console.Out.WriteLine($"Capacity after = {dic.Capacity}"); Console.Out.WriteLine($"Segments after = {dic.SegmentsCount}"); dic.Count.Should().Be(itemsCount); dic.Capacity.Should().Be(capacityBefore); dic.SegmentsCount.Should().Be(segmentsCountBefore); dic.HasArraysInLOH.Should().BeFalse(); }
public void TestSetup() { keys = Enumerable.Range(0, 100).Select(_ => Guid.NewGuid()).ToArray(); allKeys = new HashSet <Guid>(keys); dic = new StripedDictionary <Guid, string, FastGuidComparer>(); for (int i = 0; i < keys.Length / 2; i++) { dic.Add(keys[i], keys[i].ToString()); } tasks = new List <Task>(); cancellation = new CancellationTokenSource(); }
public void Add_should_not_fail_when_adding_new_element() { for (int i = 0; i < 100 * 1000; i++) { dic.Add(Guid.NewGuid(), "value"); } }