Define #deepSameContentsAs:
authorStefan Vogel <sv@exept.de>
Wed, 21 Feb 2001 14:18:23 +0100
changeset 5813 27091e298994
parent 5812 e23a3fdc75cb
child 5814 f4f6da3e7631
Define #deepSameContentsAs:
SequenceableCollection.st
--- a/SequenceableCollection.st	Fri Feb 16 21:29:36 2001 +0100
+++ b/SequenceableCollection.st	Wed Feb 21 14:18:23 2001 +0100
@@ -900,6 +900,38 @@
     "
 !
 
+deepSameContentsAs:aCollection
+    "return true, if the receiver and the arg have the same contents
+     in both the named instance vars and any indexed instVars.
+     This method descends into referenced objects, where #sameContentsAs: does not descend.
+
+     Redefinded, so that SequenceableCollections are equivalent, especially OrderedCollections with
+     unused space"
+
+    |index "{ Class: SmallInteger }"
+     stop  "{ Class: SmallInteger }" |
+
+    (aCollection == self) ifTrue:[^true].
+    (aCollection isSequenceable) ifFalse:[^false].
+
+    stop := self size.
+    stop == (aCollection size) ifFalse:[^false].
+
+    index := 1.
+    [index <= stop] whileTrue:[
+        ((self at:index) deepSameContentsAs:(aCollection at:index)) ifFalse:[^false].
+        index := index + 1
+    ].
+    ^ true
+
+    "
+     #(1 2 3 4 5) deepSameContentsAs: #(1 2 3 4 5)                        
+     #($1 $2 $3 $4 $5) deepSameContentsAs: #(1 2 3 4 5)                   
+     #($1 $2 $3 $4 $5) deepSameContentsAs: '12345'                       
+     #($1 $2 $3 $4 $5) deepSameContentsAs: '54321' asSortedCollection   
+    "
+!
+
 endsWith:aCollection
     "return true, if the receivers last elements match those
      of aCollection"
@@ -3598,6 +3630,7 @@
     "Created: 14.2.1997 / 16:13:03 / cg"
 ! !
 
+
 !SequenceableCollection methodsFor:'searching'!
 
 detect:aBlock startingAt:startIndex
@@ -5201,6 +5234,6 @@
 !SequenceableCollection class methodsFor:'documentation'!
 
 version
-    ^ '$Header: /cvs/stx/stx/libbasic/SequenceableCollection.st,v 1.147 2000-11-18 11:44:10 ca Exp $'
+    ^ '$Header: /cvs/stx/stx/libbasic/SequenceableCollection.st,v 1.148 2001-02-21 13:18:23 stefan Exp $'
 ! !
 SequenceableCollection initialize!