[csmaild-cvs] csmaild/src/Imap/Commands ImapCommand.cs,1.3,1.4
Brought to you by:
tamc
From: <ta...@us...> - 2003-07-26 05:48:07
|
Update of /cvsroot/csmaild/csmaild/src/Imap/Commands In directory sc8-pr-cvs1:/tmp/cvs-serv6209/src/Imap/Commands Modified Files: ImapCommand.cs Log Message: Parsing and optimizations of sequence strings should actually work now Index: ImapCommand.cs =================================================================== RCS file: /cvsroot/csmaild/csmaild/src/Imap/Commands/ImapCommand.cs,v retrieving revision 1.3 retrieving revision 1.4 diff -C2 -d -r1.3 -r1.4 *** ImapCommand.cs 25 Jul 2003 03:39:12 -0000 1.3 --- ImapCommand.cs 25 Jul 2003 18:46:40 -0000 1.4 *************** *** 147,151 **** ++mUnparsedArgumentIdx; // move past the space at the beginning ! if(mUnparsedArguments == string.Empty) ParseArgumentHandler(false, string.Empty); else if(((mArgumentTypes[mCurrentArgument] & ArgumentType.LiteralString) == ArgumentType.LiteralString) && mUnparsedArguments[mUnparsedArgumentIdx] == '{') // literal string --- 147,153 ---- ++mUnparsedArgumentIdx; // move past the space at the beginning ! if(mUnparsedArgumentIdx >= mUnparsedArguments.Length) // no more string to parse ! ParseArgumentHandler(false, string.Empty); ! else if(mUnparsedArguments == string.Empty) ParseArgumentHandler(false, string.Empty); else if(((mArgumentTypes[mCurrentArgument] & ArgumentType.LiteralString) == ArgumentType.LiteralString) && mUnparsedArguments[mUnparsedArgumentIdx] == '{') // literal string *************** *** 365,369 **** { isGood = false; ! if(startNumber == 0) // we started a range earlier, can't start another so soon return false; --- 367,371 ---- { isGood = false; ! if(startNumber != 0) // we started a range earlier, can't start another so soon return false; *************** *** 384,397 **** } else if(mUnparsedArguments[mUnparsedArgumentIdx] == ' ') // a space, done with the argument - { - if(startNumber != 0) // we started a range earlier - { - sequenceSet.AddRange(startNumber, sequenceNumber); - startNumber = 0; - } - else // make a range of size 1 - sequenceSet.AddRange(sequenceNumber); break; - } else { --- 386,390 ---- *************** *** 406,409 **** --- 399,411 ---- } + // add the last range + if(startNumber != 0) // we started a range earlier + { + sequenceSet.AddRange(startNumber, sequenceNumber); + startNumber = 0; + } + else // make a range of size 1 + sequenceSet.AddRange(sequenceNumber); + return isGood; } *************** *** 411,503 **** protected class SequenceSet { ! private ArrayList mStartRange = new ArrayList(); ! private ArrayList mEndRange = new ArrayList(); ! ! public void AddRange(int num) { ! AddRange(num, num); ! } ! public void AddRange(int start, int end) ! { ! int low = Math.Min(start, end); ! int high = Math.Max(start, end); ! if(mStartRange.Count == 0) { ! mStartRange.Add(low); ! mEndRange.Add(high); } - else - AddHelper(low, high); - } ! private void AddHelper(int lowVal, int highVal) ! { ! for(int idx = 0; idx < mStartRange.Count; ++idx) { ! if(lowVal == (int)mStartRange[idx]) // we start on the same value, wee! ! { ! if(highVal > (int)mEndRange[idx]) // we end higher, change some stuff ! AddHelperHelper(idx, highVal); ! break; ! } ! else if(lowVal > (int)mStartRange[idx]) // we start higher then this guy starts { ! if(lowVal < (int)mEndRange[idx]) // we start lower than this guy ends ! if(highVal > (int)mEndRange[idx]) // we end higher, change some stuff ! AddHelperHelper(idx, highVal); ! break; // done no matter what } ! else // we start lower then this guy starts { ! if(highVal > (int)mStartRange[idx]) // we end higher then this guy starts { ! // need to adjust start ! mStartRange[idx] = lowVal; ! if(highVal > (int)mEndRange[idx]) // we end higher then this guy ends ! AddHelperHelper(idx, highVal); ! break; } - continue; } } - } - - private void AddHelperHelper(int idx, int highVal) - { - // firstly, adjust the end - mEndRange[idx] = Math.Max(highVal, (int)mEndRange[idx]); ! ++idx; ! // while we haven't exhausted the array and we can combine sequences ! while(idx < mStartRange.Count && highVal > (int)mStartRange[idx]) { ! // this range can consume the entire next range ! if(highVal >= (int)mEndRange[idx]) { ! mStartRange.RemoveAt(idx); ! mEndRange.RemoveAt(idx); ! continue; // still need to see how much more we can eat } ! else // we need to combine the ranges { ! // make previous range all inclusive ! mEndRange[idx-1] = mEndRange[idx]; ! mStartRange.RemoveAt(idx); ! mEndRange.RemoveAt(idx); ! break; // done } } } public override string ToString() { ! string rv = string.Empty; ! for(int idx = 0; idx < mStartRange.Count; ++idx) ! rv += mStartRange[idx].ToString() + ":" + mEndRange[idx].ToString(); ! return rv; } } --- 413,610 ---- protected class SequenceSet { ! public class SequenceRange { ! private int mLow; ! private int mHigh; ! private SequenceRange mPrevious; ! private SequenceRange mNext; ! public int Low { ! get ! { ! return mLow; ! } ! set ! { ! if(value < mLow) ! { ! mLow = value; ! ! // we should combine with the previous ! while(mPrevious != null && value <= mPrevious.mHigh+1) ! { ! mLow = mPrevious.mLow; ! mPrevious = mPrevious.mPrevious; ! if(mPrevious != null) ! mPrevious.mNext = this; ! } ! } ! } } ! public int High { ! get { ! return mHigh; } ! set { ! if(value > mHigh) { ! mHigh = value; ! // we should combine with the next ! while(mNext != null && value >= mNext.mLow-1) ! { ! mHigh = mNext.mHigh; ! mNext = mNext.mNext; ! if(mNext != null) ! mNext.mPrevious = this; ! } } } } ! public SequenceRange(int low, int high) ! { ! mLow = low; ! mHigh = high; ! mPrevious = null; ! mNext = null; ! } ! public SequenceRange AddRange(int low, int high) { ! if(low <= mHigh + 1 && high >= mLow - 1) // they can combine with us { ! Low = low; ! High = high; ! return this; } ! else // they cannot combine with us (move to the next guy) { ! if(low < mLow) // taking our spot ! { ! SequenceRange rng = new SequenceRange(low, high); ! rng.mNext = this; // new guy is prior to us ! rng.mPrevious = mPrevious; // after our old previous ! if(mPrevious != null) ! mPrevious.mNext = rng; ! mPrevious = rng; ! return rng; // new root node ! } ! else if(mNext == null) // nobody is after us ! { ! SequenceRange rng = new SequenceRange(low, high); ! rng.mPrevious = this; ! mNext = rng; ! return this; ! } ! else ! { ! mNext.AddRange(low, high); ! return this; ! } } } + + public override string ToString() + { + return mLow + ":" + mHigh + (mNext != null ? "," + mNext.ToString() : string.Empty); + } + } + + private SequenceRange mRootNode; + + public void AddRange(int num) + { + AddRange(num, num); } + public void AddRange(int start, int end) + { + int low = Math.Min(start, end); + int high = Math.Max(start, end); + + if(mRootNode == null) + mRootNode = new SequenceRange(low, high); + else + mRootNode = mRootNode.AddRange(low, high); + } + + // private void AddHelper(int lowVal, int highVal) + // { + // for(int idx = 0; idx < mStartRange.Count; ++idx) + // { + // if(lowVal == (int)mStartRange[idx]) // we start on the same value, wee! + // { + // if(highVal > (int)mEndRange[idx]) // we end higher, change some stuff + // AddHelperHelper(idx, highVal); + // break; + // } + // else if(lowVal > (int)mStartRange[idx]) // we start higher then this guy starts + // { + // if(lowVal <= (int)mEndRange[idx]+1) // we start lower or on this guys end+1 + // { + // if(highVal > (int)mEndRange[idx]) // we end higher, change some stuff + // AddHelperHelper(idx, highVal); + // break; + // } + // else if(idx == mStartRange.Count-1) // start higher then end and at the end of ranges, just add + // { + // mStartRange.Insert(idx+1, lowVal); + // mEndRange.Insert(idx+1, highVal); + // } + // } + // else // we start lower then this guy starts + // { + // if(highVal > (int)mStartRange[idx]) // we end higher or on this guys start+1 + // { + // // need to adjust start + // mStartRange[idx] = lowVal; + // + // if(highVal > (int)mEndRange[idx]) // we end higher then this guy ends + // AddHelperHelper(idx, highVal); + // break; + // } + // continue; + // } + // } + // } + // + // private void AddHelperHelper(int idx, int highVal) + // { + // // firstly, adjust the end + // mEndRange[idx] = Math.Max(highVal, (int)mEndRange[idx]); + // + // ++idx; + // + // // while we haven't exhausted the array and we can combine sequences + // while(idx < mStartRange.Count && highVal > (int)mStartRange[idx]) + // { + // // this range can consume the entire next range + // if(highVal >= (int)mEndRange[idx]) + // { + // mStartRange.RemoveAt(idx); + // mEndRange.RemoveAt(idx); + // continue; // still need to see how much more we can eat + // } + // else // we need to combine the ranges + // { + // // make previous range all inclusive + // mEndRange[idx-1] = mEndRange[idx]; + // mStartRange.RemoveAt(idx); + // mEndRange.RemoveAt(idx); + // break; // done + // } + // } + // } + public override string ToString() { ! return mRootNode.ToString(); } } |