예제 #1
0
        /// <summary>
        /// Creates groups and computes aggregate values for each group.
        /// </summary>
        /// <param name="equalityComparer"> Equality comparer where T is group key and computes internaly the hash for each row from the result table.</param>
        /// <param name="resTable"> A result table from the matching clause.</param>
        /// <param name="hasher"> Hasher of rows. </param>
        /// <returns> Aggregate results. </returns>
        private GroupByResults SingleThreadGroupBy(RowHasher hasher, RowEqualityComparerGroupKey equalityComparer, ITableResults resTable)
        {
            #region DECL
            hasher.SetCache(equalityComparer.comparers);
            var aggResults = AggregateListResults.CreateListResults(this.aggregates);
            var groups     = new Dictionary <GroupDictKey, int>(equalityComparer);
            int position;
            TableResults.RowProxy row;
            GroupDictKey          key;
            #endregion DECL

            for (int i = 0; i < resTable.NumberOfMatchedElements; i++)
            {
                row = resTable[i];
                key = new GroupDictKey(hasher.Hash(in row), i); // It's a struct.
                if (!groups.TryGetValue(key, out position))
                {
                    position = groups.Count;
                    groups.Add(key, position);
                }

                for (int j = 0; j < aggregates.Length; j++)
                {
                    aggregates[j].Apply(in row, aggResults[j], position);
                }
            }

            return(new GroupByResultsList(groups, aggResults, resTable));
        }
 public GroupJob(Aggregate[] aggregates, RowEqualityComparerGroupKey comparer, RowHasher hasher, AggregateBucketResult[] spareBuckets, ITableResults resTable)
 {
     this.resTable     = resTable;
     comparer.resTable = this.resTable;
     this.groups       = new Dictionary <GroupDictKey, int>(comparer);
     this.hasher       = hasher;
     this.spareBuckets = spareBuckets;
     this.aggResults   = AggregateListResults.CreateListResults(aggregates);
 }
 public GroupByJobMixListsBuckets(RowHasher hasher, RowEqualityComparerGroupKey comparer, Aggregate[] aggregates, ITableResults resTable, int start, int end, ConcurrentDictionary <GroupDictKey, AggregateBucketResult[]> globalGroups) : base(hasher, aggregates, resTable, start, end, globalGroups)
 {
     this.groups     = new Dictionary <GroupDictKey, int>(comparer);
     this.aggResults = AggregateListResults.CreateListResults(aggregates);
 }
 public GroupByJobLists(RowHasher hasher, RowEqualityComparerGroupKey comparer, Aggregate[] aggregates, ITableResults resTable, int start, int end) : base(hasher, comparer, aggregates, resTable, start, end)
 {
     this.groups     = new Dictionary <GroupDictKey, int>(comparer);
     this.aggResults = AggregateListResults.CreateListResults(aggregates);
 }