Esempio n. 1
0
        private static SparseIndexing GenerateIndexes(SortStruct[] data)
        {
            SparseIndexing   Indexes  = new SparseIndexing();
            List <SparseSet> elements = new List <SparseSet>();
            var       length          = data.Length;
            SparseSet current         = default(SparseSet);

            if (length == 0)
            {
                return(Indexes);
            }
            current.Start = data[0].SparseSpace;
            int expected = data[0].SparseSpace + 1;

            for (int i = 1; i < length; i++)
            {
                if (data[i].SparseSpace != expected)
                {
                    current.Stop         = data[i - 1].SparseSpace;
                    current.BaseLocation = 0;
                    elements.Add(current);
                    current.Start = data[i].SparseSpace;
                }
                expected = data[i].SparseSpace + 1;
            }
            current.Stop = data[length - 1].SparseSpace;
            elements.Add(current);
            Indexes.Indexes = elements.ToArray();
            return(Indexes);
        }
Esempio n. 2
0
        private static List <SparseSet> GenerateIndexes(SortStruct[] indexes)
        {
            List <SparseSet> meta = new List <SparseSet>();
            var length            = indexes.Length;
            // Phase 1: Add in all of the sets we are going to see
            SparseSet currentSet = new SparseSet();

            currentSet.Start = currentSet.Stop = indexes[0].SparseSpaceSecond;
            List <SparseSet> subSets = new List <SparseSet>();

            for (int i = 1; i < indexes.Length; i++)
            {
                if (indexes[i].SparseSpaceFirst == indexes[i - 1].SparseSpaceFirst)
                {
                    if (indexes[i].SparseSpaceSecond > indexes[i - 1].SparseSpaceSecond + 1)
                    {
                        subSets.Add(currentSet);
                        currentSet.Start = currentSet.Stop = indexes[i].SparseSpaceSecond;
                    }
                    else
                    {
                        currentSet.Stop = indexes[i].SparseSpaceSecond;
                    }
                }
                else
                {
                    subSets.Add(currentSet);
                    meta.Add(new SparseSet()
                    {
                        Start    = indexes[i - 1].SparseSpaceFirst,
                        Stop     = indexes[i - 1].SparseSpaceFirst,
                        SubIndex = new SparseIndexing()
                        {
                            Indexes = subSets.ToArray()
                        }
                    });
                    subSets.Clear();
                    currentSet.Start = currentSet.Stop = indexes[i].SparseSpaceSecond;
                }
            }
            subSets.Add(currentSet);
            meta.Add(new SparseSet()
            {
                Start    = indexes[length - 1].SparseSpaceFirst,
                Stop     = indexes[length - 1].SparseSpaceFirst,
                SubIndex = new SparseIndexing()
                {
                    Indexes = subSets.ToArray()
                }
            });
            return(meta);
        }
Esempio n. 3
0
        private bool TansformD(SparseSet oSet, ref int d, out SparseSet dSet)
        {
            var oIndex = oSet.SubIndex;

            dSet = default(SparseSet);
            var subIndexes = oIndex.Indexes;

            if (subIndexes.Length >= LookUpLinearMax)
            {
                var min = 0;
                var max = oIndex.Indexes.Length - 1;
                while (min <= max)
                {
                    var mid = ((min + max) >> 1);

                    if (d < subIndexes[mid].Start)
                    {
                        max = mid - 1;
                    }
                    else if (d > subIndexes[mid].Stop)
                    {
                        min = mid + 1;
                    }
                    else
                    {
                        // then we are in a valid range
                        d    = (d - subIndexes[mid].Start + subIndexes[mid].BaseLocation);
                        dSet = subIndexes[mid];
                        return(true);
                    }
                }
            }
            else
            {
                for (var i = 0; i < subIndexes.Length; i++)
                {
                    if ((subIndexes[i].Start <= d & subIndexes[i].Stop >= d))
                    {
                        // then we are in a valid range
                        d    = (d - subIndexes[i].Start + subIndexes[i].BaseLocation);
                        dSet = subIndexes[i];
                        return(true);
                    }
                }
            }
            return(false);
        }
Esempio n. 4
0
 private bool TansformO(SparseSet[] subIndexes, ref int o, out SparseSet oSet)
 {
     // if it is large use binary search
     if (subIndexes.Length < LookUpLinearMax)
     {
         //otherwise just do a linear search\
         for (var i = 0; i < subIndexes.Length; i++)
         {
             if ((subIndexes[i].Start <= o & subIndexes[i].Stop >= o))
             {
                 o    = (o - subIndexes[i].Start + subIndexes[i].BaseLocation);
                 oSet = subIndexes[i];
                 return(true);
             }
         }
     }
     else
     {
         var min = 0;
         var max = subIndexes.Length - 1;
         while (min <= max)
         {
             var mid = ((min + max) >> 1);
             if (o < subIndexes[mid].Start)
             {
                 max = mid - 1;
             }
             else if (o > subIndexes[mid].Stop)
             {
                 min = mid + 1;
             }
             else
             {
                 // then we are in a valid range
                 o    = (o - subIndexes[mid].Start + subIndexes[mid].BaseLocation);
                 oSet = subIndexes[mid];
                 return(true);
             }
         }
     }
     oSet = default(SparseSet);
     return(false);
 }
