예제 #1
0
        public ShortHistoryStruct[] DeDuplicateHistory(ShortHistoryStruct[] inH)
        {
            ShortHistoryStruct[] outH = new ShortHistoryStruct[inH.Length];
            int cnt  = 0;
            int last = 0;

            last = 0;
            if (inH.Length == 0)
            {
                return(outH);
            }
            outH[0] = inH[0];
            for (int i = 1; i < inH.Length; i++)
            {
                if (inH[last].ID != inH[i].ID || inH[last].LastModified != inH[i].LastModified)
                {
                    cnt++;
                    outH[cnt] = inH[i];
                    last      = i;
                }
            }
            Array.Resize(ref outH, cnt + 1);
            return(outH);
        }
예제 #2
0
        public ShortHistoryStruct[] MergeHistory(ShortHistoryStruct[] inH)
        {
            if (inH.Length < 2)
            {
                return(inH);
            }
            ShortHistoryStruct[] high, low;
            ShortHistoryStruct[] ret = new ShortHistoryStruct[inH.Length];
            int numHigh = Convert.ToInt32(Math.Floor(Convert.ToDecimal(inH.Length / 2)));
            int numLow  = Convert.ToInt32(Math.Floor(Convert.ToDecimal(inH.Length / 2))) + (inH.Length % 2);

            high = new ShortHistoryStruct[numHigh];
            low  = new ShortHistoryStruct[numLow];

            for (int i = 0; i < numHigh; i++)
            {
                high[i] = inH[i];
                low[i]  = inH[i + numHigh];
            }
            if (numLow > numHigh)
            {
                low[numLow - 1] = inH[inH.Length - 1];
            }
            high = MergeHistory(high);
            low  = MergeHistory(low);
            int curr = 0;
            int curh = 0;
            int curl = 0;

            //while(curr < inH.Length)
            //{
            //    if(high[curh].LastModified.CompareTo(low[curl].LastModified) > 0)
            //    {
            //        ret[curr++] = low[curl++];

            //    }
            //    else if(high[curh].LastModified.CompareTo(low[curl].LastModified) == 0)
            //    {
            //        if (high[curh].ID.CompareTo(low[curl].ID) > 0)
            //        {
            //            ret[curr++] = low[curl++];

            //        }
            //        else
            //        {
            //            ret[curr++] = high[curh++];
            //        }
            //    }
            //    else
            //    {
            //        ret[curr++] = high[curh++];
            //    }
            //    if (curh >= numHigh)
            //    {
            //        for(;curl<numLow; curl++)
            //        {
            //            ret[curr++] = low[curl];

            //        }
            //        break;
            //    }
            //    if (curl >= numLow )
            //    {
            //        for (; curh < numHigh; curh++)
            //        {
            //            ret[curr++] = high[curh];

            //        }
            //        break;
            //    }
            //}



            while (curr < inH.Length)
            {
                if (high[curh].ID == null)
                {
                    high[curh].ID = "-1";
                }
                if (low[curl].ID == null)
                {
                    low[curl].ID = "-1";
                }

                if (Convert.ToInt64(high[curh].ID) > Convert.ToInt64(low[curl].ID))
                {
                    ret[curr++] = low[curl++];
                }
                else if (Convert.ToInt64(high[curh].ID) == Convert.ToInt64(low[curl].ID))
                {
                    if (high[curh].LastModified.CompareTo(low[curl].LastModified) > 0)
                    {
                        ret[curr++] = low[curl++];
                    }
                    else
                    {
                        ret[curr++] = high[curh++];
                    }
                }
                else
                {
                    ret[curr++] = high[curh++];
                }
                if (curh >= numHigh)
                {
                    for (; curl < numLow; curl++)
                    {
                        ret[curr++] = low[curl];
                    }
                    break;
                }
                if (curl >= numLow)
                {
                    for (; curh < numHigh; curh++)
                    {
                        ret[curr++] = high[curh];
                    }
                    break;
                }
            }



            if (curr != inH.Length)
            {
                MessageBox.Show("Problem");
            }
            if (MaxReturn < curr)
            {
                MaxReturn = curr;
            }

            return(ret);
        }