 |
Changeset 3973
- 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
| r3971 |
r3973 |
|
| 146 | 146 | { |
|---|
| 147 | 147 | Iterator i = void; |
|---|
| 148 | | i.node = tree ? (forward ? tree.leftmost : tree.rightmost) : null; |
|---|
| | 148 | i.node = count ? (forward ? tree.leftmost : tree.rightmost) : null; |
|---|
| 149 | 149 | i.bump = forward ? &Iterator.fore : &Iterator.back; |
|---|
| 150 | 150 | i.mutation = mutation; |
|---|
| … | … | |
| 167 | 167 | { |
|---|
| 168 | 168 | Iterator i = iterator (forward); |
|---|
| 169 | | i.node = tree ? tree.findFirst(key, cmp, forward) : null; |
|---|
| | 169 | i.node = count ? tree.findFirst(key, cmp, forward) : null; |
|---|
| 170 | 170 | return i; |
|---|
| 171 | 171 | } |
|---|
| … | … | |
| 319 | 319 | param: after indicates whether to look beyond or before |
|---|
| 320 | 320 | 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 |
|---|
| 323 | 323 | |
|---|
| 324 | 324 | ***********************************************************************/ |
|---|
| | 325 | |
|---|
| 325 | 326 | K nearbyKey (K key, bool after) |
|---|
| 326 | 327 | { |
|---|
| … | … | |
| 331 | 332 | return p.value; |
|---|
| 332 | 333 | } |
|---|
| 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); |
|---|
| 335 | 371 | } |
|---|
| 336 | 372 | |
|---|
| … | … | |
| 545 | 581 | if (p) |
|---|
| 546 | 582 | return *p; |
|---|
| 547 | | throw new NoSuchElementException ("missing or invalid key"); |
|---|
| | 583 | |
|---|
| | 584 | noSuchElement ("missing or invalid key"); |
|---|
| | 585 | assert (0); |
|---|
| 548 | 586 | } |
|---|
| 549 | 587 | |
|---|
| … | … | |
| 644 | 682 | } |
|---|
| 645 | 683 | return this; |
|---|
| | 684 | } |
|---|
| | 685 | |
|---|
| | 686 | |
|---|
| | 687 | /*********************************************************************** |
|---|
| | 688 | |
|---|
| | 689 | |
|---|
| | 690 | ***********************************************************************/ |
|---|
| | 691 | |
|---|
| | 692 | private void noSuchElement (char[] msg) |
|---|
| | 693 | { |
|---|
| | 694 | throw new NoSuchElementException (msg); |
|---|
| 646 | 695 | } |
|---|
| 647 | 696 | |
|---|
Download in other formats:
|
 |
 |
|
 |
Copyright © 2006-2008 Tango. All Rights Reserved. | Page Width:
Static or
Dynamic