Exemplo n.º 1
0
        private DataNode <string, Cell> BuildTree(Set <int> groupbySet, string leafColumn)
        {
            EnumeratorMgr em = new EnumeratorMgr();

            foreach (int colOrdinal in groupbySet)
            {
                em.AddEnumerable(_indexes[colOrdinal]);
            }

            int leafColOrdinal           = _colMap.FindT2(leafColumn);
            DataNode <string, Cell> root = new DataNode <string, Cell>("root");

            while (em.MoveNext())
            {
                // Get current leaf set
                // All the leaves share the same parent / parents
                Set <int> leafSet = ProduceLeafSet(em, leafColOrdinal);
                if (leafSet == null || leafSet.Count < 1)
                {
                    continue;
                }

                // Build parent nodes for these leaves
                DataRow row = _dataTbl.Rows[leafSet[0]];
                DataNode <string, Cell> currentParent = root;
                foreach (int colOrdinal in groupbySet)
                {
                    string nodeName = row[colOrdinal].ToString();
                    DataNode <string, Cell> nodeTmp = null;
                    if (!currentParent.Children.TryGetValue(nodeName, out nodeTmp))
                    {
                        nodeTmp      = AddChild(currentParent, nodeName);
                        nodeTmp.Data = new Cell(leafSet[0], colOrdinal);
                    }

                    System.Diagnostics.Debug.Assert(nodeTmp.Data != null);
                    currentParent = nodeTmp; // Move one level down
                }

                // Add these leaves
                DataRowCollection rows = _dataTbl.Rows;
                foreach (int rowIndex in leafSet)
                {
                    row = _dataTbl.Rows[rowIndex];
                    DataNode <string, Cell> leafNode = AddChild(currentParent, rowIndex.ToString());
                    leafNode.Data = new Cell(rowIndex, -1);
                }
            }

            return(root);
        }
Exemplo n.º 2
0
        /// <summary> All the leaves share the same parent / parents </summary>
        private Set <int> ProduceLeafSet(EnumeratorMgr em, int leafColOrdinal)
        {
            // Get current leaf set
            Set <int> leafSet = null;

            foreach (IEnumerator <KeyValuePair <string, Set <int> > > colEnum in em.Current)
            {
                if (leafSet == null)
                {
                    leafSet = colEnum.Current.Value;
                }
                else
                {
                    leafSet = leafSet.Intersect(colEnum.Current.Value);
                }
            }

            // To do: sort the leafSet by leaf column
            return(leafSet);
        }