private bool TryMergeCellQueries(
            CellTreeOpType opType,
            ref CellTreeNode node1,
            CellTreeNode node2)
        {
            LeafCellTreeNode leafCellTreeNode1 = node1 as LeafCellTreeNode;
            LeafCellTreeNode leafCellTreeNode2 = node2 as LeafCellTreeNode;
            CellQuery        mergedQuery1;
            CellQuery        mergedQuery2;

            if (!CellTreeSimplifier.TryMergeTwoCellQueries(leafCellTreeNode1.LeftCellWrapper.RightCellQuery, leafCellTreeNode2.LeftCellWrapper.RightCellQuery, opType, out mergedQuery1) || !CellTreeSimplifier.TryMergeTwoCellQueries(leafCellTreeNode1.LeftCellWrapper.LeftCellQuery, leafCellTreeNode2.LeftCellWrapper.LeftCellQuery, opType, out mergedQuery2))
            {
                return(false);
            }
            OpCellTreeNode opCellTreeNode = new OpCellTreeNode(this.m_viewgenContext, opType);

            opCellTreeNode.Add(node1);
            opCellTreeNode.Add(node2);
            if (opType != CellTreeOpType.FOJ)
            {
                ;
            }
            LeftCellWrapper cellWrapper = new LeftCellWrapper(this.m_viewgenContext.ViewTarget, opCellTreeNode.Attributes, opCellTreeNode.LeftFragmentQuery, mergedQuery2, mergedQuery1, this.m_viewgenContext.MemberMaps, leafCellTreeNode1.LeftCellWrapper.Cells.Concat <Cell>(leafCellTreeNode2.LeftCellWrapper.Cells));

            node1 = (CellTreeNode) new LeafCellTreeNode(this.m_viewgenContext, cellWrapper, opCellTreeNode.RightFragmentQuery);
            return(true);
        }
Exemplo n.º 2
0
        private static CellTreeNode GenerateSimplifiedView(
            CellTreeNode basicView,
            List <LeftCellWrapper> usedCells)
        {
            int count = usedCells.Count;

            for (int cellNum = 0; cellNum < count; ++cellNum)
            {
                usedCells[cellNum].RightCellQuery.InitializeBoolExpressions(count, cellNum);
            }
            return(CellTreeSimplifier.MergeNodes(basicView));
        }
        private CellTreeNode SimplifyTreeByMergingNodes(CellTreeNode rootNode)
        {
            if (rootNode is LeafCellTreeNode)
            {
                return(rootNode);
            }
            rootNode = this.RestructureTreeForMerges(rootNode);
            List <CellTreeNode> children = rootNode.Children;

            for (int index = 0; index < children.Count; ++index)
            {
                children[index] = this.SimplifyTreeByMergingNodes(children[index]);
            }
            bool flag1 = CellTreeNode.IsAssociativeOp(rootNode.OpType);
            List <CellTreeNode> cellTreeNodeList = !flag1?CellTreeSimplifier.GroupNonAssociativeLeafChildren(children) : CellTreeSimplifier.GroupLeafChildrenByExtent(children);

            OpCellTreeNode opCellTreeNode = new OpCellTreeNode(this.m_viewgenContext, rootNode.OpType);
            CellTreeNode   node1          = (CellTreeNode)null;
            bool           flag2          = false;

            foreach (CellTreeNode node2 in cellTreeNodeList)
            {
                if (node1 == null)
                {
                    node1 = node2;
                }
                else
                {
                    bool flag3 = false;
                    if (!flag2 && node1.OpType == CellTreeOpType.Leaf && node2.OpType == CellTreeOpType.Leaf)
                    {
                        flag3 = this.TryMergeCellQueries(rootNode.OpType, ref node1, node2);
                    }
                    if (!flag3)
                    {
                        opCellTreeNode.Add(node1);
                        node1 = node2;
                        if (!flag1)
                        {
                            flag2 = true;
                        }
                    }
                }
            }
            opCellTreeNode.Add(node1);
            return(opCellTreeNode.AssociativeFlatten());
        }
