private ConcurrentLinkedDictionary <K, IEnumerable <V> > newEmptyWeightedMap <K, V>() { return(new Builder <K, IEnumerable <V> >() .MaximumWeightedCapacity(Capacity()) .Weigher(Weighers.Enumerable <V>()) .Build()); }
public void weightedConcurrency(Builder <int, IList <int> > builder) { ConcurrentLinkedDictionary <int, IList <int> > map = builder .Weigher(Weighers.List <int>()) .MaximumWeightedCapacity(threads) .ConcurrencyLevel(threads) .Build(); ConcurrentQueue <List <int> > values = new ConcurrentQueue <List <int> >(); for (int i = 1; i <= threads; i++) { int[] array = new int[i]; array.SetAll(int.MinValue); values.Enqueue(array.ToList()); } executeWithTimeOut(map, () => { return(ConcurrentTestHarness.timeTasks(threads, () => { // todo: was concurrentlinkedqueue.poll blocking? List <int> value; if (values.TryDequeue(out value)) { for (int i = 0; i < iterations; i++) { map.put(i % 10, value); } } })); }); }
public void weigher_withCustom(Builder <int, byte[]> builder) { builder.Weigher(Weighers.ByteArray()); IEntryWeigher <int, byte[]> weigher = ((BoundedEntryWeigher <int, byte[]>)builder.Build().weigher).weigher; IWeigher <byte[]> customWeigher = ((EntryWeigherView <int, byte[]>)weigher).weigher; Assert.That(customWeigher, Is.SameAs((Object)Weighers.ByteArray())); }
private ConcurrentLinkedDictionary <K, IEnumerable <V> > newGuardedWeightedMap <K, V>() { var listener = guardingListener <K, IEnumerable <V> >(); return(new Builder <K, IEnumerable <V> >() .MaximumWeightedCapacity(Capacity()) .Weigher(Weighers.Enumerable <V>()) .Listener(listener) .Build()); }
public void evict_weighted(Builder <int, ICollection <int> > builder) { ConcurrentLinkedDictionary <int, ICollection <int> > map = builder .Weigher(Weighers.Collection <int>()) .MaximumWeightedCapacity(10) .Build(); map.put(1, asList(1, 2)); map.put(2, asList(3, 4, 5, 6, 7)); map.put(3, asList(8, 9, 10)); Assert.That(map.WeightedSize(), Is.EqualTo(10L)); // evict (1) map.put(4, asList(11)); Assert.That(map.ContainsKey(1), Is.EqualTo(false)); Assert.That(map.WeightedSize(), Is.EqualTo(9L)); // evict (2, 3) map.put(5, asList(12, 13, 14, 15, 16, 17, 18, 19, 20)); Assert.That(map.WeightedSize(), Is.EqualTo(10L)); Assert.That(map, validConcurrentLinkedDictionary <int, ICollection <int> >()); }