use #from: instance creation method in #asRunArray.
authorClaus Gittinger <cg@exept.de>
Tue, 07 Apr 1998 09:52:59 +0200
changeset 3367 9510bc82d4d6
parent 3366 c253cfff1d44
child 3368 5b84482d26c9
use #from: instance creation method in #asRunArray.
Coll.st
Collection.st
--- a/Coll.st	Mon Apr 06 10:41:40 1998 +0200
+++ b/Coll.st	Tue Apr 07 09:52:59 1998 +0200
@@ -654,19 +654,31 @@
 asRunArray
     "return a new RunArray with the collections elements"
 
-    |anArray|
+    ^ RunArray from:self.
 
-    anArray := RunArray new.
-    self do:[:each |
-        anArray add:each.
-    ].
-    ^ anArray
+"/    |runs lastElement occurrences|
+"/
+"/    runs := RunArray new.
+"/    occurrences := 0.
+"/    self do:[:each |
+"/        each == lastElement ifTrue:[
+"/            occurrences := occurrences + 1
+"/        ] ifFalse:[
+"/            runs add:lastElement withOccurrences:occurrences.
+"/            occurrences := 1.
+"/            lastElement := each
+"/        ].
+"/    ].
+"/    occurrences ~~ 0 ifTrue:[
+"/        runs add:lastElement withOccurrences:occurrences
+"/    ].
+"/    ^ runs
 
     "
      #(1 2 3 3 3 4 4 4 4 5 6 7) asRunArray 
     "
 
-    "Modified: 14.5.1996 / 14:58:41 / cg"
+    "Modified: / 7.4.1998 / 09:50:54 / cg"
 !
 
 asSet
@@ -1737,6 +1749,6 @@
 !Collection class methodsFor:'documentation'!
 
 version
-    ^ '$Header: /cvs/stx/stx/libbasic/Attic/Coll.st,v 1.76 1998-01-20 18:11:31 stefan Exp $'
+    ^ '$Header: /cvs/stx/stx/libbasic/Attic/Coll.st,v 1.77 1998-04-07 07:52:59 cg Exp $'
 ! !
 Collection initialize!
--- a/Collection.st	Mon Apr 06 10:41:40 1998 +0200
+++ b/Collection.st	Tue Apr 07 09:52:59 1998 +0200
@@ -654,19 +654,31 @@
 asRunArray
     "return a new RunArray with the collections elements"
 
-    |anArray|
+    ^ RunArray from:self.
 
-    anArray := RunArray new.
-    self do:[:each |
-        anArray add:each.
-    ].
-    ^ anArray
+"/    |runs lastElement occurrences|
+"/
+"/    runs := RunArray new.
+"/    occurrences := 0.
+"/    self do:[:each |
+"/        each == lastElement ifTrue:[
+"/            occurrences := occurrences + 1
+"/        ] ifFalse:[
+"/            runs add:lastElement withOccurrences:occurrences.
+"/            occurrences := 1.
+"/            lastElement := each
+"/        ].
+"/    ].
+"/    occurrences ~~ 0 ifTrue:[
+"/        runs add:lastElement withOccurrences:occurrences
+"/    ].
+"/    ^ runs
 
     "
      #(1 2 3 3 3 4 4 4 4 5 6 7) asRunArray 
     "
 
-    "Modified: 14.5.1996 / 14:58:41 / cg"
+    "Modified: / 7.4.1998 / 09:50:54 / cg"
 !
 
 asSet
@@ -1737,6 +1749,6 @@
 !Collection class methodsFor:'documentation'!
 
 version
-    ^ '$Header: /cvs/stx/stx/libbasic/Collection.st,v 1.76 1998-01-20 18:11:31 stefan Exp $'
+    ^ '$Header: /cvs/stx/stx/libbasic/Collection.st,v 1.77 1998-04-07 07:52:59 cg Exp $'
 ! !
 Collection initialize!