public void CopyFrom(FinalLine f) // avoids aliasing problems => copies values form f to this
 {
     this.StartStn  = f.StartStn;
     this.EndStn    = f.EndStn;
     this.StartTime = f.StartTime;
     this.EndTime   = f.EndTime;
 }
        // Mocking methods

        private int LoadPreSortedData() // speeds up debugging by not having to re sort file
        {
            FinalLine        f      = new FinalLine();
            StreamReader     r      = new StreamReader(SourceFile);
            List <FinalLine> sorted = new List <FinalLine>();

            FileInfo  fi           = new FileInfo(SourceFile);
            long      size         = fi.Length; // size in bits
            long      bytesRead    = 0;
            int       percent      = 0;
            const int bytesPerChar = 1; //ASCII
            string    line;

            while (!r.EndOfStream)
            {
                line = r.ReadLine();
                f.ReadLine(line);
                sorted.Add(new FinalLine(f));
                bytesRead += (line.Length + 2) * bytesPerChar; // +2 to account for return char and new line

                if (percent < bytesRead * 100 / size)
                {
                    percent++;
                    bgw.ReportProgress(percent);
                }
            }

            r.Close();
            Records.AddFirst(sorted);
            return(Records.First().Count());
        }
        public bool ComesBefore(FinalLine f) // returns true if this FinalLine comes before f according to ordering
        {
            // if result is false => swap

            if (this.StartStn < f.StartStn) // primary ordering
            {
                return(true);
            }

            else if (this.StartStn > f.StartStn)
            {
                return(false);
            }

            else // start stations are the same
            {
                if (this.EndStn < f.EndStn) // secondary ordering
                {
                    return(true);
                }

                else if (this.EndStn > f.EndStn)
                {
                    return(false);
                }

                else // end stations also the same
                {
                    if (this.StartTime <= f.StartTime) // tertiary ordering
                    {
                        return(true);
                    }

                    else
                    {
                        return(false);
                    }
                }
            }
        }
        private int FirstPass(StationDictionary stations) // reads in data and converts to numerical form
        {
            StreamReader r = new StreamReader(SourceFile);
            FinalLine    f = new FinalLine();

            FileInfo fi   = new FileInfo(SourceFile);
            long     size = fi.Length; //bytes in file

            long bytesRead = 0;
            int  percent   = 0;

            string line;

            const int bytesPerChar = 1; // UTF-8

            while (!r.EndOfStream)
            {
                line = r.ReadLine();
                if (f.TryInitialise(line, stations))
                {
                    Records.AddFirst(new List <FinalLine> {
                        new FinalLine(f)
                    });
                }

                bytesRead += (line.Length + 2) * bytesPerChar; // +2 to account for return and new line

                if (percent < (bytesRead * split) / size)
                {
                    percent++;
                    bgw.ReportProgress(percent);
                }
            }

            r.Close();
            return(Records.Count());
        }
 public FinalLine(FinalLine f) // creates new instance of class with same attributes as f
 {
     CopyFrom(f);
 }
        private void MergeFirstTwo() // merges first two lists and puts result at back
        {
            List <FinalLine> aList  = Records.First();
            List <FinalLine> bList  = Records.ElementAt(1);
            List <FinalLine> merged = new List <FinalLine>();

            FinalLine aLine   = new FinalLine();
            FinalLine bLine   = new FinalLine();
            int       a       = 0;
            int       b       = 0;
            bool      ongoing = true;

            aLine = aList[a];
            a++;
            bLine = bList[b];
            b++;

            while (ongoing)
            {
                if (aLine.ComesBefore(bLine))
                {
                    merged.Add(new FinalLine(aLine));

                    if (a < aList.Count())
                    {
                        aLine = aList[a];
                        a++;
                    }

                    else
                    {
                        ongoing = false;
                        merged.Add(new FinalLine(bLine));
                        for (int i = b; i < bList.Count(); i++)
                        {
                            merged.Add(new FinalLine(bList[i]));
                        }
                    }
                }

                else
                {
                    merged.Add(new FinalLine(bLine));

                    if (b < bList.Count())
                    {
                        bLine = bList[b];
                        b++;
                    }

                    else
                    {
                        ongoing = false;
                        merged.Add(new FinalLine(aLine));
                        for (int i = a; i < aList.Count(); i++)
                        {
                            merged.Add(new FinalLine(aList[i]));
                        }
                    }
                }
            }

            Records.RemoveFirst(); // remove first two lists
            Records.RemoveFirst();

            Records.AddLast(merged); // add merged result to back
        }