Esempio n. 1
0
        static void Main(string[] args)
        {
            int               DISK_PAGE_SIZE = 4096;//MULTITUDE OF 4
            string            mainFileName   = "MainFile.txt";
            string            tape1Name      = "tape1.txt";
            string            tape2Name      = "tape2.txt";
            string            tape3Name      = "tape3.txt";
            int               amount;
            int               max;
            bool              showSum;
            int               option;
            bool              show;
            RunInfo           ri;
            DiskFunctionality df        = new DiskFunctionality(DISK_PAGE_SIZE, mainFileName, tape1Name, tape2Name, tape3Name);
            Generator         generator = new Generator(df);



            Console.WriteLine("1 - Generate automatically");
            Console.WriteLine("2 - Generate from keyboard");
            Console.WriteLine("3 - Generate from file");
            option = Int32.Parse(Console.ReadLine());
            if (option == 1)
            {
                Console.WriteLine("Set amount of numbers");
                amount = Int32.Parse(Console.ReadLine());
                if (amount < 1)
                {
                    Console.WriteLine("Amount of numbers must be grater than 0");
                    return;
                }
                Console.WriteLine("Set maximum value of a number");
                max = Int32.Parse(Console.ReadLine());
                if (max < 1)
                {
                    Console.WriteLine("Maximum number must be grater than 0");
                    return;
                }
                generator.Generate(amount, max);
            }
            else if (option == 2)
            {
                amount = generator.GenerateFromKeyboard();
                if (amount < 1)
                {
                    Console.WriteLine("Amount of numbers must be grater than 0");
                    return;
                }
            }
            else if (option == 3)
            {
                amount = generator.GenerateFromFile();
                if (amount < 1)
                {
                    Console.WriteLine("Amount of numbers must be grater than 0");
                    return;
                }
            }
            Console.WriteLine("Show file after every phase of sorting? y/n");
            string phaseAsnwear = Console.ReadLine();

            if (phaseAsnwear == "y")
            {
                show = true;
            }
            else
            {
                show = false;
            }
            Console.WriteLine("Show sum of divisors next to each number? y/n");
            string showSumAnswear = Console.ReadLine();

            if (showSumAnswear == "y")
            {
                showSum = true;
            }
            else
            {
                showSum = false;
            }
            Console.WriteLine("File before sorting:");
            df.OpenReadStream(mainFileName);
            df.ShowFileContent(mainFileName, showSum);
            df.CloseStream(mainFileName);
            df.OpenReadStream(mainFileName);
            Console.WriteLine("Number of runs in file: " + df.GetNumberOfRuns(mainFileName));
            df.CloseStream(mainFileName);


            ri = DivideBetweenTapes(df, mainFileName, tape1Name, tape2Name);

            FibonacciMerge(df, ri, tape1Name, tape2Name, tape3Name, show, showSum);
            int r   = df.GetNumberOfReadOperations();
            int w   = df.GetNumberOfWriteOperations();
            int sum = r + w;

            Console.WriteLine("Number of disk operations: " + sum);
        }