Beispiel #1
0
 public NumberFilesManager(Arguments arguments)
 {
     m_Reader1      = new NumberStreamReader(arguments.Input1);
     m_Reader2      = new NumberStreamReader(arguments.Input2);
     m_OutputStream = new FileStream(arguments.Output, File.Exists(arguments.Output) ?
                                     FileMode.Truncate : FileMode.Create, FileAccess.Write);
     m_Operation = arguments.Operator;
     m_IsFast    = arguments.IsFast;
 }
Beispiel #2
0
        public NumberFilesManager(
            Stream inputStream1, Stream inputStream2, Stream outputSteam, Operation operation)
        {
            if (operation != Operation.Substraction && operation != Operation.Addition)
            {
                throw new ArgumentOutOfRangeException("operation");
            }

            m_Reader1      = new NumberStreamReader(inputStream1);
            m_Reader2      = new NumberStreamReader(inputStream2);
            m_OutputStream = outputSteam;
            m_Operation    = operation;
        }
Beispiel #3
0
        public static bool?FirstIsBigger(NumberStreamReader reader1, NumberStreamReader reader2)
        {
            if (reader1 == null)
            {
                throw new ArgumentNullException("reader1");
            }

            if (reader2 == null)
            {
                throw new ArgumentNullException("reader2");
            }

            if (reader1.Info == null)
            {
                throw new ArgumentNullException("rangeInfo1");
            }

            if (reader2.Info == null)
            {
                throw new ArgumentNullException("rangeInfo2");
            }

            bool?firstIsBigger = null;
            var  length1       = reader1.Info.RealPartPosition.GetLength();
            var  length2       = reader2.Info.RealPartPosition.GetLength();

            if (length1 > length2)
            {
                firstIsBigger = true;
            }
            else if (length1 < length2)
            {
                firstIsBigger = false;
            }
            else
            {
                // Need to scan file and find out which is bigger!
                reader1.Stream.Seek(reader1.Info.RealPartPosition.From, SeekOrigin.Begin);
                reader2.Stream.Seek(reader2.Info.RealPartPosition.From, SeekOrigin.Begin);

                var  enumerator1     = reader1.ReadContentFromBegin(length1).GetEnumerator();
                var  enumerator2     = reader2.ReadContentFromBegin(length1).GetEnumerator();
                bool continueReading = true;

                while (continueReading)
                {
                    continueReading = enumerator1.MoveNext();

                    if (continueReading)
                    {
                        continueReading = enumerator2.MoveNext();
                    }

                    if (continueReading)
                    {
                        continueReading = (enumerator1.Current != null && enumerator1.Current.Length > 0) ||
                                          (enumerator2.Current != null && enumerator2.Current.Length > 0);
                    }

                    if (continueReading)
                    {
                        // Compare symbols from
                        for (int i = 0; i < enumerator1.Current.Length; i++)
                        {
                            if (enumerator1.Current[i] > enumerator2.Current[i])
                            {
                                firstIsBigger   = true;
                                continueReading = false;
                                break;
                            }
                            else if (enumerator1.Current[i] < enumerator2.Current[i])
                            {
                                firstIsBigger   = false;
                                continueReading = false;
                                break;
                            }
                        }
                    }
                }
            }

            return(firstIsBigger);
        }