Exemplo n.º 4
0
        private static CellTreeNode GenerateSimplifiedView(CellTreeNode basicView, List <LeftCellWrapper> usedCells)
        {
            Debug.Assert(false == basicView.IsEmptyRightFragmentQuery, "Basic view is empty?");

            // create 'joined' variables, one for each cell
            // We know (say) that out of the 10 cells that we were given, only 7 (say) were
            // needed to construct the view for this extent.
            var numBoolVars = usedCells.Count;

            // We need the boolean expressions in Simplify. Precisely ont boolean expression is set to
            // true in each cell query

            for (var i = 0; i < numBoolVars; i++)
            {
                // In the ith cell, set its boolean to be true (i.e., ith boolean)
                usedCells[i].RightCellQuery.InitializeBoolExpressions(numBoolVars, i);
            }

            var simplifiedView = CellTreeSimplifier.MergeNodes(basicView);

            return(simplifiedView);
        }
        private CellTreeNode RestructureTreeForMerges(CellTreeNode rootNode)
        {
            List <CellTreeNode> children = rootNode.Children;

            if (!CellTreeNode.IsAssociativeOp(rootNode.OpType) || children.Count <= 1)
            {
                return(rootNode);
            }
            Set <LeafCellTreeNode> commonGrandChildren = CellTreeSimplifier.GetCommonGrandChildren(children);

            if (commonGrandChildren == null)
            {
                return(rootNode);
            }
            CellTreeOpType        opType             = children[0].OpType;
            List <OpCellTreeNode> opCellTreeNodeList = new List <OpCellTreeNode>(children.Count);

            foreach (OpCellTreeNode opCellTreeNode1 in children)
            {
                List <LeafCellTreeNode> leafCellTreeNodeList = new List <LeafCellTreeNode>(opCellTreeNode1.Children.Count);
                foreach (LeafCellTreeNode child in opCellTreeNode1.Children)
                {
                    if (!commonGrandChildren.Contains(child))
                    {
                        leafCellTreeNodeList.Add(child);
                    }
                }
                OpCellTreeNode opCellTreeNode2 = new OpCellTreeNode(this.m_viewgenContext, opCellTreeNode1.OpType, Helpers.AsSuperTypeList <LeafCellTreeNode, CellTreeNode>((IEnumerable <LeafCellTreeNode>)leafCellTreeNodeList));
                opCellTreeNodeList.Add(opCellTreeNode2);
            }
            CellTreeNode cellTreeNode1 = (CellTreeNode) new OpCellTreeNode(this.m_viewgenContext, rootNode.OpType, Helpers.AsSuperTypeList <OpCellTreeNode, CellTreeNode>((IEnumerable <OpCellTreeNode>)opCellTreeNodeList));
            CellTreeNode cellTreeNode2 = (CellTreeNode) new OpCellTreeNode(this.m_viewgenContext, opType, Helpers.AsSuperTypeList <LeafCellTreeNode, CellTreeNode>((IEnumerable <LeafCellTreeNode>)commonGrandChildren));

            return(new OpCellTreeNode(this.m_viewgenContext, opType, new CellTreeNode[2]
            {
                cellTreeNode2,
                cellTreeNode1
            }).AssociativeFlatten());
        }
Exemplo n.º 6
0
        // effects: see CellTreeNode.Simplify below
        internal static CellTreeNode MergeNodes(CellTreeNode rootNode)
        {
            var simplifier = new CellTreeSimplifier(rootNode.ViewgenContext);

            return(simplifier.SimplifyTreeByMergingNodes(rootNode));
        }
        internal static bool TryMergeTwoCellQueries(
            CellQuery query1,
            CellQuery query2,
            CellTreeOpType opType,
            out CellQuery mergedQuery)
        {
            mergedQuery = (CellQuery)null;
            BoolExpression boolExpression1 = (BoolExpression)null;
            BoolExpression boolExpression2 = (BoolExpression)null;

            switch (opType)
            {
            case CellTreeOpType.Union:
            case CellTreeOpType.FOJ:
                boolExpression1 = BoolExpression.True;
                boolExpression2 = BoolExpression.True;
                break;

            case CellTreeOpType.LOJ:
            case CellTreeOpType.LASJ:
                boolExpression2 = BoolExpression.True;
                break;
            }
            Dictionary <MemberPath, MemberPath> remap = new Dictionary <MemberPath, MemberPath>(MemberPath.EqualityComparer);

            if (!query1.Extent.Equals((object)query2.Extent))
            {
                return(false);
            }
            MemberPath     extentMemberPath = query1.SourceExtentMemberPath;
            BoolExpression and1             = BoolExpression.True;
            BoolExpression and2             = BoolExpression.True;
            BoolExpression boolExpression3  = (BoolExpression)null;

            switch (opType)
            {
            case CellTreeOpType.Union:
            case CellTreeOpType.FOJ:
                and1            = BoolExpression.CreateAnd(query1.WhereClause, boolExpression1);
                and2            = BoolExpression.CreateAnd(query2.WhereClause, boolExpression2);
                boolExpression3 = BoolExpression.CreateOr(BoolExpression.CreateAnd(query1.WhereClause, boolExpression1), BoolExpression.CreateAnd(query2.WhereClause, boolExpression2));
                break;

            case CellTreeOpType.LOJ:
                and2            = BoolExpression.CreateAnd(query2.WhereClause, boolExpression2);
                boolExpression3 = query1.WhereClause;
                break;

            case CellTreeOpType.IJ:
                boolExpression3 = BoolExpression.CreateAnd(query1.WhereClause, query2.WhereClause);
                break;

            case CellTreeOpType.LASJ:
                and2            = BoolExpression.CreateAnd(query2.WhereClause, boolExpression2);
                boolExpression3 = BoolExpression.CreateAnd(query1.WhereClause, BoolExpression.CreateNot(and2));
                break;
            }
            List <BoolExpression> boolExprs = CellTreeSimplifier.MergeBoolExpressions(query1, query2, and1, and2, opType);

            ProjectedSlot[] result;
            if (!ProjectedSlot.TryMergeRemapSlots(query1.ProjectedSlots, query2.ProjectedSlots, out result))
            {
                return(false);
            }
            BoolExpression whereClause = boolExpression3.RemapBool(remap);

            CellQuery.SelectDistinct elimDupl = CellTreeSimplifier.MergeDupl(query1.SelectDistinctFlag, query2.SelectDistinctFlag);
            whereClause.ExpensiveSimplify();
            mergedQuery = new CellQuery(result, whereClause, boolExprs, elimDupl, extentMemberPath);
            return(true);
        }
 // effects: see CellTreeNode.Simplify below
 internal static CellTreeNode MergeNodes(CellTreeNode rootNode)
 {
     var simplifier = new CellTreeSimplifier(rootNode.ViewgenContext);
     return simplifier.SimplifyTreeByMergingNodes(rootNode);
 }