Exemple #1
0
        public void TestUsers()
        {
            //const string userId = "1251";
            var db = new Sedgewick();

            var query = (from u in db.Users
                         where u.Active == "Y"
                         select new { u.Name, u.UserId }).ToList();

            foreach (var item in query.OrderBy(c => c.Name))
            {
                Console.WriteLine(item);
            }
        }
Exemple #2
0
        public void TestActiveRecordJoin()
        {
            var db = new Sedgewick();

            var query = from c in db.Employee
                        where c.Ssn == "540046966"
                        join x in db.EmployeeExtension on c.EmployeeId equals x.EmployeeId
                        select new
            {
                Name     = c.NameFirst + " " + c.NameLast,
                Atribute = x.FieldName,
                Values   = x
            };


            foreach (var item in query)
            {
                ObjectDumper.Write(item);
            }
        }
Exemple #3
0
        public void TestActiveRecordVisitor()
        {
            //const string lastName = "ROBINSON";
            //const string zip = "01970";
            const string ssn = "540046966";

            var db = new Sedgewick();

            var query = from c in db.Employee
                        where c.Ssn == ssn
                        join x in db.EmployeeExtension on c.EmployeeId equals x.EmployeeId
                        select new
            {
                Name    = c.NameFirst + " " + c.NameLast,
                Address = c.Address1,
                c.City,
                c.State,
                PostalCode = c.Zip,
                Extensions = x
            };

            // TODO: it looks like DbLinq does not translate the SelectMany for joins
            //       so the join systax must be used until I can fix it?
            //var query = db.Employee
            //    .Where(c => c.Ssn == ssn)
            //    .SelectMany(c => db.EmployeeExtension.Where(x => c.EmployeeId == x.EmployeeId),
            //                (c,x) => new {
            //                                  Name = c.NameFirst + " " + c.NameLast,
            //                                  Address = c.Address1,
            //                                  c.City,
            //                                  c.State,
            //                                  PostalCode = c.Zip,
            //                                  Extensions = x
            //                              });

            foreach (var item in query)
            {
                ObjectDumper.Write(item);
                ObjectDumper.Write(item.Extensions);
            }
        }
Exemple #4
0
        /// <summary>divide source file to N sorted files and return count</summary>
        int DivideAndSortInitial(string fname)
        {
            int           maxCount = 4096 * 8;
            int           idx      = 0;
            List <string> list     = new List <string>();

            //string[] arr = new string[0];
            using (StreamReader sr = new StreamReader(fname))
            {
                while (true)
                {
                    string line = sr.ReadLine();
                    if (line == null)
                    {
                        break;
                    }

                    list.Add(line);

                    if (list.Count == maxCount)
                    {
                        //list.Sort();
                        string[] arr = Sedgewick.Sort(list.ToArray());
                        File.WriteAllLines(tmpPath + "\\p0_" + idx + ".txt", arr);
                        //File.WriteAllLines(tmpPath+"\\p0_"+idx+".txt", list);
                        list.Clear();
                        idx++;
                    }
                }

                if (list.Count > 0)
                {
                    //list.Sort();
                    //File.WriteAllLines(tmpPath + "\\p0_" + idx + ".txt", list);
                    string[] arr = Sedgewick.Sort(list.ToArray());
                    File.WriteAllLines(tmpPath + "\\p0_" + idx + ".txt", arr);
                    idx++;
                }
            }
            return(idx);
        }
Exemple #5
0
        private                               TypeItem[] GetFilteredTypes()
        {
            bool containsMSCorLib = false;

            var typeRelatedAssemblies = ProjectSettings.UseBuiltInNames
                ? TypeCollector.GetAssembliesTypeHasAccessTo(_declaringType, out containsMSCorLib)
                : TypeCollector.GetAssembliesTypeHasAccessTo(_declaringType);

            if (_attribute.IncludeAdditionalAssemblies != null)
            {
                IncludeAdditionalAssemblies(typeRelatedAssemblies);
            }

            var filteredTypes = TypeCollector.GetFilteredTypesFromAssemblies(typeRelatedAssemblies, _attribute);

            bool replaceBuiltInNames = ProjectSettings.UseBuiltInNames && containsMSCorLib;

            int filteredTypesLength = filteredTypes.Count;

            var typeItems = new TypeItem[filteredTypesLength];

            for (int i = 0; i < filteredTypesLength; i++)
            {
                var type = filteredTypes[i];

                string fullTypeName = type.FullName;
                Assert.IsNotNull(fullTypeName);

                if (replaceBuiltInNames)
                {
                    fullTypeName = fullTypeName.ReplaceWithBuiltInName(true);
                }

                typeItems[i] = new TypeItem(type, fullTypeName, _attribute.Grouping);
            }

            Sedgewick.SortInPlace(typeItems);

            return(typeItems);
        }
