예제 #1
0
        /// <summary>
        /// Creates jobs for the parallel group by.
        /// Note that the last job in the array has the end set to the end of the result table.
        /// Each job will receive a range from result table, hasher, comparer (cache on) and aggregates.
        /// Note that they are all copies, because they contain a private state (hasher contains reference to the equality comparers to enable caching when computing the hash).
        /// The comparers and hashers build in the constructor of this class are given to the last job, just like the aggregates passed to the construtor.
        /// </summary>
        private GroupByJob[] CreateJobs(ITableResults resTable, Aggregate[] aggs, ExpressionComparer[] comparers, ExpressionHasher[] hashers)
        {
            GroupByJob[] jobs     = new GroupByJob[this.ThreadCount];
            int          current  = 0;
            int          addition = resTable.NumberOfMatchedElements / this.ThreadCount;

            if (addition == 0)
            {
                throw new ArgumentException($"{this.GetType()}, a range for a thread cannot be 0.");
            }

            // Set their internal cache.
            var lastComp   = RowEqualityComparerGroupKey.Factory(resTable, comparers, true);
            var lastHasher = new RowHasher(hashers);

            lastHasher.SetCache(lastComp.comparers);

            for (int i = 0; i < jobs.Length - 1; i++)
            {
                var tmpComp = lastComp.Clone(cacheResults: true);
                var tmpHash = lastHasher.Clone();
                tmpHash.SetCache(tmpComp.comparers);
                jobs[i]  = CreateJob(tmpHash, tmpComp, aggs, resTable, current, current + addition);
                current += addition;
            }

            jobs[jobs.Length - 1] = CreateJob(lastHasher, lastComp, aggs, resTable, current, resTable.NumberOfMatchedElements);
            return(jobs);
        }
예제 #2
0
        /// <summary>
        /// Creates jobs for the parallel group by.
        /// Note that the last job in the array has the end set to the end of the result table.
        /// Each job will receive a range from result table, hasher, comparer and aggregates.
        /// Note that they are all copies, because they contain a private stete (hasher contains reference to the equality comparers to enable caching when computing the hash, aggregates
        /// contain references to storage arrays to avoid casting in a tight loop).
        /// The comparers and hashers build in the constructor of this class are given to the last job, just like the aggregates passed to the construtor.
        /// The global Dictionary recieves a comparer that has no internal comparers set to some hasher.
        /// </summary>
        private GroupByJob[] CreateJobs(ITableResults resTable, Aggregate[] aggs, ExpressionComparer[] comparers, ExpressionHasher[] hashers)
        {
            GroupByJob[] jobs     = new GroupByJob[this.ThreadCount];
            int          current  = 0;
            int          addition = resTable.NumberOfMatchedElements / this.ThreadCount;

            if (addition == 0)
            {
                throw new ArgumentException($"{this.GetType()}, a range for a thread cannot be 0.");
            }

            var lastComp   = RowEqualityComparerGroupKey.Factory(resTable, comparers, true);
            var lastHasher = new RowHasher(hashers);

            lastHasher.SetCache(lastComp.comparers);

            // It needs only comparator that has no comparers set as a cache to some hasher.
            var globalGroups = new ConcurrentDictionary <GroupDictKey, AggregateBucketResult[]>(lastComp.Clone(cacheResults: false));

            for (int i = 0; i < jobs.Length - 1; i++)
            {
                var tmpComp = lastComp.Clone(cacheResults: true);
                var tmpHash = lastHasher.Clone();
                tmpHash.SetCache(tmpComp.comparers);
                jobs[i]  = CreateJob(tmpHash, tmpComp, aggs, resTable, current, current + addition, globalGroups);
                current += addition;
            }
            jobs[jobs.Length - 1] = CreateJob(lastHasher, lastComp, aggs, resTable, current, resTable.NumberOfMatchedElements, globalGroups);
            return(jobs);
        }
예제 #3
0
        public static RowEqualityComparerInt Factory(ITableResults resTable, ExpressionComparer[] comparers, RowHasher hasher, bool cacheResults)
        {
            var newComparers = comparers.CloneHard(cacheResults);

            var newHasher = hasher.Clone();

            if (cacheResults)
            {
                newHasher.SetCache(newComparers);
            }
            else
            {
                newHasher.UnsetCache();
            }

            return(new RowEqualityComparerInt(resTable, newComparers, newHasher, cacheResults));
        }
 /// <summary>
 /// Clones comparer and hasher. The cache is always set to true even for the hasher.
 /// </summary>
 protected static void CloneHasherAndComparer(RowEqualityComparerGroupKey comparer, RowHasher hasher, out RowEqualityComparerGroupKey retComparer, out RowHasher retHasher)
 {
     retComparer = comparer.Clone(cacheResults: true);
     retHasher   = hasher.Clone();
     retHasher.SetCache(retComparer.comparers);
 }