bool TryGetGroup(TKey key, out BatchGroup <TKey, TValue> group) { foreach (BatchGroup <TKey, TValue> g in batched) { if (g.Key.Equals(key)) { group = g; return(true); } } group = null; return(false); }
BatchGroup <TKey, TValue> CreateBatch(TKey key) { if (recycledBatches.Count > 0) { BatchGroup <TKey, TValue> group = recycledBatches.Dequeue(); group.Key = key; return(group); } else { BatchCount++; return(new BatchGroup <TKey, TValue>(key)); } }
public void BatchItem(TKey key, TValue value, bool dontOptimize = false) { if (!dontOptimize) { ElementCount++; BatchGroup <TKey, TValue> group; if (TryGetGroup(key, out group)) { group.List.Add(value); } else { BatchGroup <TKey, TValue> batch = CreateBatch(key); batch.Add(value); batched.Add(batch); } } else { unoptimizedBatch.Add(value); } }