Exemple #6
0
        static void SortTest1(string[] args)
        {
            CreateRandomFile(@"..\..\dic.txt");
            string[]      aArray = File.ReadAllLines(@"Rndm-dic.txt", Encoding.Default);
            string[]      bArray = File.ReadAllLines(@"Rndm-dic.txt", Encoding.Default);
            List <string> aList  = new List <string>(aArray);
            List <string> sList  = new List <string>(aArray);
            List <string> sList2 = new List <string>(aArray);

            SortTests.Sorting.sfList sList3 = new sfList(aArray);

            KeyedList <string, int> kList     = new KeyedList <string, int>(aArray.Length);
            KeyedList <string, int> kListDesc = new KeyedList <string, int>(aArray.Length);
            int val = 1;

            foreach (string s in sList)
            {
                kList.Add(s, val); //val contains original line position of string
                kListDesc.Add(s, val);
                ++val;
            }
            sList.Clear();

            TimeCounter StopWatch = new TimeCounter();

            StopWatch.SetOneProcessorAffinity();
            Console.WriteLine("base Cycles = {0} IsHighRes = {1}", TimeCounter.Frequency, TimeCounter.IsHighResolution);
            StopWatch.Start();
            //List<string> cList = StringSort.Sort(aList);
            List <string> cList = new List <string>(aList);

            StopWatch.Stop();
            Console.WriteLine("MS to sort copy: {0}", StopWatch.ElapsedMilSec);
            int n = 0;

            foreach (string s in cList)
            {
                Console.WriteLine(s);
                if (++n > 1)
                {
                    break;
                }
            }

            aList.Clear();

            StopWatch.StartNew();
            Array.Sort <string>(bArray, CompareString);
            StopWatch.Stop();
            Console.WriteLine("MS to Array.Sort<string> bArray: {0}", StopWatch.ElapsedMilSec);
            for (int i = 0; i < bArray.Length; ++i)
            {
                Console.WriteLine(bArray[i]);
                if (i == 1)
                {
                    break;
                }
            }
            //reset bArray to unsorted
            aArray.CopyTo(bArray, 0);

            StopWatch.StartNew();
            StringSort.Sort(aArray);
            StopWatch.Stop();
            Console.WriteLine("MS to sort aArray: {0}", StopWatch.ElapsedMilSec);
            for (int i = 0; i < aArray.Length; ++i)
            {
                Console.WriteLine(aArray[i]);
                if (i == 1)
                {
                    break;
                }
            }

            StopWatch.StartNew();
            Sedgewick.Sort(ref bArray);
            StopWatch.Stop();
            Console.WriteLine("MS to Sedgewick Sort bArray: {0}", StopWatch.ElapsedMilSec);
            for (int i = 0; i < bArray.Length; ++i)
            {
                Console.WriteLine(bArray[i]);
                if (i == 1)
                {
                    break;
                }
            }

            StopWatch.StartNew();
            sList2.Sort(CompareString); //sort using List<string> method
                                        //sList2.Sort(CompareString);
            StopWatch.Stop();
            Console.WriteLine("MS to List.Sort() sList2: {0}", StopWatch.ElapsedMilSec);
            for (int i = 0; i < sList2.Count; ++i)
            {
                Console.WriteLine(sList2[i]);
                if (i == 1)
                {
                    break;
                }
            }
            sList2.Clear();

            StopWatch.StartNew();
            sList3.Sort(); //sort using StringSort replacement
            StopWatch.Stop();
            Console.WriteLine("MS to sfList.Sort() sList3: {0}", StopWatch.ElapsedMilSec);
            for (int i = 0; i < sList3.Count; ++i)
            {
                Console.WriteLine(sList3[i]);
                if (i == 1)
                {
                    break;
                }
            }

            StopWatch.StartNew();
            kList.Sort();
            StopWatch.Stop();
            Console.WriteLine("MS to KeyedList.Sort() kList: {0}", StopWatch.ElapsedMilSec);
            for (int i = 0; i < kList.Count; ++i)
            {
                Console.WriteLine(kList[i]);
                if (i == 1)
                {
                    break;
                }
            }
            //test the sort
            bool sorted = IsSortedTest(kList, kList.SortAscd);

            Console.WriteLine("Test: kList is sorted = {0}", sorted);

            kListDesc.SortAscd = false; //try sorting in descending order
            StopWatch.StartNew();
            kListDesc.Sort();
            StopWatch.Stop();
            Console.WriteLine("MS to KeyedList.Sort() kListDesc: {0}", StopWatch.ElapsedMilSec);
            for (int i = 0; i < kListDesc.Count; ++i)
            {
                Console.WriteLine(kListDesc[i]);
                if (i == 1)
                {
                    break;
                }
            }
            //test the sort
            sorted = IsSortedTest(kListDesc, kListDesc.SortAscd);
            Console.WriteLine("Test: kListDesc is sorted descending = {0}", sorted);

            string[] wArray = File.ReadAllLines(@"Rndm-dic.txt", Encoding.Default);

            //this is slower than stringSort
            //WQSort wqs = new WQSort();
            //StopWatch.StartNew();
            //wqs.Sort(wArray);
            //StopWatch.Stop();
            //Console.WriteLine("MS to WQSort.Sort() wArray: {0}", StopWatch.ElapsedMilSec);
            //for (int i = 0; i < wArray.Length; ++i)
            //{
            //  Console.WriteLine(wArray[i]);
            //  if (i == 1) break;
            //}
            List <int> lstInt = new List <int>(wArray.Length);
            Random     rand   = new Random((int)StopWatch.ElapsedMilSec);

            for (int i = 0; i < wArray.Length; ++i)
            {
                lstInt.Add(rand.Next());
            }
            StopWatch.StartNew();
            lstInt.Sort();
            StopWatch.Stop();
            Console.WriteLine("MS to List<int>.Sort() with {0} elements: {1:f1}", wArray.Length, StopWatch.ElapsedMilSec);
            Console.WriteLine("First, Second, Last integer in sorted List");
            Console.WriteLine(lstInt[0]);
            Console.WriteLine(lstInt[1]);
            Console.WriteLine(lstInt[wArray.Length - 1]);
            StopWatch.RestoreProcessorAffinity(); //set this thread back to default Proccessor Affinity
        }