Example #1
0
            Grouping.GroupCollection Grouping.IGroupAlgorithm.Group(Column sourceColumn, ArrayRange indices, SortOrder order)
            {
                DupCollection coll = new DupCollection();

                if (order == SortOrder.None)
                {
                    order = SortOrder.Ascending;
                }
                coll.m_sortedIndex = sourceColumn.GetSortIndex(order, indices, false);
                System.Collections.Generic.List <DupGroup> groups = new System.Collections.Generic.List <DupGroup>();
                int iGroupFirst = 0;

                for (int i = 1, j = 0; i < coll.m_sortedIndex.Length; j = i++)
                {
                    if (sourceColumn.CompareRow(coll.m_sortedIndex[j], coll.m_sortedIndex[i]) != 0)
                    {
                        //create group;
                        Range range = Range.FirstToLast(iGroupFirst, i);
                        groups.Add(new DupGroup(range));
                        iGroupFirst = i;
                    }
                }
                Range rangeLast = Range.FirstToLast(iGroupFirst, coll.m_sortedIndex.Length);

                if (rangeLast.Length > 0)
                {
                    groups.Add(new DupGroup(rangeLast));
                }
                coll.m_Groups = groups.ToArray();

                return(coll);
            }
Example #2
0
                public override ArrayRange GetIndices(Grouping.GroupCollection coll)
                {
                    DupCollection dcoll = (DupCollection)coll;

                    return(new ArrayRange(dcoll.m_sortedIndex, range));
                }
Example #3
0
            Grouping.GroupCollection Grouping.IGroupAlgorithm.Group(Column sourceColumn, ArrayRange indices, SortOrder order)
            {
                using (Profiling.GetMarker(Profiling.MarkerId.GroupByDuplicate).Auto())
                {
                    DupCollection coll = new DupCollection();
                    if (order == SortOrder.None)
                    {
                        order = SortOrder.Ascending;
                    }
                    coll.m_sortedIndex = sourceColumn.GetSortIndex(order, indices, false);
                    System.Collections.Generic.List <DupGroup> groups = new System.Collections.Generic.List <DupGroup>();
                    int iGroupFirst = 0;
                    for (int i = 1, j = 0; i < coll.m_sortedIndex.Length; j = i++)
                    {
                        if (sourceColumn.CompareRow(coll.m_sortedIndex[j], coll.m_sortedIndex[i]) != 0)
                        {
                            //create group;
                            Range range = Range.FirstLast(iGroupFirst, i);
                            groups.Add(new DupGroup(range));
                            iGroupFirst = i;
                        }
                    }
                    Range rangeLast = Range.FirstLast(iGroupFirst, coll.m_sortedIndex.Length);
                    if (rangeLast.length > 0)
                    {
                        groups.Add(new DupGroup(rangeLast));
                    }
                    coll.m_Groups = groups.ToArray();


#if (PROFILER_DEBUG_TEST)
                    {
                        UnityEngine.Debug.LogWarning("Testing GroupByDuplicate result...");
                        //test if grouping data is good
                        foreach (var g in coll.m_Groups)
                        {
                            Debug.Assert(g.range.first >= 0);
                            Debug.Assert(g.range.first < coll.m_sortedIndex.Length);
                            Debug.Assert(g.range.last > 0);
                            Debug.Assert(g.range.last <= coll.m_sortedIndex.Length);

                            //indices before should all be -1 compared to group's first index
                            for (long i = 0; i != g.range.first; ++i)
                            {
                                int c = sourceColumn.CompareRow(coll.m_sortedIndex[i], coll.m_sortedIndex[g.range.first]);
                                if (c != -1)
                                {
                                    Debug.Assert(c == -1, "index " + i + " should be -1 compared to group starting at index " + g.range.first + "."
                                                 + "\n Result=" + c
                                                 + "\n val[" + i + "]=" + sourceColumn.GetRowValueString(coll.m_sortedIndex[i])
                                                 + "\n val[" + g.range.first + "]=" + sourceColumn.GetRowValueString(coll.m_sortedIndex[g.range.first])
                                                 );
                                }
                            }
                            //indices inside group should all be 0 compared to group's first index
                            for (long i = g.range.first; i != g.range.last; ++i)
                            {
                                int c = sourceColumn.CompareRow(coll.m_sortedIndex[i], coll.m_sortedIndex[g.range.first]);
                                if (c != 0)
                                {
                                    Debug.Assert(c == 0, "index " + i + " should be 0 compared to group starting at index " + g.range.first + "."
                                                 + "\n Result=" + c
                                                 + "\n val[" + i + "]=" + sourceColumn.GetRowValueString(coll.m_sortedIndex[i])
                                                 + "\n val[" + g.range.first + "]=" + sourceColumn.GetRowValueString(coll.m_sortedIndex[g.range.first])
                                                 );
                                }
                            }
                            //indices after group should all be 1 compared to group's first index
                            for (long i = g.range.last; i != coll.m_sortedIndex.Length; ++i)
                            {
                                int c = sourceColumn.CompareRow(coll.m_sortedIndex[i], coll.m_sortedIndex[g.range.first]);
                                if (c != 1)
                                {
                                    Debug.Assert(c == 1, "index " + i + " should be 1 compared to group starting at index " + g.range.first + "."
                                                 + "\n Result=" + c
                                                 + "\n val[" + i + "]=" + sourceColumn.GetRowValueString(coll.m_sortedIndex[i])
                                                 + "\n val[" + g.range.first + "]=" + sourceColumn.GetRowValueString(coll.m_sortedIndex[g.range.first])
                                                 );
                                }
                            }
                        }

                        UnityEngine.Debug.LogWarning("Testing GroupByDuplicate result done");
                    }
#endif
                    return(coll);
                }
            }