Download Reference Manual
The Developer's Library for D
About Wiki Forums Source Search Contact

Changeset 3973

Show
Ignore:
Timestamp:
10/05/08 01:40:29 (2 months ago)
Author:
kris
Message:

fixes #1234 :: added firstKey() and lastKey()

Kudos to Keinfarbton

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/tango/util/container/SortedMap.d

    r3971 r3973  
    146146        { 
    147147                Iterator i = void; 
    148                 i.node = tree ? (forward ? tree.leftmost : tree.rightmost) : null; 
     148                i.node = count ? (forward ? tree.leftmost : tree.rightmost) : null; 
    149149                i.bump = forward ? &Iterator.fore : &Iterator.back; 
    150150                i.mutation = mutation; 
     
    167167        { 
    168168                Iterator i = iterator (forward); 
    169                 i.node = tree ? tree.findFirst(key, cmp, forward) : null; 
     169                i.node = count ? tree.findFirst(key, cmp, forward) : null; 
    170170                return i; 
    171171        } 
     
    319319                param: after indicates whether to look beyond or before 
    320320                       the given key, where there is no exact match 
    321                 Throws: NoSUchElementException if none found 
    322                 Returns: a pointer to the value, or null if not present 
     321                throws: NoSuchElementException if none found 
     322                returns: a pointer to the value, or null if not present 
    323323              
    324324        ***********************************************************************/ 
     325 
    325326        K nearbyKey (K key, bool after) 
    326327        { 
     
    331332                       return p.value; 
    332333                   } 
    333              
    334                 throw new NoSuchElementException ("Element not found"); 
     334 
     335                noSuchElement ("no such key"); 
     336                assert (0); 
     337        } 
     338 
     339        /*********************************************************************** 
     340         
     341                Return the first key of the map 
     342 
     343                throws: NoSuchElementException where the map is empty 
     344                      
     345        ***********************************************************************/ 
     346 
     347        K firstKey () 
     348        { 
     349                if (count) 
     350                    return tree.leftmost.value; 
     351 
     352                noSuchElement ("no such key"); 
     353                assert (0); 
     354        } 
     355 
     356        /*********************************************************************** 
     357         
     358                Return the last key of the map 
     359 
     360                throws: NoSuchElementException where the map is empty 
     361                      
     362        ***********************************************************************/ 
     363 
     364        K lastKey () 
     365        { 
     366                if (count) 
     367                    return tree.rightmost.value; 
     368 
     369                noSuchElement ("no such key"); 
     370                assert (0); 
    335371        } 
    336372 
     
    545581                if (p) 
    546582                    return *p; 
    547                 throw new NoSuchElementException ("missing or invalid key"); 
     583 
     584                noSuchElement ("missing or invalid key"); 
     585                assert (0); 
    548586        } 
    549587 
     
    644682                   } 
    645683                return this; 
     684        } 
     685 
     686             
     687        /*********************************************************************** 
     688 
     689                  
     690        ***********************************************************************/ 
     691 
     692        private void noSuchElement (char[] msg) 
     693        { 
     694                throw new NoSuchElementException (msg); 
    646695        } 
    647696