public TSStreamReader(string filename)
 {
     fs             = new FileStream(filename, FileMode.Open, FileAccess.Read, FileShare.ReadWrite | FileShare.Delete);
     streamReader   = new StreamReader(fs);
     bRead          = false;
     currentThisinh = new ThiSinh();
 }
Beispiel #2
0
 static public int CompareDiemTong(ThiSinh first, ThiSinh second)
 {
     if (first.m_dDiemTong < second.m_dDiemTong)
     {
         return(1);
     }
     else if (first.m_dDiemTong == second.m_dDiemTong)
     {
         return(0);
     }
     return(-1);
 }
Beispiel #3
0
 static public int CompareID(ThiSinh first, ThiSinh second)
 {
     return((int)(first.m_nThiSinhID - second.m_nThiSinhID));
 }
Beispiel #4
0
        public int [] Distribute(string sfi, string[] sfo, int numfile)
        {
            int n = 0;

            int i, q, r;
            int m, mh;
            int k = 0;

            int[] numrun = new int[numfile];

            ThiSinh b;

            StreamReader fi = new StreamReader(new FileStream(sfi, FileMode.Open, FileAccess.Read));

            while ((n < m_nSize) && (!fi.EndOfStream))
            {
                m_arrThiSinh[n] = new ThiSinh();
                m_arrThiSinh[n].FromString(fi.ReadLine());
                //Console.WriteLine(m_arrThiSinh[n].ToString());
                n++;
            }

            m  = min(m_nSize, n);
            mh = m / 2;
            i  = mh - 1;
            while (i >= 0)
            {
                shift <ThiSinh>(m_arrThiSinh, i, m - 1, ThiSinh.CompareID);
                i--;
            }
            StreamWriter[] fo = new StreamWriter[numfile];
            for (int f = 0; f < numfile; f++)
            {
                fo[f]     = new StreamWriter(new FileStream(sfo[f], FileMode.Create, FileAccess.Write, FileShare.ReadWrite));
                numrun[f] = 0;
            }

            q = m - 1;
            while (!fi.EndOfStream)
            {
                b = new ThiSinh();
                b.FromString(fi.ReadLine());
                //Console.WriteLine(b.ToString());
                n++;
                fo[k].WriteLine(m_arrThiSinh[0].ToString());

                if (ThiSinh.CompareID(m_arrThiSinh[0], b) < 0)
                {
                    m_arrThiSinh[0] = b;
                    shift <ThiSinh>(m_arrThiSinh, 0, q, ThiSinh.CompareID);
                }
                else
                {
                    m_arrThiSinh[0] = m_arrThiSinh[q];
                    shift <ThiSinh>(m_arrThiSinh, 0, q - 1, ThiSinh.CompareID);
                    m_arrThiSinh[q] = b;
                    if (q < mh)
                    {
                        shift <ThiSinh>(m_arrThiSinh, q, m - 1, ThiSinh.CompareID);
                    }
                    q = q - 1;
                    if (q < 0)
                    {
                        q = m - 1;
                        numrun[k]++;
                        k++;
                        if (k >= numfile)
                        {
                            k -= numfile;
                        }
                    }
                }
            }
            r = m - 1;
            while (q >= 0)
            {
                fo[k].WriteLine(m_arrThiSinh[0].ToString());
                m_arrThiSinh[0] = m_arrThiSinh[q];
                shift <ThiSinh>(m_arrThiSinh, 0, q - 1, ThiSinh.CompareID);
                m_arrThiSinh[q] = m_arrThiSinh[r];
                r = r - 1;
                if (q < mh)
                {
                    shift <ThiSinh>(m_arrThiSinh, q, r, ThiSinh.CompareID);
                }
                q = q - 1;
            }

            numrun[k]++;
            k++;
            if (k >= numfile)
            {
                k -= numfile;
            }
            while (r >= 0)
            {
                fo[k].WriteLine(m_arrThiSinh[0].ToString());
                m_arrThiSinh[0] = m_arrThiSinh[r];
                r = r - 1;
                shift <ThiSinh>(m_arrThiSinh, 0, r, ThiSinh.CompareID);
            }

            numrun[k]++;
            k++;
            if (k >= numfile)
            {
                k -= numfile;
            }

            for (int f = 0; f < numfile; f++)
            {
                //Console.WriteLine("Tap tin {0} co {1} run", sfo[f], numrun[f]);
                fo[f].Close();
            }

            fi.Close();
            return(numrun);
        }