equal
deleted
inserted
replaced
328 ! ! |
328 ! ! |
329 |
329 |
330 !SortedCollection methodsFor:'accessing'! |
330 !SortedCollection methodsFor:'accessing'! |
331 |
331 |
332 largest:n |
332 largest:n |
333 "return the n largest elements" |
333 "return a collection containing the n largest elements, largest last. |
334 |
334 Raises an exception, if the receiver does not contain at least n elements" |
|
335 |
|
336 |mySize| |
|
337 |
|
338 mySize := self size. |
|
339 n > mySize ifTrue:[ |
|
340 self notEnoughElementsError |
|
341 ]. |
335 sortBlock == DefaultSortBlock ifTrue:[ |
342 sortBlock == DefaultSortBlock ifTrue:[ |
336 ^ self copyFrom:(self size-n+1) |
343 ^ self copyFrom:(mySize-n+1) |
337 ]. |
344 ]. |
|
345 "/ do not trust the sortblock to sort small-to-large |
338 ^ super largest:n |
346 ^ super largest:n |
339 |
347 |
340 " |
348 " |
341 #(10 35 20 45 30 5) asSortedCollection largest:3 |
349 #(10 35 20 45 30 5) asSortedCollection largest:3 |
|
350 (#(10 35 20 45 30 5) asSortedCollection:[:a :b | a > b]) largest:3 |
|
351 |
|
352 #(10 35 20 45 30 5) asSortedCollection largest:6 |
|
353 #(10 35 20 45 30 5) asSortedCollection largest:7 |
342 " |
354 " |
343 ! |
355 ! |
344 |
356 |
345 max |
357 max |
346 "Return the largest element." |
358 "Return the largest element." |
988 ! ! |
1000 ! ! |
989 |
1001 |
990 !SortedCollection class methodsFor:'documentation'! |
1002 !SortedCollection class methodsFor:'documentation'! |
991 |
1003 |
992 version |
1004 version |
993 ^ '$Header: /cvs/stx/stx/libbasic/SortedCollection.st,v 1.76 2012-08-10 19:28:52 stefan Exp $' |
1005 ^ '$Header: /cvs/stx/stx/libbasic/SortedCollection.st,v 1.77 2014-02-12 14:33:40 cg Exp $' |
994 ! |
1006 ! |
995 |
1007 |
996 version_CVS |
1008 version_CVS |
997 ^ '$Header: /cvs/stx/stx/libbasic/SortedCollection.st,v 1.76 2012-08-10 19:28:52 stefan Exp $' |
1009 ^ '$Header: /cvs/stx/stx/libbasic/SortedCollection.st,v 1.77 2014-02-12 14:33:40 cg Exp $' |
998 ! ! |
1010 ! ! |
|
1011 |
999 |
1012 |
1000 SortedCollection initialize! |
1013 SortedCollection initialize! |