internal void AddCollectionMultiplied(CacheBreakdownCollection newCollection, long factor) { foreach (var keyValueEntry in newCollection.Tuples) { var tuple = keyValueEntry.Key; var count = keyValueEntry.Value; Add(tuple, count * factor); } }
internal static void PreLoadTuplesForOneAndTwo() { var TupleCollectionForOne = new CacheBreakdownCollection(); TupleCollectionForOne.Add(Tuple.Create <long, long>(0, 0), 1); var TupleCollectionForTwo = new CacheBreakdownCollection(); TupleCollectionForTwo.Add(Tuple.Create <long, long>(1, 0), 1); TupleCollectionForTwo.Add(Tuple.Create <long, long>(0, 0), 1); TupleCache.Add(1, TupleCollectionForOne); TupleCache.Add(2, TupleCollectionForTwo); }
internal CacheBreakdownCollection GetTupleList(long startValue) { if (TupleCache.ContainsKey(startValue)) { return(TupleCache[startValue]); } //Identify the first split. var minusOne = startValue - 1; var isEvenSplit = minusOne % 2; var lowerHalf = minusOne / 2; var upperHalf = lowerHalf + isEvenSplit; //Initialise the collection. var tupleCollectionToReturn = new CacheBreakdownCollection(); tupleCollectionToReturn.Add(Tuple.Create(upperHalf, lowerHalf), 1); //Recurse and Recombine! var lowerTupleCollection = GetTupleList(lowerHalf); if (isEvenSplit == 0) { tupleCollectionToReturn.AddCollectionMultiplied(lowerTupleCollection, 2); } else { var upperTupleCollection = GetTupleList(lowerHalf + 1); tupleCollectionToReturn.AddCollection(upperTupleCollection); tupleCollectionToReturn.AddCollection(lowerTupleCollection); } //Store. TupleCache[startValue] = tupleCollectionToReturn; return(tupleCollectionToReturn); }
internal void AddCollection(CacheBreakdownCollection newCollection) { AddCollectionMultiplied(newCollection, 1); }