Пример #1
0
 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);
     }
 }
Пример #2
0
        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);
        }
Пример #3
0
        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);
        }
Пример #4
0
 internal void AddCollection(CacheBreakdownCollection newCollection)
 {
     AddCollectionMultiplied(newCollection, 1);
 }