SequenceableCollection.st
author Claus Gittinger <cg@exept.de>
Sat, 11 May 1996 11:16:03 +0200
changeset 1370 b051117cc302
parent 1369 5e7b6fabd248
child 1385 f90c476be6e3
permissions -rw-r--r--
moved #upTo: down into SeqColl
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
     1
"
5
67342904af11 *** empty log message ***
claus
parents: 3
diff changeset
     2
 COPYRIGHT (c) 1989 by Claus Gittinger
159
514c749165c3 *** empty log message ***
claus
parents: 118
diff changeset
     3
	      All Rights Reserved
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
     4
a27a279701f8 Initial revision
claus
parents:
diff changeset
     5
 This software is furnished under a license and may be used
a27a279701f8 Initial revision
claus
parents:
diff changeset
     6
 only in accordance with the terms of that license and with the
a27a279701f8 Initial revision
claus
parents:
diff changeset
     7
 inclusion of the above copyright notice.   This software may not
a27a279701f8 Initial revision
claus
parents:
diff changeset
     8
 be provided or otherwise made available to, or used by, any
a27a279701f8 Initial revision
claus
parents:
diff changeset
     9
 other person.  No title to or ownership of the software is
a27a279701f8 Initial revision
claus
parents:
diff changeset
    10
 hereby transferred.
a27a279701f8 Initial revision
claus
parents:
diff changeset
    11
"
a27a279701f8 Initial revision
claus
parents:
diff changeset
    12
a27a279701f8 Initial revision
claus
parents:
diff changeset
    13
Collection subclass:#SequenceableCollection
911
8bf5e91a7f68 Use doWhile: instead of whileTrue in topological sort (is compiled to inlined code).
Stefan Vogel <sv@exept.de>
parents: 890
diff changeset
    14
	instanceVariableNames:''
8bf5e91a7f68 Use doWhile: instead of whileTrue in topological sort (is compiled to inlined code).
Stefan Vogel <sv@exept.de>
parents: 890
diff changeset
    15
	classVariableNames:''
8bf5e91a7f68 Use doWhile: instead of whileTrue in topological sort (is compiled to inlined code).
Stefan Vogel <sv@exept.de>
parents: 890
diff changeset
    16
	poolDictionaries:''
8bf5e91a7f68 Use doWhile: instead of whileTrue in topological sort (is compiled to inlined code).
Stefan Vogel <sv@exept.de>
parents: 890
diff changeset
    17
	category:'Collections-Abstract'
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
    18
!
a27a279701f8 Initial revision
claus
parents:
diff changeset
    19
88
81dacba7a63a *** empty log message ***
claus
parents: 77
diff changeset
    20
!SequenceableCollection class methodsFor:'documentation'!
81dacba7a63a *** empty log message ***
claus
parents: 77
diff changeset
    21
81dacba7a63a *** empty log message ***
claus
parents: 77
diff changeset
    22
copyright
81dacba7a63a *** empty log message ***
claus
parents: 77
diff changeset
    23
"
81dacba7a63a *** empty log message ***
claus
parents: 77
diff changeset
    24
 COPYRIGHT (c) 1989 by Claus Gittinger
159
514c749165c3 *** empty log message ***
claus
parents: 118
diff changeset
    25
	      All Rights Reserved
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
    26
88
81dacba7a63a *** empty log message ***
claus
parents: 77
diff changeset
    27
 This software is furnished under a license and may be used
81dacba7a63a *** empty log message ***
claus
parents: 77
diff changeset
    28
 only in accordance with the terms of that license and with the
81dacba7a63a *** empty log message ***
claus
parents: 77
diff changeset
    29
 inclusion of the above copyright notice.   This software may not
81dacba7a63a *** empty log message ***
claus
parents: 77
diff changeset
    30
 be provided or otherwise made available to, or used by, any
81dacba7a63a *** empty log message ***
claus
parents: 77
diff changeset
    31
 other person.  No title to or ownership of the software is
81dacba7a63a *** empty log message ***
claus
parents: 77
diff changeset
    32
 hereby transferred.
81dacba7a63a *** empty log message ***
claus
parents: 77
diff changeset
    33
"
81dacba7a63a *** empty log message ***
claus
parents: 77
diff changeset
    34
!
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
    35
88
81dacba7a63a *** empty log message ***
claus
parents: 77
diff changeset
    36
documentation
81dacba7a63a *** empty log message ***
claus
parents: 77
diff changeset
    37
"
81dacba7a63a *** empty log message ***
claus
parents: 77
diff changeset
    38
    SequenceableCollections have ordered elements which can be accessed via
81dacba7a63a *** empty log message ***
claus
parents: 77
diff changeset
    39
    a numeric index. 
81dacba7a63a *** empty log message ***
claus
parents: 77
diff changeset
    40
    SequenceableCollection is an abstract class - there are no instances of 
81dacba7a63a *** empty log message ***
claus
parents: 77
diff changeset
    41
    it in the system. See concrete subclasses (such as OrderedCollection).
1289
3abde2c376de checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1245
diff changeset
    42
3abde2c376de checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1245
diff changeset
    43
    [author:]
3abde2c376de checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1245
diff changeset
    44
        Claus Gittinger
88
81dacba7a63a *** empty log message ***
claus
parents: 77
diff changeset
    45
"
81dacba7a63a *** empty log message ***
claus
parents: 77
diff changeset
    46
! !
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
    47
a27a279701f8 Initial revision
claus
parents:
diff changeset
    48
!SequenceableCollection class methodsFor:'instance creation'!
a27a279701f8 Initial revision
claus
parents:
diff changeset
    49
a27a279701f8 Initial revision
claus
parents:
diff changeset
    50
new:size withAll:element
360
claus
parents: 359
diff changeset
    51
    "return a new collection of size, where all elements are
claus
parents: 359
diff changeset
    52
     initialized to element."
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
    53
a27a279701f8 Initial revision
claus
parents:
diff changeset
    54
    |newCollection|
a27a279701f8 Initial revision
claus
parents:
diff changeset
    55
a27a279701f8 Initial revision
claus
parents:
diff changeset
    56
    newCollection := self new:size.
a27a279701f8 Initial revision
claus
parents:
diff changeset
    57
    newCollection atAllPut:element.
a27a279701f8 Initial revision
claus
parents:
diff changeset
    58
    ^ newCollection
360
claus
parents: 359
diff changeset
    59
!
claus
parents: 359
diff changeset
    60
claus
parents: 359
diff changeset
    61
withSize:size
claus
parents: 359
diff changeset
    62
    "return a new collection of size.
claus
parents: 359
diff changeset
    63
     For variable size collections, this is different from #new:,
claus
parents: 359
diff changeset
    64
     in that #new: creates an empty collection with preallocated size,
claus
parents: 359
diff changeset
    65
     while #withSize: creates a non empty one."
claus
parents: 359
diff changeset
    66
claus
parents: 359
diff changeset
    67
    |newCollection|
claus
parents: 359
diff changeset
    68
claus
parents: 359
diff changeset
    69
    newCollection := self new:size.
claus
parents: 359
diff changeset
    70
    newCollection grow:size.
claus
parents: 359
diff changeset
    71
    ^ newCollection
claus
parents: 359
diff changeset
    72
claus
parents: 359
diff changeset
    73
    "
claus
parents: 359
diff changeset
    74
     (OrderedCollection new:10) inspect.
claus
parents: 359
diff changeset
    75
     (OrderedCollection withSize:10) inspect.
claus
parents: 359
diff changeset
    76
     (Array new:10) inspect.
claus
parents: 359
diff changeset
    77
     (Array withSize:10) inspect.
claus
parents: 359
diff changeset
    78
    "
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
    79
! !
a27a279701f8 Initial revision
claus
parents:
diff changeset
    80
a27a279701f8 Initial revision
claus
parents:
diff changeset
    81
!SequenceableCollection methodsFor:'accessing'!
a27a279701f8 Initial revision
claus
parents:
diff changeset
    82
1366
531162d17aaa lifted #after: / #before:
Claus Gittinger <cg@exept.de>
parents: 1359
diff changeset
    83
after:anObject
531162d17aaa lifted #after: / #before:
Claus Gittinger <cg@exept.de>
parents: 1359
diff changeset
    84
    "return the element, after anObject.
531162d17aaa lifted #after: / #before:
Claus Gittinger <cg@exept.de>
parents: 1359
diff changeset
    85
     If anObject is not in the receiver, report an error.
531162d17aaa lifted #after: / #before:
Claus Gittinger <cg@exept.de>
parents: 1359
diff changeset
    86
     This depends on #after:ifAbsent: being implemented in a concrete class."
531162d17aaa lifted #after: / #before:
Claus Gittinger <cg@exept.de>
parents: 1359
diff changeset
    87
531162d17aaa lifted #after: / #before:
Claus Gittinger <cg@exept.de>
parents: 1359
diff changeset
    88
    ^ self after:anObject ifAbsent:[self errorValueNotFound:anObject]
531162d17aaa lifted #after: / #before:
Claus Gittinger <cg@exept.de>
parents: 1359
diff changeset
    89
531162d17aaa lifted #after: / #before:
Claus Gittinger <cg@exept.de>
parents: 1359
diff changeset
    90
    "
531162d17aaa lifted #after: / #before:
Claus Gittinger <cg@exept.de>
parents: 1359
diff changeset
    91
     #(4 3 2 1) asOrderedCollection after:3. 
531162d17aaa lifted #after: / #before:
Claus Gittinger <cg@exept.de>
parents: 1359
diff changeset
    92
     #(4 3 2 1) asOrderedCollection after:5 
531162d17aaa lifted #after: / #before:
Claus Gittinger <cg@exept.de>
parents: 1359
diff changeset
    93
     #(4 3 2 1) asOrderedCollection after:1 
531162d17aaa lifted #after: / #before:
Claus Gittinger <cg@exept.de>
parents: 1359
diff changeset
    94
    "
531162d17aaa lifted #after: / #before:
Claus Gittinger <cg@exept.de>
parents: 1359
diff changeset
    95
531162d17aaa lifted #after: / #before:
Claus Gittinger <cg@exept.de>
parents: 1359
diff changeset
    96
    "Created: 10.5.1996 / 13:59:29 / cg"
531162d17aaa lifted #after: / #before:
Claus Gittinger <cg@exept.de>
parents: 1359
diff changeset
    97
    "Modified: 10.5.1996 / 14:03:33 / cg"
531162d17aaa lifted #after: / #before:
Claus Gittinger <cg@exept.de>
parents: 1359
diff changeset
    98
!
531162d17aaa lifted #after: / #before:
Claus Gittinger <cg@exept.de>
parents: 1359
diff changeset
    99
531162d17aaa lifted #after: / #before:
Claus Gittinger <cg@exept.de>
parents: 1359
diff changeset
   100
after:anObject ifAbsent:exceptionBlock
531162d17aaa lifted #after: / #before:
Claus Gittinger <cg@exept.de>
parents: 1359
diff changeset
   101
    "return the element, after anObject. If there is no such element,
531162d17aaa lifted #after: / #before:
Claus Gittinger <cg@exept.de>
parents: 1359
diff changeset
   102
     return the value from exceptionBlock."
531162d17aaa lifted #after: / #before:
Claus Gittinger <cg@exept.de>
parents: 1359
diff changeset
   103
531162d17aaa lifted #after: / #before:
Claus Gittinger <cg@exept.de>
parents: 1359
diff changeset
   104
    ^ self subclassResponsibility
531162d17aaa lifted #after: / #before:
Claus Gittinger <cg@exept.de>
parents: 1359
diff changeset
   105
531162d17aaa lifted #after: / #before:
Claus Gittinger <cg@exept.de>
parents: 1359
diff changeset
   106
    "Created: 10.5.1996 / 14:00:10 / cg"
531162d17aaa lifted #after: / #before:
Claus Gittinger <cg@exept.de>
parents: 1359
diff changeset
   107
!
531162d17aaa lifted #after: / #before:
Claus Gittinger <cg@exept.de>
parents: 1359
diff changeset
   108
32
ee1a621c696c *** empty log message ***
claus
parents: 13
diff changeset
   109
at:index ifAbsent:exceptionBlock
61
claus
parents: 44
diff changeset
   110
    "return the element at index if valid. 
claus
parents: 44
diff changeset
   111
     If the index is invalid, return the result of evaluating 
302
1f76060d58a4 *** empty log message ***
claus
parents: 293
diff changeset
   112
     the exceptionblock.
1f76060d58a4 *** empty log message ***
claus
parents: 293
diff changeset
   113
     NOTICE: 
1f76060d58a4 *** empty log message ***
claus
parents: 293
diff changeset
   114
	in ST-80, this message is only defined for Dictionaries,
1f76060d58a4 *** empty log message ***
claus
parents: 293
diff changeset
   115
	however, having a common protocol with indexed collections
1f76060d58a4 *** empty log message ***
claus
parents: 293
diff changeset
   116
	often simplifies things."
32
ee1a621c696c *** empty log message ***
claus
parents: 13
diff changeset
   117
ee1a621c696c *** empty log message ***
claus
parents: 13
diff changeset
   118
    ((index < 1) or:[index > self size]) ifTrue:[
159
514c749165c3 *** empty log message ***
claus
parents: 118
diff changeset
   119
	^ exceptionBlock value
32
ee1a621c696c *** empty log message ***
claus
parents: 13
diff changeset
   120
    ].
ee1a621c696c *** empty log message ***
claus
parents: 13
diff changeset
   121
    ^ self at:index
ee1a621c696c *** empty log message ***
claus
parents: 13
diff changeset
   122
95
d22739a0c6e9 *** empty log message ***
claus
parents: 88
diff changeset
   123
    "
d22739a0c6e9 *** empty log message ***
claus
parents: 88
diff changeset
   124
     #(1 2 3) at:4 ifAbsent:['no such index']
302
1f76060d58a4 *** empty log message ***
claus
parents: 293
diff changeset
   125
     #(1 2 3) asOrderedCollection at:4 ifAbsent:['no such index'] 
1f76060d58a4 *** empty log message ***
claus
parents: 293
diff changeset
   126