Esempio n. 5
0
        private bool TransformT(SparseSet dSet, ref int t)
        {
            var dIndex     = dSet.SubIndex;
            var subIndexes = dIndex.Indexes;

            if (subIndexes.Length >= LookUpLinearMax)
            {
                var min = 0;
                var max = dIndex.Indexes.Length - 1;
                while (min <= max)
                {
                    var mid = ((min + max) >> 1);
                    if (t < subIndexes[mid].Start)
                    {
                        max = mid - 1;
                    }
                    else if (t > subIndexes[mid].Stop)
                    {
                        min = mid + 1;
                    }
                    else
                    {
                        // then we are in a valid range
                        t = (t - subIndexes[mid].Start + subIndexes[mid].BaseLocation);
                        return(true);
                    }
                }
            }
            else
            {
                for (var i = 0; i < subIndexes.Length; i++)
                {
                    if ((subIndexes[i].Start <= t & subIndexes[i].Stop >= t))
                    {
                        // then we are in a valid range
                        t = (t - subIndexes[i].Start + subIndexes[i].BaseLocation);
                        return(true);
                    }
                }
            }
            return(false);
        }
Esempio n. 6
0
        private static List <Pair <int, List <SparseSet> > > GenerateIndexes(SortStruct[] indexes)
        {
            var meta       = new List <Pair <int, List <SparseSet> > >();
            var length     = indexes.Length;
            var subSetsI   = new List <SparseSet>();
            var subSetsJ   = new List <SparseSet>();
            var currentSet = new SparseSet();

            currentSet.Start = currentSet.Stop = indexes[0].SparseSpaceThird;
            for (var i = 1; i < length; i++)
            {
                if (indexes[i].SparseSpaceFirst == indexes[i - 1].SparseSpaceFirst)
                {
                    if (indexes[i].SparseSpaceSecond == indexes[i - 1].SparseSpaceSecond)
                    {
                        if (indexes[i].SparseSpaceThird > indexes[i - 1].SparseSpaceThird + 1)
                        {
                            subSetsJ.Add(currentSet);
                            currentSet.Stop = currentSet.Start = indexes[i].SparseSpaceThird;
                        }
                        else
                        {
                            if (currentSet.Stop == indexes[i].SparseSpaceThird)
                            {
                                throw new InvalidOperationException(string.Format("Sparse space was duplicated!\r\n{0}->{1}->{2} had more than one definition!", indexes[i].SparseSpaceFirst,
                                                                                  indexes[i].SparseSpaceSecond, indexes[i].SparseSpaceThird));
                            }
                            currentSet.Stop = indexes[i].SparseSpaceThird;
                        }
                    }
                    else
                    {
                        subSetsJ.Add(currentSet);
                        subSetsI.Add(new SparseSet()
                        {
                            Start    = indexes[i - 1].SparseSpaceSecond,
                            Stop     = indexes[i - 1].SparseSpaceSecond,
                            SubIndex = new SparseIndexing()
                            {
                                Indexes = subSetsJ.ToArray()
                            }
                        });
                        subSetsJ.Clear();
                        currentSet.Start = currentSet.Stop = indexes[i].SparseSpaceThird;
                    }
                }
                else
                {
                    subSetsJ.Add(currentSet);
                    subSetsI.Add(new SparseSet()
                    {
                        Start    = indexes[i - 1].SparseSpaceSecond,
                        Stop     = indexes[i - 1].SparseSpaceSecond,
                        SubIndex = new SparseIndexing()
                        {
                            Indexes = subSetsJ.ToArray()
                        }
                    });
                    subSetsJ.Clear();
                    meta.Add(new Pair <int, List <SparseSet> >(indexes[i - 1].SparseSpaceFirst, subSetsI));
                    subSetsI         = new List <SparseSet>();
                    currentSet.Start = currentSet.Stop = indexes[i].SparseSpaceThird;
                }
            }
            subSetsJ.Add(currentSet);
            subSetsI.Add(new SparseSet()
            {
                Start    = indexes[length - 1].SparseSpaceSecond,
                Stop     = indexes[length - 1].SparseSpaceSecond,
                SubIndex = new SparseIndexing()
                {
                    Indexes = subSetsJ.ToArray()
                }
            });
            subSetsJ.Clear();
            meta.Add(new Pair <int, List <SparseSet> >(indexes[length - 1].SparseSpaceFirst, subSetsI));
            return(meta);
        }