示例#1
0
        internal static TableEngine <TInput> Create(Graph <Key, Int32> dependencyGraph, Dictionary <ColumnKey, Column <TInput> > columns, Dictionary <AggregateKey, Aggregate <TInput> > aggregates, ImmutableArray <AggregateKey> requestedAggregates)
        {
            if (dependencyGraph == null)
            {
                throw new ArgumentNullException(nameof(dependencyGraph));
            }

            var(layers, detached) = dependencyGraph.TopologicalSort();

            var columnIndexes    = new Dictionary <ColumnKey, Int32>();
            var aggregateIndexes = new Dictionary <AggregateKey, Int32>();

            foreach (var layer in layers)
            {
                foreach (var key in layer)
                {
                    key.Switch
                    (
                        columnKey => columnIndexes.Add(columnKey, columnIndexes.Count),
                        aggregateKey => aggregateIndexes.Add(aggregateKey, aggregateIndexes.Count)
                    );
                }
            }

            Dictionary <Key, ImmutableArray <Int32> > columnMappings    = new Dictionary <Key, ImmutableArray <Int32> >();
            Dictionary <Key, ImmutableArray <Int32> > aggregateMappings = new Dictionary <Key, ImmutableArray <Int32> >();

            foreach (ColumnKey columnKey in columns.Keys)
            {
                Column <TInput> column = columns[columnKey];

                columnMappings.Add(columnKey, column.ColumnDependencies.Select(ck => columnIndexes[ck]).ToImmutableArray());
                aggregateMappings.Add(columnKey, column.AggregateDependencies.Select(ak => aggregateIndexes[ak]).ToImmutableArray());
            }

            foreach (AggregateKey aggregateKey in aggregates.Keys)
            {
                Aggregate <TInput> aggregate = aggregates[aggregateKey];

                columnMappings.Add(aggregateKey, aggregate.ColumnDependencies.Select(ck => columnIndexes[ck]).ToImmutableArray());
                aggregateMappings.Add(aggregateKey, aggregate.AggregateDependencies.Select(ak => aggregateIndexes[ak]).ToImmutableArray());
            }

            return(new TableEngine <TInput>(
                       layers,
                       columnIndexes,
                       aggregateIndexes,
                       columns,
                       aggregates,
                       columnMappings,
                       aggregateMappings,
                       requestedAggregates,
                       AggregateRow.Create(aggregateIndexes.Count)
                       ));
        }
示例#2
0
 private TableEngine(
     List <List <Key> > layers,
     Dictionary <ColumnKey, Int32> columnIndexes,
     Dictionary <AggregateKey, Int32> aggregateIndexes,
     Dictionary <ColumnKey, Column <TInput> > columns,
     Dictionary <AggregateKey, Aggregate <TInput> > aggregates,
     Dictionary <Key, ImmutableArray <Int32> > columnMappings,
     Dictionary <Key, ImmutableArray <Int32> > aggregateMappings,
     ImmutableArray <AggregateKey> requestedAggregateKeys,
     AggregateRow aggregateRow
     )
 {
     Layers                      = layers;
     ColumnIndexes               = columnIndexes;
     AggregateIndexes            = aggregateIndexes;
     Columns                     = columns;
     Aggregates                  = aggregates;
     ColumnDependencyMappings    = columnMappings;
     AggregateDependencyMappings = aggregateMappings;
     RequestedAggregateKeys      = requestedAggregateKeys;
     AggregateRow                = aggregateRow;
 }
示例#3
0
 internal AggregateValueBag(AggregateRow row, ImmutableArray <Int32> indexMappings)
 {
     Row           = row;
     IndexMappings = indexMappings;
 }