95
d22739a0c6e9 *** empty log message ***
claus
parents: 88
diff changeset
   127
     (Dictionary with:(#foo -> #bar)
159
514c749165c3 *** empty log message ***
claus
parents: 118
diff changeset
   128
		 with:(#frob -> #baz)) 
514c749165c3 *** empty log message ***
claus
parents: 118
diff changeset
   129
	 at:#foobar ifAbsent:['no such index']
95
d22739a0c6e9 *** empty log message ***
claus
parents: 88
diff changeset
   130
    "
362
claus
parents: 360
diff changeset
   131
!
claus
parents: 360
diff changeset
   132
1366
531162d17aaa lifted #after: / #before:
Claus Gittinger <cg@exept.de>
parents: 1359
diff changeset
   133
before:anObject
531162d17aaa lifted #after: / #before:
Claus Gittinger <cg@exept.de>
parents: 1359
diff changeset
   134
    "return the element before the argument, anObject.
531162d17aaa lifted #after: / #before:
Claus Gittinger <cg@exept.de>
parents: 1359
diff changeset
   135
     If anObject is not in the receiver, report an error.
531162d17aaa lifted #after: / #before:
Claus Gittinger <cg@exept.de>
parents: 1359
diff changeset
   136
     This depends on #before:ifAbsent: being implemented in a concrete class."
531162d17aaa lifted #after: / #before:
Claus Gittinger <cg@exept.de>
parents: 1359
diff changeset
   137
531162d17aaa lifted #after: / #before:
Claus Gittinger <cg@exept.de>
parents: 1359
diff changeset
   138
    ^ self before:anObject ifAbsent:[self errorValueNotFound:anObject]
531162d17aaa lifted #after: / #before:
Claus Gittinger <cg@exept.de>
parents: 1359
diff changeset
   139
531162d17aaa lifted #after: / #before:
Claus Gittinger <cg@exept.de>
parents: 1359
diff changeset
   140
    "
531162d17aaa lifted #after: / #before:
Claus Gittinger <cg@exept.de>
parents: 1359
diff changeset
   141
     #(4 3 2 1) asOrderedCollection before:3. 
531162d17aaa lifted #after: / #before:
Claus Gittinger <cg@exept.de>
parents: 1359
diff changeset
   142
     #(4 3 2 1) asOrderedCollection before:4 
531162d17aaa lifted #after: / #before:
Claus Gittinger <cg@exept.de>
parents: 1359
diff changeset
   143
     #(4 3 2 1) asOrderedCollection before:0 
531162d17aaa lifted #after: / #before:
Claus Gittinger <cg@exept.de>
parents: 1359
diff changeset
   144
    "
531162d17aaa lifted #after: / #before:
Claus Gittinger <cg@exept.de>
parents: 1359
diff changeset
   145
531162d17aaa lifted #after: / #before:
Claus Gittinger <cg@exept.de>
parents: 1359
diff changeset
   146
    "Created: 10.5.1996 / 14:03:27 / cg"
531162d17aaa lifted #after: / #before:
Claus Gittinger <cg@exept.de>
parents: 1359
diff changeset
   147
    "Modified: 10.5.1996 / 14:03:44 / cg"
531162d17aaa lifted #after: / #before:
Claus Gittinger <cg@exept.de>
parents: 1359
diff changeset
   148
!
531162d17aaa lifted #after: / #before:
Claus Gittinger <cg@exept.de>
parents: 1359
diff changeset
   149
531162d17aaa lifted #after: / #before:
Claus Gittinger <cg@exept.de>
parents: 1359
diff changeset
   150
before:anObject ifAbsent:exceptionBlock
531162d17aaa lifted #after: / #before:
Claus Gittinger <cg@exept.de>
parents: 1359
diff changeset
   151
    "return the element, before anObject. If there is no such element,
531162d17aaa lifted #after: / #before:
Claus Gittinger <cg@exept.de>
parents: 1359
diff changeset
   152
     return the value from exceptionBlock."
531162d17aaa lifted #after: / #before:
Claus Gittinger <cg@exept.de>
parents: 1359
diff changeset
   153
531162d17aaa lifted #after: / #before:
Claus Gittinger <cg@exept.de>
parents: 1359
diff changeset
   154
    ^ self subclassResponsibility
531162d17aaa lifted #after: / #before:
Claus Gittinger <cg@exept.de>
parents: 1359
diff changeset
   155
531162d17aaa lifted #after: / #before:
Claus Gittinger <cg@exept.de>
parents: 1359
diff changeset
   156
    "Created: 10.5.1996 / 14:03:53 / cg"
531162d17aaa lifted #after: / #before:
Claus Gittinger <cg@exept.de>
parents: 1359
diff changeset
   157
!
531162d17aaa lifted #after: / #before:
Claus Gittinger <cg@exept.de>
parents: 1359
diff changeset
   158
602
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
   159
first
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
   160
    "return the first element"
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
   161
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
   162
    ^ self at:1
362
claus
parents: 360
diff changeset
   163
!
claus
parents: 360
diff changeset
   164
claus
parents: 360
diff changeset
   165
keyAtEqualValue:value
claus
parents: 360
diff changeset
   166
    "return the index of a value.
claus
parents: 360
diff changeset
   167
     This is normally not used (use indexOf:), but makes the
claus
parents: 360
diff changeset
   168
     protocol more compatible with dictionaries."
claus
parents: 360
diff changeset
   169
claus
parents: 360
diff changeset
   170
    ^ self indexOf:value
claus
parents: 360
diff changeset
   171
!
claus
parents: 360
diff changeset
   172
claus
parents: 360
diff changeset
   173
keyAtEqualValue:value ifAbsent:exceptionBlock
claus
parents: 360
diff changeset
   174
    "return the index of a value.
claus
parents: 360
diff changeset
   175
     This is normally not used (use indexOf:), but makes the
claus
parents: 360
diff changeset
   176
     protocol more compatible with dictionaries."
claus
parents: 360
diff changeset
   177
claus
parents: 360
diff changeset
   178
    ^ self indexOf:value ifAbsent:exceptionBlock
602
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
   179
!
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
   180
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
   181
keyAtValue:value
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
   182
    "return the index of a value.
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
   183
     This is normally not used (use indexOf:), but makes the
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
   184
     protocol more compatible with dictionaries."
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
   185
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
   186
    ^ self identityIndexOf:value
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
   187
!
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
   188
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
   189
keyAtValue:value ifAbsent:exceptionBlock
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
   190
    "return the index of a value.
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
   191
     This is normally not used (use indexOf:), but makes the
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
   192
     protocol more compatible with dictionaries."
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
   193
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
   194
    ^ self identityIndexOf:value ifAbsent:exceptionBlock
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
   195
!
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
   196
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
   197
last
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
   198
    "return the last element"
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
   199
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
   200
    ^ self at:(self size)
1370
b051117cc302 moved #upTo: down into SeqColl
Claus Gittinger <cg@exept.de>
parents: 1369
diff changeset
   201
!
b051117cc302 moved #upTo: down into SeqColl
Claus Gittinger <cg@exept.de>
parents: 1369
diff changeset
   202
b051117cc302 moved #upTo: down into SeqColl
Claus Gittinger <cg@exept.de>
parents: 1369
diff changeset
   203
upTo:anElement
b051117cc302 moved #upTo: down into SeqColl
Claus Gittinger <cg@exept.de>
parents: 1369
diff changeset
   204
    "return a new collection consisting of the receivers elements upTo
b051117cc302 moved #upTo: down into SeqColl
Claus Gittinger <cg@exept.de>
parents: 1369
diff changeset
   205
     (but excluding) anElement.
b051117cc302 moved #upTo: down into SeqColl
Claus Gittinger <cg@exept.de>
parents: 1369
diff changeset
   206
     If anElement is not in the receiver, the returned collection
b051117cc302 moved #upTo: down into SeqColl
Claus Gittinger <cg@exept.de>
parents: 1369
diff changeset
   207
     will consist of all elements of the receiver"
b051117cc302 moved #upTo: down into SeqColl
Claus Gittinger <cg@exept.de>
parents: 1369
diff changeset
   208
b051117cc302 moved #upTo: down into SeqColl
Claus Gittinger <cg@exept.de>
parents: 1369
diff changeset
   209
    |pos|
b051117cc302 moved #upTo: down into SeqColl
Claus Gittinger <cg@exept.de>
parents: 1369
diff changeset
   210
b051117cc302 moved #upTo: down into SeqColl
Claus Gittinger <cg@exept.de>
parents: 1369
diff changeset
   211
    pos := self indexOf:anElement.
b051117cc302 moved #upTo: down into SeqColl
Claus Gittinger <cg@exept.de>
parents: 1369
diff changeset
   212
    pos == 0 ifTrue:[^ self copy].
b051117cc302 moved #upTo: down into SeqColl
Claus Gittinger <cg@exept.de>
parents: 1369
diff changeset
   213
b051117cc302 moved #upTo: down into SeqColl
Claus Gittinger <cg@exept.de>
parents: 1369
diff changeset
   214
    ^ self copyFrom:1 to:(pos - 1)
b051117cc302 moved #upTo: down into SeqColl
Claus Gittinger <cg@exept.de>
parents: 1369
diff changeset
   215
b051117cc302 moved #upTo: down into SeqColl
Claus Gittinger <cg@exept.de>
parents: 1369
diff changeset
   216
    "
b051117cc302 moved #upTo: down into SeqColl
Claus Gittinger <cg@exept.de>
parents: 1369
diff changeset
   217
     #(1 2 3 4 5 6 7 8 9) upTo:5  
b051117cc302 moved #upTo: down into SeqColl
Claus Gittinger <cg@exept.de>
parents: 1369
diff changeset
   218
     'hello world' upTo:Character space  
b051117cc302 moved #upTo: down into SeqColl
Claus Gittinger <cg@exept.de>
parents: 1369
diff changeset
   219
     #(9 8 7 6 5 4 3 2 1) asSortedCollection upTo:5 
b051117cc302 moved #upTo: down into SeqColl
Claus Gittinger <cg@exept.de>
parents: 1369
diff changeset
   220
b051117cc302 moved #upTo: down into SeqColl
Claus Gittinger <cg@exept.de>
parents: 1369
diff changeset
   221
     raises an error:
b051117cc302 moved #upTo: down into SeqColl
Claus Gittinger <cg@exept.de>
parents: 1369
diff changeset
   222
b051117cc302 moved #upTo: down into SeqColl
Claus Gittinger <cg@exept.de>
parents: 1369
diff changeset
   223
     (Dictionary new 
b051117cc302 moved #upTo: down into SeqColl
Claus Gittinger <cg@exept.de>
parents: 1369
diff changeset
   224
        at:#foo put:'foo';
b051117cc302 moved #upTo: down into SeqColl
Claus Gittinger <cg@exept.de>
parents: 1369
diff changeset
   225
        at:#bar put:'bar';
b051117cc302 moved #upTo: down into SeqColl
Claus Gittinger <cg@exept.de>
parents: 1369
diff changeset
   226
        at:#baz put:'baz';
b051117cc302 moved #upTo: down into SeqColl
Claus Gittinger <cg@exept.de>
parents: 1369
diff changeset
   227
        yourself) upTo:#bar
b051117cc302 moved #upTo: down into SeqColl
Claus Gittinger <cg@exept.de>
parents: 1369
diff changeset
   228
                
b051117cc302 moved #upTo: down into SeqColl
Claus Gittinger <cg@exept.de>
parents: 1369
diff changeset
   229
    "
b051117cc302 moved #upTo: down into SeqColl
Claus Gittinger <cg@exept.de>
parents: 1369
diff changeset
   230
b051117cc302 moved #upTo: down into SeqColl
Claus Gittinger <cg@exept.de>
parents: 1369
diff changeset
   231
    "Modified: 11.5.1996 / 11:14:05 / cg"
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   232
! !
a27a279701f8 Initial revision
claus
parents:
diff changeset
   233
602
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
   234
!SequenceableCollection methodsFor:'adding & removing'!
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
   235
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
   236
add:anObject
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
   237
    "append the argument, anObject to the collection.
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
   238
     Return the argument, anObject.
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
   239
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
   240
     Notice, that this is modifies the receiver NOT a copy.
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
   241
     Also note, that it may be a slow operation for some collections,
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
   242
     due to the grow:-message, which is inefficient for fixed size 
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
   243
     collections (i.e. for Strings and Arrays it is not recommened)."
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
   244
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
   245
    |newSize|
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
   246
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
   247
    newSize := self size + 1.
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
   248
    self grow:newSize.
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
   249
    self at:newSize put:anObject.
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
   250
    ^ anObject
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
   251
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
   252
    "
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
   253
     |a|
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
   254
     a := #(1 2 3 4 5 6 7 8).
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
   255
     a add:'hello'.
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
   256
     a
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
   257
    "
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
   258
    "
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
   259
     |c|
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
   260
     c := #(1 2 3 4 5 6 7 8) asOrderedCollection.
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
   261
     c add:'hello'.
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
   262
     c
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
   263
    "
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
   264
!
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
   265
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
   266
add:anElement beforeIndex:index
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
   267
    "insert the first argument, anObject into the collection before slot index.
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
   268
     Return the receiver (sigh - ST-80 compatibility).
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
   269
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
   270
     Notice, that this is modifies the receiver NOT a copy.
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
   271
     Also note, that it may be a slow operation for some collections,
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
   272
     due to the grow:-message, which is inefficient for fixed size 
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
   273
     collections (i.e. for Strings and Arrays it is not recommened)."
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
   274
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
   275
    |newSize|
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
   276
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
   277
    newSize := self size + 1.
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
   278
    self grow:newSize.
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
   279
    self replaceFrom:index + 1 to:newSize with:self startingAt:index.
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
   280
    self at:index put:anElement
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
   281
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
   282
    "
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
   283
     #(1 2 3 4 5 6 7 8) add:'hello' beforeIndex:5
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
   284
    "
202
40ca7cc6fb9c *** empty log message ***
claus
parents: 186
diff changeset
   285
!
40ca7cc6fb9c *** empty log message ***
claus
parents: 186
diff changeset
   286
602
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
   287
addFirst:anObject
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
   288
    "prepend the argument, anObject to the collection.
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
   289
     Return the argument, anObject.
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
   290
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
   291
     Notice, that this is modifies the receiver NOT a copy.
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
   292
     Also note, that it may be a slow operation for some collections,
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
   293
     due to the grow:-message, which is inefficient for fixed size 
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
   294
     collections (i.e. for Strings and Arrays it is not recommened)."
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
   295
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
   296
    |newSize|
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
   297
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
   298
    newSize := self size + 1.
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
   299
    self grow:newSize.
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
   300
    self replaceFrom:2 to:newSize with:self startingAt:1.
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
   301
    self at:1 put:anObject.
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
   302
    ^ anObject
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
   303
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
   304
    "
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
   305
     |a| 
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
   306
     a:= #(1 2 3 4 5 6 7 8). 
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
   307
     a addFirst:'hello'. 
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
   308
     a 
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
   309
    "
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
   310
    "
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
   311
     |c|
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
   312
     c := #(1 2 3 4 5 6 7 8) asOrderedCollection.
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
   313
     c addFirst:'hello'.
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
   314
     c
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
   315
    "
69
4564b6328136 *** empty log message ***
claus
parents: 61
diff changeset
   316
!
4564b6328136 *** empty log message ***
claus
parents: 61
diff changeset
   317
602
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
   318
remove:anElement ifAbsent:aBlock
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
   319
    "search for anElement and, if present remove and return it.
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
   320
     If not present, return the value of evaluating aBlock.
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
   321
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
   322
     Notice, that this is modifies the receiver NOT a copy.
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
   323
     Also note, that it may be a slow operation for some collections,
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
   324
     due to the grow:-message, which is inefficient for fixed size 
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
   325
     collections (i.e. for Strings and Arrays it is not recommened)."
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
   326
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
   327
    |any 
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
   328
     dstIndex "{ Class: SmallInteger }"
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
   329
     sz       "{ Class: SmallInteger }"|
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
   330
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
   331
    dstIndex := 1.
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
   332
    any := false.
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
   333
    sz := self size.
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
   334
    1 to:sz do:[:srcIndex |
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
   335
	(anElement = (self at:srcIndex)) ifTrue:[
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
   336
	    any := true
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
   337
	] ifFalse:[
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
   338
	    (dstIndex ~~ srcIndex) ifTrue:[
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
   339
		self at:dstIndex put:(self at:srcIndex)
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
   340
	    ].
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
   341
	    dstIndex := dstIndex + 1
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
   342
	]
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
   343
    ].
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
   344
    any ifTrue:[
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
   345
	self grow:dstIndex - 1.
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
   346
	^ anElement
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
   347
    ].
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
   348
    ^ aBlock value
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
   349
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
   350
    "
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
   351
     #(1 2 3 4 5 6 7 8 9 0) remove:3 ifAbsent:[Transcript showCr:'no']
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
   352
     #(1 2 3 4 5 6 7 8 9 0) remove:99 ifAbsent:[#oops]
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
   353
    "
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
   354
!
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
   355
1369
5e7b6fabd248 raised #atAll:put: up in the hierarchy
Claus Gittinger <cg@exept.de>
parents: 1366
diff changeset
   356
removeAllSuchThat:aBlock
5e7b6fabd248 raised #atAll:put: up in the hierarchy
Claus Gittinger <cg@exept.de>
parents: 1366
diff changeset
   357
    "remove all elements that meet a test criteria as specified in aBlock.
5e7b6fabd248 raised #atAll:put: up in the hierarchy
Claus Gittinger <cg@exept.de>
parents: 1366
diff changeset
   358
     The argument, aBlock is evaluated for successive elements and all those,
5e7b6fabd248 raised #atAll:put: up in the hierarchy
Claus Gittinger <cg@exept.de>
parents: 1366
diff changeset
   359
     for which it returns true, are removed.
5e7b6fabd248 raised #atAll:put: up in the hierarchy
Claus Gittinger <cg@exept.de>
parents: 1366
diff changeset
   360
     Return a collection containing the removed elements."
5e7b6fabd248 raised #atAll:put: up in the hierarchy
Claus Gittinger <cg@exept.de>
parents: 1366
diff changeset
   361
5e7b6fabd248 raised #atAll:put: up in the hierarchy
Claus Gittinger <cg@exept.de>
parents: 1366
diff changeset
   362
    "/ this is a q&d implementation (possibly slow).
5e7b6fabd248 raised #atAll:put: up in the hierarchy
Claus Gittinger <cg@exept.de>
parents: 1366
diff changeset
   363
5e7b6fabd248 raised #atAll:put: up in the hierarchy
Claus Gittinger <cg@exept.de>
parents: 1366
diff changeset
   364
    |runIndex removed element|
5e7b6fabd248 raised #atAll:put: up in the hierarchy
Claus Gittinger <cg@exept.de>
parents: 1366
diff changeset
   365
5e7b6fabd248 raised #atAll:put: up in the hierarchy
Claus Gittinger <cg@exept.de>
parents: 1366
diff changeset
   366
    removed := self species new.
5e7b6fabd248 raised #atAll:put: up in the hierarchy
Claus Gittinger <cg@exept.de>
parents: 1366
diff changeset
   367
5e7b6fabd248 raised #atAll:put: up in the hierarchy
Claus Gittinger <cg@exept.de>
parents: 1366
diff changeset
   368
    runIndex := 1.
5e7b6fabd248 raised #atAll:put: up in the hierarchy
Claus Gittinger <cg@exept.de>
parents: 1366
diff changeset
   369
    [runIndex <= self size] whileTrue:[
5e7b6fabd248 raised #atAll:put: up in the hierarchy
Claus Gittinger <cg@exept.de>
parents: 1366
diff changeset
   370
        element := self at:runIndex.
5e7b6fabd248 raised #atAll:put: up in the hierarchy
Claus Gittinger <cg@exept.de>
parents: 1366
diff changeset
   371
        (aBlock value:element) ifTrue:[
5e7b6fabd248 raised #atAll:put: up in the hierarchy
Claus Gittinger <cg@exept.de>
parents: 1366
diff changeset
   372
            removed add:element.
5e7b6fabd248 raised #atAll:put: up in the hierarchy
Claus Gittinger <cg@exept.de>
parents: 1366
diff changeset
   373
            self removeAtIndex:runIndex
5e7b6fabd248 raised #atAll:put: up in the hierarchy
Claus Gittinger <cg@exept.de>
parents: 1366
diff changeset
   374
        ] ifFalse:[
5e7b6fabd248 raised #atAll:put: up in the hierarchy
Claus Gittinger <cg@exept.de>
parents: 1366
diff changeset
   375
            runIndex := runIndex + 1
5e7b6fabd248 raised #atAll:put: up in the hierarchy
Claus Gittinger <cg@exept.de>
parents: 1366
diff changeset
   376
        ]
5e7b6fabd248 raised #atAll:put: up in the hierarchy
Claus Gittinger <cg@exept.de>
parents: 1366
diff changeset
   377
    ].
5e7b6fabd248 raised #atAll:put: up in the hierarchy
Claus Gittinger <cg@exept.de>
parents: 1366
diff changeset
   378
    ^ removed
5e7b6fabd248 raised #atAll:put: up in the hierarchy
Claus Gittinger <cg@exept.de>
parents: 1366
diff changeset
   379
5e7b6fabd248 raised #atAll:put: up in the hierarchy
Claus Gittinger <cg@exept.de>
parents: 1366
diff changeset
   380
    "
5e7b6fabd248 raised #atAll:put: up in the hierarchy
Claus Gittinger <cg@exept.de>
parents: 1366
diff changeset
   381
     |coll|
5e7b6fabd248 raised #atAll:put: up in the hierarchy
Claus Gittinger <cg@exept.de>
parents: 1366
diff changeset
   382
5e7b6fabd248 raised #atAll:put: up in the hierarchy
Claus Gittinger <cg@exept.de>
parents: 1366
diff changeset
   383
     coll := OrderedCollection withAll:(1 to:10).
5e7b6fabd248 raised #atAll:put: up in the hierarchy
Claus Gittinger <cg@exept.de>
parents: 1366
diff changeset
   384
     Transcript showCr:(coll removeAllSuchThat:[:el | el even]).
5e7b6fabd248 raised #atAll:put: up in the hierarchy
Claus Gittinger <cg@exept.de>
parents: 1366
diff changeset
   385
     Transcript showCr:coll
5e7b6fabd248 raised #atAll:put: up in the hierarchy
Claus Gittinger <cg@exept.de>
parents: 1366
diff changeset
   386
    "
5e7b6fabd248 raised #atAll:put: up in the hierarchy
Claus Gittinger <cg@exept.de>
parents: 1366
diff changeset
   387
5e7b6fabd248 raised #atAll:put: up in the hierarchy
Claus Gittinger <cg@exept.de>
parents: 1366
diff changeset
   388
    "Created: 11.5.1996 / 09:49:30 / cg"
5e7b6fabd248 raised #atAll:put: up in the hierarchy
Claus Gittinger <cg@exept.de>
parents: 1366
diff changeset
   389
!
5e7b6fabd248 raised #atAll:put: up in the hierarchy
Claus Gittinger <cg@exept.de>
parents: 1366
diff changeset
   390
602
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
   391
removeAtIndex:anIndex
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
   392
    "remove the element stored at anIndex. Return the removed object.
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
   393
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
   394
     Notice, that this is modifies the receiver NOT a copy.
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
   395
     Also note, that it may be a slow operation for some collections,
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
   396
     due to the grow:-message, which is inefficient for fixed size 
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
   397
     collections (i.e. for Strings and Arrays it is not recommened)."
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
   398
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
   399
    |element|
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
   400
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
   401
    element := self at:anIndex.
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
   402
    self removeFromIndex:anIndex toIndex:anIndex.
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
   403
    ^ element
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
   404
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
   405
    "
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
   406
     #(1 2 3 4 5 6 7 8 9) asOrderedCollection removeAtIndex:3
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
   407
     #(1 2 3 4 5) asOrderedCollection removeAtIndex:6
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
   408
     #($a $b $c $d $e $f $g) removeAtIndex:3
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
   409
    "
13
62303f84ff5f *** empty log message ***
claus
parents: 5
diff changeset
   410
!
62303f84ff5f *** empty log message ***
claus
parents: 5
diff changeset
   411
602
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
   412
removeFirst
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
   413
    "remove the first element of the receiver and return it.
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
   414
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
   415
     Notice, that this is modifies the receiver NOT a copy.
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
   416
     Also note, that it may be a slow operation for some collections,
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
   417
     due to the grow:-message, which is inefficient for fixed size 
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
   418
     collections (i.e. for Strings and Arrays it is not recommened)."
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
   419
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
   420
    ^ self removeAtIndex:1
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
   421
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
   422
    "
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
   423
     |a|
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
   424
     a := #(1 2 3 4 5 6).
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
   425
     a removeFirst.
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
   426
     a 
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
   427
    "
13
62303f84ff5f *** empty log message ***
claus
parents: 5
diff changeset
   428
!
62303f84ff5f *** empty log message ***
claus
parents: 5
diff changeset
   429
602
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
   430
removeFromIndex:startIndex toIndex:endIndex
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
   431
    "remove the elements stored at indexes between startIndex and endIndex.
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
   432
     Return the receiver.
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
   433
     Returning the receiver is a historic leftover - it may at one
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
   434
     time return a collection of the removed elements.
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
   435
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
   436
     Notice, that this is modifies the receiver - NOT a copy; 
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
   437
     therefore any other users of the receiver will also see this change.
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
   438
     Also note, that it may be a slow operation for some collections,
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
   439
     due to the grow:-message, which is inefficient for fixed size 
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
   440
     collections (i.e. for Strings and Arrays it is not recommened)."
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
   441
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
   442
    |size newSize|
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
   443
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
   444
    (endIndex >= (size := self size)) ifTrue:[
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
   445
	self grow:(startIndex - 1)
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
   446
    ] ifFalse:[
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
   447
	newSize := size - endIndex + startIndex - 1.
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
   448
	self replaceFrom:startIndex to:newSize with:self startingAt:(endIndex + 1).
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
   449
	self grow:newSize
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
   450
    ]
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
   451
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
   452
"/    |newSize|
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
   453
"/
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
   454
"/    newSize := self size - endIndex + startIndex - 1.
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
   455
"/    newSize <= 0 ifTrue:[
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
   456
"/        self grow:0
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
   457
"/    ] ifFalse:[
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
   458
"/        self replaceFrom:startIndex to:newSize with:self startingAt:(endIndex + 1).
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
   459
"/        self grow:newSize
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
   460
"/    ]
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
   461
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
   462
    "
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
   463
     #(1 2 3 4 5 6 7 8 9 0) asOrderedCollection removeFromIndex:3 toIndex:5 
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
   464
     #(1 2 3 4 5 6 7 8 9 0) removeFromIndex:3 toIndex:5 
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
   465
     #(1 2 3 4 5 6 7 8 9 0) asOrderedCollection removeFromIndex:1 toIndex:10 
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
   466
     #(1 2 3 4 5 6 7 8 9 0) removeFromIndex:1 toIndex:10 
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
   467
    "
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
   468
!
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
   469
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
   470
removeIndex:index
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
   471
    "remove the argument stored at index. Return the receiver.
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
   472
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
   473
     Notice, that this is modifies the receiver NOT a copy.
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
   474
     Also note, that it may be a slow operation for some collections,
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
   475
     due to the grow:-message, which is inefficient for fixed size 
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
   476
     collections (i.e. for Strings and Arrays it is not recommened)."
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
   477
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
   478
    self removeFromIndex:index toIndex:index
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
   479
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
   480
    "
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
   481
     #(1 2 3 4 5 6 7 8 9) asOrderedCollection removeIndex:3
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
   482
     #(1 2 3 4 5) asOrderedCollection removeIndex:6
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
   483
     #($a $b $c $d $e $f $g) removeIndex:3
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
   484
    "
77
6c38ca59927f *** empty log message ***
claus
parents: 69
diff changeset
   485
!
6c38ca59927f *** empty log message ***
claus
parents: 69
diff changeset
   486
602
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
   487
removeLast
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
   488
    "remove the last element of the receiver and return it.
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
   489
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
   490
     Notice, that this is modifies the receiver NOT a copy.
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
   491
     Also note, that it may be a slow operation for some collections,
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
   492
     due to the grow:-message, which is inefficient for fixed size
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
   493
     collections (i.e. for Strings and Arrays it is not recommened)."
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
   494
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
   495
    ^ self removeAtIndex:(self size) 
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
   496
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
   497
    "
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
   498
     |a|
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
   499
     a := #(1 2 3 4 5 6).
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
   500
     a removeLast.
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
   501
     a   
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
   502
    "
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
   503
! !
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
   504
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
   505
!SequenceableCollection methodsFor:'comparing'!
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
   506
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
   507
= aCollection
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
   508
    "return true if the receiver and aCollection represent collections
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
   509
     with equal contents."
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
   510
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
   511
    |index "{ Class: SmallInteger }"
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
   512
     stop  "{ Class: SmallInteger }" |
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
   513
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
   514
    (aCollection == self) ifTrue:[^true].
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
   515
    (aCollection isSequenceable) ifFalse:[^false].
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
   516
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
   517
    stop := self size.
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
   518
    stop == (aCollection size) ifFalse:[^false].
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
   519
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
   520
    index := 1.
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
   521
    [index <= stop] whileTrue:[
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
   522
	(self at:index) = (aCollection at:index) ifFalse:[^false].
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
   523
	index := index + 1
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
   524
    ].
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
   525
    ^ true
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
   526
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
   527
    "
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
   528
     #(1 2 3 4 5) = #(1 2 3 4 5)                        
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
   529
     #($1 $2 $3 $4 $5) = #(1 2 3 4 5)                   
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
   530
     #($1 $2 $3 $4 $5) = '12345'                       
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
   531
     #($1 $2 $3 $4 $5) = '54321' asSortedCollection   
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
   532
    "
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
   533
!
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
   534
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
   535
endsWith:aCollection
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
   536
    "return true, if the receivers last elements match those
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
   537
     of aCollection"
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
   538
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
   539
    |index1 "{ Class: SmallInteger }"
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
   540
     index2 "{ Class: SmallInteger }" 
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
   541
     stop   "{ Class: SmallInteger }" 
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
   542
     sz     "{ Class: SmallInteger }"|
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
   543
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
   544
    (aCollection == self) ifTrue:[^ true].
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
   545
    (aCollection isSequenceable) ifFalse:[^ false].
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
   546
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
   547
    stop := aCollection size.
77
6c38ca59927f *** empty log message ***
claus
parents: 69
diff changeset
   548
    sz := self size.
602
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
   549
    stop > sz ifTrue:[^false].
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
   550
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
   551
    index1 := sz.
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
   552
    index2 := stop.
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
   553
    [index2 > 0] whileTrue:[
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
   554
	(self at:index1) = (aCollection at:index2) ifFalse:[^ false].
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
   555
	index1 := index1 - 1.
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
   556
	index2 := index2 - 1
77
6c38ca59927f *** empty log message ***
claus
parents: 69
diff changeset
   557
    ].
602
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
   558
    ^ true
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
   559
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
   560
    "
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
   561
     'abcde' endsWith:#($d $e)
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
   562
     #[1 2 3 4] endsWith:#(3 4)    
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
   563
     #(1 2 3 4) asOrderedCollection endsWith:#(3 4)
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
   564
    "
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
   565
!
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
   566
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
   567
hash
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
   568
    "return a hash key for the receiver"
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
   569
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
   570
    "this hash is stupid - but for larger collections, the hashing
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
   571
     time can become much bigger than the time lost in added probing.
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
   572
     Time will show ..."
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
   573
1145
a094d90e11bf dont use [0] blocks - use 0 constant instead
Claus Gittinger <cg@exept.de>
parents: 1016
diff changeset
   574
    ^ ((self at:1 ifAbsent:0) hash * self size) bitAnd:16r3FFFFFFF
602
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
   575
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
   576
    "
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
   577
     #(1 2 3 4 5) hash
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
   578
     #(1 2 3 4 5.0) asOrderedCollection hash
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
   579
    "
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
   580
!
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
   581
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
   582
startsWith:aCollection
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
   583
    "return true, if the receivers first elements match those
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
   584
     of aCollection"
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
   585
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
   586
    |index "{ Class: SmallInteger }"
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
   587
     stop  "{ Class: SmallInteger }" |
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
   588
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
   589
    (aCollection == self) ifTrue:[^true].
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
   590
    (aCollection isSequenceable) ifFalse:[^false].
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
   591
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
   592
    stop := aCollection size.
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
   593
    stop > self size ifTrue:[^false].
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
   594
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
   595
    index := 1.
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
   596
    [index <= stop] whileTrue:[
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
   597
	(self at:index) = (aCollection at:index) ifFalse:[^false].
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
   598
	index := index + 1
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
   599
    ].
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
   600
    ^ true
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
   601
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
   602
    "
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
   603
     'abcde' startsWith:#($a $b $c)
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
   604
     #[1 2 3 4] startsWith:#(1 2 3)
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
   605
     #(1 2 3 4) asOrderedCollection startsWith:#(1 2 3)
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
   606
    "
13
62303f84ff5f *** empty log message ***
claus
parents: 5
diff changeset
   607
! !
62303f84ff5f *** empty log message ***
claus
parents: 5
diff changeset
   608
260
cefb485445a7 *** empty log message ***
claus
parents: 252
diff changeset
   609
!SequenceableCollection methodsFor:'converting'!
cefb485445a7 *** empty log message ***
claus
parents: 252
diff changeset
   610
1188
a9efdd724afc more asString methods
ca
parents: 1159
diff changeset
   611
asStringWith:sepChar
a9efdd724afc more asString methods
ca
parents: 1159
diff changeset
   612
    "return a string generated by concatenating my elements 
a9efdd724afc more asString methods
ca
parents: 1159
diff changeset
   613
     (which must be strings or nil) and embedding sepChar characters in between.
a9efdd724afc more asString methods
ca
parents: 1159
diff changeset
   614
     Nil entries and empty strings are counted as empty lines."
a9efdd724afc more asString methods
ca
parents: 1159
diff changeset
   615
a9efdd724afc more asString methods
ca
parents: 1159
diff changeset
   616
    ^ self asStringWith:sepChar from:1 to:(self size)
a9efdd724afc more asString methods
ca
parents: 1159
diff changeset
   617
!
a9efdd724afc more asString methods
ca
parents: 1159
diff changeset
   618
a9efdd724afc more asString methods
ca
parents: 1159
diff changeset
   619
asStringWith:sepCharacter from:firstLine to:lastLine
a9efdd724afc more asString methods
ca
parents: 1159
diff changeset
   620
    "return part of myself as a string with embedded sepCharacters.
a9efdd724afc more asString methods
ca
parents: 1159
diff changeset
   621
     My elements must be strings or nil; nil entries and empty strings are
a9efdd724afc more asString methods
ca
parents: 1159
diff changeset
   622
     taken as empty lines."
a9efdd724afc more asString methods
ca
parents: 1159
diff changeset
   623
a9efdd724afc more asString methods
ca
parents: 1159
diff changeset
   624
    ^ self 
a9efdd724afc more asString methods
ca
parents: 1159
diff changeset
   625
        asStringWith:sepCharacter 
a9efdd724afc more asString methods
ca
parents: 1159
diff changeset
   626
        from:firstLine 
a9efdd724afc more asString methods
ca
parents: 1159
diff changeset
   627
        to:lastLine
a9efdd724afc more asString methods
ca
parents: 1159
diff changeset
   628
        compressTabs:false
a9efdd724afc more asString methods
ca
parents: 1159
diff changeset
   629
        final:nil
a9efdd724afc more asString methods
ca
parents: 1159
diff changeset
   630
    "
a9efdd724afc more asString methods
ca
parents: 1159
diff changeset
   631
     creating entries for searchpath:
a9efdd724afc more asString methods
ca
parents: 1159
diff changeset
   632
a9efdd724afc more asString methods
ca
parents: 1159
diff changeset
   633
     #('foo' 'bar' 'baz' '/foo/bar') asStringWith:$;   
a9efdd724afc more asString methods
ca
parents: 1159
diff changeset
   634
a9efdd724afc more asString methods
ca
parents: 1159
diff changeset
   635
     #('foo' 'bar' 'baz' '/foo/bar') asStringWith:$: from:1 to:3   
a9efdd724afc more asString methods
ca
parents: 1159
diff changeset
   636
    "
a9efdd724afc more asString methods
ca
parents: 1159
diff changeset
   637
a9efdd724afc more asString methods
ca
parents: 1159
diff changeset
   638
    "Modified: 23.2.1996 / 15:28:55 / cg"
a9efdd724afc more asString methods
ca
parents: 1159
diff changeset
   639
!
a9efdd724afc more asString methods
ca
parents: 1159
diff changeset
   640
260
cefb485445a7 *** empty log message ***
claus
parents: 252
diff changeset
   641
asStringWith:sepCharacter from:firstLine to:lastLine compressTabs:compressTabs final:endCharacter
cefb485445a7 *** empty log message ***
claus
parents: 252
diff changeset
   642
    "return part of myself as a string with embedded sepCharacters.
263
e0195b4ad1ac *** empty log message ***
claus
parents: 260
diff changeset
   643
     My elements must be strings or nil; nil entries and empty strings are
260
cefb485445a7 *** empty log message ***
claus
parents: 252
diff changeset
   644
     taken as empty lines.
cefb485445a7 *** empty log message ***
claus
parents: 252
diff changeset
   645
     If the argument compressTabs is true, leading spaces are converted
cefb485445a7 *** empty log message ***
claus
parents: 252
diff changeset
   646
     to tab-characters (8col tabs). The last line is followed by a final
cefb485445a7 *** empty log message ***
claus
parents: 252
diff changeset
   647
     character (if non-nil).
cefb485445a7 *** empty log message ***
claus
parents: 252
diff changeset
   648
cefb485445a7 *** empty log message ***
claus
parents: 252
diff changeset
   649
     This method is tuned for big collections, in not creating many
263
e0195b4ad1ac *** empty log message ***
claus
parents: 260
diff changeset
   650
     intermediate strings (has linear runtime). For very small collections
e0195b4ad1ac *** empty log message ***
claus
parents: 260
diff changeset
   651
     and small strings, it may be faster to use the comma , operation."
260
cefb485445a7 *** empty log message ***
claus
parents: 252
diff changeset
   652
293
31df3850e98c *** empty log message ***
claus
parents: 282
diff changeset
   653
    |idx1        "{ Class:SmallInteger }"
31df3850e98c *** empty log message ***
claus
parents: 282
diff changeset
   654
     idx2        "{ Class:SmallInteger }"
31df3850e98c *** empty log message ***
claus
parents: 282
diff changeset
   655
     totalLength "{ Class:SmallInteger }"
260
cefb485445a7 *** empty log message ***
claus
parents: 252
diff changeset
   656
     pos         "{ Class:SmallInteger }"
1003
c82f2dcf5611 care for embedded 16bit strings when concatenating a stringCollection
Claus Gittinger <cg@exept.de>
parents: 929
diff changeset
   657
     newString lineString spaces idx nTabs sepCnt
1015
a564efc63383 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1003
diff changeset
   658
     any16Bit stringClass|
260
cefb485445a7 *** empty log message ***
claus
parents: 252
diff changeset
   659
cefb485445a7 *** empty log message ***
claus
parents: 252
diff changeset
   660
    "
cefb485445a7 *** empty log message ***
claus
parents: 252
diff changeset
   661
     first accumulate the size of the string, to avoid
cefb485445a7 *** empty log message ***
claus
parents: 252
diff changeset
   662
     countless reallocations. If tabs are compressed,
cefb485445a7 *** empty log message ***
claus
parents: 252
diff changeset
   663
     the size computed is not exact, but gives an upper bound ...
1003
c82f2dcf5611 care for embedded 16bit strings when concatenating a stringCollection
Claus Gittinger <cg@exept.de>
parents: 929
diff changeset
   664
     On the fly, look if a 16bit string is needed.
260
cefb485445a7 *** empty log message ***
claus
parents: 252
diff changeset
   665
    "
1003
c82f2dcf5611 care for embedded 16bit strings when concatenating a stringCollection
Claus Gittinger <cg@exept.de>
parents: 929
diff changeset
   666
    any16Bit := false.
1015
a564efc63383 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1003
diff changeset
   667
    stringClass := String.
a564efc63383 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1003
diff changeset
   668
260
cefb485445a7 *** empty log message ***
claus
parents: 252
diff changeset
   669
    totalLength := 0.
cefb485445a7 *** empty log message ***
claus
parents: 252
diff changeset
   670
    sepCnt := sepCharacter notNil ifTrue:[1] ifFalse:[0].
cefb485445a7 *** empty log message ***
claus
parents: 252
diff changeset
   671
293
31df3850e98c *** empty log message ***
claus
parents: 282
diff changeset
   672
    idx1 := firstLine.
31df3850e98c *** empty log message ***
claus
parents: 282
diff changeset
   673
    idx2 := lastLine.
31df3850e98c *** empty log message ***
claus
parents: 282
diff changeset
   674
    idx1 to:idx2 do:[:lineIndex |
1015
a564efc63383 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1003
diff changeset
   675
	lineString := self at:lineIndex.
a564efc63383 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1003
diff changeset
   676
a564efc63383 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1003
diff changeset
   677
	lineString isNil ifTrue:[
a564efc63383 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1003
diff changeset
   678
	    totalLength := totalLength + sepCnt
a564efc63383 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1003
diff changeset
   679
	] ifFalse: [
a564efc63383 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1003
diff changeset
   680
	    (lineString bitsPerCharacter == 16) ifTrue:[
a564efc63383 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1003
diff changeset
   681
		any16Bit := true.
1016
9588a8d5a64e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1015
diff changeset
   682
		stringClass := lineString class
1015
a564efc63383 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1003
diff changeset
   683
	    ].
a564efc63383 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1003
diff changeset
   684
	    totalLength := totalLength + lineString size + sepCnt
a564efc63383 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1003
diff changeset
   685
	].
260
cefb485445a7 *** empty log message ***
claus
parents: 252
diff changeset
   686
    ].
cefb485445a7 *** empty log message ***
claus
parents: 252
diff changeset
   687
    endCharacter isNil ifTrue:[
1015
a564efc63383 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1003
diff changeset
   688
	totalLength := totalLength - 1
260
cefb485445a7 *** empty log message ***
claus
parents: 252
diff changeset
   689
    ].
cefb485445a7 *** empty log message ***
claus
parents: 252
diff changeset
   690
    spaces := '        '.
1016
9588a8d5a64e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1015
diff changeset
   691
    newString := stringClass new:totalLength.
260
cefb485445a7 *** empty log message ***
claus
parents: 252
diff changeset
   692
cefb485445a7 *** empty log message ***
claus
parents: 252
diff changeset
   693
    "
cefb485445a7 *** empty log message ***
claus
parents: 252
diff changeset
   694
     now, replace ...
cefb485445a7 *** empty log message ***
claus
parents: 252
diff changeset
   695
    "
cefb485445a7 *** empty log message ***
claus
parents: 252
diff changeset
   696
    pos := 1.
293
31df3850e98c *** empty log message ***
claus
parents: 282
diff changeset
   697
    idx1 to:idx2 do:[:lineIndex |
1015
a564efc63383 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1003
diff changeset
   698
	|thisLen|
a564efc63383 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1003
diff changeset
   699
a564efc63383 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1003
diff changeset
   700
	lineString := self at:lineIndex.
a564efc63383 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1003
diff changeset
   701
	thisLen := lineString size.
a564efc63383 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1003
diff changeset
   702
	thisLen ~~ 0 ifTrue:[
a564efc63383 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1003
diff changeset
   703
	    compressTabs ifTrue:[
a564efc63383 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1003
diff changeset
   704
		"
a564efc63383 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1003
diff changeset
   705
		 mhmh: could use withTabs from String-class here,
a564efc63383 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1003
diff changeset
   706
		 but we should avoid creating too many temporary strings
a564efc63383 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1003
diff changeset
   707
		 (especially, since this method is typically used when converting
a564efc63383 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1003
diff changeset
   708
		 big texts such as when saving in the filebrowser ...).
a564efc63383 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1003
diff changeset
   709
		 Therefore, we convert tabs inline here doing a direct replace
a564efc63383 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1003
diff changeset
   710
		 in newString."
a564efc63383 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1003
diff changeset
   711
a564efc63383 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1003
diff changeset
   712
		idx := lineString findFirst:[:c | (c ~~ Character space)].
a564efc63383 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1003
diff changeset
   713
		nTabs := (idx-1) // 8.
a564efc63383 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1003
diff changeset
   714
		nTabs ~~ 0 ifTrue:[
a564efc63383 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1003
diff changeset
   715
		    "any tabs"
a564efc63383 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1003
diff changeset
   716
		    newString atAll:(pos to:pos+nTabs-1) put:(Character tab).
a564efc63383 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1003
diff changeset
   717
		    pos := pos + nTabs.
a564efc63383 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1003
diff changeset
   718
		    newString replaceFrom:pos with:lineString startingAt:(nTabs * 8 + 1).
a564efc63383 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1003
diff changeset
   719
		    pos := pos + thisLen - (nTabs * 8).
a564efc63383 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1003
diff changeset
   720
		] ifFalse:[
a564efc63383 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1003
diff changeset
   721
		    newString replaceFrom:pos with:lineString.
a564efc63383 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1003
diff changeset
   722
		    pos := pos + thisLen
a564efc63383 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1003
diff changeset
   723
		].
a564efc63383 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1003
diff changeset
   724
	    ] ifFalse:[
a564efc63383 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1003
diff changeset
   725
		newString replaceFrom:pos with:lineString.
a564efc63383 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1003
diff changeset
   726
		pos := pos + thisLen
a564efc63383 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1003
diff changeset
   727
	    ]
a564efc63383 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1003
diff changeset
   728
	].
a564efc63383 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1003
diff changeset
   729
	(sepCharacter notNil 
a564efc63383 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1003
diff changeset
   730
	and:[lineIndex ~~ lastLine]) ifTrue:[
a564efc63383 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1003
diff changeset
   731
	    newString at:pos put:sepCharacter.
a564efc63383 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1003
diff changeset
   732
	    pos := pos + 1
a564efc63383 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1003
diff changeset
   733
	] ifFalse:[
a564efc63383 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1003
diff changeset
   734
	    endCharacter notNil ifTrue:[
a564efc63383 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1003
diff changeset
   735
		newString at:pos put:endCharacter.
a564efc63383 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1003
diff changeset
   736
		pos := pos + 1
a564efc63383 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1003
diff changeset
   737
	    ]
a564efc63383 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1003
diff changeset
   738
	]
260
cefb485445a7 *** empty log message ***
claus
parents: 252
diff changeset
   739
    ].
cefb485445a7 *** empty log message ***
claus
parents: 252
diff changeset
   740
cefb485445a7 *** empty log message ***
claus
parents: 252
diff changeset
   741
    "
cefb485445a7 *** empty log message ***
claus
parents: 252
diff changeset
   742
     in case of tab compression, the result has to be
cefb485445a7 *** empty log message ***
claus
parents: 252
diff changeset
   743
     cut to size ... sorry
cefb485445a7 *** empty log message ***
claus
parents: 252
diff changeset
   744
    "
cefb485445a7 *** empty log message ***
claus
parents: 252
diff changeset
   745
    pos ~~ totalLength ifTrue:[
1015
a564efc63383 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1003
diff changeset
   746
	^ newString copyTo:(pos - 1)
260
cefb485445a7 *** empty log message ***
claus
parents: 252
diff changeset
   747
    ].
cefb485445a7 *** empty log message ***
claus
parents: 252
diff changeset
   748
    ^ newString
cefb485445a7 *** empty log message ***
claus
parents: 252
diff changeset
   749
cefb485445a7 *** empty log message ***
claus
parents: 252
diff changeset
   750
    "
cefb485445a7 *** empty log message ***
claus
parents: 252
diff changeset
   751
     creating entries for searchpath:
cefb485445a7 *** empty log message ***
claus
parents: 252
diff changeset
   752
cefb485445a7 *** empty log message ***
claus
parents: 252
diff changeset
   753
     #('foo' 'bar' 'baz' '/foo/bar') 
1015
a564efc63383 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1003
diff changeset
   754
	asStringWith:$: from:1 to:4 compressTabs:false final:nil 
260
cefb485445a7 *** empty log message ***
claus
parents: 252
diff changeset
   755
cefb485445a7 *** empty log message ***
claus
parents: 252
diff changeset
   756
     with trailing colon:
cefb485445a7 *** empty log message ***
claus
parents: 252
diff changeset
   757
cefb485445a7 *** empty log message ***
claus
parents: 252
diff changeset
   758
     #('foo' 'bar' 'baz' '/foo/bar') 
1015
a564efc63383 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1003
diff changeset
   759
	asStringWith:$: from:1 to:4 compressTabs:false final:$: 
260
cefb485445a7 *** empty log message ***
claus
parents: 252
diff changeset
   760
cefb485445a7 *** empty log message ***
claus
parents: 252
diff changeset
   761
     concatenating all elements:
cefb485445a7 *** empty log message ***
claus
parents: 252
diff changeset
   762
cefb485445a7 *** empty log message ***
claus
parents: 252
diff changeset
   763
     #('foo' 'bar' 'baz') 
1015
a564efc63383 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1003
diff changeset
   764
	asStringWith:nil from:1 to:3 compressTabs:false final:nil 
260
cefb485445a7 *** empty log message ***
claus
parents: 252
diff changeset
   765
cefb485445a7 *** empty log message ***
claus
parents: 252
diff changeset
   766
     creating a string from a collection of lines:
cefb485445a7 *** empty log message ***
claus
parents: 252
diff changeset
   767
cefb485445a7 *** empty log message ***
claus
parents: 252
diff changeset
   768
     #('foo' 'bar' 'baz') 
1015
a564efc63383 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1003
diff changeset
   769
	asStringWith:(Character cr) from:1 to:3 compressTabs:false final:(Character cr) 
260
cefb485445a7 *** empty log message ***
claus
parents: 252
diff changeset
   770
    "
1003
c82f2dcf5611 care for embedded 16bit strings when concatenating a stringCollection
Claus Gittinger <cg@exept.de>
parents: 929
diff changeset
   771
c82f2dcf5611 care for embedded 16bit strings when concatenating a stringCollection
Claus Gittinger <cg@exept.de>
parents: 929
diff changeset
   772
    "Modified: 23.2.1996 / 15:28:55 / cg"
379
5b5a130ccd09 revision added
claus
parents: 375
diff changeset
   773
!
5b5a130ccd09 revision added
claus
parents: 375
diff changeset
   774
602
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
   775
asStringWithCRs
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
   776
    "return a string generated by concatenating my elements 
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
   777
     (which must be strings or nil) and embedding cr characters in between.
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
   778
     Nil entries and empty strings are counted as empty lines."
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
   779
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
   780
    ^ self asStringWithCRsFrom:1 to:(self size)
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
   781
!
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
   782
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
   783
asStringWithCRsFrom:firstLine to:lastLine
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
   784
    "return a string generated by concatenating some of my elements 
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
   785
     (which must be strings or nil) and embedding cr characters in between.
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
   786
     Nil entries and empty strings are counted as empty lines."
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
   787
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
   788
    ^ self asStringWithCRsFrom:firstLine to:lastLine compressTabs:false withCR:true
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
   789
!
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
   790
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
   791
asStringWithCRsFrom:firstLine to:lastLine compressTabs:compressTabs
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
   792
    "return part of myself as a string with embedded cr's.
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
   793
     My elements must be strings or nil.
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
   794
     If the argument compressTabs is true, leading spaces are converted
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
   795
     to tab-characters (8col tabs).
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
   796
     Nil entries and empty strings are taken as empty lines."
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
   797
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
   798
    ^ self asStringWithCRsFrom:firstLine to:lastLine compressTabs:compressTabs withCR:true
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
   799
!
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
   800
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
   801
asStringWithCRsFrom:firstLine to:lastLine compressTabs:compressTabs withCR:withCR
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
   802
    "return part of myself as a string with embedded cr's.
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
   803
     My elements must be strings or nil; nil entries and empty strings are
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
   804
     taken as empty lines.
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
   805
     If the argument compressTabs is true, leading spaces are converted
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
   806
     to tab-characters (8col tabs). WithCR controls whether the last line
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
   807
     should be followed by a cr or not."
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
   808
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
   809
    ^ self asStringWith:(Character cr)
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
   810
		   from:firstLine 
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
   811
		     to:lastLine 
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
   812
	   compressTabs:compressTabs 
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
   813
		  final:(withCR ifTrue:[Character cr] ifFalse:[nil])
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
   814
!
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
   815
379
5b5a130ccd09 revision added
claus
parents: 375
diff changeset
   816
decodeAsLiteralArray
1245
c8afea3d5af0 commentary
Claus Gittinger <cg@exept.de>
parents: 1188
diff changeset
   817
    "given a literalEncoding in the receiver,
c8afea3d5af0 commentary
Claus Gittinger <cg@exept.de>
parents: 1188
diff changeset
   818
     create & return the corresponding object.
c8afea3d5af0 commentary
Claus Gittinger <cg@exept.de>
parents: 1188
diff changeset
   819
     The inverse operation to #literalArrayEncoding."
c8afea3d5af0 commentary
Claus Gittinger <cg@exept.de>
parents: 1188
diff changeset
   820
379
5b5a130ccd09 revision added
claus
parents: 375
diff changeset
   821
    |cls|
5b5a130ccd09 revision added
claus
parents: 375
diff changeset
   822
5b5a130ccd09 revision added
claus
parents: 375
diff changeset
   823
    cls := Smalltalk at:(self first) ifAbsent:nil.
5b5a130ccd09 revision added
claus
parents: 375
diff changeset
   824
    cls isNil ifTrue:[
1245
c8afea3d5af0 commentary
Claus Gittinger <cg@exept.de>
parents: 1188
diff changeset
   825
        ^ self error:'unknown class in spec:' , self first.
379
5b5a130ccd09 revision added
claus
parents: 375
diff changeset
   826
    ].
5b5a130ccd09 revision added
claus
parents: 375
diff changeset
   827
    ^ cls new fromLiteralArrayEncoding:self.
5b5a130ccd09 revision added
claus
parents: 375
diff changeset
   828
5b5a130ccd09 revision added
claus
parents: 375
diff changeset
   829
    "
5b5a130ccd09 revision added
claus
parents: 375
diff changeset
   830
     #(Point 10 20) decodeAsLiteralArray  
5b5a130ccd09 revision added
claus
parents: 375
diff changeset
   831
     #(Rectangle 100 200 400 500) decodeAsLiteralArray 
5b5a130ccd09 revision added
claus
parents: 375
diff changeset
   832
    "
1245
c8afea3d5af0 commentary
Claus Gittinger <cg@exept.de>
parents: 1188
diff changeset
   833
c8afea3d5af0 commentary
Claus Gittinger <cg@exept.de>
parents: 1188
diff changeset
   834
    "Modified: 22.4.1996 / 12:59:03 / cg"
422
claus
parents: 384
diff changeset
   835
!
claus
parents: 384
diff changeset
   836
claus
parents: 384
diff changeset
   837
literalArrayEncoding
1245
c8afea3d5af0 commentary
Claus Gittinger <cg@exept.de>
parents: 1188
diff changeset
   838
    "encode myself as an array literal, from which a copy of the receiver
c8afea3d5af0 commentary
Claus Gittinger <cg@exept.de>
parents: 1188
diff changeset
   839
     can be reconstructed with #decodeAsLiteralArray."
c8afea3d5af0 commentary
Claus Gittinger <cg@exept.de>
parents: 1188
diff changeset
   840
422
claus
parents: 384
diff changeset
   841
    ^ (self collect:[:el | el literalArrayEncoding]) asArray
claus
parents: 384
diff changeset
   842
claus
parents: 384
diff changeset
   843
    "
claus
parents: 384
diff changeset
   844
     (Array with:(Color red:50 green:50 blue:50)
1245
c8afea3d5af0 commentary
Claus Gittinger <cg@exept.de>
parents: 1188
diff changeset
   845
            with:(1 @ 2)
422
claus
parents: 384
diff changeset
   846
     ) literalArrayEncoding   
claus
parents: 384
diff changeset
   847
    "
1245
c8afea3d5af0 commentary
Claus Gittinger <cg@exept.de>
parents: 1188
diff changeset
   848
c8afea3d5af0 commentary
Claus Gittinger <cg@exept.de>
parents: 1188
diff changeset
   849
    "Modified: 22.4.1996 / 13:00:56 / cg"
260
cefb485445a7 *** empty log message ***
claus
parents: 252
diff changeset
   850
! !
cefb485445a7 *** empty log message ***
claus
parents: 252
diff changeset
   851
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   852
!SequenceableCollection methodsFor:'copying'!
a27a279701f8 Initial revision
claus
parents:
diff changeset
   853
a27a279701f8 Initial revision
claus
parents:
diff changeset
   854
, aCollection
a27a279701f8 Initial revision
claus
parents:
diff changeset
   855
    "return a new collection formed from concatenating the receiver with
44
b262907c93ea *** empty log message ***
claus
parents: 42
diff changeset
   856
     the argument. The class of the new collection is determined by the
b262907c93ea *** empty log message ***
claus
parents: 42
diff changeset
   857
     receivers class, so mixing classes is possible, if the second collections
b262907c93ea *** empty log message ***
claus
parents: 42
diff changeset
   858
     elements can be stored into instances of the receivers class."
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   859
a27a279701f8 Initial revision
claus
parents:
diff changeset
   860
    |newCollection 
a27a279701f8 Initial revision
claus
parents:
diff changeset
   861
     mySize    "{ Class: SmallInteger }"
a27a279701f8 Initial revision
claus
parents:
diff changeset
   862
     newSize   "{ Class: SmallInteger }"
a27a279701f8 Initial revision
claus
parents:
diff changeset
   863
     otherSize "{ Class: SmallInteger }"
a27a279701f8 Initial revision
claus
parents:
diff changeset
   864
     dstIndex  "{ Class: SmallInteger }"|
a27a279701f8 Initial revision
claus
parents:
diff changeset
   865
a27a279701f8 Initial revision
claus
parents:
diff changeset
   866
    mySize := self size.
a27a279701f8 Initial revision
claus
parents:
diff changeset
   867
    otherSize := aCollection size.
a27a279701f8 Initial revision
claus
parents:
diff changeset
   868
    newSize := mySize + otherSize.
202
40ca7cc6fb9c *** empty log message ***
claus
parents: 186
diff changeset
   869
252
   870
    newCollection := self copyEmptyAndGrow:newSize.   "must grow, otherwise replace fails"
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   871
a27a279701f8 Initial revision
claus
parents:
diff changeset
   872
    newCollection replaceFrom:1 to:mySize with:self startingAt:1.
a27a279701f8 Initial revision
claus
parents:
diff changeset
   873
    dstIndex := mySize + 1.
202
40ca7cc6fb9c *** empty log message ***
claus
parents: 186
diff changeset
   874
    aCollection isSequenceable ifTrue:[
40ca7cc6fb9c *** empty log message ***
claus
parents: 186
diff changeset
   875
	"
40ca7cc6fb9c *** empty log message ***
claus
parents: 186
diff changeset
   876
	 yes, aCollection has indexed elements
40ca7cc6fb9c *** empty log message ***
claus
parents: 186
diff changeset
   877
	"
159
514c749165c3 *** empty log message ***
claus
parents: 118
diff changeset
   878
	newCollection replaceFrom:dstIndex to:newSize
514c749165c3 *** empty log message ***
claus
parents: 118
diff changeset
   879
			     with:aCollection startingAt:1.
514c749165c3 *** empty log message ***
claus
parents: 118
diff changeset
   880
	^ newCollection
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   881
    ] ifFalse:[
202
40ca7cc6fb9c *** empty log message ***
claus
parents: 186
diff changeset
   882
	"
40ca7cc6fb9c *** empty log message ***
claus
parents: 186
diff changeset
   883
	 no, enumerate aCollection
40ca7cc6fb9c *** empty log message ***
claus
parents: 186
diff changeset
   884
	"
159
514c749165c3 *** empty log message ***
claus
parents: 118
diff changeset
   885
	aCollection do:[:element |
514c749165c3 *** empty log message ***
claus
parents: 118
diff changeset
   886
	    newCollection at:dstIndex put:element.
514c749165c3 *** empty log message ***
claus
parents: 118
diff changeset
   887
	    dstIndex := dstIndex + 1
514c749165c3 *** empty log message ***
claus
parents: 118
diff changeset
   888
	]
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   889
    ].
a27a279701f8 Initial revision
claus
parents:
diff changeset
   890
    ^ newCollection
44
b262907c93ea *** empty log message ***
claus
parents: 42
diff changeset
   891
95
d22739a0c6e9 *** empty log message ***
claus
parents: 88
diff changeset
   892
    "
d22739a0c6e9 *** empty log message ***
claus
parents: 88
diff changeset
   893
     #($a $b $c) , #(1 2 3)
d22739a0c6e9 *** empty log message ***
claus
parents: 88
diff changeset
   894
     #($a $b $c) , '123'
d22739a0c6e9 *** empty log message ***
claus
parents: 88
diff changeset
   895
     'abc' , '123'
d22739a0c6e9 *** empty log message ***
claus
parents: 88
diff changeset
   896
     'abc' , #($q $w $e $r $t $y) asSortedCollection
d22739a0c6e9 *** empty log message ***
claus
parents: 88
diff changeset
   897
     'abc' , #(1 2 3 4 5)"  "-- will fail, since strings cannot store integers
d22739a0c6e9 *** empty log message ***
claus
parents: 88
diff changeset
   898
     'abc' asArray , #(1 2 3 4 5)
d22739a0c6e9 *** empty log message ***
claus
parents: 88
diff changeset
   899
    "
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   900
!
a27a279701f8 Initial revision
claus
parents:
diff changeset
   901
602
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
   902
copyFirst:count
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
   903
    "return a new collection consisting of the receivers first count
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
   904
     elements - this is just a rename of copyTo: - for compatibility."
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
   905
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
   906
    ^ self copyFrom:1 to:count
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
   907
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
   908
    "
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
   909
     #($a $b $c $d $e $f $g) copyFirst:5
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
   910
     '1234567890' copyFirst:4
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
   911
    "
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
   912
!
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
   913
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
   914
copyFrom:start
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
   915
    "return a new collection consisting of receivers elements
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
   916
     from start to the end of the collection"
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
   917
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
   918
    ^ self copyFrom:start to:(self size)
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
   919
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
   920
    "
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
   921
     #($a $b $c $d $e $f $g) copyFrom:2
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
   922
     '1234567890' copyFrom:2
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
   923
    "
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
   924
!
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
   925
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
   926
copyFrom:start to:stop
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
   927
    "return a new collection consisting of receivers elements
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
   928
     between start and stop"
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
   929
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
   930
    |newCollection newSize|
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
   931
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
   932
    newSize := stop - start + 1.
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
   933
    newCollection := self copyEmptyAndGrow:newSize.
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
   934
    newCollection replaceFrom:1 to:newSize with:self startingAt:start.
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
   935
    ^ newCollection
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
   936
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
   937
    "
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
   938
     #($a $b $c $d $e $f $g) copyFrom:2 to:5
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
   939
     '1234567890' copyFrom:2 to:5
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
   940
    "
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
   941
!
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
   942
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
   943
copyLast:count
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
   944
    "return a new collection consisting of the receivers last count
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
   945
     elements."
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
   946
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
   947
    |sz|
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
   948
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
   949
    sz := self size.
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
   950
    ^ self copyFrom:(sz - count + 1) to:sz
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
   951
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
   952
    "
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
   953
     #($a $b $c $d $e $f $g) copyLast:5
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
   954
     '1234567890' copyLast:4
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
   955
    "
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
   956
!
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
   957
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
   958
copyReplaceFrom:startIndex to:endIndex with:aCollection
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
   959
    "return a copy of the receiver, where the elements from startIndex to
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
   960
     endIndex have been replaced by the elements of aCollection"
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
   961
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
   962
    |newColl sz replSize|
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
   963
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
   964
    replSize := aCollection size.
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
   965
    sz := self size - (endIndex - startIndex + 1) + replSize.
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
   966
    newColl := self copyEmptyAndGrow:sz.
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
   967
    newColl replaceFrom:1 to:(startIndex - 1) with:self.
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
   968
    newColl replaceFrom:startIndex with:aCollection.
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
   969
    newColl replaceFrom:(startIndex + replSize) with:self startingAt:(endIndex + 1).
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
   970
    ^ newColl
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
   971
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
   972
    "
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
   973
     #(1 2 3 4 5 6 7 8 9 0) copyReplaceFrom:3 to:6 with:#(a b c d e f g h i j k)
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
   974
     'hello world' copyReplaceFrom:6 to:6 with:' there, '  
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
   975
    "
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
   976
!
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
   977
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
   978
copyReplaceFrom:startIndex with:aCollection
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
   979
    "return a copy of the receiver, where the elements from startIndex to
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
   980
     the end have been replaced by the elements of aCollection"
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
   981
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
   982
    ^ self copyReplaceFrom:startIndex to:(self size) with:aCollection
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
   983
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
   984
    "
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
   985
     #(1 2 3 4 5 6 7 8 9 0) copyReplaceFrom:3 with:#(a b c)  
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
   986
     'hello world' copyReplaceFrom:7 with:'smalltalk fan'  
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
   987
    "
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
   988
!
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
   989
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
   990
copyThrough:element
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
   991
    "return a new collection consisting of the receiver elements
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
   992
     up-to (AND including) the first occurence of element."
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
   993
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
   994
    |idx|
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
   995
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
   996
    idx := self indexOf:element.
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
   997
    idx == 0 ifTrue:[^ nil].    "question: is this ok?"
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
   998
    ^ self copyFrom:1 to:idx
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
   999
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  1000
    "
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  1001
     #($a $b $c $d $e $f $g) copyThrough:$d
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  1002
     '1234567890' copyThrough:$5
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  1003
     '1234567890' copyThrough:$a
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  1004
     '1234567890' copyThrough:$1
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  1005
    "
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  1006
!
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  1007
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  1008
copyTo:stop
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  1009
    "return a new collection consisting of receivers elements
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  1010
     from 1 up to (including) index stop"
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  1011
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  1012
    ^ self copyFrom:1 to:stop
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  1013
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  1014
    "
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  1015
     #($a $b $c $d $e $f $g) copyTo:5
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  1016
     '1234567890' copyTo:4
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  1017
    "
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  1018
!
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  1019
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  1020
copyUpTo:element
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  1021
    "return a new collection consisting of the receiver elements
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  1022
     up-to (but excluding) the first occurence of element;
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  1023
     or to the end, if element is not included"
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  1024
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  1025
    |idx|
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  1026
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  1027
    idx := self indexOf:element.
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  1028
    idx == 0 ifTrue:[^ self copy].    "question: is this ok?"
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  1029
    idx == 1 ifTrue:[^ self copyEmpty].
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  1030
    ^ self copyFrom:1 to:(idx-1)
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  1031
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  1032
    "
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  1033
     #($a $b $c $d $e $f $g) copyUpTo:$d
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  1034
     '1234567890' copyUpTo:$5
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  1035
     '1234567890' copyUpTo:$a
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  1036
     '1234567890' copyUpTo:$1
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  1037
     '123456789' copyUpTo:$0
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  1038
    "
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  1039
!
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  1040
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1041
copyWith:newElement
233
98f588af201a comments
claus
parents: 202
diff changeset
  1042
    "return a new collection containing the receivers elements
98f588af201a comments
claus
parents: 202
diff changeset
  1043
     and the single new element, newElement. 
98f588af201a comments
claus
parents: 202
diff changeset
  1044
     This is different from concatentation, which expects another collection
98f588af201a comments
claus
parents: 202
diff changeset
  1045
     as argument, but equivalent to copy-and-addLast."
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1046
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1047
    |newCollection mySize newSize|
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1048
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1049
    mySize := self size.
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1050
    newSize := mySize + 1.
252
  1051
    newCollection := self copyEmptyAndGrow:newSize.
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1052
    newCollection replaceFrom:1 to:mySize with:self startingAt:1.
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1053
    newCollection at:newSize put:newElement.
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1054
    ^newCollection
44
b262907c93ea *** empty log message ***
claus
parents: 42
diff changeset
  1055
95
d22739a0c6e9 *** empty log message ***
claus
parents: 88
diff changeset
  1056
    "
d22739a0c6e9 *** empty log message ***
claus
parents: 88
diff changeset
  1057
     #(1 2 3 4 5) copyWith:$a
d22739a0c6e9 *** empty log message ***
claus
parents: 88
diff changeset
  1058
     'abcdefg' copyWith:$h
d22739a0c6e9 *** empty log message ***
claus
parents: 88
diff changeset
  1059
     'abcdefg' copyWith:'123'   -- will fail: string cannot be stored into string
d22739a0c6e9 *** empty log message ***
claus
parents: 88
diff changeset
  1060
     'abcdefg' copyWith:1       -- will fail: integer cannot be stored into string
d22739a0c6e9 *** empty log message ***
claus
parents: 88
diff changeset
  1061
    "
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1062
!
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1063
61
claus
parents: 44
diff changeset
  1064
copyWithout:elementToSkip
claus
parents: 44
diff changeset
  1065
    "return a new collection consisting of a copy of the receiver, with
claus
parents: 44
diff changeset
  1066
     ALL elements equal to elementToSkip are left out.
claus
parents: 44
diff changeset
  1067
     No error is reported, if elementToSkip is not in the collection."
claus
parents: 44
diff changeset
  1068
293
31df3850e98c *** empty log message ***
claus
parents: 282
diff changeset
  1069
    |n         "{ Class: SmallInteger }"
31df3850e98c *** empty log message ***
claus
parents: 282
diff changeset
  1070
     sz        "{ Class: SmallInteger }"
31df3850e98c *** empty log message ***
claus
parents: 282
diff changeset
  1071
     srcIndex  "{ Class: SmallInteger }"
31df3850e98c *** empty log message ***
claus
parents: 282
diff changeset
  1072
     dstIndex  "{ Class: SmallInteger }"
31df3850e98c *** empty log message ***
claus
parents: 282
diff changeset
  1073
     skipIndex "{ Class: SmallInteger }"
31df3850e98c *** empty log message ***
claus
parents: 282
diff changeset
  1074
     copy l|
61
claus
parents: 44
diff changeset
  1075
claus
parents: 44
diff changeset
  1076
    "the code below may look like overkill, 
claus
parents: 44
diff changeset
  1077
     however, for big collections its better to move data
claus
parents: 44
diff changeset
  1078
     around in big chunks"
claus
parents: 44
diff changeset
  1079
claus
parents: 44
diff changeset
  1080
    n := self occurrencesOf:elementToSkip.
claus
parents: 44
diff changeset
  1081
    n == 0 ifTrue:[^ self copy].
claus
parents: 44
diff changeset
  1082
claus
parents: 44
diff changeset
  1083
    sz := self size.
252
  1084
    copy := self copyEmptyAndGrow:(sz - n).
61
claus
parents: 44
diff changeset
  1085
claus
parents: 44
diff changeset
  1086
    srcIndex := 1.
claus
parents: 44
diff changeset
  1087
    dstIndex := 1.
claus
parents: 44
diff changeset
  1088
claus
parents: 44
diff changeset
  1089
    n timesRepeat:[
159
514c749165c3 *** empty log message ***
claus
parents: 118
diff changeset
  1090
	skipIndex := self indexOf:elementToSkip startingAt:srcIndex.
514c749165c3 *** empty log message ***
claus
parents: 118
diff changeset
  1091
	l := skipIndex - srcIndex.
514c749165c3 *** empty log message ***
claus
parents: 118
diff changeset
  1092
	l ~~ 0 ifTrue:[
514c749165c3 *** empty log message ***
claus
parents: 118
diff changeset
  1093
	    copy replaceFrom:dstIndex to:(dstIndex + l - 1) 
514c749165c3 *** empty log message ***
claus
parents: 118
diff changeset
  1094
			with:self startingAt:srcIndex.
514c749165c3 *** empty log message ***
claus
parents: 118
diff changeset
  1095
	    dstIndex := dstIndex + l
514c749165c3 *** empty log message ***
claus
parents: 118
diff changeset
  1096
	].
514c749165c3 *** empty log message ***
claus
parents: 118
diff changeset
  1097
	srcIndex := skipIndex + 1
61
claus
parents: 44
diff changeset
  1098
    ].
claus
parents: 44
diff changeset
  1099
    l := sz - srcIndex.
claus
parents: 44
diff changeset
  1100
    copy replaceFrom:dstIndex to:(dstIndex + l)
159
514c749165c3 *** empty log message ***
claus
parents: 118
diff changeset
  1101
		with:self startingAt:srcIndex.
61
claus
parents: 44
diff changeset
  1102
    ^ copy
claus
parents: 44
diff changeset
  1103
95
d22739a0c6e9 *** empty log message ***
claus
parents: 88
diff changeset
  1104
    "
d22739a0c6e9 *** empty log message ***
claus
parents: 88
diff changeset
  1105
     #($a $b $c $d $e $f $g) copyWithout:$d
d22739a0c6e9 *** empty log message ***
claus
parents: 88
diff changeset
  1106
     #($a $b $c $d $e $f $g) copyWithout:$a
d22739a0c6e9 *** empty log message ***
claus
parents: 88
diff changeset
  1107
     #($a $b $c $d $e $f $g) copyWithout:$g
202
40ca7cc6fb9c *** empty log message ***
claus
parents: 186
diff changeset
  1108
     'abcdefghi' copyWithout:$h    
40ca7cc6fb9c *** empty log message ***
claus
parents: 186
diff changeset
  1109
     'abcdefg' copyWithout:$h       
95
d22739a0c6e9 *** empty log message ***
claus
parents: 88
diff changeset
  1110
     #($a $b $c $a $a $d $e $a $f $g) copyWithout:$a
d22739a0c6e9 *** empty log message ***
claus
parents: 88
diff changeset
  1111
     #($a $b $c $d $e $f $g) copyWithout:$x
d22739a0c6e9 *** empty log message ***
claus
parents: 88
diff changeset
  1112
     #(90 80 70 60 50) copyWithout:70
d22739a0c6e9 *** empty log message ***
claus
parents: 88
diff changeset
  1113
     #(90 80 70 80 60 45 80 50) copyWithout:80
d22739a0c6e9 *** empty log message ***
claus
parents: 88
diff changeset
  1114
    "
61
claus
parents: 44
diff changeset
  1115
!
claus
parents: 44
diff changeset
  1116
602
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  1117
copyWithoutFirst:elementToSkip
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  1118
    "return a new collection consisting of a copy of the receivers elements
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  1119
     without the first elementToSkip, if it was present. 
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  1120
     No error is reported, if elementToSkip is not in the collection."
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  1121
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  1122
    |copy skipIndex sz|
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  1123
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  1124
    skipIndex := self indexOf:elementToSkip startingAt:1.
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  1125
    (skipIndex == 0) ifTrue:[^ self copy].
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  1126
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  1127
    sz := self size - 1.
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  1128
    copy := self copyEmptyAndGrow:sz.
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  1129
    copy replaceFrom:1 to:(skipIndex - 1) with:self startingAt:1.
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  1130
    copy replaceFrom:skipIndex to:sz with:self startingAt:(skipIndex + 1).
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  1131
    ^ copy
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  1132
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  1133
    "
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  1134
     #($a $b $c $d $e $f $g) copyWithoutFirst:$d
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  1135
     #($a $b $c $d $e $f $g) copyWithoutFirst:$x
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  1136
     #(90 80 70 60 50) copyWithoutFirst:70
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  1137
     #(90 80 70 80 60 45 80 50) copyWithoutFirst:80
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  1138
    "
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  1139
!
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  1140
61
claus
parents: 44
diff changeset
  1141
copyWithoutIndex:omitIndex
claus
parents: 44
diff changeset
  1142
    "return a new collection consisting of receivers elements
claus
parents: 44
diff changeset
  1143
     without the argument stored at omitIndex"
claus
parents: 44
diff changeset
  1144
claus
parents: 44
diff changeset
  1145
    |copy sz|
claus
parents: 44
diff changeset
  1146
202
40ca7cc6fb9c *** empty log message ***
claus
parents: 186
diff changeset
  1147
    sz := self size - 1.
252
  1148
    copy := self copyEmptyAndGrow:sz.
293
31df3850e98c *** empty log message ***
claus
parents: 282
diff changeset
  1149
    copy replaceFrom:1 to:(omitIndex - 1) with:self startingAt:1.
31df3850e98c *** empty log message ***
claus
parents: 282
diff changeset
  1150
    copy replaceFrom:omitIndex to:sz with:self startingAt:(omitIndex + 1).
61
claus
parents: 44
diff changeset
  1151
    ^ copy
claus
parents: 44
diff changeset
  1152
95
d22739a0c6e9 *** empty log message ***
claus
parents: 88
diff changeset
  1153
    "
d22739a0c6e9 *** empty log message ***
claus
parents: 88
diff changeset
  1154
     #(1 2 3 4 5 6 7 8 9 0) copyWithoutIndex:3
d22739a0c6e9 *** empty log message ***
claus
parents: 88
diff changeset
  1155
     'abcdefghijkl' copyWithoutIndex:5
d22739a0c6e9 *** empty log message ***
claus
parents: 88
diff changeset
  1156
    "
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1157
!
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1158
202
40ca7cc6fb9c *** empty log message ***
claus
parents: 186
diff changeset
  1159
copyWithoutLast:count
40ca7cc6fb9c *** empty log message ***
claus
parents: 186
diff changeset
  1160
    "return a new collection consisting of the receivers elements
40ca7cc6fb9c *** empty log message ***
claus
parents: 186
diff changeset
  1161
     except the last count elements."
40ca7cc6fb9c *** empty log message ***
claus
parents: 186
diff changeset
  1162
40ca7cc6fb9c *** empty log message ***
claus
parents: 186
diff changeset
  1163
    |sz|
40ca7cc6fb9c *** empty log message ***
claus
parents: 186
diff changeset
  1164
40ca7cc6fb9c *** empty log message ***
claus
parents: 186
diff changeset
  1165
    sz := self size.
40ca7cc6fb9c *** empty log message ***
claus
parents: 186
diff changeset
  1166
    ^ self copyTo:(sz - count)
40ca7cc6fb9c *** empty log message ***
claus
parents: 186
diff changeset
  1167
40ca7cc6fb9c *** empty log message ***
claus
parents: 186
diff changeset
  1168
    "
40ca7cc6fb9c *** empty log message ***
claus
parents: 186
diff changeset
  1169
     #($a $b $c $d $e $f $g) copyWithoutLast:5 
40ca7cc6fb9c *** empty log message ***
claus
parents: 186
diff changeset
  1170
     '1234567890' copyWithoutLast:4 
40ca7cc6fb9c *** empty log message ***
claus
parents: 186
diff changeset
  1171
    "
602
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  1172
! !
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  1173
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  1174
!SequenceableCollection methodsFor:'enumerating'!
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  1175
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  1176
collect:aBlock
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  1177
    "evaluate the argument, aBlock for every element in the collection
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  1178
     and return a collection of the results"
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  1179
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  1180
    |newCollection
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  1181
     sz  "{ Class:SmallInteger }"|
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  1182
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  1183
    sz := self size.
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  1184
    newCollection := self copyEmptyAndGrow:sz.
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  1185
    1 to:sz do:[:index |
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  1186
	newCollection at:index put:(aBlock value:(self at:index)).
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  1187
    ].
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  1188
    ^ newCollection
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  1189
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  1190
    "
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  1191
     #(one two three four five six) collect:[:element | element asUppercase]  
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  1192
     #(1 2 3 4 5 6 7 8 9) collect:[:element | element factorial]   
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  1193
     (1 to:9) collect:[:element | element * element]   
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  1194
    "
202
40ca7cc6fb9c *** empty log message ***
claus
parents: 186
diff changeset
  1195
!
40ca7cc6fb9c *** empty log message ***
claus
parents: 186
diff changeset
  1196
602
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  1197
do:aBlock
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  1198
    "evaluate the argument, aBlock for every element in the collection."
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  1199
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  1200
    |stop "{ Class:SmallInteger }"|
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  1201
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  1202
    stop := self size.
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  1203
    1 to:stop do:[:index |
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  1204
	aBlock value:(self at:index).
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  1205
    ]
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  1206
    "
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  1207
     #(one two three four five six) do:[:element | Transcript showCr:element]
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  1208
    "
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  1209
!
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  1210
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  1211
from:startIndex do:aBlock
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  1212
    "evaluate the argument, aBlock for the elements starting with the
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  1213
     element at startIndex to the end."
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  1214
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  1215
    ^ self from:startIndex to:self size do:aBlock
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1216
95
d22739a0c6e9 *** empty log message ***
claus
parents: 88
diff changeset
  1217
    "
602
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  1218
     #(one two three four five six) from:3 do:[:element | Transcript showCr:element]
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  1219
    "
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  1220
!
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  1221
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  1222
from:start to:stop collect:aBlock
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  1223
    "evaluate the argument, aBlock for the elements indexed by start
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  1224
     to stop in the collection and return a collection of the results"
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  1225
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  1226
    |newCollection sz
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  1227
     idx  "{ Class:SmallInteger }"|
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  1228
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  1229
    sz := stop - start + 1.
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  1230
    newCollection := self copyEmptyAndGrow:sz.
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  1231
    idx := 1.
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  1232
    start to:stop do:[:index |
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  1233
	newCollection at:idx put:(aBlock value:(self at:index)).
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  1234
	idx := idx + 1
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  1235
    ].
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  1236
    ^ newCollection
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  1237
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  1238
    "
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  1239
     #(one two three four five six) from:2 to:4 collect:[:element | element asUppercase]  
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  1240
    "
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  1241
!
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  1242
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  1243
from:index1 to:index2 do:aBlock
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  1244
    "evaluate the argument, aBlock for the elements with index index1 to
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  1245
     index2 in the collection"
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  1246
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  1247
    |start "{ Class:SmallInteger }"
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  1248
     stop  "{ Class:SmallInteger }" |
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  1249
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  1250
    start := index1.
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  1251
    stop := index2.
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  1252
    start to:stop do:[:index |
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  1253
	aBlock value:(self at:index).
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  1254
    ]
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  1255
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  1256
    "
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  1257
     #(one two three four five six) from:3 to:5 do:[:element | Transcript showCr:element]
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  1258
    "
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  1259
!
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  1260
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  1261
from:index1 to:index2 reverseDo:aBlock
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  1262
    "evaluate the argument, aBlock for the elements with index index1 to
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  1263
     index2 in the collection. Step in reverse order"
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  1264
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  1265
    |start "{ Class:SmallInteger }"
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  1266
     stop  "{ Class:SmallInteger }" |
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  1267
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  1268
    start := index1.
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  1269
    stop := index2.
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  1270
    stop to:start by:-1 do:[:index |
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  1271
	aBlock value:(self at:index).
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  1272
    ]
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  1273
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  1274
    "
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  1275
     #(one two three four five six) from:3 to:5 reverseDo:[:element | Transcript showCr:element]
95
d22739a0c6e9 *** empty log message ***
claus
parents: 88
diff changeset
  1276
    "
61
claus
parents: 44
diff changeset
  1277
!
claus
parents: 44
diff changeset
  1278
602
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  1279
keysAndValuesDo:aTwoArgBlock
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  1280
    "evaluate the argument, aBlock for every element in the collection,
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  1281
     passing both index and element as arguments."
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  1282
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  1283
    |stop  "{ Class:SmallInteger }"|
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  1284
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  1285
    stop := self size.
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  1286
    1 to:stop do:[:index |
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  1287
	aTwoArgBlock value:index value:(self at:index).
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  1288
    ]
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  1289
    "
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  1290
     #(one two three four five six) keysAndValuesDo:[:key :element | Transcript show:key; space; showCr:element]
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  1291
    "
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  1292
!
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  1293
1359
5ff95f3f0baf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1289
diff changeset
  1294
keysAndValuesReverseDo:aTwoArgBlock
5ff95f3f0baf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1289
diff changeset
  1295
    "evaluate the argument, aBlock in reverse order, for every element 
5ff95f3f0baf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1289
diff changeset
  1296
     in the collection, passing both index and element as arguments."
5ff95f3f0baf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1289
diff changeset
  1297
5ff95f3f0baf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1289
diff changeset
  1298
    |stop  "{ Class:SmallInteger }"|
5ff95f3f0baf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1289
diff changeset
  1299
5ff95f3f0baf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1289
diff changeset
  1300
    stop := self size.
5ff95f3f0baf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1289
diff changeset
  1301
    stop to:1 by:-1 do:[:index |
5ff95f3f0baf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1289
diff changeset
  1302
        aTwoArgBlock value:index value:(self at:index).
5ff95f3f0baf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1289
diff changeset
  1303
    ]
5ff95f3f0baf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1289
diff changeset
  1304
5ff95f3f0baf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1289
diff changeset
  1305
    "
5ff95f3f0baf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1289
diff changeset
  1306
     #(one two three four five six) 
5ff95f3f0baf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1289
diff changeset
  1307
        keysAndValuesReverseDo:[:key :element | Transcript show:key; space; showCr:element]
5ff95f3f0baf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1289
diff changeset
  1308
    "
5ff95f3f0baf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1289
diff changeset
  1309
5ff95f3f0baf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1289
diff changeset
  1310
    "Modified: 9.5.1996 / 00:57:23 / cg"
5ff95f3f0baf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1289
diff changeset
  1311
!
5ff95f3f0baf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1289
diff changeset
  1312
602
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  1313
nonNilElementsDo:aBlock
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  1314
    "evaluate the argument, aBlock for every non-nil element in the collection."
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  1315
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  1316
    |stop "{ Class:SmallInteger }"
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  1317
     element|
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  1318
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  1319
    stop := self size.
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  1320
    1 to:stop do:[:index |
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  1321
	(element := self at:index) notNil ifTrue:[
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  1322
	    aBlock value:element.
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  1323
	]
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  1324
    ]
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  1325
    "
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  1326
     #(one nil three nil five nil seven) nonNilElementsDo:[:element | Transcript showCr:element]
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  1327
    "
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  1328
!
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  1329
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  1330
pairWiseCollect:aBlock
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  1331
    "evaluate the argument, aBlock for every pair of elements in the collection.
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  1332
     The block is called with 2 arguments for each 2 elements in the receiver.
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  1333
     An error will be reported, if the number of elements in the receiver
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  1334
     is not a multiple of 2.
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  1335
     Collect the results and return a new collection containing those."
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  1336
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  1337
    |stop newCollection dstIdx "{ Class:SmallInteger }"|
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  1338
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  1339
    stop := self size.
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  1340
    newCollection := self copyEmptyAndGrow:stop // 2.
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  1341
    dstIdx := 1.
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  1342
    1 to:stop by:2 do:[:index |
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  1343
	newCollection at:dstIdx put:(aBlock value:(self at:index) value:(self at:index+1)).
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  1344
	dstIdx := dstIdx + 1
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  1345
    ].
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  1346
    ^ newCollection
44
b262907c93ea *** empty log message ***
claus
parents: 42
diff changeset
  1347
95
d22739a0c6e9 *** empty log message ***
claus
parents: 88
diff changeset
  1348
    "
602
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  1349
     #(1 one 2 two 3 three 4 four 5 five 6 six) 
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  1350
     pairWiseCollect:[:num :sym | sym->num] 
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  1351
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  1352
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  1353
     #(1 1  1 2  1 3  1 4  1 5) 
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  1354
     pairWiseCollect:[:x :y | x@y] 
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  1355
    "
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  1356
!
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  1357
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  1358
pairWiseDo:aBlock
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  1359
    "evaluate the argument, aBlock for every pair of elements in the collection.
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  1360
     The block is called with 2 arguments for each 2 elements in the receiver.
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  1361
     An error will be reported, if the number of elements in the receiver
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  1362
     is not a multiple of 2."
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  1363
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  1364
    |stop "{ Class:SmallInteger }"|
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  1365
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  1366
    stop := self size.
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  1367
    1 to:stop by:2 do:[:index |
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  1368
	aBlock value:(self at:index) value:(self at:index+1).
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  1369
    ]
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  1370
    "
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  1371
     #(1 one 2 two 3 three 4 four 5 five 6 six) 
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  1372
     pairWiseDo:[:num :sym | Transcript show:num; show:' is: '; showCr:sym]
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  1373
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  1374
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  1375
     #(1 1  1 2  1 3  1 4  1 5) 
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  1376
     pairWiseDo:[:x :y | Transcript showCr:x@y]
95
d22739a0c6e9 *** empty log message ***
claus
parents: 88
diff changeset
  1377
    "
61
claus
parents: 44
diff changeset
  1378
!
claus
parents: 44
diff changeset
  1379
602
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  1380
reverseDo:aBlock
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  1381
    "evaluate the argument, aBlock for every element in the collection
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  1382
     in reverse order"
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  1383
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  1384
    |sz  "{ Class:SmallInteger }"|
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  1385
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  1386
    sz := self size.
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  1387
    sz to:1 by:-1 do:[:index |
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  1388
	aBlock value:(self at:index).
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  1389
    ]
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  1390
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  1391
    "
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  1392
     #(one two three four five six) reverseDo:[:element | Transcript showCr:element]
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  1393
    "
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  1394
!
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  1395
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  1396
select:aBlock
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  1397
    "evaluate the argument, aBlock for every element in the collection
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  1398
     and return a collection of all elements for which the block return
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  1399
     true"
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  1400
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  1401
    |element newColl species needCopy
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  1402
     sz  "{ Class:SmallInteger }"|
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  1403
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  1404
    sz := self size.
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  1405
    species := self species.
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  1406
    species growIsCheap ifFalse:[
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  1407
	newColl := OrderedCollection new:sz.
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  1408
	needCopy := true
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  1409
    ] ifTrue:[
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  1410
	newColl := self copyEmpty:sz.
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  1411
	needCopy := false
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  1412
    ].
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  1413
    1 to:sz do:[:index |
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  1414
	element := self at:index.
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  1415
	(aBlock value:element) ifTrue:[
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  1416
	    newColl add:element
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  1417
	].
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  1418
    ].
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  1419
    needCopy ifTrue:[
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  1420
	newColl := (species withAll:newColl) postCopyFrom:self
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  1421
    ].
61
claus
parents: 44
diff changeset
  1422
    ^ newColl
claus
parents: 44
diff changeset
  1423
95
d22739a0c6e9 *** empty log message ***
claus
parents: 88
diff changeset
  1424
    "
602
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  1425
     #(one two three four five six) select:[:element | element startsWith:'f']   
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  1426
     #(1 2 3 4 5 6 7 8 9) select:[:element | element odd]   
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  1427
     (#(17 12 1 98 51) asSortedCollection:[:a :b | b < a]) select:[:element | element odd]   
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  1428
     (1 to:9) select:[:element | element odd]   
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  1429
     (Smalltalk allClasses) select:[:class | class name startsWith:'S']   
95
d22739a0c6e9 *** empty log message ***
claus
parents: 88
diff changeset
  1430
    "
186
a4c3032fc825 *** empty log message ***
claus
parents: 159
diff changeset
  1431
!
a4c3032fc825 *** empty log message ***
claus
parents: 159
diff changeset
  1432
602
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  1433
with:aSequenceableCollection do:aTwoArgBlock
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  1434
    "evaluate the argument, aBlock for successive elements from
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  1435
     each the receiver and the argument, aSequenceableCollection.
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  1436
     The second argument, aBlock must be a two-argument block.
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  1437
     The collection argument must implement access via a numeric key."
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  1438
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  1439
    |stop  "{ Class: SmallInteger }" |
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  1440
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  1441
    stop := self size.
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  1442
    1 to:stop do:[:index |
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  1443
	aTwoArgBlock value:(self at:index) value:(aSequenceableCollection at:index).
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  1444
    ]
186
a4c3032fc825 *** empty log message ***
claus
parents: 159
diff changeset
  1445
    "
602
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  1446
     #(one two three four five six) with:(1 to:10) do:[:el1 :el2 | Transcript show:el1; space; showCr:el2]
186
a4c3032fc825 *** empty log message ***
claus
parents: 159
diff changeset
  1447
    "
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1448
! !
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1449
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1450
!SequenceableCollection methodsFor:'filling and replacing'!
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1451
602
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  1452
atAllPut:anObject
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  1453
    "replace all elements of the collection by the argument, anObject.
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  1454
     Notice: This operation modifies the receiver, NOT a copy;
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  1455
     therefore the change may affect all others referencing the receiver."
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  1456
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  1457
    self from:1 to:(self size) put:anObject
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  1458
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  1459
    "
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  1460
     (Array new:10) atAllPut:1
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  1461
     (String new:10) atAllPut:$a
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  1462
    "
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  1463
!
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  1464
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1465
from:index1 to:index2 put:anObject
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1466
    "replace the elements from index1 to index2 of the collection
44
b262907c93ea *** empty log message ***
claus
parents: 42
diff changeset
  1467
     by the argument, anObject.
b262907c93ea *** empty log message ***
claus
parents: 42
diff changeset
  1468
     Notice: This operation modifies the receiver, NOT a copy;
b262907c93ea *** empty log message ***
claus
parents: 42
diff changeset
  1469
     therefore the change may affect all others referencing the receiver."
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1470
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1471
    |index "{ Class: SmallInteger }"
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1472
     end   "{ Class: SmallInteger }"|
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1473
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1474
    index := index1.
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1475
    end := index2.
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1476
    [index <= end] whileTrue:[
159
514c749165c3 *** empty log message ***
claus
parents: 118
diff changeset
  1477
	self at:index put:anObject.
514c749165c3 *** empty log message ***
claus
parents: 118
diff changeset
  1478
	index := index + 1
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1479
    ]
44
b262907c93ea *** empty log message ***
claus
parents: 42
diff changeset
  1480
95
d22739a0c6e9 *** empty log message ***
claus
parents: 88
diff changeset
  1481
    "
d22739a0c6e9 *** empty log message ***
claus
parents: 88
diff changeset
  1482
     #(1 2 3 4 5 6 7 8 9 0) from:3 to:6 put:$X
d22739a0c6e9 *** empty log message ***
claus
parents: 88
diff changeset
  1483
     'abcdefghijkl' from:3 to:6 put:$X
d22739a0c6e9 *** empty log message ***
claus
parents: 88
diff changeset
  1484
    "
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1485
!
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1486
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1487
replaceAll:oldObject by:newObject
44
b262907c93ea *** empty log message ***
claus
parents: 42
diff changeset
  1488
    "replace all oldObjects by newObject in the receiver.
b262907c93ea *** empty log message ***
claus
parents: 42
diff changeset
  1489
     Notice: This operation modifies the receiver, NOT a copy;
b262907c93ea *** empty log message ***
claus
parents: 42
diff changeset
  1490
     therefore the change may affect all others referencing the receiver."
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1491
362
claus
parents: 360
diff changeset
  1492
    ^ self replaceAll:oldObject by:newObject from:1 to:self size
claus
parents: 360
diff changeset
  1493
claus
parents: 360
diff changeset
  1494
    "
claus
parents: 360
diff changeset
  1495
     '123123abc123' replaceAll:$1 by:$*  
claus
parents: 360
diff changeset
  1496
    "
claus
parents: 360
diff changeset
  1497
!
293
31df3850e98c *** empty log message ***
claus
parents: 282
diff changeset
  1498
362
claus
parents: 360
diff changeset
  1499
replaceAll:oldObject by:newObject from:startIndex to:stopIndex
claus
parents: 360
diff changeset
  1500
    "replace all oldObjects found between startIndex and endIndex,
claus
parents: 360
diff changeset
  1501
     by newObject in the receiver.
claus
parents: 360
diff changeset
  1502
     Notice: This operation modifies the receiver, NOT a copy;
claus
parents: 360
diff changeset
  1503
     therefore the change may affect all others referencing the receiver."
claus
parents: 360
diff changeset
  1504
claus
parents: 360
diff changeset
  1505
    |start "{ Class: SmallInteger }"
claus
parents: 360
diff changeset
  1506
     stop  "{ Class: SmallInteger }"|
claus
parents: 360
diff changeset
  1507
claus
parents: 360
diff changeset
  1508
    start := startIndex.
claus
parents: 360
diff changeset
  1509
    stop := stopIndex.
claus
parents: 360
diff changeset
  1510
    startIndex to:stopIndex do:[:index |
159
514c749165c3 *** empty log message ***
claus
parents: 118
diff changeset
  1511
	(self at:index) = oldObject ifTrue:[
514c749165c3 *** empty log message ***
claus
parents: 118
diff changeset
  1512
	    self at:index put:newObject
514c749165c3 *** empty log message ***
claus
parents: 118
diff changeset
  1513
	]
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1514
    ]
44
b262907c93ea *** empty log message ***
claus
parents: 42
diff changeset
  1515
95
d22739a0c6e9 *** empty log message ***
claus
parents: 88
diff changeset
  1516
    "
362
claus
parents: 360
diff changeset
  1517
     '123123abc123' replaceAll:$1 by:$*              
claus
parents: 360
diff changeset
  1518
     '123123abc123' replaceAll:$1 by:$* from:1 to:6   
95
d22739a0c6e9 *** empty log message ***
claus
parents: 88
diff changeset
  1519
    "
d22739a0c6e9 *** empty log message ***
claus
parents: 88
diff changeset
  1520
!
d22739a0c6e9 *** empty log message ***
claus
parents: 88
diff changeset
  1521
602
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  1522
replaceAll:oldObject with:newObject
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  1523
    "ST-80 compatibility: an alias for #replaceAll:by:"
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  1524
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  1525
    ^ self replaceAll:oldObject by:newObject
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  1526
!
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  1527
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  1528
replaceAll:oldObject with:newObject from:startIndex to:stopIndex
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  1529
    "ST-80 compatibility: an alias for #replaceAll:by:from:to:"
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  1530
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  1531
    ^ self replaceAll:oldObject by:newObject from:startIndex to:stopIndex
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  1532
!
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  1533
95
d22739a0c6e9 *** empty log message ***
claus
parents: 88
diff changeset
  1534
replaceAny:aCollection by:newObject
d22739a0c6e9 *** empty log message ***
claus
parents: 88
diff changeset
  1535
    "replace all elements, which are in aCollection by newObject in the receiver.
d22739a0c6e9 *** empty log message ***
claus
parents: 88
diff changeset
  1536
     Notice: This operation modifies the receiver, NOT a copy;
d22739a0c6e9 *** empty log message ***
claus
parents: 88
diff changeset
  1537
     therefore the change may affect all others referencing the receiver."
d22739a0c6e9 *** empty log message ***
claus
parents: 88
diff changeset
  1538
362
claus
parents: 360
diff changeset
  1539
    ^ self replaceAny:aCollection by:newObject from:1 to:self size 
claus
parents: 360
diff changeset
  1540
claus
parents: 360
diff changeset
  1541
    "
claus
parents: 360
diff changeset
  1542
     '123123abc123' replaceAny:#($1 $2) by:$*      
claus
parents: 360
diff changeset
  1543
     #('foo' 'bar' 'foo' 'baz' foo 1 2 3) replaceAny:#(foo 1) by:'*'  
claus
parents: 360
diff changeset
  1544
    "
claus
parents: 360
diff changeset
  1545
!
293
31df3850e98c *** empty log message ***
claus
parents: 282
diff changeset
  1546
362
claus
parents: 360
diff changeset
  1547
replaceAny:aCollection by:newObject from:startIndex to:stopIndex
claus
parents: 360
diff changeset
  1548
    "replace all elements within a range,
claus
parents: 360
diff changeset
  1549
     which are in contained in aCollection by newObject.
claus
parents: 360
diff changeset
  1550
     Notice: This operation modifies the receiver, NOT a copy;
claus
parents: 360
diff changeset
  1551
     therefore the change may affect all others referencing the receiver."
claus
parents: 360
diff changeset
  1552
claus
parents: 360
diff changeset
  1553
    |start "{ Class: SmallInteger }"
claus
parents: 360
diff changeset
  1554
     stop "{ Class: SmallInteger }"|
claus
parents: 360
diff changeset
  1555
claus
parents: 360
diff changeset
  1556
    start := startIndex.
claus
parents: 360
diff changeset
  1557
    stop := stopIndex.
claus
parents: 360
diff changeset
  1558
    startIndex to:stopIndex do:[:index |
159
514c749165c3 *** empty log message ***
claus
parents: 118
diff changeset
  1559
	(aCollection includes:(self at:index)) ifTrue:[
514c749165c3 *** empty log message ***
claus
parents: 118
diff changeset
  1560
	    self at:index put:newObject
514c749165c3 *** empty log message ***
claus
parents: 118
diff changeset
  1561
	]
95
d22739a0c6e9 *** empty log message ***
claus
parents: 88
diff changeset
  1562
    ]
d22739a0c6e9 *** empty log message ***
claus
parents: 88
diff changeset
  1563
d22739a0c6e9 *** empty log message ***
claus
parents: 88
diff changeset
  1564
    "
362
claus
parents: 360
diff changeset
  1565
     '123123abc123' replaceAny:#($1 $2) by:$* from:1 to:6      
95
d22739a0c6e9 *** empty log message ***
claus
parents: 88
diff changeset
  1566
     #('foo' 'bar' 'foo' 'baz' foo 1 2 3) replaceAny:#(foo 1) by:'*'  
d22739a0c6e9 *** empty log message ***
claus
parents: 88
diff changeset
  1567
    "
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1568
!
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1569
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1570
replaceFrom:start to:stop with:replacementCollection
44
b262907c93ea *** empty log message ***
claus
parents: 42
diff changeset
  1571
    "replace elements in the receiver between index start and stop,
b262907c93ea *** empty log message ***
claus
parents: 42
diff changeset
  1572
     with elements taken from replacementCollection starting at 1.
b262907c93ea *** empty log message ***
claus
parents: 42
diff changeset
  1573
     Notice: This operation modifies the receiver, NOT a copy;
b262907c93ea *** empty log message ***
claus
parents: 42
diff changeset
  1574
     therefore the change may affect all others referencing the receiver."
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1575
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1576
    ^ self replaceFrom:start
159
514c749165c3 *** empty log message ***
claus
parents: 118
diff changeset
  1577
		    to:stop
514c749165c3 *** empty log message ***
claus
parents: 118
diff changeset
  1578
		  with:replacementCollection
514c749165c3 *** empty log message ***
claus
parents: 118
diff changeset
  1579
	    startingAt:1
61
claus
parents: 44
diff changeset
  1580
95
d22739a0c6e9 *** empty log message ***
claus
parents: 88
diff changeset
  1581
    "
d22739a0c6e9 *** empty log message ***
claus
parents: 88
diff changeset
  1582
     '1234567890' replaceFrom:5 to:7 with:'abcdef'
d22739a0c6e9 *** empty log message ***
claus
parents: 88
diff changeset
  1583
     #($a $b $c $d $e) replaceFrom:2 to:3 with:'12345'
d22739a0c6e9 *** empty log message ***
claus
parents: 88
diff changeset
  1584
    "
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1585
!
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1586
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1587
replaceFrom:start to:stop with:replacementCollection startingAt:repStart
44
b262907c93ea *** empty log message ***
claus
parents: 42
diff changeset
  1588
    "replace elements in the receiver between index start and stop,
b262907c93ea *** empty log message ***
claus
parents: 42
diff changeset
  1589
     with elements  taken from replacementCollection starting at repStart.
b262907c93ea *** empty log message ***
claus
parents: 42
diff changeset
  1590
     Notice: This operation modifies the receiver, NOT a copy;
b262907c93ea *** empty log message ***
claus
parents: 42
diff changeset
  1591
     therefore the change may affect all others referencing the receiver."
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1592
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1593
    |srcIndex "{ Class: SmallInteger }"
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1594
     dstIndex "{ Class: SmallInteger }"
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1595
     end      "{ Class: SmallInteger }" |
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1596
293
31df3850e98c *** empty log message ***
claus
parents: 282
diff changeset
  1597
    (repStart < start) ifTrue:[
31df3850e98c *** empty log message ***
claus
parents: 282
diff changeset
  1598
	" must do reverse copy "
31df3850e98c *** empty log message ***
claus
parents: 282
diff changeset
  1599
	srcIndex := repStart + (stop - start).
31df3850e98c *** empty log message ***
claus
parents: 282
diff changeset
  1600
	dstIndex := stop.
31df3850e98c *** empty log message ***
claus
parents: 282
diff changeset
  1601
	end := start.
31df3850e98c *** empty log message ***
claus
parents: 282
diff changeset
  1602
	[dstIndex >= end] whileTrue:[
31df3850e98c *** empty log message ***
claus
parents: 282
diff changeset
  1603
	    self at:dstIndex put:(replacementCollection at:srcIndex).
31df3850e98c *** empty log message ***
claus
parents: 282
diff changeset
  1604
	    srcIndex := srcIndex - 1.
31df3850e98c *** empty log message ***
claus
parents: 282
diff changeset
  1605
	    dstIndex := dstIndex - 1
31df3850e98c *** empty log message ***
claus
parents: 282
diff changeset
  1606
	].
31df3850e98c *** empty log message ***
claus
parents: 282
diff changeset
  1607
	^ self
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1608
    ].
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1609
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1610
    srcIndex := repStart.
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1611
    dstIndex := start.
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1612
    end := stop.
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1613
    [dstIndex <= end] whileTrue:[
159
514c749165c3 *** empty log message ***
claus
parents: 118
diff changeset
  1614
	self at:dstIndex put:(replacementCollection at:srcIndex).
514c749165c3 *** empty log message ***
claus
parents: 118
diff changeset
  1615
	srcIndex := srcIndex + 1.
514c749165c3 *** empty log message ***
claus
parents: 118
diff changeset
  1616
	dstIndex := dstIndex + 1
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1617
    ]
61
claus
parents: 44
diff changeset
  1618
95
d22739a0c6e9 *** empty log message ***
claus
parents: 88
diff changeset
  1619
    "
282
94f5c3a6230d *** empty log message ***
claus
parents: 266
diff changeset
  1620
     '1234567890' replaceFrom:5 to:7 with:'abcdef' startingAt:3  
94f5c3a6230d *** empty log message ***
claus
parents: 266
diff changeset
  1621
     #($a $b $c $d $e) replaceFrom:2 to:3 with:'12345' startingAt:4 
94f5c3a6230d *** empty log message ***
claus
parents: 266
diff changeset
  1622
     #($a $b $c $d $e) asOrderedCollection replaceFrom:2 to:3 with:'12345' startingAt:4 
94f5c3a6230d *** empty log message ***
claus
parents: 266
diff changeset
  1623
94f5c3a6230d *** empty log message ***
claus
parents: 266
diff changeset
  1624
     |c|
94f5c3a6230d *** empty log message ***
claus
parents: 266
diff changeset
  1625
     c := #($a $b $c $d $e) asOrderedCollection.
94f5c3a6230d *** empty log message ***
claus
parents: 266
diff changeset
  1626
     c replaceFrom:2 to:3 with:c startingAt:4  
94f5c3a6230d *** empty log message ***
claus
parents: 266
diff changeset
  1627
94f5c3a6230d *** empty log message ***
claus
parents: 266
diff changeset
  1628
     |c|
94f5c3a6230d *** empty log message ***
claus
parents: 266
diff changeset
  1629
     c := #($a $b $c $d $e) asOrderedCollection.
94f5c3a6230d *** empty log message ***
claus
parents: 266
diff changeset
  1630
     c replaceFrom:4 to:5 with:c startingAt:2  
95
d22739a0c6e9 *** empty log message ***
claus
parents: 88
diff changeset
  1631
    "
61
claus
parents: 44
diff changeset
  1632
!
claus
parents: 44
diff changeset
  1633
602
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  1634
replaceFrom:start with:replacementCollection
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  1635
    "replace elements in the receiver starting at start,
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  1636
     with elements taken from replacementCollection starting at 1
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  1637
     to the end of replacementCollection.
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  1638
     Notice: This operation modifies the receiver, NOT a copy;
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  1639
     therefore the change may affect all others referencing the receiver."
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  1640
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  1641
    ^ self replaceFrom:start 
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  1642
		    to:(start + replacementCollection size - 1)
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  1643
		  with:replacementCollection
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  1644
	    startingAt:1
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  1645
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  1646
    "
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  1647
     '1234567890' replaceFrom:5 with:'abc'
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  1648
     #($a $b $c $d $e) replaceFrom:2 with:'123'
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  1649
    "
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  1650
!
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  1651
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  1652
replaceFrom:start with:replacementCollection startingAt:offset
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  1653
    "replace elements in the receiver starting at start,
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  1654
     with elements taken from replacementCollection starting at offset
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  1655
     to the end of replacementCollection.
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  1656
     Notice: This operation modifies the receiver, NOT a copy;
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  1657
     therefore the change may affect all others referencing the receiver."
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  1658
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  1659
    ^ self replaceFrom:start 
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  1660
		    to:(start + replacementCollection size - offset)
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  1661
		  with:replacementCollection
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  1662
	    startingAt:offset
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  1663
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  1664
    "
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  1665
     '1234567890' replaceFrom:5 with:'abcdef' startingAt:3
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  1666
     #($a $b $c $d $e) replaceFrom:2 with:'12345' startingAt:4
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  1667
    "
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  1668
!
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  1669
61
claus
parents: 44
diff changeset
  1670
startingAt:sourceStart replaceElementsIn:destColl from:destStartIndex to:destEndIndex
claus
parents: 44
diff changeset
  1671
    "replace elements in destColl with elements from the receiver.
claus
parents: 44
diff changeset
  1672
     Notice: This operation modifies the destination collection, NOT a copy;
claus
parents: 44
diff changeset
  1673
     therefore the change may affect all others referencing this object."
claus
parents: 44
diff changeset
  1674
claus
parents: 44
diff changeset
  1675
    destColl replaceFrom:destStartIndex to:destEndIndex with:self startingAt:sourceStart
claus
parents: 44
diff changeset
  1676
claus
parents: 44
diff changeset
  1677
    "
claus
parents: 44
diff changeset
  1678
     |s|
claus
parents: 44
diff changeset
  1679
     s := 'abcdefghijklmnop'.
claus
parents: 44
diff changeset
  1680
     '1234567890' startingAt:1 replaceElementsIn:s from:1 to:3.
claus
parents: 44
diff changeset
  1681
     s'123defghijklmnop'
claus
parents: 44
diff changeset
  1682
    "
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1683
! !
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1684
602
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  1685
!SequenceableCollection methodsFor:'queries'!
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  1686
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  1687
firstIndex
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  1688
    "return the first elements index"
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  1689
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  1690
    ^ 1
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  1691
!
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  1692
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  1693
isSequenceable
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  1694
    "return true, if the receiver is some kind of sequenceableCollection"
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  1695
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  1696
    ^ true
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1697
!
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1698
602
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  1699
isSequenceableCollection
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  1700
    "OBSOLETE: use isSequenceable for ST-80 compatibility.
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  1701
     This method is a historic leftover and will be removed."
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  1702
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  1703
    ^ true
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1704
!
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1705
602
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  1706
keys
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  1707
    "return a collection with all keys in the Smalltalk dictionary"
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  1708
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  1709
    |sz|
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  1710
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1711
    sz := self size.
602
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  1712
    sz == 0 ifTrue:[
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  1713
	^ #()
61
claus
parents: 44
diff changeset
  1714
    ].
602
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  1715
    ^ 1 to:sz
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1716
!
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1717
602
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  1718
lastIndex
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  1719
    "return the last elements index"
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  1720
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  1721
    ^ self size
61
claus
parents: 44
diff changeset
  1722
!
claus
parents: 44
diff changeset
  1723
602
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  1724
size
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  1725
    "return the number of elements in the collection.
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  1726
     concrete implementations must define this"
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  1727
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  1728
    ^ self subclassResponsibility
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1729
! !
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1730
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1731
!SequenceableCollection methodsFor:'searching'!
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1732
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1733
detect:aBlock ifNone:exceptionBlock
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1734
    "find the first element, for which evaluation of the argument, aBlock
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1735
     return true; if none does so, return the evaluation of exceptionBlock
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1736
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1737
    reimplemented here for speed"
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1738
32
ee1a621c696c *** empty log message ***
claus
parents: 13
diff changeset
  1739
    |stop  "{ Class: SmallInteger }"
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1740
     element|
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1741
32
ee1a621c696c *** empty log message ***
claus
parents: 13
diff changeset
  1742
    stop := self size.
ee1a621c696c *** empty log message ***
claus
parents: 13
diff changeset
  1743
    1 to:stop do:[:index |
159
514c749165c3 *** empty log message ***
claus
parents: 118
diff changeset
  1744
	element := self at:index.
514c749165c3 *** empty log message ***
claus
parents: 118
diff changeset
  1745
	(aBlock value:element) ifTrue:[
514c749165c3 *** empty log message ***
claus
parents: 118
diff changeset
  1746
	    ^ element
514c749165c3 *** empty log message ***
claus
parents: 118
diff changeset
  1747
	].
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1748
    ].
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1749
    ^ exceptionBlock value
159
514c749165c3 *** empty log message ***
claus
parents: 118
diff changeset
  1750
514c749165c3 *** empty log message ***
claus
parents: 118
diff changeset
  1751
    "
514c749165c3 *** empty log message ***
claus
parents: 118
diff changeset
  1752
     #(11 12 13 14) detect:[:n | n odd] ifNone:['sorry']    
514c749165c3 *** empty log message ***
claus
parents: 118
diff changeset
  1753
     #(12 14 16 18) detect:[:n | n odd] ifNone:['sorry']     
514c749165c3 *** empty log message ***
claus
parents: 118
diff changeset
  1754
    "
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1755
!
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1756
602
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  1757
findFirst:aBlock
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  1758
    "find the first element, for which evaluation of the argument, aBlock
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  1759
     returns true; return its index or 0 if none detected."
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  1760
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  1761
    |stop  "{ Class: SmallInteger }" |
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  1762
32
ee1a621c696c *** empty log message ***
claus
parents: 13
diff changeset
  1763
    stop := self size.
602
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  1764
    1 to:stop do:[:index |
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  1765
	(aBlock value:(self at:index)) ifTrue:[^ index].
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1766
    ].
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1767
    ^ 0
159
514c749165c3 *** empty log message ***
claus
parents: 118
diff changeset
  1768
95
d22739a0c6e9 *** empty log message ***
claus
parents: 88
diff changeset
  1769
    "
602
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  1770
     #(1 2 3 4 5 6) findFirst:[:x | (x >= 3)]
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  1771
     #(1 2 3 4 5 6) findFirst:[:x | (x >= 3) and:[x even]]
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  1772
     #(1 2 3 4 5 6) findFirst:[:x | (x >= 8)]           
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  1773
     'one.two.three' findFirst:[:c | (c == $.)]
95
d22739a0c6e9 *** empty log message ***
claus
parents: 88
diff changeset
  1774
    "
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1775
!
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1776
929
674de4c05dcb added findFirst:startingAt: and findLast:startingAt:
Claus Gittinger <cg@exept.de>
parents: 911
diff changeset
  1777
findFirst:aBlock startingAt:startIndex
674de4c05dcb added findFirst:startingAt: and findLast:startingAt:
Claus Gittinger <cg@exept.de>
parents: 911
diff changeset
  1778
    "find the first element, for which evaluation of the argument, aBlock
674de4c05dcb added findFirst:startingAt: and findLast:startingAt:
Claus Gittinger <cg@exept.de>
parents: 911
diff changeset
  1779
     returns true; return its index or 0 if none detected."
674de4c05dcb added findFirst:startingAt: and findLast:startingAt:
Claus Gittinger <cg@exept.de>
parents: 911
diff changeset
  1780
674de4c05dcb added findFirst:startingAt: and findLast:startingAt:
Claus Gittinger <cg@exept.de>
parents: 911
diff changeset
  1781
    |start "{ Class: SmallInteger }"
674de4c05dcb added findFirst:startingAt: and findLast:startingAt:
Claus Gittinger <cg@exept.de>
parents: 911
diff changeset
  1782
     stop  "{ Class: SmallInteger }" |
674de4c05dcb added findFirst:startingAt: and findLast:startingAt:
Claus Gittinger <cg@exept.de>
parents: 911
diff changeset
  1783
674de4c05dcb added findFirst:startingAt: and findLast:startingAt:
Claus Gittinger <cg@exept.de>
parents: 911
diff changeset
  1784
    start := startIndex. "/ as a compiler hint
674de4c05dcb added findFirst:startingAt: and findLast:startingAt:
Claus Gittinger <cg@exept.de>
parents: 911
diff changeset
  1785
    stop := self size.
674de4c05dcb added findFirst:startingAt: and findLast:startingAt:
Claus Gittinger <cg@exept.de>
parents: 911
diff changeset
  1786
    start to:stop do:[:index |
674de4c05dcb added findFirst:startingAt: and findLast:startingAt:
Claus Gittinger <cg@exept.de>
parents: 911
diff changeset
  1787
	(aBlock value:(self at:index)) ifTrue:[^ index].
674de4c05dcb added findFirst:startingAt: and findLast:startingAt:
Claus Gittinger <cg@exept.de>
parents: 911
diff changeset
  1788
    ].
674de4c05dcb added findFirst:startingAt: and findLast:startingAt:
Claus Gittinger <cg@exept.de>
parents: 911
diff changeset
  1789
    ^ 0
674de4c05dcb added findFirst:startingAt: and findLast:startingAt:
Claus Gittinger <cg@exept.de>
parents: 911
diff changeset
  1790
674de4c05dcb added findFirst:startingAt: and findLast:startingAt:
Claus Gittinger <cg@exept.de>
parents: 911
diff changeset
  1791
    "
674de4c05dcb added findFirst:startingAt: and findLast:startingAt:
Claus Gittinger <cg@exept.de>
parents: 911
diff changeset
  1792
     #(1 4 3 4 3 6) findFirst:[:x | (x > 3)] startingAt:4
674de4c05dcb added findFirst:startingAt: and findLast:startingAt:
Claus Gittinger <cg@exept.de>
parents: 911
diff changeset
  1793
     'one.two.three' findFirst:[:c | (c == $.)] startingAt:5
674de4c05dcb added findFirst:startingAt: and findLast:startingAt:
Claus Gittinger <cg@exept.de>
parents: 911
diff changeset
  1794
    "
674de4c05dcb added findFirst:startingAt: and findLast:startingAt:
Claus Gittinger <cg@exept.de>
parents: 911
diff changeset
  1795
!
674de4c05dcb added findFirst:startingAt: and findLast:startingAt:
Claus Gittinger <cg@exept.de>
parents: 911
diff changeset
  1796
602
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  1797
findLast:aBlock
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  1798
    "find the last element, for which evaluation of the argument, aBlock
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  1799
     returns true; return its index or 0 if none detected."
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  1800
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  1801
    |start "{ Class: SmallInteger }"|
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  1802
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  1803
    start := self size.
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  1804
    start to:1 by:-1 do:[:index |
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  1805
	(aBlock value:(self at:index)) ifTrue:[^ index].
252
  1806
    ].
  1807
    ^ 0
  1808
  1809
    "
602
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  1810
     #(1 99 3 99 5 6) findLast:[:x | (x == 99)]
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  1811
     'one.two.three' findLast:[:c | (c == $.)]
252
  1812
    "
  1813
!
  1814
929
674de4c05dcb added findFirst:startingAt: and findLast:startingAt:
Claus Gittinger <cg@exept.de>
parents: 911
diff changeset
  1815
findLast:aBlock startingAt:startIndex
674de4c05dcb added findFirst:startingAt: and findLast:startingAt:
Claus Gittinger <cg@exept.de>
parents: 911
diff changeset
  1816
    "find the last element, for which evaluation of the argument, aBlock
674de4c05dcb added findFirst:startingAt: and findLast:startingAt:
Claus Gittinger <cg@exept.de>
parents: 911
diff changeset
  1817
     returns true; return its index or 0 if none detected."
674de4c05dcb added findFirst:startingAt: and findLast:startingAt:
Claus Gittinger <cg@exept.de>
parents: 911
diff changeset
  1818
674de4c05dcb added findFirst:startingAt: and findLast:startingAt:
Claus Gittinger <cg@exept.de>
parents: 911
diff changeset
  1819
    |start "{ Class: SmallInteger }"|
674de4c05dcb added findFirst:startingAt: and findLast:startingAt:
Claus Gittinger <cg@exept.de>
parents: 911
diff changeset
  1820
674de4c05dcb added findFirst:startingAt: and findLast:startingAt:
Claus Gittinger <cg@exept.de>
parents: 911
diff changeset
  1821
    start := startIndex.
674de4c05dcb added findFirst:startingAt: and findLast:startingAt:
Claus Gittinger <cg@exept.de>
parents: 911
diff changeset
  1822
    start to:1 by:-1 do:[:index |
674de4c05dcb added findFirst:startingAt: and findLast:startingAt:
Claus Gittinger <cg@exept.de>
parents: 911
diff changeset
  1823
	(aBlock value:(self at:index)) ifTrue:[^ index].
674de4c05dcb added findFirst:startingAt: and findLast:startingAt:
Claus Gittinger <cg@exept.de>
parents: 911
diff changeset
  1824
    ].
674de4c05dcb added findFirst:startingAt: and findLast:startingAt:
Claus Gittinger <cg@exept.de>
parents: 911
diff changeset
  1825
    ^ 0
674de4c05dcb added findFirst:startingAt: and findLast:startingAt:
Claus Gittinger <cg@exept.de>
parents: 911
diff changeset
  1826
674de4c05dcb added findFirst:startingAt: and findLast:startingAt:
Claus Gittinger <cg@exept.de>
parents: 911
diff changeset
  1827
    "
674de4c05dcb added findFirst:startingAt: and findLast:startingAt:
Claus Gittinger <cg@exept.de>
parents: 911
diff changeset
  1828
     #(1 99 3 99 5 6) findLast:[:x | (x == 99)] startingAt:3
674de4c05dcb added findFirst:startingAt: and findLast:startingAt:
Claus Gittinger <cg@exept.de>
parents: 911
diff changeset
  1829
     'one.two.three' findLast:[:c | (c == $.)] startingAt:7
674de4c05dcb added findFirst:startingAt: and findLast:startingAt:
Claus Gittinger <cg@exept.de>
parents: 911
diff changeset
  1830
    "
674de4c05dcb added findFirst:startingAt: and findLast:startingAt:
Claus Gittinger <cg@exept.de>
parents: 911
diff changeset
  1831
!
674de4c05dcb added findFirst:startingAt: and findLast:startingAt:
Claus Gittinger <cg@exept.de>
parents: 911
diff changeset
  1832
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1833
identityIndexOf:anElement
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1834
    "search the collection for anElement using identity compare (i.e. ==);
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1835
     if found, return the index otherwise return 0."
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1836
32
ee1a621c696c *** empty log message ***
claus
parents: 13
diff changeset
  1837
    ^ self identityIndexOf:anElement startingAt:1
44
b262907c93ea *** empty log message ***
claus
parents: 42
diff changeset
  1838
95
d22739a0c6e9 *** empty log message ***
claus
parents: 88
diff changeset
  1839
    "
159
514c749165c3 *** empty log message ***
claus
parents: 118
diff changeset
  1840
     #(10 20 30 40 50 60 70) identityIndexOf:40
514c749165c3 *** empty log message ***
claus
parents: 118
diff changeset
  1841
     #(10 20 30 40 50 60 70) identityIndexOf:40.0
514c749165c3 *** empty log message ***
claus
parents: 118
diff changeset
  1842
     #(10 20 30 40 50 60 70) indexOf:40.0
360
claus
parents: 359
diff changeset
  1843
claus
parents: 359
diff changeset
  1844
    be careful:
claus
parents: 359
diff changeset
  1845
claus
parents: 359
diff changeset
  1846
     #(10 20 30 40.0 50 60 70) indexOf:40.0
claus
parents: 359
diff changeset
  1847
     #(10 20 30 40.0 50 60 70) identityIndexOf:40.0
claus
parents: 359
diff changeset
  1848
95
d22739a0c6e9 *** empty log message ***
claus
parents: 88
diff changeset
  1849
    "
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1850
!
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1851
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1852
identityIndexOf:anElement ifAbsent:exceptionBlock
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1853
    "search the collection for anElement using identity compare (i.e. ==);
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1854
     if found, return the index otherwise return the value of the
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1855
     exceptionBlock."
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1856
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1857
    |index|
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1858
32
ee1a621c696c *** empty log message ***
claus
parents: 13
diff changeset
  1859
    index := self identityIndexOf:anElement startingAt:1.
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1860
    (index == 0) ifTrue:[^ exceptionBlock value].
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1861
    ^ index
159
514c749165c3 *** empty log message ***
claus
parents: 118
diff changeset
  1862
514c749165c3 *** empty log message ***
claus
parents: 118
diff changeset
  1863
    "
514c749165c3 *** empty log message ***
claus
parents: 118
diff changeset
  1864
     #(10 20 30 40 50 60 70) identityIndexOf:40  ifAbsent:['none']  
514c749165c3 *** empty log message ***
claus
parents: 118
diff changeset
  1865
     #(10 20 30 40 50 60 70) identityIndexOf:35  ifAbsent:['none']  
514c749165c3 *** empty log message ***
claus
parents: 118
diff changeset
  1866
     #(10 20 30 40 50 60 70) identityIndexOf:40.0 ifAbsent:['none'] 
514c749165c3 *** empty log message ***
claus
parents: 118
diff changeset
  1867
     #(10 20 30 40 50 60 70) indexOf:40.0         ifAbsent:['none'] 
514c749165c3 *** empty log message ***
claus
parents: 118
diff changeset
  1868
    "
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1869
!
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1870
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1871
identityIndexOf:anElement startingAt:start
159
514c749165c3 *** empty log message ***
claus
parents: 118
diff changeset
  1872
    "search the collection for anElement, starting search at index start
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1873
     using identity compare  (i.e. ==);
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1874
     if found, return the index otherwise return 0."
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1875
32
ee1a621c696c *** empty log message ***
claus
parents: 13
diff changeset
  1876
    |startIndex "{ Class: SmallInteger }"
ee1a621c696c *** empty log message ***
claus
parents: 13
diff changeset
  1877
     stop       "{ Class: SmallInteger }" |
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1878
32
ee1a621c696c *** empty log message ***
claus
parents: 13
diff changeset
  1879
    startIndex := start.
ee1a621c696c *** empty log message ***
claus
parents: 13
diff changeset
  1880
    stop := self size.
ee1a621c696c *** empty log message ***
claus
parents: 13
diff changeset
  1881
    startIndex to:stop do:[:index |
159
514c749165c3 *** empty log message ***
claus
parents: 118
diff changeset
  1882
	anElement == (self at:index) ifTrue:[^ index].
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1883
    ].
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1884
    ^ 0
44
b262907c93ea *** empty log message ***
claus
parents: 42
diff changeset
  1885
95
d22739a0c6e9 *** empty log message ***
claus
parents: 88
diff changeset
  1886
    "
159
514c749165c3 *** empty log message ***
claus
parents: 118
diff changeset
  1887
     #(10 20 30 40 10 20 30 40) identityIndexOf:40   startingAt:5
514c749165c3 *** empty log message ***
claus
parents: 118
diff changeset
  1888
     #(10 20 30 40 10 20 30 40) identityIndexOf:40.0 startingAt:5
514c749165c3 *** empty log message ***
claus
parents: 118
diff changeset
  1889
     #(10 20 30 40 10 20 30 40) indexOf:40.0         startingAt:5 
95
d22739a0c6e9 *** empty log message ***
claus
parents: 88
diff changeset
  1890
    "
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1891
!
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1892
1159
dcbb3e070a05 added fallback methods #indexOf:startingAt:endingAt: / #identity...
Claus Gittinger <cg@exept.de>
parents: 1145
diff changeset
  1893
identityIndexOf:anElement startingAt:start endingAt:stop
dcbb3e070a05 added fallback methods #indexOf:startingAt:endingAt: / #identity...
Claus Gittinger <cg@exept.de>
parents: 1145
diff changeset
  1894
    "search the collection for anElement, starting the search at index start;
dcbb3e070a05 added fallback methods #indexOf:startingAt:endingAt: / #identity...
Claus Gittinger <cg@exept.de>
parents: 1145
diff changeset
  1895
     ending at stop.
dcbb3e070a05 added fallback methods #indexOf:startingAt:endingAt: / #identity...
Claus Gittinger <cg@exept.de>
parents: 1145
diff changeset
  1896
     If found (within the range), return the index, otherwise return 0.
dcbb3e070a05 added fallback methods #indexOf:startingAt:endingAt: / #identity...
Claus Gittinger <cg@exept.de>
parents: 1145
diff changeset
  1897
     The comparison is done using = 
dcbb3e070a05 added fallback methods #indexOf:startingAt:endingAt: / #identity...
Claus Gittinger <cg@exept.de>
parents: 1145
diff changeset
  1898
     (i.e. equality test - not identity test)."
dcbb3e070a05 added fallback methods #indexOf:startingAt:endingAt: / #identity...
Claus Gittinger <cg@exept.de>
parents: 1145
diff changeset
  1899
dcbb3e070a05 added fallback methods #indexOf:startingAt:endingAt: / #identity...
Claus Gittinger <cg@exept.de>
parents: 1145
diff changeset
  1900
    |startIndex "{ Class: SmallInteger }"
dcbb3e070a05 added fallback methods #indexOf:startingAt:endingAt: / #identity...
Claus Gittinger <cg@exept.de>
parents: 1145
diff changeset
  1901
     stopIndex  "{ Class: SmallInteger }" |
dcbb3e070a05 added fallback methods #indexOf:startingAt:endingAt: / #identity...
Claus Gittinger <cg@exept.de>
parents: 1145
diff changeset
  1902
dcbb3e070a05 added fallback methods #indexOf:startingAt:endingAt: / #identity...
Claus Gittinger <cg@exept.de>
parents: 1145
diff changeset
  1903
    startIndex := start.
dcbb3e070a05 added fallback methods #indexOf:startingAt:endingAt: / #identity...
Claus Gittinger <cg@exept.de>
parents: 1145
diff changeset
  1904
    stopIndex := self size min:stop.
dcbb3e070a05 added fallback methods #indexOf:startingAt:endingAt: / #identity...
Claus Gittinger <cg@exept.de>
parents: 1145
diff changeset
  1905
    startIndex to:stopIndex do:[:index |
dcbb3e070a05 added fallback methods #indexOf:startingAt:endingAt: / #identity...
Claus Gittinger <cg@exept.de>
parents: 1145
diff changeset
  1906
        anElement == (self at:index) ifTrue:[^ index].
dcbb3e070a05 added fallback methods #indexOf:startingAt:endingAt: / #identity...
Claus Gittinger <cg@exept.de>
parents: 1145
diff changeset
  1907
    ].
dcbb3e070a05 added fallback methods #indexOf:startingAt:endingAt: / #identity...
Claus Gittinger <cg@exept.de>
parents: 1145
diff changeset
  1908
    ^ 0
dcbb3e070a05 added fallback methods #indexOf:startingAt:endingAt: / #identity...
Claus Gittinger <cg@exept.de>
parents: 1145
diff changeset
  1909
dcbb3e070a05 added fallback methods #indexOf:startingAt:endingAt: / #identity...
Claus Gittinger <cg@exept.de>
parents: 1145
diff changeset
  1910
    "Created: 12.4.1996 / 18:23:07 / cg"
dcbb3e070a05 added fallback methods #indexOf:startingAt:endingAt: / #identity...
Claus Gittinger <cg@exept.de>
parents: 1145
diff changeset
  1911
!
dcbb3e070a05 added fallback methods #indexOf:startingAt:endingAt: / #identity...
Claus Gittinger <cg@exept.de>
parents: 1145
diff changeset
  1912
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1913
identityIndexOf:anElement startingAt:start ifAbsent:exceptionBlock
159
514c749165c3 *** empty log message ***
claus
parents: 118
diff changeset
  1914
    "search the collection for anElement, starting search at index start;
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1915
     if found, return the index otherwise return the value of the
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1916
     exceptionBlock.
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1917
     This one searches for identical objects (i.e. ==)."
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1918
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1919
    |index|
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1920
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1921
    index := self identityIndexOf:anElement startingAt:start.
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1922
    (index == 0) ifTrue:[^ exceptionBlock value].
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1923
    ^ index
159
514c749165c3 *** empty log message ***
claus
parents: 118
diff changeset
  1924
514c749165c3 *** empty log message ***
claus
parents: 118
diff changeset
  1925
    "
514c749165c3 *** empty log message ***
claus
parents: 118
diff changeset
  1926
     #(10 20 30 40 10) identityIndexOf:10 startingAt:3 ifAbsent:['none'] 
514c749165c3 *** empty log message ***
claus
parents: 118
diff changeset
  1927
     #(10 20 30 40 10) identityIndexOf:35 startingAt:3 ifAbsent:['none'] 
514c749165c3 *** empty log message ***
claus
parents: 118
diff changeset
  1928
    "
514c749165c3 *** empty log message ***
claus
parents: 118
diff changeset
  1929
!
514c749165c3 *** empty log message ***
claus
parents: 118
diff changeset
  1930
602
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  1931
includes:anElement
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  1932
    "return true if the collection contains anElement; false otherwise.
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  1933
     Comparison is done using equality compare (i.e. =).
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  1934
     See #includesIdentical: if identity is asked for."
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  1935
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  1936
    ((self indexOf:anElement startingAt:1) == 0) ifTrue:[^ false].
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  1937
    ^ true
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  1938
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  1939
    "
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  1940
     #(10 20 30 40 50 60 70) includes:99      
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  1941
     #(10 20 30 40 50 60 70) includes:40     
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  1942
     #(10 20 30 40 50 60 70) includes:40.0    
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  1943
    "
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  1944
!
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  1945
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  1946
includesIdentical:anElement
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  1947
    "return true if the collection contains anElement; false otherwise.
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  1948
     Comparison is done using identity compare (i.e. ==).
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  1949
     See #includes: if equality is asked for."
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  1950
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  1951
    ((self identityIndexOf:anElement startingAt:1) == 0) ifTrue:[^ false].
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  1952
    ^ true
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  1953
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  1954
    "
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  1955
     #(10 20 30 40 50 60 70) includesIdentical:40     
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  1956
     #(10 20 30 40 50 60 70) includesIdentical:40.0    
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  1957
     #(10 20 30 40 50 60 70) includes:40     
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  1958
     #(10 20 30 40 50 60 70) includes:40.0    
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  1959
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  1960
     be careful:
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  1961
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  1962
     #(10 20 30 40.0 50 60 70) includes:40.0    
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  1963
     #(10 20 30 40.0 50 60 70) includesIdentical:40.0    
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  1964
    "
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  1965
!
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  1966
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  1967
indexOf:anElement
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  1968
    "search the collection for anElement;
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  1969
     if found, return the index otherwise return 0.
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  1970
     The comparison is done using = 
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  1971
     (i.e. equality test - not identity test)."
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  1972
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  1973
    ^ self indexOf:anElement startingAt:1
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  1974
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  1975
    "
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  1976
     #(10 20 30 40 50 60 70) indexOf:40
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  1977
     #(10 20 30 40 50 60 70) indexOf:40.0
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  1978
    "
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  1979
!
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  1980
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  1981
indexOf:anElement ifAbsent:exceptionBlock
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  1982
    "search the collection for anElement;
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  1983
     if found, return the index otherwise return the value of the
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  1984
     exceptionBlock.
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  1985
     The comparison is done using = 
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  1986
     (i.e. equality test - not identity test)."
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  1987
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  1988
    |index|
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  1989
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  1990
    index := self indexOf:anElement startingAt:1.
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  1991
    (index == 0) ifTrue:[^ exceptionBlock value].
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  1992
    ^ index
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  1993
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  1994
    "
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  1995
     #(10 20 30 40 10 20 30 40) indexOf:40   ifAbsent:['none'] 
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  1996
     #(10 20 30 40 10 20 30 40) indexOf:40.0 ifAbsent:['none'] 
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  1997
     #(10 20 30 40 10 20 30 40) indexOf:35   ifAbsent:['none'] 
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  1998
    "
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  1999
!
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  2000
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  2001
indexOf:elementToFind replaceWith:replacement startingAt:start stoppingAt:stop
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  2002
    "search for the first occurence of elementToFind starting at start,
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  2003
     stopping the search at stop. If found, replace the element by replacement
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  2004
     and return the index.
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  2005
     If not found, return 0."
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  2006
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  2007
    |idx|
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  2008
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  2009
    idx := self indexOf:elementToFind startingAt:start.
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  2010
    ((idx > 0) and:[idx <= stop]) ifTrue:[
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  2011
	self at:idx put:replacement.
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  2012
	^ idx
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  2013
    ].
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  2014
    ^ 0
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  2015
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  2016
    "
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  2017
     |a|
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  2018
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  2019
     a := #(10 20 30 40 50 60 70).
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  2020
     (a indexOf:30 replaceWith:nil startingAt:1 stoppingAt:7) printNL.
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  2021
     a printNL.
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  2022
    "
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  2023
!
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  2024
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  2025
indexOf:anElement startingAt:start
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  2026
    "search the collection for anElement, starting the search at index start;
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  2027
     if found, return the index otherwise return 0.
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  2028
     The comparison is done using = 
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  2029
     (i.e. equality test - not identity test)."
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  2030
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  2031
    |startIndex "{ Class: SmallInteger }"
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  2032
     stop       "{ Class: SmallInteger }" |
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  2033
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  2034
    startIndex := start.
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  2035
    stop := self size.
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  2036
    startIndex to:stop do:[:index |
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  2037
	anElement = (self at:index) ifTrue:[^ index].
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  2038
    ].
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  2039
    ^ 0
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  2040
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  2041
    "
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  2042
     #(10 20 30 40 10 20 30 40) indexOf:40   startingAt:5  
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  2043
     #(10 20 30 40 10 20 30 40) indexOf:40.0 startingAt:5  
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  2044
    "
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  2045
!
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  2046
1159
dcbb3e070a05 added fallback methods #indexOf:startingAt:endingAt: / #identity...
Claus Gittinger <cg@exept.de>
parents: 1145
diff changeset
  2047
indexOf:anElement startingAt:start endingAt:stop
dcbb3e070a05 added fallback methods #indexOf:startingAt:endingAt: / #identity...
Claus Gittinger <cg@exept.de>
parents: 1145
diff changeset
  2048
    "search the collection for anElement, starting the search at index start;
dcbb3e070a05 added fallback methods #indexOf:startingAt:endingAt: / #identity...
Claus Gittinger <cg@exept.de>
parents: 1145
diff changeset
  2049
     ending at stop.
dcbb3e070a05 added fallback methods #indexOf:startingAt:endingAt: / #identity...
Claus Gittinger <cg@exept.de>
parents: 1145
diff changeset
  2050
     If found (within the range), return the index, otherwise return 0.
dcbb3e070a05 added fallback methods #indexOf:startingAt:endingAt: / #identity...
Claus Gittinger <cg@exept.de>
parents: 1145
diff changeset
  2051
     The comparison is done using = 
dcbb3e070a05 added fallback methods #indexOf:startingAt:endingAt: / #identity...
Claus Gittinger <cg@exept.de>
parents: 1145
diff changeset
  2052
     (i.e. equality test - not identity test)."
dcbb3e070a05 added fallback methods #indexOf:startingAt:endingAt: / #identity...
Claus Gittinger <cg@exept.de>
parents: 1145
diff changeset
  2053
dcbb3e070a05 added fallback methods #indexOf:startingAt:endingAt: / #identity...
Claus Gittinger <cg@exept.de>
parents: 1145
diff changeset
  2054
    |startIndex "{ Class: SmallInteger }"
dcbb3e070a05 added fallback methods #indexOf:startingAt:endingAt: / #identity...
Claus Gittinger <cg@exept.de>
parents: 1145
diff changeset
  2055
     stopIndex  "{ Class: SmallInteger }" |
dcbb3e070a05 added fallback methods #indexOf:startingAt:endingAt: / #identity...
Claus Gittinger <cg@exept.de>
parents: 1145
diff changeset
  2056
dcbb3e070a05 added fallback methods #indexOf:startingAt:endingAt: / #identity...
Claus Gittinger <cg@exept.de>
parents: 1145
diff changeset
  2057
    startIndex := start.
dcbb3e070a05 added fallback methods #indexOf:startingAt:endingAt: / #identity...
Claus Gittinger <cg@exept.de>
parents: 1145
diff changeset
  2058
    stopIndex := self size min:stop.
dcbb3e070a05 added fallback methods #indexOf:startingAt:endingAt: / #identity...
Claus Gittinger <cg@exept.de>
parents: 1145
diff changeset
  2059
    startIndex to:stopIndex do:[:index |
dcbb3e070a05 added fallback methods #indexOf:startingAt:endingAt: / #identity...
Claus Gittinger <cg@exept.de>
parents: 1145
diff changeset
  2060
        anElement = (self at:index) ifTrue:[^ index].
dcbb3e070a05 added fallback methods #indexOf:startingAt:endingAt: / #identity...
Claus Gittinger <cg@exept.de>
parents: 1145
diff changeset
  2061
    ].
dcbb3e070a05 added fallback methods #indexOf:startingAt:endingAt: / #identity...
Claus Gittinger <cg@exept.de>
parents: 1145
diff changeset
  2062
    ^ 0
dcbb3e070a05 added fallback methods #indexOf:startingAt:endingAt: / #identity...
Claus Gittinger <cg@exept.de>
parents: 1145
diff changeset
  2063
dcbb3e070a05 added fallback methods #indexOf:startingAt:endingAt: / #identity...
Claus Gittinger <cg@exept.de>
parents: 1145
diff changeset
  2064
    "
dcbb3e070a05 added fallback methods #indexOf:startingAt:endingAt: / #identity...
Claus Gittinger <cg@exept.de>
parents: 1145
diff changeset
  2065
     #(10 20 30 40 10 20 30 40) indexOf:40   startingAt:3 endingAt:99  
dcbb3e070a05 added fallback methods #indexOf:startingAt:endingAt: / #identity...
Claus Gittinger <cg@exept.de>
parents: 1145
diff changeset
  2066
     #(10 20 30 40 10 20 30 40) indexOf:40   startingAt:3 endingAt:5  
dcbb3e070a05 added fallback methods #indexOf:startingAt:endingAt: / #identity...
Claus Gittinger <cg@exept.de>
parents: 1145
diff changeset
  2067
     #(10 20 30 40 10 20 30 40) indexOf:40   startingAt:1 endingAt:3   
dcbb3e070a05 added fallback methods #indexOf:startingAt:endingAt: / #identity...
Claus Gittinger <cg@exept.de>
parents: 1145
diff changeset
  2068
     #(10 20 30 40 10 20 30 40) indexOf:40.0 startingAt:5  
dcbb3e070a05 added fallback methods #indexOf:startingAt:endingAt: / #identity...
Claus Gittinger <cg@exept.de>
parents: 1145
diff changeset
  2069
    "
dcbb3e070a05 added fallback methods #indexOf:startingAt:endingAt: / #identity...
Claus Gittinger <cg@exept.de>
parents: 1145
diff changeset
  2070
dcbb3e070a05 added fallback methods #indexOf:startingAt:endingAt: / #identity...
Claus Gittinger <cg@exept.de>
parents: 1145
diff changeset
  2071
    "Created: 12.4.1996 / 17:37:13 / cg"
dcbb3e070a05 added fallback methods #indexOf:startingAt:endingAt: / #identity...
Claus Gittinger <cg@exept.de>
parents: 1145
diff changeset
  2072
!
dcbb3e070a05 added fallback methods #indexOf:startingAt:endingAt: / #identity...
Claus Gittinger <cg@exept.de>
parents: 1145
diff changeset
  2073
602
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  2074
indexOf:anElement startingAt:start ifAbsent:exceptionBlock
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  2075
    "search the collection for anElement starting the search at index start;
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  2076
     if found, return the index otherwise return the value of the
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  2077
     exceptionBlock.
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  2078
     The comparison is done using = 
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  2079
     (i.e. equality test - not identity test)."
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  2080
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  2081
    |index|
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  2082
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  2083
    index := self indexOf:anElement startingAt:start.
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  2084
    (index == 0) ifTrue:[^ exceptionBlock value].
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  2085
    ^ index
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  2086
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  2087
    "
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  2088
     #(10 20 30 40 10 20 30 40) indexOf:40   startingAt:5 ifAbsent:['none'] 
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  2089
     #(10 20 30 40 10 20 30 40) indexOf:40.0 startingAt:5 ifAbsent:['none'] 
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  2090
     #(10 20 30 40 10 20 30 40) indexOf:35   startingAt:5 ifAbsent:['none'] 
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  2091
    "
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  2092
!
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  2093
159
514c749165c3 *** empty log message ***
claus
parents: 118
diff changeset
  2094
indexOfAny:aCollection
514c749165c3 *** empty log message ***
claus
parents: 118
diff changeset
  2095
    "search the collection for an element in aCollection.
514c749165c3 *** empty log message ***
claus
parents: 118
diff changeset
  2096
     if found, return the index otherwise return 0.
514c749165c3 *** empty log message ***
claus
parents: 118
diff changeset
  2097
     The comparison is done using = 
514c749165c3 *** empty log message ***
claus
parents: 118
diff changeset
  2098
     (i.e. equality test - not identity test).
514c749165c3 *** empty log message ***
claus
parents: 118
diff changeset
  2099
514c749165c3 *** empty log message ***
claus
parents: 118
diff changeset
  2100
     Notice, that for big collections, the runtime of this search
514c749165c3 *** empty log message ***
claus
parents: 118
diff changeset
  2101
     grows proportional to size(receiver) * size(aCollection).
514c749165c3 *** empty log message ***
claus
parents: 118
diff changeset
  2102
     You may think about using other mechanisms (Sets, Dictionaries etc)."
514c749165c3 *** empty log message ***
claus
parents: 118
diff changeset
  2103
514c749165c3 *** empty log message ***
claus
parents: 118
diff changeset
  2104
    ^ self indexOfAny:aCollection startingAt:1
514c749165c3 *** empty log message ***
claus
parents: 118
diff changeset
  2105
514c749165c3 *** empty log message ***
claus
parents: 118
diff changeset
  2106
    "
514c749165c3 *** empty log message ***
claus
parents: 118
diff changeset
  2107
     #(10 20 30 40 50 60 70) indexOfAny:#(40 30 50)
514c749165c3 *** empty log message ***
claus
parents: 118
diff changeset
  2108
     #(10 20 30 40 50 60 70) indexOfAny:#(40.0 30.0 50)
514c749165c3 *** empty log message ***
claus
parents: 118
diff changeset
  2109
    "
514c749165c3 *** empty log message ***
claus
parents: 118
diff changeset
  2110
!
514c749165c3 *** empty log message ***
claus
parents: 118
diff changeset
  2111
514c749165c3 *** empty log message ***
claus
parents: 118
diff changeset
  2112
indexOfAny:aCollection startingAt:start
514c749165c3 *** empty log message ***
claus
parents: 118
diff changeset
  2113
    "search the collection for an element in aCollection,
514c749165c3 *** empty log message ***
claus
parents: 118
diff changeset
  2114
     starting the search at index start;
514c749165c3 *** empty log message ***
claus
parents: 118
diff changeset
  2115
     if found, return the index otherwise return 0.
514c749165c3 *** empty log message ***
claus
parents: 118
diff changeset
  2116
     The comparison is done using = 
514c749165c3 *** empty log message ***
claus
parents: 118
diff changeset
  2117
     (i.e. equality test - not identity test).
514c749165c3 *** empty log message ***
claus
parents: 118
diff changeset
  2118
514c749165c3 *** empty log message ***
claus
parents: 118
diff changeset
  2119
     Notice, that for big collections, the runtime of this search
514c749165c3 *** empty log message ***
claus
parents: 118
diff changeset
  2120
     grows proportional to size(receiver) * size(aCollection).
514c749165c3 *** empty log message ***
claus
parents: 118
diff changeset
  2121
     You may think about using other mechanisms (Sets, Dictionaries etc)."
514c749165c3 *** empty log message ***
claus
parents: 118
diff changeset
  2122
514c749165c3 *** empty log message ***
claus
parents: 118
diff changeset
  2123
514c749165c3 *** empty log message ***
claus
parents: 118
diff changeset
  2124
    |startIndex "{ Class: SmallInteger }"
514c749165c3 *** empty log message ***
claus
parents: 118
diff changeset
  2125
     stop       "{ Class: SmallInteger }" |
514c749165c3 *** empty log message ***
claus
parents: 118
diff changeset
  2126
514c749165c3 *** empty log message ***
claus
parents: 118
diff changeset
  2127
    startIndex := start.
514c749165c3 *** empty log message ***
claus
parents: 118
diff changeset
  2128
    stop := self size.
514c749165c3 *** empty log message ***
claus
parents: 118
diff changeset
  2129
    startIndex to:stop do:[:index |
514c749165c3 *** empty log message ***
claus
parents: 118
diff changeset
  2130
	(aCollection includes:(self at:index)) ifTrue:[^ index].
514c749165c3 *** empty log message ***
claus
parents: 118
diff changeset
  2131
    ].
514c749165c3 *** empty log message ***
claus
parents: 118
diff changeset
  2132
    ^ 0
514c749165c3 *** empty log message ***
claus
parents: 118
diff changeset
  2133
    "
514c749165c3 *** empty log message ***
claus
parents: 118
diff changeset
  2134
     #(10 20 30 40 10 20 30 40) indexOfAny:#(40 50 30) startingAt:5  
514c749165c3 *** empty log message ***
claus
parents: 118
diff changeset
  2135
     #(10 20 30 40 10 20 30 40) indexOfAny:#(40.0 50 30.0) startingAt:5  
514c749165c3 *** empty log message ***
claus
parents: 118
diff changeset
  2136
    "
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  2137
!
a27a279701f8 Initial revision
claus
parents:
diff changeset
  2138
518
5372a8875432 added indexOfAny:startingAt:ifAbsent:
Claus Gittinger <cg@exept.de>
parents: 424
diff changeset
  2139
indexOfAny:aCollection startingAt:start ifAbsent:exceptionBlock
5372a8875432 added indexOfAny:startingAt:ifAbsent:
Claus Gittinger <cg@exept.de>
parents: 424
diff changeset
  2140
    "search the collection for an element in aCollection,
5372a8875432 added indexOfAny:startingAt:ifAbsent:
Claus Gittinger <cg@exept.de>
parents: 424
diff changeset
  2141
     starting the search at index start;
5372a8875432 added indexOfAny:startingAt:ifAbsent:
Claus Gittinger <cg@exept.de>
parents: 424
diff changeset
  2142
     if found, return the index. If not, return the value returned by exceptionBlock.
5372a8875432 added indexOfAny:startingAt:ifAbsent:
Claus Gittinger <cg@exept.de>
parents: 424
diff changeset
  2143
     The comparison is done using = 
5372a8875432 added indexOfAny:startingAt:ifAbsent:
Claus Gittinger <cg@exept.de>
parents: 424
diff changeset
  2144
     (i.e. equality test - not identity test).
5372a8875432 added indexOfAny:startingAt:ifAbsent:
Claus Gittinger <cg@exept.de>
parents: 424
diff changeset
  2145
5372a8875432 added indexOfAny:startingAt:ifAbsent:
Claus Gittinger <cg@exept.de>
parents: 424
diff changeset
  2146
     Notice, that for big collections, the runtime of this search
5372a8875432 added indexOfAny:startingAt:ifAbsent:
Claus Gittinger <cg@exept.de>
parents: 424
diff changeset
  2147
     grows proportional to size(receiver) * size(aCollection).
5372a8875432 added indexOfAny:startingAt:ifAbsent:
Claus Gittinger <cg@exept.de>
parents: 424
diff changeset
  2148
     You may think about using other mechanisms (Sets, Dictionaries etc)."
5372a8875432 added indexOfAny:startingAt:ifAbsent:
Claus Gittinger <cg@exept.de>
parents: 424
diff changeset
  2149
5372a8875432 added indexOfAny:startingAt:ifAbsent:
Claus Gittinger <cg@exept.de>
parents: 424
diff changeset
  2150
5372a8875432 added indexOfAny:startingAt:ifAbsent:
Claus Gittinger <cg@exept.de>
parents: 424
diff changeset
  2151
    |val|
5372a8875432 added indexOfAny:startingAt:ifAbsent:
Claus Gittinger <cg@exept.de>
parents: 424
diff changeset
  2152
5372a8875432 added indexOfAny:startingAt:ifAbsent:
Claus Gittinger <cg@exept.de>
parents: 424
diff changeset
  2153
    val := self indexOfAny:aCollection startingAt:start .
5372a8875432 added indexOfAny:startingAt:ifAbsent:
Claus Gittinger <cg@exept.de>
parents: 424
diff changeset
  2154
    val == 0 ifTrue:[^ exceptionBlock value].
5372a8875432 added indexOfAny:startingAt:ifAbsent:
Claus Gittinger <cg@exept.de>
parents: 424
diff changeset
  2155
    ^ val.
5372a8875432 added indexOfAny:startingAt:ifAbsent:
Claus Gittinger <cg@exept.de>
parents: 424
diff changeset
  2156
5372a8875432 added indexOfAny:startingAt:ifAbsent:
Claus Gittinger <cg@exept.de>
parents: 424
diff changeset
  2157
    "
5372a8875432 added indexOfAny:startingAt:ifAbsent:
Claus Gittinger <cg@exept.de>
parents: 424
diff changeset
  2158
     #(10 20 30 40 10 20 30 40) indexOfAny:#(40 50 30) startingAt:5 ifAbsent:-1  
5372a8875432 added indexOfAny:startingAt:ifAbsent:
Claus Gittinger <cg@exept.de>
parents: 424
diff changeset
  2159
     #(10 20 30 40 10 20 30 40) indexOfAny:#(40.0 50 30.0) startingAt:5 ifAbsent:-1  
5372a8875432 added indexOfAny:startingAt:ifAbsent:
Claus Gittinger <cg@exept.de>
parents: 424
diff changeset
  2160
     #(10 20 30 40 10 20 30 40) indexOfAny:#(99 88 77) startingAt:5 ifAbsent:['oops']  
5372a8875432 added indexOfAny:startingAt:ifAbsent:
Claus Gittinger <cg@exept.de>
parents: 424
diff changeset
  2161
    "
5372a8875432 added indexOfAny:startingAt:ifAbsent:
Claus Gittinger <cg@exept.de>
parents: 424
diff changeset
  2162
!
5372a8875432 added indexOfAny:startingAt:ifAbsent:
Claus Gittinger <cg@exept.de>
parents: 424
diff changeset
  2163
368
a3c21a89ec37 *** empty log message ***
claus
parents: 362
diff changeset
  2164
indexOfSubCollection:aCollection
a3c21a89ec37 *** empty log message ***
claus
parents: 362
diff changeset
  2165
    "find a subcollection. 
a3c21a89ec37 *** empty log message ***
claus
parents: 362
diff changeset
  2166
     If found, return the index; if not found, return 0."
a3c21a89ec37 *** empty log message ***
claus
parents: 362
diff changeset
  2167
1145
a094d90e11bf dont use [0] blocks - use 0 constant instead
Claus Gittinger <cg@exept.de>
parents: 1016
diff changeset
  2168
    ^ self indexOfSubCollection:aCollection startingAt:1 ifAbsent:0
368
a3c21a89ec37 *** empty log message ***
claus
parents: 362
diff changeset
  2169
a3c21a89ec37 *** empty log message ***
claus
parents: 362
diff changeset
  2170
    "
a3c21a89ec37 *** empty log message ***
claus
parents: 362
diff changeset
  2171
     #(1 2 3 4 5 6 7) indexOfSubCollection:#()  
a3c21a89ec37 *** empty log message ***
claus
parents: 362
diff changeset
  2172
     #(1 2 3 4 5 6 7) indexOfSubCollection:#(1)      
a3c21a89ec37 *** empty log message ***
claus
parents: 362
diff changeset
  2173
     #(1 2 3 4 5 6 7) indexOfSubCollection:#(1 2 3 4) 
a3c21a89ec37 *** empty log message ***
claus
parents: 362
diff changeset
  2174
     #(1 2 3 4 5 6 7) indexOfSubCollection:#(2 3 5)   
a3c21a89ec37 *** empty log message ***
claus
parents: 362
diff changeset
  2175
     #(1 2 3 2 3 4 5) indexOfSubCollection:#(2 3 4)  
a3c21a89ec37 *** empty log message ***
claus
parents: 362
diff changeset
  2176
     #(1 2 3 4 5 6 7) indexOfSubCollection:#(5 6 7)  
a3c21a89ec37 *** empty log message ***
claus
parents: 362
diff changeset
  2177
     #(1 2 3 4 5 6 7) indexOfSubCollection:#(5 6 8)  
a3c21a89ec37 *** empty log message ***
claus
parents: 362
diff changeset
  2178
     #(1 2 3 4 5 6 7) indexOfSubCollection:#(5 6 7 8)  
a3c21a89ec37 *** empty log message ***
claus
parents: 362
diff changeset
  2179
    "
a3c21a89ec37 *** empty log message ***
claus
parents: 362
diff changeset
  2180
!
a3c21a89ec37 *** empty log message ***
claus
parents: 362
diff changeset
  2181
602
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  2182
indexOfSubCollection:aCollection ifAbsent:exceptionBlock
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  2183
    "find a subcollection. If found, return the index;
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  2184
     if not found, return the result of evaluating exceptionBlock."
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  2185
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  2186
    ^ self indexOfSubCollection:aCollection startingAt:1 ifAbsent:exceptionBlock
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  2187
!
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  2188
368
a3c21a89ec37 *** empty log message ***
claus
parents: 362
diff changeset
  2189
indexOfSubCollection:aCollection startingAt:startIndex
a3c21a89ec37 *** empty log message ***
claus
parents: 362
diff changeset
  2190
    "find a subcollection starting at index. 
a3c21a89ec37 *** empty log message ***
claus
parents: 362
diff changeset
  2191
     If found, return the index; if not found, return 0."
a3c21a89ec37 *** empty log message ***
claus
parents: 362
diff changeset
  2192
1145
a094d90e11bf dont use [0] blocks - use 0 constant instead
Claus Gittinger <cg@exept.de>
parents: 1016
diff changeset
  2193
    ^ self indexOfSubCollection:aCollection startingAt:startIndex ifAbsent:0
368
a3c21a89ec37 *** empty log message ***
claus
parents: 362
diff changeset
  2194
!
a3c21a89ec37 *** empty log message ***
claus
parents: 362
diff changeset
  2195
a3c21a89ec37 *** empty log message ***
claus
parents: 362
diff changeset
  2196
indexOfSubCollection:aCollection startingAt:startIndex ifAbsent:exceptionBlock
a3c21a89ec37 *** empty log message ***
claus
parents: 362
diff changeset
  2197
    "find a subcollection, starting at index. If found, return the index;
a3c21a89ec37 *** empty log message ***
claus
parents: 362
diff changeset
  2198
     if not found, return the result of evaluating exceptionBlock.
a3c21a89ec37 *** empty log message ***
claus
parents: 362
diff changeset
  2199
     This is a q&d hack - not very efficient"
a3c21a89ec37 *** empty log message ***
claus
parents: 362
diff changeset
  2200
a3c21a89ec37 *** empty log message ***
claus
parents: 362
diff changeset
  2201
    |same first 
a3c21a89ec37 *** empty log message ***
claus
parents: 362
diff changeset
  2202
     mySize     "{Class: SmallInteger }"
a3c21a89ec37 *** empty log message ***
claus
parents: 362
diff changeset
  2203
     checkIndex "{Class: SmallInteger }"
a3c21a89ec37 *** empty log message ***
claus
parents: 362
diff changeset
  2204
     cmpIndex   "{Class: SmallInteger }"
a3c21a89ec37 *** empty log message ***
claus
parents: 362
diff changeset
  2205
     sz         "{Class: SmallInteger }"|
a3c21a89ec37 *** empty log message ***
claus
parents: 362
diff changeset
  2206
a3c21a89ec37 *** empty log message ***
claus
parents: 362
diff changeset
  2207
    mySize := self size.
a3c21a89ec37 *** empty log message ***
claus
parents: 362
diff changeset
  2208
    sz := aCollection size.
a3c21a89ec37 *** empty log message ***
claus
parents: 362
diff changeset
  2209
    sz == 0 ifTrue:[^ exceptionBlock value].
a3c21a89ec37 *** empty log message ***
claus
parents: 362
diff changeset
  2210
    first := aCollection at:1.
a3c21a89ec37 *** empty log message ***
claus
parents: 362
diff changeset
  2211
a3c21a89ec37 *** empty log message ***
claus
parents: 362
diff changeset
  2212
    checkIndex := startIndex - 1.    
a3c21a89ec37 *** empty log message ***
claus
parents: 362
diff changeset
  2213
    [true] whileTrue:[
a3c21a89ec37 *** empty log message ***
claus
parents: 362
diff changeset
  2214
	checkIndex := self indexOf:first startingAt:checkIndex+1.
a3c21a89ec37 *** empty log message ***
claus
parents: 362
diff changeset
  2215
	checkIndex == 0 ifTrue:[^ exceptionBlock value].
a3c21a89ec37 *** empty log message ***
claus
parents: 362
diff changeset
  2216
a3c21a89ec37 *** empty log message ***
claus
parents: 362
diff changeset
  2217
	(checkIndex + sz - 1) > mySize ifTrue:[
a3c21a89ec37 *** empty log message ***
claus
parents: 362
diff changeset
  2218
	    ^ 0
a3c21a89ec37 *** empty log message ***
claus
parents: 362
diff changeset
  2219
	].
a3c21a89ec37 *** empty log message ***
claus
parents: 362
diff changeset
  2220
	same := true.
a3c21a89ec37 *** empty log message ***
claus
parents: 362
diff changeset
  2221
	cmpIndex := 1.
a3c21a89ec37 *** empty log message ***
claus
parents: 362
diff changeset
  2222
	[same and:[cmpIndex <= sz]] whileTrue:[
a3c21a89ec37 *** empty log message ***
claus
parents: 362
diff changeset
  2223
	    (self at:checkIndex + cmpIndex - 1) = (aCollection at:cmpIndex) ifFalse:[
a3c21a89ec37 *** empty log message ***
claus
parents: 362
diff changeset
  2224
		same := false
a3c21a89ec37 *** empty log message ***
claus
parents: 362
diff changeset
  2225
	    ] ifTrue:[
a3c21a89ec37 *** empty log message ***
claus
parents: 362
diff changeset
  2226
		cmpIndex := cmpIndex + 1
a3c21a89ec37 *** empty log message ***
claus
parents: 362
diff changeset
  2227
	    ]
a3c21a89ec37 *** empty log message ***
claus
parents: 362
diff changeset
  2228
	].
a3c21a89ec37 *** empty log message ***
claus
parents: 362
diff changeset
  2229
	same ifTrue:[^ checkIndex].
a3c21a89ec37 *** empty log message ***
claus
parents: 362
diff changeset
  2230
    ]    
a3c21a89ec37 *** empty log message ***
claus
parents: 362
diff changeset
  2231
a3c21a89ec37 *** empty log message ***
claus
parents: 362
diff changeset
  2232
    "
a3c21a89ec37 *** empty log message ***
claus
parents: 362
diff changeset
  2233
     #(1 2 3 4 5 6 7) indexOfSubCollection:#()  startingAt:2 
a3c21a89ec37 *** empty log message ***
claus
parents: 362
diff changeset
  2234
     #(1 2 3 4 5 6 7) indexOfSubCollection:#(1) startingAt:2     
a3c21a89ec37 *** empty log message ***
claus
parents: 362
diff changeset
  2235
     #(1 2 1 2 1 2 3) indexOfSubCollection:#(1 2 3) startingAt:2 
a3c21a89ec37 *** empty log message ***
claus
parents: 362
diff changeset
  2236
     #(1 2 1 2 1 2 3) indexOfSubCollection:#(1 2)   startingAt:2  
a3c21a89ec37 *** empty log message ***
claus
parents: 362
diff changeset
  2237
     #(1 2 1 2 1 2 3) indexOfSubCollection:#(1 2)   startingAt:3  
a3c21a89ec37 *** empty log message ***
claus
parents: 362
diff changeset
  2238
     #(1 2 1 2 1 2 3) indexOfSubCollection:#(1 2)   startingAt:4 
a3c21a89ec37 *** empty log message ***
claus
parents: 362
diff changeset
  2239
    "
602
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  2240
!
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  2241
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  2242
lastIndexOf:anElement
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  2243
    "search the collection backwards for anElement;
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  2244
     if found, return the index otherwise return 0.
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  2245
     The comparison is done using = 
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  2246
     (i.e. equality test - not identity test)."
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  2247
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  2248
    ^ self lastIndexOf:anElement startingAt:self size 
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  2249
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  2250
    "
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  2251
     #(10 20 30 40 50 60 70) lastIndexOf:40    
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  2252
     #(10 20 30 40 50 60 70) lastIndexOf:40.0  
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  2253
     #(10 20 30 40 50 60 70) lastIndexOf:35    
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  2254
     #(10 20 30 40 50 60 70) lastIndexOf:10    
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  2255
    "
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  2256
!
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  2257
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  2258
lastIndexOf:anElement ifAbsent:exceptionBlock
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  2259
    "search the collection backwards for anElement;
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  2260
     if found, return the index otherwise return the value of the
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  2261
     exceptionBlock.
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  2262
     The comparison is done using = 
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  2263
     (i.e. equality test - not identity test)."
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  2264
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  2265
    |index|
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  2266
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  2267
    index := self lastIndexOf:anElement startingAt:self size.
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  2268
    (index == 0) ifTrue:[^ exceptionBlock value].
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  2269
    ^ index
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  2270
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  2271
    "
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  2272
     #(10 20 30 40 10 20 30 40) lastIndexOf:40   ifAbsent:['none'] 
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  2273
     #(10 20 30 40 10 20 30 40) lastIndexOf:40.0 ifAbsent:['none'] 
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  2274
     #(10 20 30 40 10 20 30 40) lastIndexOf:35   ifAbsent:['none'] 
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  2275
     #(10 20 30 40 10 20 30 40) lastIndexOf:10   ifAbsent:['none'] 
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  2276
    "
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  2277
!
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  2278
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  2279
lastIndexOf:anElement startingAt:start
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  2280
    "search the collection backwards for anElement, starting the search at index start;
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  2281
     if found, return the index otherwise return 0.
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  2282
     The comparison is done using = 
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  2283
     (i.e. equality test - not identity test)."
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  2284
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  2285
    |startIndex "{ Class: SmallInteger }"|
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  2286
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  2287
    startIndex := start.
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  2288
    startIndex to:1 by:-1 do:[:index |
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  2289
	anElement = (self at:index) ifTrue:[^ index].
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  2290
    ].
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  2291
    ^ 0
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  2292
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  2293
    "
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  2294
     #(10 20 30 40 10 20 30 40) lastIndexOf:40   startingAt:8  
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  2295
     #(10 20 30 40 10 20 30 40) lastIndexOf:40.0 startingAt:8  
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  2296
     #(10 20 30 40 10 20 30 40) lastIndexOf:35   startingAt:8  
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  2297
     #(10 20 30 40 10 20 30 40) lastIndexOf:10   startingAt:8  
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  2298
     #(10 20 30 40 10 20 30 40) lastIndexOf:10   startingAt:4  
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  2299
    "
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  2300
!
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  2301
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  2302
lastIndexOf:anElement startingAt:start ifAbsent:exceptionBlock
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  2303
    "search the collection backwards for anElement starting the search at 
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  2304
     index start; if found, return the index 
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  2305
     otherwise return the value of the exceptionBlock.
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  2306
     The comparison is done using = 
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  2307
     (i.e. equality test - not identity test)."
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  2308
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  2309
    |index|
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  2310
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  2311
    index := self lastIndexOf:anElement startingAt:start.
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  2312
    (index == 0) ifTrue:[^ exceptionBlock value].
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  2313
    ^ index
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  2314
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  2315
    "
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  2316
     #(10 20 30 40 10 20 30 40) lastIndexOf:40   startingAt:8 ifAbsent:['none'] 
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  2317
     #(10 20 30 40 10 20 30 40) lastIndexOf:40.0 startingAt:8 ifAbsent:['none'] 
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  2318
     #(10 20 30 40 10 20 30 40) lastIndexOf:35   startingAt:8 ifAbsent:['none'] 
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  2319
     #(10 20 30 40 10 20 30 40) lastIndexOf:10   startingAt:8 ifAbsent:['none'] 
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  2320
    "
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  2321
!
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  2322
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  2323
nextIndexOf:anElement from:start to:stop
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  2324
    "search the collection for anElement, starting the search at index start,
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  2325
     stopping at:stop;
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  2326
     if found, return the index otherwise return 0.
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  2327
     The comparison is done using = 
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  2328
     (i.e. equality test - not identity test)."
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  2329
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  2330
    |startIndex "{ Class: SmallInteger }"
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  2331
     stopIndex  "{ Class: SmallInteger }" |
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  2332
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  2333
    startIndex := start.
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  2334
    stopIndex :=  stop.
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  2335
    startIndex to:stop do:[:index |
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  2336
	anElement = (self at:index) ifTrue:[^ index].
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  2337
    ].
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  2338
    ^ 0
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  2339
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  2340
    "
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  2341
     #(10 20 30 40 10 20 30 40) nextIndexOf:40   from:2 to:6  
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  2342
     #(10 20 30 40 10 20 30 40) nextIndexOf:40.0 from:2 to:6   
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  2343
     #(10 20 30 40 10 20 30 40) nextIndexOf:35   from:2 to:6   
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  2344
    "
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  2345
!
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  2346
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  2347
nextIndexOf:anElement from:start to:stop ifAbsent:exceptionBlock
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  2348
    "search the collection for anElement, starting the search at index start
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  2349
     and stopping at stop;
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  2350
     if found, return the index otherwise return the value of the
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  2351
     exceptionBlock.
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  2352
     The comparison is done using = 
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  2353
     (i.e. equality test - not identity test)."
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  2354
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  2355
    |index|
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  2356
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  2357
    index := self nextIndexOf:anElement from:start to:stop.
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  2358
    (index == 0) ifTrue:[^ exceptionBlock value].
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  2359
    ^ index
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  2360
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  2361
    "
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  2362
     #(10 20 30 40 10 20 30 40) nextIndexOf:40   from:2 to:6 ifAbsent:['none'] 
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  2363
     #(10 20 30 40 10 20 30 40) nextIndexOf:40.0 from:2 to:6 ifAbsent:['none'] 
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  2364
     #(10 20 30 40 10 20 30 40) nextIndexOf:35   from:2 to:6 ifAbsent:['none'] 
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  2365
    "
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  2366
! !
a27a279701f8 Initial revision
claus
parents:
diff changeset
  2367
a27a279701f8 Initial revision
claus
parents:
diff changeset
  2368
!SequenceableCollection methodsFor:'sorting & reordering'!
a27a279701f8 Initial revision
claus
parents:
diff changeset
  2369
890
0235f2dc2d74 more integer decls for inlinable loops in sort methods
Claus Gittinger <cg@exept.de>
parents: 869
diff changeset
  2370
quickSortFrom:inBegin to:inEnd
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  2371
    "actual quicksort worker for sort-message"
a27a279701f8 Initial revision
claus
parents:
diff changeset
  2372
890
0235f2dc2d74 more integer decls for inlinable loops in sort methods
Claus Gittinger <cg@exept.de>
parents: 869
diff changeset
  2373
    |begin   "{ Class: SmallInteger }"
0235f2dc2d74 more integer decls for inlinable loops in sort methods
Claus Gittinger <cg@exept.de>
parents: 869
diff changeset
  2374
     end     "{ Class: SmallInteger }"
0235f2dc2d74 more integer decls for inlinable loops in sort methods
Claus Gittinger <cg@exept.de>
parents: 869
diff changeset
  2375
     b       "{ Class: SmallInteger }"
0235f2dc2d74 more integer decls for inlinable loops in sort methods
Claus Gittinger <cg@exept.de>
parents: 869
diff changeset
  2376
     e       "{ Class: SmallInteger }"
929
674de4c05dcb added findFirst:startingAt: and findLast:startingAt:
Claus Gittinger <cg@exept.de>
parents: 911
diff changeset
  2377
     middleElement temp1 temp2 |
674de4c05dcb added findFirst:startingAt: and findLast:startingAt:
Claus Gittinger <cg@exept.de>
parents: 911
diff changeset
  2378
674de4c05dcb added findFirst:startingAt: and findLast:startingAt:
Claus Gittinger <cg@exept.de>
parents: 911
diff changeset
  2379
    begin := inBegin.   "/ this also does a type-check
890
0235f2dc2d74 more integer decls for inlinable loops in sort methods
Claus Gittinger <cg@exept.de>
parents: 869
diff changeset
  2380
    end := inEnd.
0235f2dc2d74 more integer decls for inlinable loops in sort methods
Claus Gittinger <cg@exept.de>
parents: 869
diff changeset
  2381
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  2382
    b := begin.
a27a279701f8 Initial revision
claus
parents:
diff changeset
  2383
    e := end.
a27a279701f8 Initial revision
claus
parents:
diff changeset
  2384
    middleElement := self at:((b + e) // 2).
a27a279701f8 Initial revision
claus
parents:
diff changeset
  2385
a27a279701f8 Initial revision
claus
parents:
diff changeset
  2386
    [b < e] whileTrue:[
159
514c749165c3 *** empty log message ***
claus
parents: 118
diff changeset
  2387
	[b < end and:[(self at:b) < middleElement]] whileTrue:[b := b + 1].
514c749165c3 *** empty log message ***
claus
parents: 118
diff changeset
  2388
	[e > begin and:[middleElement < (self at:e)]] whileTrue:[e := e - 1].
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  2389
159
514c749165c3 *** empty log message ***
claus
parents: 118
diff changeset
  2390
	(b <= e) ifTrue:[
514c749165c3 *** empty log message ***
claus
parents: 118
diff changeset
  2391
	    (b == e) ifFalse:[
929
674de4c05dcb added findFirst:startingAt: and findLast:startingAt:
Claus Gittinger <cg@exept.de>
parents: 911
diff changeset
  2392
		temp1 := self at:b. temp2 := self at:e. 
674de4c05dcb added findFirst:startingAt: and findLast:startingAt:
Claus Gittinger <cg@exept.de>
parents: 911
diff changeset
  2393
		self at:b put:temp2. self at:e put:temp1
159
514c749165c3 *** empty log message ***
claus
parents: 118
diff changeset
  2394
	    ].
514c749165c3 *** empty log message ***
claus
parents: 118
diff changeset
  2395
	    b := b + 1.
514c749165c3 *** empty log message ***
claus
parents: 118
diff changeset
  2396
	    e := e - 1
514c749165c3 *** empty log message ***
claus
parents: 118
diff changeset
  2397
	]
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  2398
    ].
a27a279701f8 Initial revision
claus
parents:
diff changeset
  2399
    (begin < e) ifTrue:[self quickSortFrom:begin to:e].
a27a279701f8 Initial revision
claus
parents:
diff changeset
  2400
    (b < end) ifTrue:[self quickSortFrom:b to:end]
a27a279701f8 Initial revision
claus
parents:
diff changeset
  2401
!
a27a279701f8 Initial revision
claus
parents:
diff changeset
  2402
890
0235f2dc2d74 more integer decls for inlinable loops in sort methods
Claus Gittinger <cg@exept.de>
parents: 869
diff changeset
  2403
quickSortFrom:inBegin to:inEnd sortBlock:sortBlock
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  2404
    "actual quicksort worker for sort:-message"
a27a279701f8 Initial revision
claus
parents:
diff changeset
  2405
890
0235f2dc2d74 more integer decls for inlinable loops in sort methods
Claus Gittinger <cg@exept.de>
parents: 869
diff changeset
  2406
    |begin   "{ Class: SmallInteger }"
0235f2dc2d74 more integer decls for inlinable loops in sort methods
Claus Gittinger <cg@exept.de>
parents: 869
diff changeset
  2407
     end     "{ Class: SmallInteger }"
0235f2dc2d74 more integer decls for inlinable loops in sort methods
Claus Gittinger <cg@exept.de>
parents: 869
diff changeset
  2408
     b       "{ Class: SmallInteger }"
0235f2dc2d74 more integer decls for inlinable loops in sort methods
Claus Gittinger <cg@exept.de>
parents: 869
diff changeset
  2409
     e       "{ Class: SmallInteger }"
929
674de4c05dcb added findFirst:startingAt: and findLast:startingAt:
Claus Gittinger <cg@exept.de>
parents: 911
diff changeset
  2410
     middleElement temp1 temp2 |
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  2411
890
0235f2dc2d74 more integer decls for inlinable loops in sort methods
Claus Gittinger <cg@exept.de>
parents: 869
diff changeset
  2412
    begin := inBegin.   "/ this also does a type-check
0235f2dc2d74 more integer decls for inlinable loops in sort methods
Claus Gittinger <cg@exept.de>
parents: 869
diff changeset
  2413
    end := inEnd.
0235f2dc2d74 more integer decls for inlinable loops in sort methods
Claus Gittinger <cg@exept.de>
parents: 869
diff changeset
  2414
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  2415
    b := begin.
a27a279701f8 Initial revision
claus
parents:
diff changeset
  2416
    e := end.
a27a279701f8 Initial revision
claus
parents:
diff changeset
  2417
    middleElement := self at:((b + e) // 2).
a27a279701f8 Initial revision
claus
parents:
diff changeset
  2418
a27a279701f8 Initial revision
claus
parents:
diff changeset
  2419
    [b < e] whileTrue:[
159
514c749165c3 *** empty log message ***
claus
parents: 118
diff changeset
  2420
	[b < end and:[sortBlock value:(self at:b) value:middleElement]] whileTrue:[b := b + 1].
514c749165c3 *** empty log message ***
claus
parents: 118
diff changeset
  2421
	[e > begin and:[sortBlock value:middleElement value:(self at:e)]] whileTrue:[e := e - 1].
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  2422
159
514c749165c3 *** empty log message ***
claus
parents: 118
diff changeset
  2423
	(b <= e) ifTrue:[
514c749165c3 *** empty log message ***
claus
parents: 118
diff changeset
  2424
	    (b == e) ifFalse:[
929
674de4c05dcb added findFirst:startingAt: and findLast:startingAt:
Claus Gittinger <cg@exept.de>
parents: 911
diff changeset
  2425
		temp1 := self at:b. temp2 := self at:e. 
674de4c05dcb added findFirst:startingAt: and findLast:startingAt:
Claus Gittinger <cg@exept.de>
parents: 911
diff changeset
  2426
		self at:b put:temp2. self at:e put:temp1
159
514c749165c3 *** empty log message ***
claus
parents: 118
diff changeset
  2427
	    ].
514c749165c3 *** empty log message ***
claus
parents: 118
diff changeset
  2428
	    b := b + 1.
514c749165c3 *** empty log message ***
claus
parents: 118
diff changeset
  2429
	    e := e - 1
514c749165c3 *** empty log message ***
claus
parents: 118
diff changeset
  2430
	]
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  2431
    ].
a27a279701f8 Initial revision
claus
parents:
diff changeset
  2432
    (begin < e) ifTrue:[self quickSortFrom:begin to:e sortBlock:sortBlock].
a27a279701f8 Initial revision
claus
parents:
diff changeset
  2433
    (b < end) ifTrue:[self quickSortFrom:b to:end sortBlock:sortBlock]
a27a279701f8 Initial revision
claus
parents:
diff changeset
  2434
!
a27a279701f8 Initial revision
claus
parents:
diff changeset
  2435
890
0235f2dc2d74 more integer decls for inlinable loops in sort methods
Claus Gittinger <cg@exept.de>
parents: 869
diff changeset
  2436
quickSortFrom:inBegin to:inEnd sortBlock:sortBlock with:aCollection
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  2437
    "actual quicksort worker for sort:with:-message"
a27a279701f8 Initial revision
claus
parents:
diff changeset
  2438
890
0235f2dc2d74 more integer decls for inlinable loops in sort methods
Claus Gittinger <cg@exept.de>
parents: 869
diff changeset
  2439
    |begin   "{ Class: SmallInteger }"
0235f2dc2d74 more integer decls for inlinable loops in sort methods
Claus Gittinger <cg@exept.de>
parents: 869
diff changeset
  2440
     end     "{ Class: SmallInteger }"
0235f2dc2d74 more integer decls for inlinable loops in sort methods
Claus Gittinger <cg@exept.de>
parents: 869
diff changeset
  2441
     b       "{ Class: SmallInteger }"
0235f2dc2d74 more integer decls for inlinable loops in sort methods
Claus Gittinger <cg@exept.de>
parents: 869
diff changeset
  2442
     e       "{ Class: SmallInteger }"
929
674de4c05dcb added findFirst:startingAt: and findLast:startingAt:
Claus Gittinger <cg@exept.de>
parents: 911
diff changeset
  2443
     middleElement temp1 temp2 |
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  2444
890
0235f2dc2d74 more integer decls for inlinable loops in sort methods
Claus Gittinger <cg@exept.de>
parents: 869
diff changeset
  2445
    begin := inBegin.   "/ this also does a type-check
0235f2dc2d74 more integer decls for inlinable loops in sort methods
Claus Gittinger <cg@exept.de>
parents: 869
diff changeset
  2446
    end := inEnd.
0235f2dc2d74 more integer decls for inlinable loops in sort methods
Claus Gittinger <cg@exept.de>
parents: 869
diff changeset
  2447
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  2448
    b := begin.
a27a279701f8 Initial revision
claus
parents:
diff changeset
  2449
    e := end.
a27a279701f8 Initial revision
claus
parents:
diff changeset
  2450
    middleElement := self at:((b + e) // 2).
a27a279701f8 Initial revision
claus
parents:
diff changeset
  2451
a27a279701f8 Initial revision
claus
parents:
diff changeset
  2452
    [b < e] whileTrue:[
159
514c749165c3 *** empty log message ***
claus
parents: 118
diff changeset
  2453
	[b < end and:[sortBlock value:(self at:b) value:middleElement]] whileTrue:[b := b + 1].
514c749165c3 *** empty log message ***
claus
parents: 118
diff changeset
  2454
	[e > begin and:[sortBlock value:middleElement value:(self at:e)]] whileTrue:[e := e - 1].
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  2455
159
514c749165c3 *** empty log message ***
claus
parents: 118
diff changeset
  2456
	(b <= e) ifTrue:[
514c749165c3 *** empty log message ***
claus
parents: 118
diff changeset
  2457
	    (b == e) ifFalse:[
929
674de4c05dcb added findFirst:startingAt: and findLast:startingAt:
Claus Gittinger <cg@exept.de>
parents: 911
diff changeset
  2458
		temp1 := self at:b. temp2 := self at:e. 
674de4c05dcb added findFirst:startingAt: and findLast:startingAt:
Claus Gittinger <cg@exept.de>
parents: 911
diff changeset
  2459
		self at:b put:temp2. self at:e put:temp1.
674de4c05dcb added findFirst:startingAt: and findLast:startingAt:
Claus Gittinger <cg@exept.de>
parents: 911
diff changeset
  2460
		temp1 := aCollection at:b. temp2 := aCollection at:e. 
674de4c05dcb added findFirst:startingAt: and findLast:startingAt:
Claus Gittinger <cg@exept.de>
parents: 911
diff changeset
  2461
		aCollection at:b put:temp2. aCollection at:e put:temp1
159
514c749165c3 *** empty log message ***
claus
parents: 118
diff changeset
  2462
	    ].
514c749165c3 *** empty log message ***
claus
parents: 118
diff changeset
  2463
	    b := b + 1.
514c749165c3 *** empty log message ***
claus
parents: 118
diff changeset
  2464
	    e := e - 1
514c749165c3 *** empty log message ***
claus
parents: 118
diff changeset
  2465
	]
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  2466
    ].
a27a279701f8 Initial revision
claus
parents:
diff changeset
  2467
    (begin < e) ifTrue:[self quickSortFrom:begin to:e sortBlock:sortBlock with:aCollection].
a27a279701f8 Initial revision
claus
parents:
diff changeset
  2468
    (b < end) ifTrue:[self quickSortFrom:b to:end sortBlock:sortBlock with:aCollection]
a27a279701f8 Initial revision
claus
parents:
diff changeset
  2469
!
a27a279701f8 Initial revision
claus
parents:
diff changeset
  2470
890
0235f2dc2d74 more integer decls for inlinable loops in sort methods
Claus Gittinger <cg@exept.de>
parents: 869
diff changeset
  2471
quickSortFrom:inBegin to:inEnd with:aCollection
602
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  2472
    "actual quicksort worker for sortWith-message"
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  2473
890
0235f2dc2d74 more integer decls for inlinable loops in sort methods
Claus Gittinger <cg@exept.de>
parents: 869
diff changeset
  2474
    |begin   "{ Class: SmallInteger }"
0235f2dc2d74 more integer decls for inlinable loops in sort methods
Claus Gittinger <cg@exept.de>
parents: 869
diff changeset
  2475
     end     "{ Class: SmallInteger }"
0235f2dc2d74 more integer decls for inlinable loops in sort methods
Claus Gittinger <cg@exept.de>
parents: 869
diff changeset
  2476
     b       "{ Class: SmallInteger }"
0235f2dc2d74 more integer decls for inlinable loops in sort methods
Claus Gittinger <cg@exept.de>
parents: 869
diff changeset
  2477
     e       "{ Class: SmallInteger }"
929
674de4c05dcb added findFirst:startingAt: and findLast:startingAt:
Claus Gittinger <cg@exept.de>
parents: 911
diff changeset
  2478
     middleElement temp1 temp2 |
602
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  2479
890
0235f2dc2d74 more integer decls for inlinable loops in sort methods
Claus Gittinger <cg@exept.de>
parents: 869
diff changeset
  2480
    begin := inBegin.   "/ this also does a type-check
0235f2dc2d74 more integer decls for inlinable loops in sort methods
Claus Gittinger <cg@exept.de>
parents: 869
diff changeset
  2481
    end := inEnd.
0235f2dc2d74 more integer decls for inlinable loops in sort methods
Claus Gittinger <cg@exept.de>
parents: 869
diff changeset
  2482
602
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  2483
    b := begin.
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  2484
    e := end.
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  2485
    middleElement := self at:((b + e) // 2).
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  2486
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  2487
    [b < e] whileTrue:[
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  2488
	[b < end and:[(self at:b) < middleElement]] whileTrue:[b := b + 1].
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  2489
	[e > begin and:[middleElement < (self at:e)]] whileTrue:[e := e - 1].
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  2490
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  2491
	(b <= e) ifTrue:[
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  2492
	    (b == e) ifFalse:[
929
674de4c05dcb added findFirst:startingAt: and findLast:startingAt:
Claus Gittinger <cg@exept.de>
parents: 911
diff changeset
  2493
		temp1 := self at:b. temp2 := self at:e. 
674de4c05dcb added findFirst:startingAt: and findLast:startingAt:
Claus Gittinger <cg@exept.de>
parents: 911
diff changeset
  2494
		self at:b put:temp2. self at:e put:temp1.
674de4c05dcb added findFirst:startingAt: and findLast:startingAt:
Claus Gittinger <cg@exept.de>
parents: 911
diff changeset
  2495
		temp1 := aCollection at:b. temp2 := aCollection at:e. 
674de4c05dcb added findFirst:startingAt: and findLast:startingAt:
Claus Gittinger <cg@exept.de>
parents: 911
diff changeset
  2496
		aCollection at:b put:temp2. aCollection at:e put:temp1
602
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  2497
	    ].
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  2498
	    b := b + 1.
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  2499
	    e := e - 1
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  2500
	]
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  2501
    ].
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  2502
    (begin < e) ifTrue:[self quickSortFrom:begin to:e with:aCollection].
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  2503
    (b < end) ifTrue:[self quickSortFrom:b to:end with:aCollection]
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  2504
!
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  2505
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  2506
reverse
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  2507
    "reverse the order of the elements inplace"
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  2508
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  2509
    |lowIndex "{ Class: SmallInteger }"
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  2510
     hiIndex  "{ Class: SmallInteger }"
929
674de4c05dcb added findFirst:startingAt: and findLast:startingAt:
Claus Gittinger <cg@exept.de>
parents: 911
diff changeset
  2511
     t1 t2|
602
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  2512
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  2513
    hiIndex := self size.
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  2514
    lowIndex := 1.
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  2515
    [lowIndex < hiIndex] whileTrue:[
929
674de4c05dcb added findFirst:startingAt: and findLast:startingAt:
Claus Gittinger <cg@exept.de>
parents: 911
diff changeset
  2516
	t1 := self at:lowIndex.
674de4c05dcb added findFirst:startingAt: and findLast:startingAt:
Claus Gittinger <cg@exept.de>
parents: 911
diff changeset
  2517
	t2 := self at:hiIndex.
674de4c05dcb added findFirst:startingAt: and findLast:startingAt:
Claus Gittinger <cg@exept.de>
parents: 911
diff changeset
  2518
	self at:lowIndex put:t2.
674de4c05dcb added findFirst:startingAt: and findLast:startingAt:
Claus Gittinger <cg@exept.de>
parents: 911
diff changeset
  2519
	self at:hiIndex put:t1.
674de4c05dcb added findFirst:startingAt: and findLast:startingAt:
Claus Gittinger <cg@exept.de>
parents: 911
diff changeset
  2520
602
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  2521
	lowIndex := lowIndex + 1.
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  2522
	hiIndex := hiIndex - 1
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  2523
    ]
69
4564b6328136 *** empty log message ***
claus
parents: 61
diff changeset
  2524
    "
602
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  2525
     #(4 5 6 7 7) reverse
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  2526
     #(1 4 7 10 2 5) asOrderedCollection reverse
69
4564b6328136 *** empty log message ***
claus
parents: 61
diff changeset
  2527
    "
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  2528
!
a27a279701f8 Initial revision
claus
parents:
diff changeset
  2529
a27a279701f8 Initial revision
claus
parents:
diff changeset
  2530
sort
a27a279701f8 Initial revision
claus
parents:
diff changeset
  2531
    "sort the collection inplace. The elements are compared using
159
514c749165c3 *** empty log message ***
claus
parents: 118
diff changeset
  2532
     > and < i.e. they should offer a magnitude-like protocol.
514c749165c3 *** empty log message ***
claus
parents: 118
diff changeset
  2533
     The implementation uses the quicksort algorithm, which may not be
514c749165c3 *** empty log message ***
claus
parents: 118
diff changeset
  2534
     the best possible for all situations."
13
62303f84ff5f *** empty log message ***
claus
parents: 5
diff changeset
  2535
32
ee1a621c696c *** empty log message ***
claus
parents: 13
diff changeset
  2536
    |stop|
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  2537
32
ee1a621c696c *** empty log message ***
claus
parents: 13
diff changeset
  2538
    stop := self size.
ee1a621c696c *** empty log message ***
claus
parents: 13
diff changeset
  2539
    (stop > 1) ifTrue:[
159
514c749165c3 *** empty log message ***
claus
parents: 118
diff changeset
  2540
	self quickSortFrom:1 to:stop
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  2541
    ]
a27a279701f8 Initial revision
claus
parents:
diff changeset
  2542
95
d22739a0c6e9 *** empty log message ***
claus
parents: 88
diff changeset
  2543
    "
d22739a0c6e9 *** empty log message ***
claus
parents: 88
diff changeset
  2544
     #(1 16 7 98 3 19 4 0) sort
d22739a0c6e9 *** empty log message ***
claus
parents: 88
diff changeset
  2545
d22739a0c6e9 *** empty log message ***
claus
parents: 88
diff changeset
  2546
     |data|
d22739a0c6e9 *** empty log message ***
claus
parents: 88
diff changeset
  2547
     data := Random new next:100000.
d22739a0c6e9 *** empty log message ***
claus
parents: 88
diff changeset
  2548
     'random  ' print. (Time millisecondsToRun:[data sort]) printNL.
d22739a0c6e9 *** empty log message ***
claus
parents: 88
diff changeset
  2549
     'sorted  ' print. (Time millisecondsToRun:[data sort]) printNL.
d22739a0c6e9 *** empty log message ***
claus
parents: 88
diff changeset
  2550
     data reverse. 
d22739a0c6e9 *** empty log message ***
claus
parents: 88
diff changeset
  2551
     'reverse ' print. (Time millisecondsToRun:[data sort]) printNL.
d22739a0c6e9 *** empty log message ***
claus
parents: 88
diff changeset
  2552
    "
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  2553
!
a27a279701f8 Initial revision
claus
parents:
diff changeset
  2554
a27a279701f8 Initial revision
claus
parents:
diff changeset
  2555
sort:sortBlock
a27a279701f8 Initial revision
claus
parents:
diff changeset
  2556
    "sort the collection inplace using the 2-arg block sortBlock
a27a279701f8 Initial revision
claus
parents:
diff changeset
  2557
     for comparison. This allows any sort criteria to be implemented."
a27a279701f8 Initial revision
claus
parents:
diff changeset
  2558
32
ee1a621c696c *** empty log message ***
claus
parents: 13
diff changeset
  2559
    |stop|
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  2560
32
ee1a621c696c *** empty log message ***
claus
parents: 13
diff changeset
  2561
    stop := self size.
ee1a621c696c *** empty log message ***
claus
parents: 13
diff changeset
  2562
    (stop > 1) ifTrue:[
159
514c749165c3 *** empty log message ***
claus
parents: 118
diff changeset
  2563
	self quickSortFrom:1 to:stop sortBlock:sortBlock
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  2564
    ]
a27a279701f8 Initial revision
claus
parents:
diff changeset
  2565
95
d22739a0c6e9 *** empty log message ***
claus
parents: 88
diff changeset
  2566
    "
d22739a0c6e9 *** empty log message ***
claus
parents: 88
diff changeset
  2567
     #(1 16 7 98 3 19 4 0) sort:[:a :b | a < b]
d22739a0c6e9 *** empty log message ***
claus
parents: 88
diff changeset
  2568
     #(1 16 7 98 3 19 4 0) sort:[:a :b | a > b]
d22739a0c6e9 *** empty log message ***
claus
parents: 88
diff changeset
  2569
    "
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  2570
!
a27a279701f8 Initial revision
claus
parents:
diff changeset
  2571
a27a279701f8 Initial revision
claus
parents:
diff changeset
  2572
sort:sortBlock with:aCollection
a27a279701f8 Initial revision
claus
parents:
diff changeset
  2573
    "sort the collection inplace using the 2-arg block sortBlock
159
514c749165c3 *** empty log message ***
claus
parents: 118
diff changeset
  2574
     for comparison. Also reorder the elements in aCollection.
514c749165c3 *** empty log message ***
claus
parents: 118
diff changeset
  2575
     Use, when you have a key collection to sort some other collection with."
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  2576
32
ee1a621c696c *** empty log message ***
claus
parents: 13
diff changeset
  2577
    |stop|
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  2578
32
ee1a621c696c *** empty log message ***
claus
parents: 13
diff changeset
  2579
    stop := self size.
ee1a621c696c *** empty log message ***
claus
parents: 13
diff changeset
  2580
    (stop > 1) ifTrue:[
159
514c749165c3 *** empty log message ***
claus
parents: 118
diff changeset
  2581
	self quickSortFrom:1 to:stop sortBlock:sortBlock with:aCollection
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  2582
    ]
a27a279701f8 Initial revision
claus
parents:
diff changeset
  2583
69
4564b6328136 *** empty log message ***
claus
parents: 61
diff changeset
  2584
    "
4564b6328136 *** empty log message ***
claus
parents: 61
diff changeset
  2585
     |c1 c2|
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  2586
     c1 := #(1 16 7 9).
a27a279701f8 Initial revision
claus
parents:
diff changeset
  2587
     c2 := #('one' 'sixteen' 'seven' 'nine').
a27a279701f8 Initial revision
claus
parents:
diff changeset
  2588
     c1 sort:[:a :b | a > b] with:c2.
95
d22739a0c6e9 *** empty log message ***
claus
parents: 88
diff changeset
  2589
     c1 printNL.
d22739a0c6e9 *** empty log message ***
claus
parents: 88
diff changeset
  2590
     c2 printNL
69
4564b6328136 *** empty log message ***
claus
parents: 61
diff changeset
  2591
    "
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  2592
!
a27a279701f8 Initial revision
claus
parents:
diff changeset
  2593
602
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  2594
sortWith:aCollection
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  2595
    "sort the receiver collection inplace, also sort aCollection with it.
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  2596
     Use, when you have a key collection to sort another collection with."
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  2597
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  2598
    |stop|
356
claus
parents: 348
diff changeset
  2599
claus
parents: 348
diff changeset
  2600
    stop := self size.
602
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  2601
    (stop > 1) ifTrue:[
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  2602
	self quickSortFrom:1 to:stop with:aCollection
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  2603
    ]
77
6c38ca59927f *** empty log message ***
claus
parents: 69
diff changeset
  2604
6c38ca59927f *** empty log message ***
claus
parents: 69
diff changeset
  2605
    "
602
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  2606
     |c1 c2|
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  2607
     c1 := #(1 16 7 9).
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  2608
     c2 := #('one' 'sixteen' 'seven' 'nine').
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  2609
     c1 sortWith:c2.
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  2610
     c1 printNL.
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  2611
     c2 printNL
424
claus
parents: 422
diff changeset
  2612
    "
claus
parents: 422
diff changeset
  2613
!
claus
parents: 422
diff changeset
  2614
602
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  2615
topologicalSort:sortBlock
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  2616
    "sort the collection inplace using a sloooow sort algorithm.
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  2617
     This algorithm has O-square runtime behavior and should be used only
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  2618
     in special situations.
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  2619
     It compares all elements, thus can be used when a>b, b>c does NOT imply
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  2620
     a>c (for example, to sort classes by inheritance)
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  2621
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  2622
     In other situations, use #sort; which implements the quicksort algorithm.
77
6c38ca59927f *** empty log message ***
claus
parents: 69
diff changeset
  2623
    "
602
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  2624
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  2625
    |smallestIndex "{ Class: SmallInteger }"
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  2626
     end           "{ Class: SmallInteger }"
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  2627
     smallest thisOne|
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  2628
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  2629
    "this is just a q&d hack - there must be better implementations for this ;-)"
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  2630
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  2631
    end := self size.
862
007dccfb6cb0 fix topologicalSort:
Stefan Vogel <sv@exept.de>
parents: 628
diff changeset
  2632
    1 to:end-1 do:[:index |
929
674de4c05dcb added findFirst:startingAt: and findLast:startingAt:
Claus Gittinger <cg@exept.de>
parents: 911
diff changeset
  2633
	|index2|
674de4c05dcb added findFirst:startingAt: and findLast:startingAt:
Claus Gittinger <cg@exept.de>
parents: 911
diff changeset
  2634
674de4c05dcb added findFirst:startingAt: and findLast:startingAt:
Claus Gittinger <cg@exept.de>
parents: 911
diff changeset
  2635
	smallest := self at:index.
674de4c05dcb added findFirst:startingAt: and findLast:startingAt:
Claus Gittinger <cg@exept.de>
parents: 911
diff changeset
  2636
	smallestIndex := index.
674de4c05dcb added findFirst:startingAt: and findLast:startingAt:
Claus Gittinger <cg@exept.de>
parents: 911
diff changeset
  2637
674de4c05dcb added findFirst:startingAt: and findLast:startingAt:
Claus Gittinger <cg@exept.de>
parents: 911
diff changeset
  2638
	index2 := index + 1.
674de4c05dcb added findFirst:startingAt: and findLast:startingAt:
Claus Gittinger <cg@exept.de>
parents: 911
diff changeset
  2639
	[
674de4c05dcb added findFirst:startingAt: and findLast:startingAt:
Claus Gittinger <cg@exept.de>
parents: 911
diff changeset
  2640
	    thisOne := self at:index2.
674de4c05dcb added findFirst:startingAt: and findLast:startingAt:
Claus Gittinger <cg@exept.de>
parents: 911
diff changeset
  2641
	    (index2 ~~ smallestIndex and:[(sortBlock value:thisOne value:smallest)]) ifTrue:[
674de4c05dcb added findFirst:startingAt: and findLast:startingAt:
Claus Gittinger <cg@exept.de>
parents: 911
diff changeset
  2642
		smallestIndex := index2.
674de4c05dcb added findFirst:startingAt: and findLast:startingAt:
Claus Gittinger <cg@exept.de>
parents: 911
diff changeset
  2643
		smallest := thisOne.
674de4c05dcb added findFirst:startingAt: and findLast:startingAt:
Claus Gittinger <cg@exept.de>
parents: 911
diff changeset
  2644
		index2 := index + 1.
674de4c05dcb added findFirst:startingAt: and findLast:startingAt:
Claus Gittinger <cg@exept.de>
parents: 911
diff changeset
  2645
	    ] ifFalse:[
674de4c05dcb added findFirst:startingAt: and findLast:startingAt:
Claus Gittinger <cg@exept.de>
parents: 911
diff changeset
  2646
		index2 := index2 + 1..
674de4c05dcb added findFirst:startingAt: and findLast:startingAt:
Claus Gittinger <cg@exept.de>
parents: 911
diff changeset
  2647
	    ].
674de4c05dcb added findFirst:startingAt: and findLast:startingAt:
Claus Gittinger <cg@exept.de>
parents: 911
diff changeset
  2648
	] doWhile:[index2 <= end].
862
007dccfb6cb0 fix topologicalSort:
Stefan Vogel <sv@exept.de>
parents: 628
diff changeset
  2649
007dccfb6cb0 fix topologicalSort:
Stefan Vogel <sv@exept.de>
parents: 628
diff changeset
  2650
"/        (index + 1) to:end do:[:index2 |
007dccfb6cb0 fix topologicalSort:
Stefan Vogel <sv@exept.de>
parents: 628
diff changeset
  2651
"/            thisOne := self at:index2.
007dccfb6cb0 fix topologicalSort:
Stefan Vogel <sv@exept.de>
parents: 628
diff changeset
  2652
"/            (sortBlock value:thisOne value:smallest) ifTrue:[
007dccfb6cb0 fix topologicalSort:
Stefan Vogel <sv@exept.de>
parents: 628
diff changeset
  2653
"/                smallestIndex := index2.
007dccfb6cb0 fix topologicalSort:
Stefan Vogel <sv@exept.de>
parents: 628
diff changeset
  2654
"/                smallest := thisOne
007dccfb6cb0 fix topologicalSort:
Stefan Vogel <sv@exept.de>
parents: 628
diff changeset
  2655
"/            ].
007dccfb6cb0 fix topologicalSort:
Stefan Vogel <sv@exept.de>
parents: 628
diff changeset
  2656
"/        ].
929
674de4c05dcb added findFirst:startingAt: and findLast:startingAt:
Claus Gittinger <cg@exept.de>
parents: 911
diff changeset
  2657
	(smallestIndex ~~ index) ifTrue:[
674de4c05dcb added findFirst:startingAt: and findLast:startingAt:
Claus Gittinger <cg@exept.de>
parents: 911
diff changeset
  2658
	    thisOne := self at:index.
674de4c05dcb added findFirst:startingAt: and findLast:startingAt:
Claus Gittinger <cg@exept.de>
parents: 911
diff changeset
  2659
	    self at:index put:smallest.
674de4c05dcb added findFirst:startingAt: and findLast:startingAt:
Claus Gittinger <cg@exept.de>
parents: 911
diff changeset
  2660
	    self at:smallestIndex put:thisOne
674de4c05dcb added findFirst:startingAt: and findLast:startingAt:
Claus Gittinger <cg@exept.de>
parents: 911
diff changeset
  2661
	].
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  2662
    ]
95
d22739a0c6e9 *** empty log message ***
claus
parents: 88
diff changeset
  2663
77
6c38ca59927f *** empty log message ***
claus
parents: 69
diff changeset
  2664
    "
602
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  2665
     #(1 16 7 98 3 19 4 0) topologicalSort:[:a :b | a < b]   
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  2666
     #(1 16 7 98 3 19 4 0) sort:[:a :b | a < b]              
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  2667
     Smalltalk allClasses asArray topologicalSort:[:a :b | b isSubclassOf:a] 
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  2668
     Smalltalk allClasses asArray sort:[:a :b | b isSubclassOf:a] 
77
6c38ca59927f *** empty log message ***
claus
parents: 69
diff changeset
  2669
    "
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  2670
! !
602
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  2671
628
7aa563e4c64a version at the end
Claus Gittinger <cg@exept.de>
parents: 602
diff changeset
  2672
!SequenceableCollection class methodsFor:'documentation'!
7aa563e4c64a version at the end
Claus Gittinger <cg@exept.de>
parents: 602
diff changeset
  2673
7aa563e4c64a version at the end
Claus Gittinger <cg@exept.de>
parents: 602
diff changeset
  2674
version
1370
b051117cc302 moved #upTo: down into SeqColl
Claus Gittinger <cg@exept.de>
parents: 1369
diff changeset
  2675
    ^ '$Header: /cvs/stx/stx/libbasic/SequenceableCollection.st,v 1.60 1996-05-11 09:16:03 cg Exp $'
628
7aa563e4c64a version at the end
Claus Gittinger <cg@exept.de>
parents: 602
diff changeset
  2676
! !