Example #1
0
        private static Portion getCostBaseline(long globalCost, Func <CacheHitInfo, CacheStats> getStats)
        {
            var cumulativeCost = 0L;
            var cacheCount     = 0;
            var _90pct         = Portion.Ratio(9, 10);
            var threshold      = globalCost * _90pct;

            var costs = from cache in Nrdo.GetCacheHitInfoUnsorted()
                        let cost = getStats(cache).CumulativeCost
                                   orderby cost descending
                                   select cost;

            foreach (var cost in costs)
            {
                cacheCount++;
                cumulativeCost += cost;
                if (cumulativeCost >= threshold)
                {
                    return(Portion.Ratio(cumulativeCost, cacheCount));
                }
            }

            // The only way we should be able to get to here is if there aren't any caches at all, but just in case, we define the threshold as equal to 90% of
            // the global cost in that case.
            return(threshold);
        }
Example #2
0
            public IEnumerable <Block> GetChunks(params int[] proportions)
            {
                var total = proportions.Sum();

                var nextBlockStart = 0;

                foreach (var size in proportions)
                {
                    var offset = Portion.Ratio(nextBlockStart, total);
                    var scale  = Portion.Ratio(size, total);
                    var block  = new Block(this, parentTransform, offset, scale, size);
                    yield return(block);

                    nextBlockStart += size;
                }
            }