Ejemplo n.º 1
0
        public void SortBackwardsSequenceOfLengthWithIndices(int length)
        {
            var comparer = new RefComparerAdapter <Comparer <int>, int>(Comparer <int> .Default);

            int[] indicesA = GenerateSequence(length), indicesB = GenerateSequence(length);

            var seq = GenerateSequence(length, 2);

            Array.Reverse(seq);

            var dl = new DenseList <int>(seq);

            dl.Sort(comparer, indicesA);

            Array.Sort(
                // HACK: Make a temporary copy of the array because we only want to sort the indices.
                seq.ToArray(), indicesB, Comparer <int> .Default
                );

            try {
                Assert.AreEqual(MapIndirect(seq, indicesB), MapIndirect(dl.ToArray(), indicesA), "indirect mapped values");
            } catch {
                Console.WriteLine("dl.values: {0}", string.Join(", ", dl.ToArray()));
                Console.WriteLine("dl.indices: {0}", string.Join(", ", indicesA.ToArray()));
                Console.WriteLine("arr.values: {0}", string.Join(", ", seq.ToArray()));
                Console.WriteLine("arr.indices: {0}", string.Join(", ", indicesB.ToArray()));
                Console.WriteLine();
                Console.WriteLine("dl.mapindirect: {0}", string.Join(", ", MapIndirect(dl.ToArray(), indicesA)));
                Console.WriteLine("arr.mapindirect: {0}", string.Join(", ", MapIndirect(seq, indicesB)));

                throw;
            }
        }
Ejemplo n.º 2
0
        public static void IndexedSort <TElement, TComparer>(
            ArraySegment <TElement> data, ArraySegment <int> indices, TComparer comparer
            )
            where TComparer : IComparer <TElement>
        {
            var adapter = new RefComparerAdapter <TComparer, TElement>(comparer);

            IndexedSortRef(data, indices, adapter);
        }
Ejemplo n.º 3
0
        public static void FastCLRSort <TElement, TComparer>(
            TElement[] data, TComparer comparer, int?offset = null, int?count = null
            )
            where TComparer : IComparer <TElement>
        {
            var adapter = new RefComparerAdapter <TComparer, TElement>(comparer);

            FastCLRSortRef(data, adapter, offset, count);
        }
Ejemplo n.º 4
0
        public static void IndexedSort <TElement, TComparer>(
            TElement[] data, int[] indices,
            TComparer comparer, int?offset = null, int?count = null
            )
            where TComparer : IComparer <TElement>
        {
            var adapter = new RefComparerAdapter <TComparer, TElement>(comparer);

            IndexedSortRef(data, indices, adapter, offset, count);
        }
Ejemplo n.º 5
0
        public void SortBackwardsSequenceOfLength(int length)
        {
            var comparer = new RefComparerAdapter <Comparer <int>, int>(Comparer <int> .Default);

            var seq = GenerateSequence(length);

            Array.Reverse(seq);
            var dl = new DenseList <int>(seq);

            dl.Sort(comparer);
            Array.Sort(seq, Comparer <int> .Default);
            Assert.AreEqual(seq, dl.ToArray());
        }
Ejemplo n.º 6
0
        public void SortRandomSequencesOfLength(int length)
        {
            var comparer      = new RefComparerAdapter <Comparer <int>, int>(Comparer <int> .Default);
            var r             = new System.Random(37);
            int sequenceCount = (length >= 500) ? 128 : 1024;

            for (int i = 0; i < sequenceCount; i++)
            {
                var seq = GenerateRandomInts(r, length);
                var dl  = new DenseList <int>(seq);
                dl.Sort(comparer);
                Array.Sort(seq, Comparer <int> .Default);
                Assert.AreEqual(seq, dl.ToArray());
            }
        }
Ejemplo n.º 7
0
        public void SortRandomSequencesOfLengthWithIndices(int length)
        {
            var comparer      = new RefComparerAdapter <Comparer <int>, int>(Comparer <int> .Default);
            var r             = new System.Random(37);
            int sequenceCount = (length >= 500) ? 128 : 1024;

            int[] indicesA = GenerateSequence(length), indicesB = GenerateSequence(length);

            for (int i = 0; i < sequenceCount; i++)
            {
                Array.Sort(indicesA);
                Array.Sort(indicesB);

                var seq = GenerateRandomInts(r, length);
                var dl  = new DenseList <int>(seq);

                dl.Sort(comparer, indicesB);

                // FIXME: Why does the argument order here need to be the opposite of the backwards sequence test?
                Array.Sort(
                    // HACK: Make a temporary copy of the array because we only want to sort the indices.
                    indicesB, seq.ToArray(), Comparer <int> .Default
                    );

                try {
                    Assert.AreEqual(MapIndirect(seq, indicesB), MapIndirect(dl.ToArray(), indicesA), "indirect mapped values");
                } catch {
                    Console.WriteLine("dl.values: {0}", string.Join(", ", dl.ToArray()));
                    Console.WriteLine("dl.indices: {0}", string.Join(", ", indicesA.ToArray()));
                    Console.WriteLine("arr.values: {0}", string.Join(", ", seq.ToArray()));
                    Console.WriteLine("arr.indices: {0}", string.Join(", ", indicesB.ToArray()));
                    Console.WriteLine();
                    Console.WriteLine("dl.mapindirect: {0}", string.Join(", ", MapIndirect(dl.ToArray(), indicesA)));
                    Console.WriteLine("arr.mapindirect: {0}", string.Join(", ", MapIndirect(seq, indicesB)));

                    throw;
                }
            }
        }