Bag.st
branchjv
changeset 18091 abbcac10730e
parent 18071 009cf668b0ed
parent 15686 2efc686ef383
child 18093 2b786a9af1d0
--- a/Bag.st	Fri Aug 23 17:31:58 2013 +0100
+++ b/Bag.st	Wed Aug 28 10:47:51 2013 +0100
@@ -142,6 +142,18 @@
      to the bags elements."
 
     ^ contents
+!
+
+sortedCounts
+    "Answer with a collection of counts with elements, sorted by decreasing count."
+    "Suggested by l. Uzonyi"
+    
+    ^ (Array new:contents size
+        streamContents:[:stream | 
+            contents associationsDo:[:each | stream nextPut:each value -> each key ]
+        ])
+        sort:[:x :y | x >= y ];
+        yourself
 ! !
 
 !Bag methodsFor:'adding & removing'!
@@ -474,10 +486,10 @@
 !Bag class methodsFor:'documentation'!
 
 version
-    ^ '$Header: /cvs/stx/stx/libbasic/Bag.st,v 1.46 2013-07-04 15:46:20 stefan Exp $'
+    ^ '$Header: /cvs/stx/stx/libbasic/Bag.st,v 1.47 2013-08-23 00:21:19 cg Exp $'
 !
 
 version_CVS
-    ^ '$Header: /cvs/stx/stx/libbasic/Bag.st,v 1.46 2013-07-04 15:46:20 stefan Exp $'
+    ^ '$Header: /cvs/stx/stx/libbasic/Bag.st,v 1.47 2013-08-23 00:21:19 cg Exp $'
 ! !