[Quantproject-developers] QuantProject/b1_ADT AdvancedSortedList.cs,1.2,1.3
Brought to you by:
glauco_1
|
From: Glauco S. <gla...@us...> - 2005-05-26 23:29:54
|
Update of /cvsroot/quantproject/QuantProject/b1_ADT In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv26023/b1_ADT Modified Files: AdvancedSortedList.cs Log Message: - better internal documentation - GetByKeyOrPrevious method has been added Index: AdvancedSortedList.cs =================================================================== RCS file: /cvsroot/quantproject/QuantProject/b1_ADT/AdvancedSortedList.cs,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 *** AdvancedSortedList.cs 1 Dec 2003 15:23:08 -0000 1.2 --- AdvancedSortedList.cs 26 May 2005 23:29:45 -0000 1.3 *************** *** 59,75 **** } ! public int previousIndexOfKey( Object key ) ! { ! if ( ((IComparable)this.GetKey( this.Count - 1 )).CompareTo( key ) < 0 ) ! // the last element key is less then the key to search ! return this.Count - 1; ! else ! // ((IComparable)this.GetKey( this.Count - 1 )).CompareTo( key ) > 0 ! return ! previousIndexOfKey_dicotomicSearch( key , 0 , this.Count - 1 ); ! } public int IndexOfKeyOrPrevious( Object key ) { int indexOfKey = this.IndexOfKey( key ); if ( indexOfKey >= 0 ) --- 59,84 ---- } ! public int previousIndexOfKey( Object key ) ! { ! if ( ((IComparable)this.GetKey( this.Count - 1 )).CompareTo( key ) < 0 ) ! // the last element key is less then the key to search ! return this.Count - 1; ! else ! // ((IComparable)this.GetKey( this.Count - 1 )).CompareTo( key ) > 0 ! return ! previousIndexOfKey_dicotomicSearch( key , 0 , this.Count - 1 ); ! } + /// <summary> + /// Returns the index for the given key. If the key is missing, it returns the + /// index for the next previous element. + /// </summary> + /// <param name="key"></param> + /// <returns></returns> public int IndexOfKeyOrPrevious( Object key ) { + if ( ((IComparable)this.GetKey( 0 )).CompareTo( key ) > 0 ) + // the given key is less then the first key in the sorted list + throw new IndexOfKeyOrPreviousException( (IComparable)this.GetKey( 0 ) , key ); int indexOfKey = this.IndexOfKey( key ); if ( indexOfKey >= 0 ) *************** *** 83,86 **** --- 92,99 ---- return this.GetKey( this.IndexOfKeyOrPrevious( key ) ); } + public object GetByKeyOrPrevious( Object key ) + { + return this[ this.GetKeyOrPrevious( key ) ]; + } public bool IsLastKey( Object key ) { |