SequenceableCollection.st
author Claus Gittinger <cg@exept.de>
Sat, 17 Jul 1999 12:21:54 +0200
changeset 4403 eb4379909671
parent 4402 7c19502120b7
child 4414 dcf1a565095b
permissions -rw-r--r--
comment
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:''
4197
8ae90a572914 raise a special signal, when a literalencodings class
Claus Gittinger <cg@exept.de>
parents: 4154
diff changeset
    15
	classVariableNames:'MissingClassInLiteralArrayErrorSignal'
911
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
2069
f6183117f922 comments
Claus Gittinger <cg@exept.de>
parents: 1673
diff changeset
    20
!SequenceableCollection class methodsFor:'documentation'!
88
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 
1385
Claus Gittinger <cg@exept.de>
parents: 1370
diff changeset
    41
    it in the system. 
Claus Gittinger <cg@exept.de>
parents: 1370
diff changeset
    42
Claus Gittinger <cg@exept.de>
parents: 1370
diff changeset
    43
    The methods found here assume that implementations of (at least)
Claus Gittinger <cg@exept.de>
parents: 1370
diff changeset
    44
    #at:/#at:put: are implemented (which are always found in Object for
Claus Gittinger <cg@exept.de>
parents: 1370
diff changeset
    45
    indexable objects).
Claus Gittinger <cg@exept.de>
parents: 1370
diff changeset
    46
Claus Gittinger <cg@exept.de>
parents: 1370
diff changeset
    47
    For performance, some subclasses redefine more methods, knowing the details
Claus Gittinger <cg@exept.de>
parents: 1370
diff changeset
    48
    of how elements are stored. 
Claus Gittinger <cg@exept.de>
parents: 1370
diff changeset
    49
    Especially, bulk data manipulation (i.e. #replaceFrom:to:with:startingAt:) 
Claus Gittinger <cg@exept.de>
parents: 1370
diff changeset
    50
    and search methods (i.e. #indexOf:startingAt:) are good candidates for this
Claus Gittinger <cg@exept.de>
parents: 1370
diff changeset
    51
    kind of tuneup.
Claus Gittinger <cg@exept.de>
parents: 1370
diff changeset
    52
Claus Gittinger <cg@exept.de>
parents: 1370
diff changeset
    53
    See concrete subclasses (such as OrderedCollection, Array or String).
1289
3abde2c376de checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1245
diff changeset
    54
3abde2c376de checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1245
diff changeset
    55
    [author:]
3abde2c376de checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1245
diff changeset
    56
        Claus Gittinger
1385
Claus Gittinger <cg@exept.de>
parents: 1370
diff changeset
    57
Claus Gittinger <cg@exept.de>
parents: 1370
diff changeset
    58
    [see also:]
Claus Gittinger <cg@exept.de>
parents: 1370
diff changeset
    59
        OrderedCollection Array
Claus Gittinger <cg@exept.de>
parents: 1370
diff changeset
    60
        CharacterArray String
88
81dacba7a63a *** empty log message ***
claus
parents: 77
diff changeset
    61
"
81dacba7a63a *** empty log message ***
claus
parents: 77
diff changeset
    62
! !
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
    63
4197
8ae90a572914 raise a special signal, when a literalencodings class
Claus Gittinger <cg@exept.de>
parents: 4154
diff changeset
    64
!SequenceableCollection class methodsFor:'initialization'!
8ae90a572914 raise a special signal, when a literalencodings class
Claus Gittinger <cg@exept.de>
parents: 4154
diff changeset
    65
8ae90a572914 raise a special signal, when a literalencodings class
Claus Gittinger <cg@exept.de>
parents: 4154
diff changeset
    66
initialize
8ae90a572914 raise a special signal, when a literalencodings class
Claus Gittinger <cg@exept.de>
parents: 4154
diff changeset
    67
    MissingClassInLiteralArrayErrorSignal isNil ifTrue:[
8ae90a572914 raise a special signal, when a literalencodings class
Claus Gittinger <cg@exept.de>
parents: 4154
diff changeset
    68
        MissingClassInLiteralArrayErrorSignal := ErrorSignal newSignalMayProceed:true.
8ae90a572914 raise a special signal, when a literalencodings class
Claus Gittinger <cg@exept.de>
parents: 4154
diff changeset
    69
        MissingClassInLiteralArrayErrorSignal nameClass:self message:#missingClassInLiteralArrayErrorSignal.
8ae90a572914 raise a special signal, when a literalencodings class
Claus Gittinger <cg@exept.de>
parents: 4154
diff changeset
    70
        MissingClassInLiteralArrayErrorSignal notifierString:'Missing class in literal encoding'.
8ae90a572914 raise a special signal, when a literalencodings class
Claus Gittinger <cg@exept.de>
parents: 4154
diff changeset
    71
    ]
8ae90a572914 raise a special signal, when a literalencodings class
Claus Gittinger <cg@exept.de>
parents: 4154
diff changeset
    72
8ae90a572914 raise a special signal, when a literalencodings class
Claus Gittinger <cg@exept.de>
parents: 4154
diff changeset
    73
    "Created: / 18.5.1999 / 14:49:51 / cg"
8ae90a572914 raise a special signal, when a literalencodings class
Claus Gittinger <cg@exept.de>
parents: 4154
diff changeset
    74
! !
8ae90a572914 raise a special signal, when a literalencodings class
Claus Gittinger <cg@exept.de>
parents: 4154
diff changeset
    75
2069
f6183117f922 comments
Claus Gittinger <cg@exept.de>
parents: 1673
diff changeset
    76
!SequenceableCollection class methodsFor:'instance creation'!
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
    77
a27a279701f8 Initial revision
claus
parents:
diff changeset
    78
new:size withAll:element
360
claus
parents: 359
diff changeset
    79
    "return a new collection of size, where all elements are
claus
parents: 359
diff changeset
    80
     initialized to element."
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
    81
a27a279701f8 Initial revision
claus
parents:
diff changeset
    82
    |newCollection|
a27a279701f8 Initial revision
claus
parents:
diff changeset
    83
a27a279701f8 Initial revision
claus
parents:
diff changeset
    84
    newCollection := self new:size.
a27a279701f8 Initial revision
claus
parents:
diff changeset
    85
    newCollection atAllPut:element.
a27a279701f8 Initial revision
claus
parents:
diff changeset
    86
    ^ newCollection
360
claus
parents: 359
diff changeset
    87
!
claus
parents: 359
diff changeset
    88
4303
4a2e5a5cb83d added #newWithConcatenationOfAll: for tune concatenation of
Claus Gittinger <cg@exept.de>
parents: 4197
diff changeset
    89
newWithConcatenationOfAll:aCollectionOfCollections
4a2e5a5cb83d added #newWithConcatenationOfAll: for tune concatenation of
Claus Gittinger <cg@exept.de>
parents: 4197
diff changeset
    90
    "this creates and returns a new collection consisting
4a2e5a5cb83d added #newWithConcatenationOfAll: for tune concatenation of
Claus Gittinger <cg@exept.de>
parents: 4197
diff changeset
    91
     of the concatenation of all elements of the argument.
4a2e5a5cb83d added #newWithConcatenationOfAll: for tune concatenation of
Claus Gittinger <cg@exept.de>
parents: 4197
diff changeset
    92
     I.e. it has the same effect as concatenating all elements
4a2e5a5cb83d added #newWithConcatenationOfAll: for tune concatenation of
Claus Gittinger <cg@exept.de>
parents: 4197
diff changeset
    93
     of the argument using #, ,but is implemented more efficiently,
4a2e5a5cb83d added #newWithConcatenationOfAll: for tune concatenation of
Claus Gittinger <cg@exept.de>
parents: 4197
diff changeset
    94
     by avoiding repeated garbage allocations.
4a2e5a5cb83d added #newWithConcatenationOfAll: for tune concatenation of
Claus Gittinger <cg@exept.de>
parents: 4197
diff changeset
    95
     This is an O runtime algorithm, in contrast to the #, loop, which is O*O"
4a2e5a5cb83d added #newWithConcatenationOfAll: for tune concatenation of
Claus Gittinger <cg@exept.de>
parents: 4197
diff changeset
    96
4a2e5a5cb83d added #newWithConcatenationOfAll: for tune concatenation of
Claus Gittinger <cg@exept.de>
parents: 4197
diff changeset
    97
    |totalSize newColl idx|
4a2e5a5cb83d added #newWithConcatenationOfAll: for tune concatenation of
Claus Gittinger <cg@exept.de>
parents: 4197
diff changeset
    98
4a2e5a5cb83d added #newWithConcatenationOfAll: for tune concatenation of
Claus Gittinger <cg@exept.de>
parents: 4197
diff changeset
    99
    totalSize := aCollectionOfCollections 
4a2e5a5cb83d added #newWithConcatenationOfAll: for tune concatenation of
Claus Gittinger <cg@exept.de>
parents: 4197
diff changeset
   100
                        inject:0
4a2e5a5cb83d added #newWithConcatenationOfAll: for tune concatenation of
Claus Gittinger <cg@exept.de>
parents: 4197
diff changeset
   101
                        into:[:sumSoFar :el | sumSoFar + el size].
4a2e5a5cb83d added #newWithConcatenationOfAll: for tune concatenation of
Claus Gittinger <cg@exept.de>
parents: 4197
diff changeset
   102
    newColl := self new:totalSize.
4a2e5a5cb83d added #newWithConcatenationOfAll: for tune concatenation of
Claus Gittinger <cg@exept.de>
parents: 4197
diff changeset
   103
    idx := 1.
4a2e5a5cb83d added #newWithConcatenationOfAll: for tune concatenation of
Claus Gittinger <cg@exept.de>
parents: 4197
diff changeset
   104
    aCollectionOfCollections do:[:el |
4a2e5a5cb83d added #newWithConcatenationOfAll: for tune concatenation of
Claus Gittinger <cg@exept.de>
parents: 4197
diff changeset
   105
        |sz|
4a2e5a5cb83d added #newWithConcatenationOfAll: for tune concatenation of
Claus Gittinger <cg@exept.de>
parents: 4197
diff changeset
   106
4a2e5a5cb83d added #newWithConcatenationOfAll: for tune concatenation of
Claus Gittinger <cg@exept.de>
parents: 4197
diff changeset
   107
        sz := el size.
4a2e5a5cb83d added #newWithConcatenationOfAll: for tune concatenation of
Claus Gittinger <cg@exept.de>
parents: 4197
diff changeset
   108
        newColl replaceFrom:idx to:(idx+sz-1) with:el startingAt:1.
4a2e5a5cb83d added #newWithConcatenationOfAll: for tune concatenation of
Claus Gittinger <cg@exept.de>
parents: 4197
diff changeset
   109
        idx := idx + sz
4a2e5a5cb83d added #newWithConcatenationOfAll: for tune concatenation of
Claus Gittinger <cg@exept.de>
parents: 4197
diff changeset
   110
    ].
4a2e5a5cb83d added #newWithConcatenationOfAll: for tune concatenation of
Claus Gittinger <cg@exept.de>
parents: 4197
diff changeset
   111
    ^ newColl
4a2e5a5cb83d added #newWithConcatenationOfAll: for tune concatenation of
Claus Gittinger <cg@exept.de>
parents: 4197
diff changeset
   112
4a2e5a5cb83d added #newWithConcatenationOfAll: for tune concatenation of
Claus Gittinger <cg@exept.de>
parents: 4197
diff changeset
   113
    "
4a2e5a5cb83d added #newWithConcatenationOfAll: for tune concatenation of
Claus Gittinger <cg@exept.de>
parents: 4197
diff changeset
   114
     this method optimizes the following (common) operation:
4a2e5a5cb83d added #newWithConcatenationOfAll: for tune concatenation of
Claus Gittinger <cg@exept.de>
parents: 4197
diff changeset
   115
4a2e5a5cb83d added #newWithConcatenationOfAll: for tune concatenation of
Claus Gittinger <cg@exept.de>
parents: 4197
diff changeset
   116
         |s|
4a2e5a5cb83d added #newWithConcatenationOfAll: for tune concatenation of
Claus Gittinger <cg@exept.de>
parents: 4197
diff changeset
   117
4a2e5a5cb83d added #newWithConcatenationOfAll: for tune concatenation of
Claus Gittinger <cg@exept.de>
parents: 4197
diff changeset
   118
         s := ''.
4a2e5a5cb83d added #newWithConcatenationOfAll: for tune concatenation of
Claus Gittinger <cg@exept.de>
parents: 4197
diff changeset
   119
         #('hello' ' ' 'world' ' ' 'this is ' 'ST/X') do:[:e|
4a2e5a5cb83d added #newWithConcatenationOfAll: for tune concatenation of
Claus Gittinger <cg@exept.de>
parents: 4197
diff changeset
   120
            s := s , e.
4a2e5a5cb83d added #newWithConcatenationOfAll: for tune concatenation of
Claus Gittinger <cg@exept.de>
parents: 4197
diff changeset
   121
         ]. 
4a2e5a5cb83d added #newWithConcatenationOfAll: for tune concatenation of
Claus Gittinger <cg@exept.de>
parents: 4197
diff changeset
   122
         s  
4a2e5a5cb83d added #newWithConcatenationOfAll: for tune concatenation of
Claus Gittinger <cg@exept.de>
parents: 4197
diff changeset
   123
4a2e5a5cb83d added #newWithConcatenationOfAll: for tune concatenation of
Claus Gittinger <cg@exept.de>
parents: 4197
diff changeset
   124
     String 
4a2e5a5cb83d added #newWithConcatenationOfAll: for tune concatenation of
Claus Gittinger <cg@exept.de>
parents: 4197
diff changeset
   125
        newWithConcatenationOfAll:#('hello' ' ' 'world' ' ' 'this is ' 'ST/X')
4a2e5a5cb83d added #newWithConcatenationOfAll: for tune concatenation of
Claus Gittinger <cg@exept.de>
parents: 4197
diff changeset
   126
4a2e5a5cb83d added #newWithConcatenationOfAll: for tune concatenation of
Claus Gittinger <cg@exept.de>
parents: 4197
diff changeset
   127
     String 
4a2e5a5cb83d added #newWithConcatenationOfAll: for tune concatenation of
Claus Gittinger <cg@exept.de>
parents: 4197
diff changeset
   128
        newWithConcatenationOfAll:#()   
4a2e5a5cb83d added #newWithConcatenationOfAll: for tune concatenation of
Claus Gittinger <cg@exept.de>
parents: 4197
diff changeset
   129
4a2e5a5cb83d added #newWithConcatenationOfAll: for tune concatenation of
Claus Gittinger <cg@exept.de>
parents: 4197
diff changeset
   130
     Array
4a2e5a5cb83d added #newWithConcatenationOfAll: for tune concatenation of
Claus Gittinger <cg@exept.de>
parents: 4197
diff changeset
   131
        newWithConcatenationOfAll:#( (1 2 3 4) (5 6 7 8) (9 10 11 12) )   
4a2e5a5cb83d added #newWithConcatenationOfAll: for tune concatenation of
Claus Gittinger <cg@exept.de>
parents: 4197
diff changeset
   132
4a2e5a5cb83d added #newWithConcatenationOfAll: for tune concatenation of
Claus Gittinger <cg@exept.de>
parents: 4197
diff changeset
   133
     timing:
4a2e5a5cb83d added #newWithConcatenationOfAll: for tune concatenation of
Claus Gittinger <cg@exept.de>
parents: 4197
diff changeset
   134
     -------
4a2e5a5cb83d added #newWithConcatenationOfAll: for tune concatenation of
Claus Gittinger <cg@exept.de>
parents: 4197
diff changeset
   135
     speed-break-even is at around 5 elements for strings;
4a2e5a5cb83d added #newWithConcatenationOfAll: for tune concatenation of
Claus Gittinger <cg@exept.de>
parents: 4197
diff changeset
   136
     for more elements, #newWithConcatenationOfAll: is much faster.
4a2e5a5cb83d added #newWithConcatenationOfAll: for tune concatenation of
Claus Gittinger <cg@exept.de>
parents: 4197
diff changeset
   137
4a2e5a5cb83d added #newWithConcatenationOfAll: for tune concatenation of
Claus Gittinger <cg@exept.de>
parents: 4197
diff changeset
   138
     |arr1 arr2 arr3 t|
4a2e5a5cb83d added #newWithConcatenationOfAll: for tune concatenation of
Claus Gittinger <cg@exept.de>
parents: 4197
diff changeset
   139
4a2e5a5cb83d added #newWithConcatenationOfAll: for tune concatenation of
Claus Gittinger <cg@exept.de>
parents: 4197
diff changeset
   140
     arr1 := #('hello' ' ' 'world' ' ' 'this is ' 'ST/X').
4a2e5a5cb83d added #newWithConcatenationOfAll: for tune concatenation of
Claus Gittinger <cg@exept.de>
parents: 4197
diff changeset
   141
     arr2 := Array new:1000 withAll:'hello'.
4a2e5a5cb83d added #newWithConcatenationOfAll: for tune concatenation of
Claus Gittinger <cg@exept.de>
parents: 4197
diff changeset
   142
     arr3 := Array new:10000 withAll:'hello'.
4a2e5a5cb83d added #newWithConcatenationOfAll: for tune concatenation of
Claus Gittinger <cg@exept.de>
parents: 4197
diff changeset
   143
4a2e5a5cb83d added #newWithConcatenationOfAll: for tune concatenation of
Claus Gittinger <cg@exept.de>
parents: 4197
diff changeset
   144
     (Array with:arr1 with:arr2 with:arr3) with:#(10000 100 10) do:[:arr :cnt |
4a2e5a5cb83d added #newWithConcatenationOfAll: for tune concatenation of
Claus Gittinger <cg@exept.de>
parents: 4197
diff changeset
   145
         t := Time millisecondsToRun:[
4a2e5a5cb83d added #newWithConcatenationOfAll: for tune concatenation of
Claus Gittinger <cg@exept.de>
parents: 4197
diff changeset
   146
            cnt timesRepeat:[
4a2e5a5cb83d added #newWithConcatenationOfAll: for tune concatenation of
Claus Gittinger <cg@exept.de>
parents: 4197
diff changeset
   147
                String 
4a2e5a5cb83d added #newWithConcatenationOfAll: for tune concatenation of
Claus Gittinger <cg@exept.de>
parents: 4197
diff changeset
   148
                    newWithConcatenationOfAll:arr
4a2e5a5cb83d added #newWithConcatenationOfAll: for tune concatenation of
Claus Gittinger <cg@exept.de>
parents: 4197
diff changeset
   149
            ]
4a2e5a5cb83d added #newWithConcatenationOfAll: for tune concatenation of
Claus Gittinger <cg@exept.de>
parents: 4197
diff changeset
   150
         ].
4a2e5a5cb83d added #newWithConcatenationOfAll: for tune concatenation of
Claus Gittinger <cg@exept.de>
parents: 4197
diff changeset
   151
         Transcript showCR:(arr size printString , ' elements - time for #newWithConcatenationOfAll :' , (t/cnt) asFloat printString , 'mS').
4a2e5a5cb83d added #newWithConcatenationOfAll: for tune concatenation of
Claus Gittinger <cg@exept.de>
parents: 4197
diff changeset
   152
         Transcript endEntry.
4a2e5a5cb83d added #newWithConcatenationOfAll: for tune concatenation of
Claus Gittinger <cg@exept.de>
parents: 4197
diff changeset
   153
4a2e5a5cb83d added #newWithConcatenationOfAll: for tune concatenation of
Claus Gittinger <cg@exept.de>
parents: 4197
diff changeset
   154
         t := Time millisecondsToRun:[
4a2e5a5cb83d added #newWithConcatenationOfAll: for tune concatenation of
Claus Gittinger <cg@exept.de>
parents: 4197
diff changeset
   155
            cnt timesRepeat:[
4a2e5a5cb83d added #newWithConcatenationOfAll: for tune concatenation of
Claus Gittinger <cg@exept.de>
parents: 4197
diff changeset
   156
                 |s|
4a2e5a5cb83d added #newWithConcatenationOfAll: for tune concatenation of
Claus Gittinger <cg@exept.de>
parents: 4197
diff changeset
   157
4a2e5a5cb83d added #newWithConcatenationOfAll: for tune concatenation of
Claus Gittinger <cg@exept.de>
parents: 4197
diff changeset
   158
                 s := ''.
4a2e5a5cb83d added #newWithConcatenationOfAll: for tune concatenation of
Claus Gittinger <cg@exept.de>
parents: 4197
diff changeset
   159
                 arr do:[:e|
4a2e5a5cb83d added #newWithConcatenationOfAll: for tune concatenation of
Claus Gittinger <cg@exept.de>
parents: 4197
diff changeset
   160
                    s := s , e.
4a2e5a5cb83d added #newWithConcatenationOfAll: for tune concatenation of
Claus Gittinger <cg@exept.de>
parents: 4197
diff changeset
   161
                 ]. 
4a2e5a5cb83d added #newWithConcatenationOfAll: for tune concatenation of
Claus Gittinger <cg@exept.de>
parents: 4197
diff changeset
   162
                 s  
4a2e5a5cb83d added #newWithConcatenationOfAll: for tune concatenation of
Claus Gittinger <cg@exept.de>
parents: 4197
diff changeset
   163
            ]
4a2e5a5cb83d added #newWithConcatenationOfAll: for tune concatenation of
Claus Gittinger <cg@exept.de>
parents: 4197
diff changeset
   164
         ].  
4a2e5a5cb83d added #newWithConcatenationOfAll: for tune concatenation of
Claus Gittinger <cg@exept.de>
parents: 4197
diff changeset
   165
         Transcript showCR:(arr size printString , ' elements - time for loop over #, :' , (t/cnt) asFloat printString , 'mS').
4a2e5a5cb83d added #newWithConcatenationOfAll: for tune concatenation of
Claus Gittinger <cg@exept.de>
parents: 4197
diff changeset
   166
         Transcript endEntry.
4a2e5a5cb83d added #newWithConcatenationOfAll: for tune concatenation of
Claus Gittinger <cg@exept.de>
parents: 4197
diff changeset
   167
     ]
4a2e5a5cb83d added #newWithConcatenationOfAll: for tune concatenation of
Claus Gittinger <cg@exept.de>
parents: 4197
diff changeset
   168
    "
4a2e5a5cb83d added #newWithConcatenationOfAll: for tune concatenation of
Claus Gittinger <cg@exept.de>
parents: 4197
diff changeset
   169
!
4a2e5a5cb83d added #newWithConcatenationOfAll: for tune concatenation of
Claus Gittinger <cg@exept.de>
parents: 4197
diff changeset
   170
360
claus
parents: 359
diff changeset
   171
withSize:size
claus
parents: 359
diff changeset
   172
    "return a new collection of size.
claus
parents: 359
diff changeset
   173
     For variable size collections, this is different from #new:,
claus
parents: 359
diff changeset
   174
     in that #new: creates an empty collection with preallocated size,
claus
parents: 359
diff changeset
   175
     while #withSize: creates a non empty one."
claus
parents: 359
diff changeset
   176
claus
parents: 359
diff changeset
   177
    |newCollection|
claus
parents: 359
diff changeset
   178
claus
parents: 359
diff changeset
   179
    newCollection := self new:size.
claus
parents: 359
diff changeset
   180
    newCollection grow:size.
claus
parents: 359
diff changeset
   181
    ^ newCollection
claus
parents: 359
diff changeset
   182
claus
parents: 359
diff changeset
   183
    "
claus
parents: 359
diff changeset
   184
     (OrderedCollection new:10) inspect.
claus
parents: 359
diff changeset
   185
     (OrderedCollection withSize:10) inspect.
claus
parents: 359
diff changeset
   186
     (Array new:10) inspect.
claus
parents: 359
diff changeset
   187
     (Array withSize:10) inspect.
claus
parents: 359
diff changeset
   188
    "
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   189
! !
a27a279701f8 Initial revision
claus
parents:
diff changeset
   190
4197
8ae90a572914 raise a special signal, when a literalencodings class
Claus Gittinger <cg@exept.de>
parents: 4154
diff changeset
   191
!SequenceableCollection class methodsFor:'Signal constants'!
8ae90a572914 raise a special signal, when a literalencodings class
Claus Gittinger <cg@exept.de>
parents: 4154
diff changeset
   192
8ae90a572914 raise a special signal, when a literalencodings class
Claus Gittinger <cg@exept.de>
parents: 4154
diff changeset
   193
missingClassInLiteralArrayErrorSignal
8ae90a572914 raise a special signal, when a literalencodings class
Claus Gittinger <cg@exept.de>
parents: 4154
diff changeset
   194
    ^ MissingClassInLiteralArrayErrorSignal
8ae90a572914 raise a special signal, when a literalencodings class
Claus Gittinger <cg@exept.de>
parents: 4154
diff changeset
   195
8ae90a572914 raise a special signal, when a literalencodings class
Claus Gittinger <cg@exept.de>
parents: 4154
diff changeset
   196
    "Created: / 18.5.1999 / 14:50:04 / cg"
8ae90a572914 raise a special signal, when a literalencodings class
Claus Gittinger <cg@exept.de>
parents: 4154
diff changeset
   197
! !
8ae90a572914 raise a special signal, when a literalencodings class
Claus Gittinger <cg@exept.de>
parents: 4154
diff changeset
   198
4370
a1e3b976c7be checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4338
diff changeset
   199
!SequenceableCollection class methodsFor:'Squeak compatibility'!
a1e3b976c7be checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4338
diff changeset
   200
a1e3b976c7be checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4338
diff changeset
   201
streamContents:blockWithArg
a1e3b976c7be checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4338
diff changeset
   202
    |stream|
a1e3b976c7be checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4338
diff changeset
   203
a1e3b976c7be checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4338
diff changeset
   204
    stream := WriteStream on:(self new:100).
a1e3b976c7be checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4338
diff changeset
   205
    blockWithArg value:stream.
a1e3b976c7be checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4338
diff changeset
   206
    ^ stream contents
a1e3b976c7be checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4338
diff changeset
   207
a1e3b976c7be checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4338
diff changeset
   208
! !
a1e3b976c7be checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4338
diff changeset
   209
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   210
!SequenceableCollection methodsFor:'accessing'!
a27a279701f8 Initial revision
claus
parents:
diff changeset
   211
1366
531162d17aaa lifted #after: / #before:
Claus Gittinger <cg@exept.de>
parents: 1359
diff changeset
   212
after:anObject
531162d17aaa lifted #after: / #before:
Claus Gittinger <cg@exept.de>
parents: 1359
diff changeset
   213
    "return the element, after anObject.
531162d17aaa lifted #after: / #before:
Claus Gittinger <cg@exept.de>
parents: 1359
diff changeset
   214
     If anObject is not in the receiver, report an error.
531162d17aaa lifted #after: / #before:
Claus Gittinger <cg@exept.de>
parents: 1359
diff changeset
   215
     This depends on #after:ifAbsent: being implemented in a concrete class."
531162d17aaa lifted #after: / #before:
Claus Gittinger <cg@exept.de>
parents: 1359
diff changeset
   216
531162d17aaa lifted #after: / #before:
Claus Gittinger <cg@exept.de>
parents: 1359
diff changeset
   217
    ^ self after:anObject ifAbsent:[self errorValueNotFound:anObject]
531162d17aaa lifted #after: / #before:
Claus Gittinger <cg@exept.de>
parents: 1359
diff changeset
   218
531162d17aaa lifted #after: / #before:
Claus Gittinger <cg@exept.de>
parents: 1359
diff changeset
   219
    "
531162d17aaa lifted #after: / #before:
Claus Gittinger <cg@exept.de>
parents: 1359
diff changeset
   220
     #(4 3 2 1) asOrderedCollection after:3. 
531162d17aaa lifted #after: / #before:
Claus Gittinger <cg@exept.de>
parents: 1359
diff changeset
   221
     #(4 3 2 1) asOrderedCollection after:5 
531162d17aaa lifted #after: / #before:
Claus Gittinger <cg@exept.de>
parents: 1359
diff changeset
   222
     #(4 3 2 1) asOrderedCollection after:1 
531162d17aaa lifted #after: / #before:
Claus Gittinger <cg@exept.de>
parents: 1359
diff changeset
   223
    "
531162d17aaa lifted #after: / #before:
Claus Gittinger <cg@exept.de>
parents: 1359
diff changeset
   224
531162d17aaa lifted #after: / #before:
Claus Gittinger <cg@exept.de>
parents: 1359
diff changeset
   225
    "Created: 10.5.1996 / 13:59:29 / cg"
531162d17aaa lifted #after: / #before:
Claus Gittinger <cg@exept.de>
parents: 1359
diff changeset
   226
    "Modified: 10.5.1996 / 14:03:33 / cg"
531162d17aaa lifted #after: / #before:
Claus Gittinger <cg@exept.de>
parents: 1359
diff changeset
   227
!
531162d17aaa lifted #after: / #before:
Claus Gittinger <cg@exept.de>
parents: 1359
diff changeset
   228
531162d17aaa lifted #after: / #before:
Claus Gittinger <cg@exept.de>
parents: 1359
diff changeset
   229
after:anObject ifAbsent:exceptionBlock
531162d17aaa lifted #after: / #before:
Claus Gittinger <cg@exept.de>
parents: 1359
diff changeset
   230
    "return the element, after anObject. If there is no such element,
531162d17aaa lifted #after: / #before:
Claus Gittinger <cg@exept.de>
parents: 1359
diff changeset
   231
     return the value from exceptionBlock."
531162d17aaa lifted #after: / #before:
Claus Gittinger <cg@exept.de>
parents: 1359
diff changeset
   232
531162d17aaa lifted #after: / #before:
Claus Gittinger <cg@exept.de>
parents: 1359
diff changeset
   233
    ^ self subclassResponsibility
531162d17aaa lifted #after: / #before:
Claus Gittinger <cg@exept.de>
parents: 1359
diff changeset
   234
531162d17aaa lifted #after: / #before:
Claus Gittinger <cg@exept.de>
parents: 1359
diff changeset
   235
    "Created: 10.5.1996 / 14:00:10 / cg"
531162d17aaa lifted #after: / #before:
Claus Gittinger <cg@exept.de>
parents: 1359
diff changeset
   236
!
531162d17aaa lifted #after: / #before:
Claus Gittinger <cg@exept.de>
parents: 1359
diff changeset
   237
32
ee1a621c696c *** empty log message ***
claus
parents: 13
diff changeset
   238
at:index ifAbsent:exceptionBlock
61
claus
parents: 44
diff changeset
   239
    "return the element at index if valid. 
claus
parents: 44
diff changeset
   240
     If the index is invalid, return the result of evaluating 
302
1f76060d58a4 *** empty log message ***
claus
parents: 293
diff changeset
   241
     the exceptionblock.
1f76060d58a4 *** empty log message ***
claus
parents: 293
diff changeset
   242
     NOTICE: 
1f76060d58a4 *** empty log message ***
claus
parents: 293
diff changeset
   243
	in ST-80, this message is only defined for Dictionaries,
1f76060d58a4 *** empty log message ***
claus
parents: 293
diff changeset
   244
	however, having a common protocol with indexed collections
1f76060d58a4 *** empty log message ***
claus
parents: 293
diff changeset
   245
	often simplifies things."
32
ee1a621c696c *** empty log message ***
claus
parents: 13
diff changeset
   246
ee1a621c696c *** empty log message ***
claus
parents: 13
diff changeset
   247
    ((index < 1) or:[index > self size]) ifTrue:[
159
514c749165c3 *** empty log message ***
claus
parents: 118
diff changeset
   248
	^ exceptionBlock value
32
ee1a621c696c *** empty log message ***
claus
parents: 13
diff changeset
   249
    ].
ee1a621c696c *** empty log message ***
claus
parents: 13
diff changeset
   250
    ^ self at:index
ee1a621c696c *** empty log message ***
claus
parents: 13
diff changeset
   251
95
d22739a0c6e9 *** empty log message ***
claus
parents: 88
diff changeset
   252
    "
d22739a0c6e9 *** empty log message ***
claus
parents: 88
diff changeset
   253
     #(1 2 3) at:4 ifAbsent:['no such index']
302
1f76060d58a4 *** empty log message ***
claus
parents: 293
diff changeset
   254
     #(1 2 3) asOrderedCollection at:4 ifAbsent:['no such index'] 
1f76060d58a4 *** empty log message ***
claus
parents: 293
diff changeset
   255
95
d22739a0c6e9 *** empty log message ***
claus
parents: 88
diff changeset
   256
     (Dictionary with:(#foo -> #bar)
159
514c749165c3 *** empty log message ***
claus
parents: 118
diff changeset
   257
		 with:(#frob -> #baz)) 
514c749165c3 *** empty log message ***
claus
parents: 118
diff changeset
   258
	 at:#foobar ifAbsent:['no such index']
95
d22739a0c6e9 *** empty log message ***
claus
parents: 88
diff changeset
   259
    "
362
claus
parents: 360
diff changeset
   260
!
claus
parents: 360
diff changeset
   261
1366
531162d17aaa lifted #after: / #before:
Claus Gittinger <cg@exept.de>
parents: 1359
diff changeset
   262
before:anObject
531162d17aaa lifted #after: / #before:
Claus Gittinger <cg@exept.de>
parents: 1359
diff changeset
   263
    "return the element before the argument, anObject.
531162d17aaa lifted #after: / #before:
Claus Gittinger <cg@exept.de>
parents: 1359
diff changeset
   264
     If anObject is not in the receiver, report an error.
531162d17aaa lifted #after: / #before:
Claus Gittinger <cg@exept.de>
parents: 1359
diff changeset
   265
     This depends on #before:ifAbsent: being implemented in a concrete class."
531162d17aaa lifted #after: / #before:
Claus Gittinger <cg@exept.de>
parents: 1359
diff changeset
   266
531162d17aaa lifted #after: / #before:
Claus Gittinger <cg@exept.de>
parents: 1359
diff changeset
   267
    ^ self before:anObject ifAbsent:[self errorValueNotFound:anObject]
531162d17aaa lifted #after: / #before:
Claus Gittinger <cg@exept.de>
parents: 1359
diff changeset
   268
531162d17aaa lifted #after: / #before:
Claus Gittinger <cg@exept.de>
parents: 1359
diff changeset
   269
    "
531162d17aaa lifted #after: / #before:
Claus Gittinger <cg@exept.de>
parents: 1359
diff changeset
   270
     #(4 3 2 1) asOrderedCollection before:3. 
531162d17aaa lifted #after: / #before:
Claus Gittinger <cg@exept.de>
parents: 1359
diff changeset
   271
     #(4 3 2 1) asOrderedCollection before:4 
531162d17aaa lifted #after: / #before:
Claus Gittinger <cg@exept.de>
parents: 1359
diff changeset
   272
     #(4 3 2 1) asOrderedCollection before:0 
531162d17aaa lifted #after: / #before:
Claus Gittinger <cg@exept.de>
parents: 1359
diff changeset
   273
    "
531162d17aaa lifted #after: / #before:
Claus Gittinger <cg@exept.de>
parents: 1359
diff changeset
   274
531162d17aaa lifted #after: / #before:
Claus Gittinger <cg@exept.de>
parents: 1359
diff changeset
   275
    "Created: 10.5.1996 / 14:03:27 / cg"
531162d17aaa lifted #after: / #before:
Claus Gittinger <cg@exept.de>
parents: 1359
diff changeset
   276
    "Modified: 10.5.1996 / 14:03:44 / cg"
531162d17aaa lifted #after: / #before:
Claus Gittinger <cg@exept.de>
parents: 1359
diff changeset
   277
!
531162d17aaa lifted #after: / #before:
Claus Gittinger <cg@exept.de>
parents: 1359
diff changeset
   278
531162d17aaa lifted #after: / #before:
Claus Gittinger <cg@exept.de>
parents: 1359
diff changeset
   279
before:anObject ifAbsent:exceptionBlock
531162d17aaa lifted #after: / #before:
Claus Gittinger <cg@exept.de>
parents: 1359
diff changeset
   280
    "return the element, before anObject. If there is no such element,
531162d17aaa lifted #after: / #before:
Claus Gittinger <cg@exept.de>
parents: 1359
diff changeset
   281
     return the value from exceptionBlock."
531162d17aaa lifted #after: / #before:
Claus Gittinger <cg@exept.de>
parents: 1359
diff changeset
   282
531162d17aaa lifted #after: / #before:
Claus Gittinger <cg@exept.de>
parents: 1359
diff changeset
   283
    ^ self subclassResponsibility
531162d17aaa lifted #after: / #before:
Claus Gittinger <cg@exept.de>
parents: 1359
diff changeset
   284
531162d17aaa lifted #after: / #before:
Claus Gittinger <cg@exept.de>
parents: 1359
diff changeset
   285
    "Created: 10.5.1996 / 14:03:53 / cg"
531162d17aaa lifted #after: / #before:
Claus Gittinger <cg@exept.de>
parents: 1359
diff changeset
   286
!
531162d17aaa lifted #after: / #before:
Claus Gittinger <cg@exept.de>
parents: 1359
diff changeset
   287
602
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
   288
first
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
   289
    "return the first element"
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
    ^ self at:1
3468
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
   292
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
   293
    "
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
   294
     args:    
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
   295
     returns: firstElement <object>
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
   296
    "
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
   297
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
   298
    "Modified: / 20.5.1998 / 14:50:25 / cg"
362
claus
parents: 360
diff changeset
   299
!
claus
parents: 360
diff changeset
   300
claus
parents: 360
diff changeset
   301
keyAtEqualValue:value
claus
parents: 360
diff changeset
   302
    "return the index of a value.
claus
parents: 360
diff changeset
   303
     This is normally not used (use indexOf:), but makes the
claus
parents: 360
diff changeset
   304
     protocol more compatible with dictionaries."
claus
parents: 360
diff changeset
   305
claus
parents: 360
diff changeset
   306
    ^ self indexOf:value
claus
parents: 360
diff changeset
   307
!
claus
parents: 360
diff changeset
   308
claus
parents: 360
diff changeset
   309
keyAtEqualValue:value ifAbsent:exceptionBlock
claus
parents: 360
diff changeset
   310
    "return the index of a value.
claus
parents: 360
diff changeset
   311
     This is normally not used (use indexOf:), but makes the
claus
parents: 360
diff changeset
   312
     protocol more compatible with dictionaries."
claus
parents: 360
diff changeset
   313
claus
parents: 360
diff changeset
   314
    ^ self indexOf:value ifAbsent:exceptionBlock
602
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
   315
!
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
   316
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
   317
keyAtValue:value
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
   318
    "return the index of a value.
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
   319
     This is normally not used (use indexOf:), but makes the
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
   320
     protocol more compatible with dictionaries."
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
    ^ self identityIndexOf:value
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
   323
!
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
   324
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
   325
keyAtValue:value ifAbsent:exceptionBlock
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
   326
    "return the index of a value.
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
   327
     This is normally not used (use indexOf:), but makes the
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
   328
     protocol more compatible with dictionaries."
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
   329
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
   330
    ^ self identityIndexOf:value ifAbsent:exceptionBlock
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
   331
!
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
   332
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
   333
last
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
   334
    "return the last element"
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
   335
3408
411024a56ffd check for being empty in #last
Claus Gittinger <cg@exept.de>
parents: 3234
diff changeset
   336
    |sz|
411024a56ffd check for being empty in #last
Claus Gittinger <cg@exept.de>
parents: 3234
diff changeset
   337
411024a56ffd check for being empty in #last
Claus Gittinger <cg@exept.de>
parents: 3234
diff changeset
   338
    (sz := self size) == 0 ifFalse:[
411024a56ffd check for being empty in #last
Claus Gittinger <cg@exept.de>
parents: 3234
diff changeset
   339
        ^ self at:sz
411024a56ffd check for being empty in #last
Claus Gittinger <cg@exept.de>
parents: 3234
diff changeset
   340
    ].
411024a56ffd check for being empty in #last
Claus Gittinger <cg@exept.de>
parents: 3234
diff changeset
   341
    "error if collection is empty"
411024a56ffd check for being empty in #last
Claus Gittinger <cg@exept.de>
parents: 3234
diff changeset
   342
    ^ self emptyCollectionError
411024a56ffd check for being empty in #last
Claus Gittinger <cg@exept.de>
parents: 3234
diff changeset
   343
1370
b051117cc302 moved #upTo: down into SeqColl
Claus Gittinger <cg@exept.de>
parents: 1369
diff changeset
   344
!
b051117cc302 moved #upTo: down into SeqColl
Claus Gittinger <cg@exept.de>
parents: 1369
diff changeset
   345
3037
1293e34a06cf added #swap:with: for compatibility
Claus Gittinger <cg@exept.de>
parents: 3003
diff changeset
   346
swap:index1 with:index2
1293e34a06cf added #swap:with: for compatibility
Claus Gittinger <cg@exept.de>
parents: 3003
diff changeset
   347
    "exchange two elements"
1293e34a06cf added #swap:with: for compatibility
Claus Gittinger <cg@exept.de>
parents: 3003
diff changeset
   348
1293e34a06cf added #swap:with: for compatibility
Claus Gittinger <cg@exept.de>
parents: 3003
diff changeset
   349
    |t|
1293e34a06cf added #swap:with: for compatibility
Claus Gittinger <cg@exept.de>
parents: 3003
diff changeset
   350
1293e34a06cf added #swap:with: for compatibility
Claus Gittinger <cg@exept.de>
parents: 3003
diff changeset
   351
    t := self at:index1.
1293e34a06cf added #swap:with: for compatibility
Claus Gittinger <cg@exept.de>
parents: 3003
diff changeset
   352
    self at:index1 put:(self at:index2).
1293e34a06cf added #swap:with: for compatibility
Claus Gittinger <cg@exept.de>
parents: 3003
diff changeset
   353
    self at:index2 put:t
1293e34a06cf added #swap:with: for compatibility
Claus Gittinger <cg@exept.de>
parents: 3003
diff changeset
   354
1293e34a06cf added #swap:with: for compatibility
Claus Gittinger <cg@exept.de>
parents: 3003
diff changeset
   355
    "Modified: 15.10.1997 / 19:27:08 / cg"
1293e34a06cf added #swap:with: for compatibility
Claus Gittinger <cg@exept.de>
parents: 3003
diff changeset
   356
!
1293e34a06cf added #swap:with: for compatibility
Claus Gittinger <cg@exept.de>
parents: 3003
diff changeset
   357
1370
b051117cc302 moved #upTo: down into SeqColl
Claus Gittinger <cg@exept.de>
parents: 1369
diff changeset
   358
upTo:anElement
b051117cc302 moved #upTo: down into SeqColl
Claus Gittinger <cg@exept.de>
parents: 1369
diff changeset
   359
    "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
   360
     (but excluding) anElement.
b051117cc302 moved #upTo: down into SeqColl
Claus Gittinger <cg@exept.de>
parents: 1369
diff changeset
   361
     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
   362
     will consist of all elements of the receiver"
b051117cc302 moved #upTo: down into SeqColl
Claus Gittinger <cg@exept.de>
parents: 1369
diff changeset
   363
b051117cc302 moved #upTo: down into SeqColl
Claus Gittinger <cg@exept.de>
parents: 1369
diff changeset
   364
    |pos|
b051117cc302 moved #upTo: down into SeqColl
Claus Gittinger <cg@exept.de>
parents: 1369
diff changeset
   365
b051117cc302 moved #upTo: down into SeqColl
Claus Gittinger <cg@exept.de>
parents: 1369
diff changeset
   366
    pos := self indexOf:anElement.
b051117cc302 moved #upTo: down into SeqColl
Claus Gittinger <cg@exept.de>
parents: 1369
diff changeset
   367
    pos == 0 ifTrue:[^ self copy].
b051117cc302 moved #upTo: down into SeqColl
Claus Gittinger <cg@exept.de>
parents: 1369
diff changeset
   368
b051117cc302 moved #upTo: down into SeqColl
Claus Gittinger <cg@exept.de>
parents: 1369
diff changeset
   369
    ^ self copyFrom:1 to:(pos - 1)
b051117cc302 moved #upTo: down into SeqColl
Claus Gittinger <cg@exept.de>
parents: 1369
diff changeset
   370
b051117cc302 moved #upTo: down into SeqColl
Claus Gittinger <cg@exept.de>
parents: 1369
diff changeset
   371
    "
b051117cc302 moved #upTo: down into SeqColl
Claus Gittinger <cg@exept.de>
parents: 1369
diff changeset
   372
     #(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
   373
     'hello world' upTo:Character space  
b051117cc302 moved #upTo: down into SeqColl
Claus Gittinger <cg@exept.de>
parents: 1369
diff changeset
   374
     #(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
   375
b051117cc302 moved #upTo: down into SeqColl
Claus Gittinger <cg@exept.de>
parents: 1369
diff changeset
   376
     raises an error:
b051117cc302 moved #upTo: down into SeqColl
Claus Gittinger <cg@exept.de>
parents: 1369
diff changeset
   377
b051117cc302 moved #upTo: down into SeqColl
Claus Gittinger <cg@exept.de>
parents: 1369
diff changeset
   378
     (Dictionary new 
b051117cc302 moved #upTo: down into SeqColl
Claus Gittinger <cg@exept.de>
parents: 1369
diff changeset
   379
        at:#foo put:'foo';
b051117cc302 moved #upTo: down into SeqColl
Claus Gittinger <cg@exept.de>
parents: 1369
diff changeset
   380
        at:#bar put:'bar';
b051117cc302 moved #upTo: down into SeqColl
Claus Gittinger <cg@exept.de>
parents: 1369
diff changeset
   381
        at:#baz put:'baz';
b051117cc302 moved #upTo: down into SeqColl
Claus Gittinger <cg@exept.de>
parents: 1369
diff changeset
   382
        yourself) upTo:#bar
b051117cc302 moved #upTo: down into SeqColl
Claus Gittinger <cg@exept.de>
parents: 1369
diff changeset
   383
                
b051117cc302 moved #upTo: down into SeqColl
Claus Gittinger <cg@exept.de>
parents: 1369
diff changeset
   384
    "
b051117cc302 moved #upTo: down into SeqColl
Claus Gittinger <cg@exept.de>
parents: 1369
diff changeset
   385
b051117cc302 moved #upTo: down into SeqColl
Claus Gittinger <cg@exept.de>
parents: 1369
diff changeset
   386
    "Modified: 11.5.1996 / 11:14:05 / cg"
3764
ab05f8d25063 extented #upTo: added
tz
parents: 3738
diff changeset
   387
!
ab05f8d25063 extented #upTo: added
tz
parents: 3738
diff changeset
   388
ab05f8d25063 extented #upTo: added
tz
parents: 3738
diff changeset
   389
upTo:anElement count:count
ab05f8d25063 extented #upTo: added
tz
parents: 3738
diff changeset
   390
    "return a new collection consisting of the receivers elements upTo
ab05f8d25063 extented #upTo: added
tz
parents: 3738
diff changeset
   391
     (but excluding) count found anElements, i.e. the first found count-1 
ab05f8d25063 extented #upTo: added
tz
parents: 3738
diff changeset
   392
     elements are included in the returned collection; if count < 0 the 
ab05f8d25063 extented #upTo: added
tz
parents: 3738
diff changeset
   393
     procedure is done from the end of the collection backwards.
ab05f8d25063 extented #upTo: added
tz
parents: 3738
diff changeset
   394
     If anElement is not in the receiver, the returned collection
ab05f8d25063 extented #upTo: added
tz
parents: 3738
diff changeset
   395
     will consist of all elements of the receiver"
ab05f8d25063 extented #upTo: added
tz
parents: 3738
diff changeset
   396
ab05f8d25063 extented #upTo: added
tz
parents: 3738
diff changeset
   397
    |startPos endPos pos found|
ab05f8d25063 extented #upTo: added
tz
parents: 3738
diff changeset
   398
ab05f8d25063 extented #upTo: added
tz
parents: 3738
diff changeset
   399
    (count == 0 or: [count == 1]) ifTrue:[
ab05f8d25063 extented #upTo: added
tz
parents: 3738
diff changeset
   400
        ^ self upTo:anElement
ab05f8d25063 extented #upTo: added
tz
parents: 3738
diff changeset
   401
    ].
ab05f8d25063 extented #upTo: added
tz
parents: 3738
diff changeset
   402
ab05f8d25063 extented #upTo: added
tz
parents: 3738
diff changeset
   403
    startPos := 1.
ab05f8d25063 extented #upTo: added
tz
parents: 3738
diff changeset
   404
    endPos   := self size.
ab05f8d25063 extented #upTo: added
tz
parents: 3738
diff changeset
   405
    found    := 0.
ab05f8d25063 extented #upTo: added
tz
parents: 3738
diff changeset
   406
ab05f8d25063 extented #upTo: added
tz
parents: 3738
diff changeset
   407
    count > 1 ifTrue:[
ab05f8d25063 extented #upTo: added
tz
parents: 3738
diff changeset
   408
        pos := 0.
ab05f8d25063 extented #upTo: added
tz
parents: 3738
diff changeset
   409
        [pos < self size and: [found < count]]
ab05f8d25063 extented #upTo: added
tz
parents: 3738
diff changeset
   410
            whileTrue: [pos := pos + 1. (self at: pos) == anElement ifTrue: [found := found + 1]].
ab05f8d25063 extented #upTo: added
tz
parents: 3738
diff changeset
   411
        found == count ifTrue:[
ab05f8d25063 extented #upTo: added
tz
parents: 3738
diff changeset
   412
            endPos   := pos - 1
ab05f8d25063 extented #upTo: added
tz
parents: 3738
diff changeset
   413
        ]
ab05f8d25063 extented #upTo: added
tz
parents: 3738
diff changeset
   414
    ].     
ab05f8d25063 extented #upTo: added
tz
parents: 3738
diff changeset
   415
ab05f8d25063 extented #upTo: added
tz
parents: 3738
diff changeset
   416
    count < 0 ifTrue:[
ab05f8d25063 extented #upTo: added
tz
parents: 3738
diff changeset
   417
        pos := self size + 1.
ab05f8d25063 extented #upTo: added
tz
parents: 3738
diff changeset
   418
        [pos > 1 and: [found < count abs]]
ab05f8d25063 extented #upTo: added
tz
parents: 3738
diff changeset
   419
            whileTrue: [pos := pos - 1. (self at: pos) == anElement ifTrue: [found := found + 1]].
ab05f8d25063 extented #upTo: added
tz
parents: 3738
diff changeset
   420
        found == count abs ifTrue:[
ab05f8d25063 extented #upTo: added
tz
parents: 3738
diff changeset
   421
            startPos := pos + 1
ab05f8d25063 extented #upTo: added
tz
parents: 3738
diff changeset
   422
        ]
ab05f8d25063 extented #upTo: added
tz
parents: 3738
diff changeset
   423
    ].    
ab05f8d25063 extented #upTo: added
tz
parents: 3738
diff changeset
   424
ab05f8d25063 extented #upTo: added
tz
parents: 3738
diff changeset
   425
    ^ self copyFrom: startPos to: endPos
ab05f8d25063 extented #upTo: added
tz
parents: 3738
diff changeset
   426
ab05f8d25063 extented #upTo: added
tz
parents: 3738
diff changeset
   427
    "
ab05f8d25063 extented #upTo: added
tz
parents: 3738
diff changeset
   428
     'hello1_hello2_hello3' upTo:$_ count:  2     returns first two 'hellos' 
ab05f8d25063 extented #upTo: added
tz
parents: 3738
diff changeset
   429
     'hello1_hello2_hello3' upTo:$_ count: -1     returns last 'hello'
ab05f8d25063 extented #upTo: added
tz
parents: 3738
diff changeset
   430
    "
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   431
! !
a27a279701f8 Initial revision
claus
parents:
diff changeset
   432
602
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
   433
!SequenceableCollection methodsFor:'adding & removing'!
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
   434
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
   435
add:anObject
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
   436
    "append the argument, anObject to the collection.
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
   437
     Return the argument, anObject.
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
   438
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
   439
     Notice, that this is modifies the receiver NOT a copy.
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
   440
     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
   441
     due to the grow:-message, which is inefficient for fixed size 
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
   442
     collections (i.e. for Strings and Arrays it is not recommened)."
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
    |newSize|
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
   445
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
   446
    newSize := self size + 1.
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
   447
    self grow:newSize.
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
   448
    self at:newSize put:anObject.
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
   449
    ^ anObject
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
     |a|
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
   453
     a := #(1 2 3 4 5 6 7 8).
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
   454
     a add:'hello'.
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
   455
     a
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
   456
    "
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
   457
    "
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
   458
     |c|
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
   459
     c := #(1 2 3 4 5 6 7 8) asOrderedCollection.
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
   460
     c add:'hello'.
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
   461
     c
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
!
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
   464
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
   465
add:anElement beforeIndex:index
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
   466
    "insert the first argument, anObject into the collection before slot index.
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
   467
     Return the receiver (sigh - ST-80 compatibility).
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
     Notice, that this is modifies the receiver NOT a copy.
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
   470
     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
   471
     due to the grow:-message, which is inefficient for fixed size 
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
   472
     collections (i.e. for Strings and Arrays it is not recommened)."
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
   473
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
   474
    |newSize|
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
   475
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
   476
    newSize := self size + 1.
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
   477
    self grow:newSize.
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
   478
    self replaceFrom:index + 1 to:newSize with:self startingAt:index.
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
   479
    self at:index put:anElement
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
    "
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
   482
     #(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
   483
    "
202
40ca7cc6fb9c *** empty log message ***
claus
parents: 186
diff changeset
   484
!
40ca7cc6fb9c *** empty log message ***
claus
parents: 186
diff changeset
   485
602
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
   486
addFirst:anObject
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
   487
    "prepend the argument, anObject to the collection.
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
   488
     Return the argument, anObject.
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
    |newSize|
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
    newSize := self size + 1.
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
   498
    self grow:newSize.
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
   499
    self replaceFrom:2 to:newSize with:self startingAt:1.
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
   500
    self at:1 put:anObject.
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
   501
    ^ anObject
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
     |a| 
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
   505
     a:= #(1 2 3 4 5 6 7 8). 
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
   506
     a addFirst:'hello'. 
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
   507
     a 
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
   508
    "
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
   509
    "
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
   510
     |c|
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
   511
     c := #(1 2 3 4 5 6 7 8) asOrderedCollection.
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
   512
     c addFirst:'hello'.
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
   513
     c
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
   514
    "
69
4564b6328136 *** empty log message ***
claus
parents: 61
diff changeset
   515
!
4564b6328136 *** empty log message ***
claus
parents: 61
diff changeset
   516
602
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
   517
remove:anElement ifAbsent:aBlock
2346
7ebe79ad61a3 added #removeIdentical:ifAbsent:
Claus Gittinger <cg@exept.de>
parents: 2294
diff changeset
   518
    "search for an object which is equal to anElement;
7ebe79ad61a3 added #removeIdentical:ifAbsent:
Claus Gittinger <cg@exept.de>
parents: 2294
diff changeset
   519
     if found remove and return it; if not, return the value from evaluating aBlock.
7ebe79ad61a3 added #removeIdentical:ifAbsent:
Claus Gittinger <cg@exept.de>
parents: 2294
diff changeset
   520
     Use equality compare (=) to search for an occurrence.
602
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
   521
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
   522
     Notice, that this is modifies the receiver NOT a copy.
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
   523
     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
   524
     due to the grow:-message, which is inefficient for fixed size 
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
   525
     collections (i.e. for Strings and Arrays it is not recommened)."
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
    |any 
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
   528
     dstIndex "{ Class: SmallInteger }"
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
   529
     sz       "{ Class: SmallInteger }"|
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
   530
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
   531
    dstIndex := 1.
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
   532
    any := false.
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
   533
    sz := self size.
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
   534
    1 to:sz do:[:srcIndex |
2346
7ebe79ad61a3 added #removeIdentical:ifAbsent:
Claus Gittinger <cg@exept.de>
parents: 2294
diff changeset
   535
        (anElement = (self at:srcIndex)) ifTrue:[
7ebe79ad61a3 added #removeIdentical:ifAbsent:
Claus Gittinger <cg@exept.de>
parents: 2294
diff changeset
   536
            any := true
7ebe79ad61a3 added #removeIdentical:ifAbsent:
Claus Gittinger <cg@exept.de>
parents: 2294
diff changeset
   537
        ] ifFalse:[
7ebe79ad61a3 added #removeIdentical:ifAbsent:
Claus Gittinger <cg@exept.de>
parents: 2294
diff changeset
   538
            (dstIndex ~~ srcIndex) ifTrue:[
7ebe79ad61a3 added #removeIdentical:ifAbsent:
Claus Gittinger <cg@exept.de>
parents: 2294
diff changeset
   539
                self at:dstIndex put:(self at:srcIndex)
7ebe79ad61a3 added #removeIdentical:ifAbsent:
Claus Gittinger <cg@exept.de>
parents: 2294
diff changeset
   540
            ].
7ebe79ad61a3 added #removeIdentical:ifAbsent:
Claus Gittinger <cg@exept.de>
parents: 2294
diff changeset
   541
            dstIndex := dstIndex + 1
7ebe79ad61a3 added #removeIdentical:ifAbsent:
Claus Gittinger <cg@exept.de>
parents: 2294
diff changeset
   542
        ]
602
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
    any ifTrue:[
2346
7ebe79ad61a3 added #removeIdentical:ifAbsent:
Claus Gittinger <cg@exept.de>
parents: 2294
diff changeset
   545
        self grow:dstIndex - 1.
7ebe79ad61a3 added #removeIdentical:ifAbsent:
Claus Gittinger <cg@exept.de>
parents: 2294
diff changeset
   546
        ^ anElement
602
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
   547
    ].
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
   548
    ^ aBlock value
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
   549
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
   550
    "
1422
9a0b792f2953 showCr: -> showCR:
Claus Gittinger <cg@exept.de>
parents: 1421
diff changeset
   551
     #(1 2 3 4 5 6 7 8 9 0) remove:3 ifAbsent:[Transcript showCR:'no']
602
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
   552
     #(1 2 3 4 5 6 7 8 9 0) remove:99 ifAbsent:[#oops]
2346
7ebe79ad61a3 added #removeIdentical:ifAbsent:
Claus Gittinger <cg@exept.de>
parents: 2294
diff changeset
   553
     #(1.0 2.0 3.0 4.0 5.0) remove:5 ifAbsent:[#oops]
7ebe79ad61a3 added #removeIdentical:ifAbsent:
Claus Gittinger <cg@exept.de>
parents: 2294
diff changeset
   554
     #(1.0 2.0 3.0 4.0 5.0) removeIdentical:5 ifAbsent:[#oops]
602
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
   555
    "
2346
7ebe79ad61a3 added #removeIdentical:ifAbsent:
Claus Gittinger <cg@exept.de>
parents: 2294
diff changeset
   556
7ebe79ad61a3 added #removeIdentical:ifAbsent:
Claus Gittinger <cg@exept.de>
parents: 2294
diff changeset
   557
    "Modified: 1.2.1997 / 11:49:01 / cg"
602
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
   558
!
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
   559
1369
5e7b6fabd248 raised #atAll:put: up in the hierarchy
Claus Gittinger <cg@exept.de>
parents: 1366
diff changeset
   560
removeAllSuchThat:aBlock
5e7b6fabd248 raised #atAll:put: up in the hierarchy
Claus Gittinger <cg@exept.de>
parents: 1366
diff changeset
   561
    "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
   562
     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
   563
     for which it returns true, are removed.
5e7b6fabd248 raised #atAll:put: up in the hierarchy
Claus Gittinger <cg@exept.de>
parents: 1366
diff changeset
   564
     Return a collection containing the removed elements."
5e7b6fabd248 raised #atAll:put: up in the hierarchy
Claus Gittinger <cg@exept.de>
parents: 1366
diff changeset
   565
5e7b6fabd248 raised #atAll:put: up in the hierarchy
Claus Gittinger <cg@exept.de>
parents: 1366
diff changeset
   566
    "/ 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
   567
5e7b6fabd248 raised #atAll:put: up in the hierarchy
Claus Gittinger <cg@exept.de>
parents: 1366
diff changeset
   568
    |runIndex removed element|
5e7b6fabd248 raised #atAll:put: up in the hierarchy
Claus Gittinger <cg@exept.de>
parents: 1366
diff changeset
   569
5e7b6fabd248 raised #atAll:put: up in the hierarchy
Claus Gittinger <cg@exept.de>
parents: 1366
diff changeset
   570
    removed := self species new.
5e7b6fabd248 raised #atAll:put: up in the hierarchy
Claus Gittinger <cg@exept.de>
parents: 1366
diff changeset
   571
5e7b6fabd248 raised #atAll:put: up in the hierarchy
Claus Gittinger <cg@exept.de>
parents: 1366
diff changeset
   572
    runIndex := 1.
5e7b6fabd248 raised #atAll:put: up in the hierarchy
Claus Gittinger <cg@exept.de>
parents: 1366
diff changeset
   573
    [runIndex <= self size] whileTrue:[
5e7b6fabd248 raised #atAll:put: up in the hierarchy
Claus Gittinger <cg@exept.de>
parents: 1366
diff changeset
   574
        element := self at:runIndex.
5e7b6fabd248 raised #atAll:put: up in the hierarchy
Claus Gittinger <cg@exept.de>
parents: 1366
diff changeset
   575
        (aBlock value:element) ifTrue:[
5e7b6fabd248 raised #atAll:put: up in the hierarchy
Claus Gittinger <cg@exept.de>
parents: 1366
diff changeset
   576
            removed add:element.
5e7b6fabd248 raised #atAll:put: up in the hierarchy
Claus Gittinger <cg@exept.de>
parents: 1366
diff changeset
   577
            self removeAtIndex:runIndex
5e7b6fabd248 raised #atAll:put: up in the hierarchy
Claus Gittinger <cg@exept.de>
parents: 1366
diff changeset
   578
        ] ifFalse:[
5e7b6fabd248 raised #atAll:put: up in the hierarchy
Claus Gittinger <cg@exept.de>
parents: 1366
diff changeset
   579
            runIndex := runIndex + 1
5e7b6fabd248 raised #atAll:put: up in the hierarchy
Claus Gittinger <cg@exept.de>
parents: 1366
diff changeset
   580
        ]
5e7b6fabd248 raised #atAll:put: up in the hierarchy
Claus Gittinger <cg@exept.de>
parents: 1366
diff changeset
   581
    ].
5e7b6fabd248 raised #atAll:put: up in the hierarchy
Claus Gittinger <cg@exept.de>
parents: 1366
diff changeset
   582
    ^ removed
5e7b6fabd248 raised #atAll:put: up in the hierarchy
Claus Gittinger <cg@exept.de>
parents: 1366
diff changeset
   583
5e7b6fabd248 raised #atAll:put: up in the hierarchy
Claus Gittinger <cg@exept.de>
parents: 1366
diff changeset
   584
    "
5e7b6fabd248 raised #atAll:put: up in the hierarchy
Claus Gittinger <cg@exept.de>
parents: 1366
diff changeset
   585
     |coll|
5e7b6fabd248 raised #atAll:put: up in the hierarchy
Claus Gittinger <cg@exept.de>
parents: 1366
diff changeset
   586
5e7b6fabd248 raised #atAll:put: up in the hierarchy
Claus Gittinger <cg@exept.de>
parents: 1366
diff changeset
   587
     coll := OrderedCollection withAll:(1 to:10).
1422
9a0b792f2953 showCr: -> showCR:
Claus Gittinger <cg@exept.de>
parents: 1421
diff changeset
   588
     Transcript showCR:(coll removeAllSuchThat:[:el | el even]).
9a0b792f2953 showCr: -> showCR:
Claus Gittinger <cg@exept.de>
parents: 1421
diff changeset
   589
     Transcript showCR:coll
1369
5e7b6fabd248 raised #atAll:put: up in the hierarchy
Claus Gittinger <cg@exept.de>
parents: 1366
diff changeset
   590
    "
5e7b6fabd248 raised #atAll:put: up in the hierarchy
Claus Gittinger <cg@exept.de>
parents: 1366
diff changeset
   591
5e7b6fabd248 raised #atAll:put: up in the hierarchy
Claus Gittinger <cg@exept.de>
parents: 1366
diff changeset
   592
    "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
   593
!
5e7b6fabd248 raised #atAll:put: up in the hierarchy
Claus Gittinger <cg@exept.de>
parents: 1366
diff changeset
   594
602
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
   595
removeAtIndex:anIndex
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
   596
    "remove the element stored at anIndex. Return the removed object.
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
   597
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
   598
     Notice, that this is modifies the receiver NOT a copy.
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
   599
     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
   600
     due to the grow:-message, which is inefficient for fixed size 
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
   601
     collections (i.e. for Strings and Arrays it is not recommened)."
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
    |element|
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
   604
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
   605
    element := self at:anIndex.
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
   606
    self removeFromIndex:anIndex toIndex:anIndex.
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
   607
    ^ element
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
   608
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
   609
    "
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
   610
     #(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
   611
     #(1 2 3 4 5) asOrderedCollection removeAtIndex:6
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
   612
     #($a $b $c $d $e $f $g) removeAtIndex:3
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
   613
    "
13
62303f84ff5f *** empty log message ***
claus
parents: 5
diff changeset
   614
!
62303f84ff5f *** empty log message ***
claus
parents: 5
diff changeset
   615
602
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
   616
removeFirst
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
   617
    "remove the first element of the receiver and return it.
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
   618
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
   619
     Notice, that this is modifies the receiver NOT a copy.
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
   620
     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
   621
     due to the grow:-message, which is inefficient for fixed size 
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
   622
     collections (i.e. for Strings and Arrays it is not recommened)."
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
   623
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
   624
    ^ self removeAtIndex:1
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
   625
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
   626
    "
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
   627
     |a|
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
   628
     a := #(1 2 3 4 5 6).
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
   629
     a removeFirst.
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
   630
     a 
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
   631
    "
13
62303f84ff5f *** empty log message ***
claus
parents: 5
diff changeset
   632
!
62303f84ff5f *** empty log message ***
claus
parents: 5
diff changeset
   633
2294
ed349da6fa4e added #removeFromIndex:
Claus Gittinger <cg@exept.de>
parents: 2275
diff changeset
   634
removeFromIndex:startIndex
ed349da6fa4e added #removeFromIndex:
Claus Gittinger <cg@exept.de>
parents: 2275
diff changeset
   635
    "remove the elements stored at indexes from startIndex to the end.
ed349da6fa4e added #removeFromIndex:
Claus Gittinger <cg@exept.de>
parents: 2275
diff changeset
   636
     Return the receiver.
ed349da6fa4e added #removeFromIndex:
Claus Gittinger <cg@exept.de>
parents: 2275
diff changeset
   637
     Returning the receiver is a historic leftover - it may at one
ed349da6fa4e added #removeFromIndex:
Claus Gittinger <cg@exept.de>
parents: 2275
diff changeset
   638
     time return a collection of the removed elements.
ed349da6fa4e added #removeFromIndex:
Claus Gittinger <cg@exept.de>
parents: 2275
diff changeset
   639
ed349da6fa4e added #removeFromIndex:
Claus Gittinger <cg@exept.de>
parents: 2275
diff changeset
   640
     Notice, that this is modifies the receiver - NOT a copy; 
ed349da6fa4e added #removeFromIndex:
Claus Gittinger <cg@exept.de>
parents: 2275
diff changeset
   641
     therefore any other users of the receiver will also see this change.
ed349da6fa4e added #removeFromIndex:
Claus Gittinger <cg@exept.de>
parents: 2275
diff changeset
   642
     Also note, that it may be a slow operation for some collections,
ed349da6fa4e added #removeFromIndex:
Claus Gittinger <cg@exept.de>
parents: 2275
diff changeset
   643
     due to the grow:-message, which is inefficient for fixed size 
ed349da6fa4e added #removeFromIndex:
Claus Gittinger <cg@exept.de>
parents: 2275
diff changeset
   644
     collections (i.e. for Strings and Arrays it is not recommened)."
ed349da6fa4e added #removeFromIndex:
Claus Gittinger <cg@exept.de>
parents: 2275
diff changeset
   645
ed349da6fa4e added #removeFromIndex:
Claus Gittinger <cg@exept.de>
parents: 2275
diff changeset
   646
    ^ self removeFromIndex:startIndex toIndex:(self size)
ed349da6fa4e added #removeFromIndex:
Claus Gittinger <cg@exept.de>
parents: 2275
diff changeset
   647
ed349da6fa4e added #removeFromIndex:
Claus Gittinger <cg@exept.de>
parents: 2275
diff changeset
   648
    "
ed349da6fa4e added #removeFromIndex:
Claus Gittinger <cg@exept.de>
parents: 2275
diff changeset
   649
     #(1 2 3 4 5 6 7 8 9 0) asOrderedCollection removeFromIndex:3 
ed349da6fa4e added #removeFromIndex:
Claus Gittinger <cg@exept.de>
parents: 2275
diff changeset
   650
     #(1 2 3 4 5 6 7 8 9 0) removeFromIndex:3
ed349da6fa4e added #removeFromIndex:
Claus Gittinger <cg@exept.de>
parents: 2275
diff changeset
   651
    "
ed349da6fa4e added #removeFromIndex:
Claus Gittinger <cg@exept.de>
parents: 2275
diff changeset
   652
ed349da6fa4e added #removeFromIndex:
Claus Gittinger <cg@exept.de>
parents: 2275
diff changeset
   653
    "Modified: 28.1.1997 / 12:35:20 / cg"
ed349da6fa4e added #removeFromIndex:
Claus Gittinger <cg@exept.de>
parents: 2275
diff changeset
   654
!
ed349da6fa4e added #removeFromIndex:
Claus Gittinger <cg@exept.de>
parents: 2275
diff changeset
   655
602
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
   656
removeFromIndex:startIndex toIndex:endIndex
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
   657
    "remove the elements stored at indexes between startIndex and endIndex.
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
   658
     Return the receiver.
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
   659
     Returning the receiver is a historic leftover - it may at one
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
   660
     time return a collection of the removed elements.
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
   661
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
   662
     Notice, that this is modifies the receiver - NOT a copy; 
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
   663
     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
   664
     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
   665
     due to the grow:-message, which is inefficient for fixed size 
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
   666
     collections (i.e. for Strings and Arrays it is not recommened)."
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
   667
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
   668
    |size newSize|
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
   669
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
   670
    (endIndex >= (size := self size)) ifTrue:[
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
   671
	self grow:(startIndex - 1)
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
   672
    ] ifFalse:[
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
   673
	newSize := size - endIndex + startIndex - 1.
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
   674
	self replaceFrom:startIndex to:newSize with:self startingAt:(endIndex + 1).
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
   675
	self grow:newSize
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
   676
    ]
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
   677
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
   678
"/    |newSize|
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
   679
"/
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
   680
"/    newSize := self size - endIndex + startIndex - 1.
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
   681
"/    newSize <= 0 ifTrue:[
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
   682
"/        self grow:0
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
   683
"/    ] ifFalse:[
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
   684
"/        self replaceFrom:startIndex to:newSize with:self startingAt:(endIndex + 1).
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
   685
"/        self grow:newSize
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
   686
"/    ]
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
   687
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
   688
    "
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
   689
     #(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
   690
     #(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
   691
     #(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
   692
     #(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
   693
    "
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
   694
!
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
   695
2346
7ebe79ad61a3 added #removeIdentical:ifAbsent:
Claus Gittinger <cg@exept.de>
parents: 2294
diff changeset
   696
removeIdentical:anElement ifAbsent:aBlock
7ebe79ad61a3 added #removeIdentical:ifAbsent:
Claus Gittinger <cg@exept.de>
parents: 2294
diff changeset
   697
    "search for an object which is identical to anElement;
7ebe79ad61a3 added #removeIdentical:ifAbsent:
Claus Gittinger <cg@exept.de>
parents: 2294
diff changeset
   698
     if found remove and return it; if not, return the value from evaluating aBlock.
2363
57cc0807827a checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2347
diff changeset
   699
     Uses identity compare (==) to search for an occurrence.
2346
7ebe79ad61a3 added #removeIdentical:ifAbsent:
Claus Gittinger <cg@exept.de>
parents: 2294
diff changeset
   700
7ebe79ad61a3 added #removeIdentical:ifAbsent:
Claus Gittinger <cg@exept.de>
parents: 2294
diff changeset
   701
     Notice, that this is modifies the receiver NOT a copy.
7ebe79ad61a3 added #removeIdentical:ifAbsent:
Claus Gittinger <cg@exept.de>
parents: 2294
diff changeset
   702
     Also note, that it may be a slow operation for some collections,
7ebe79ad61a3 added #removeIdentical:ifAbsent:
Claus Gittinger <cg@exept.de>
parents: 2294
diff changeset
   703
     due to the grow:-message, which is inefficient for fixed size 
7ebe79ad61a3 added #removeIdentical:ifAbsent:
Claus Gittinger <cg@exept.de>
parents: 2294
diff changeset
   704
     collections (i.e. for Strings and Arrays it is not recommened)."
7ebe79ad61a3 added #removeIdentical:ifAbsent:
Claus Gittinger <cg@exept.de>
parents: 2294
diff changeset
   705
2363
57cc0807827a checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2347
diff changeset
   706
    |any el
2346
7ebe79ad61a3 added #removeIdentical:ifAbsent:
Claus Gittinger <cg@exept.de>
parents: 2294
diff changeset
   707
     dstIndex "{ Class: SmallInteger }"
7ebe79ad61a3 added #removeIdentical:ifAbsent:
Claus Gittinger <cg@exept.de>
parents: 2294
diff changeset
   708
     sz       "{ Class: SmallInteger }"|
7ebe79ad61a3 added #removeIdentical:ifAbsent:
Claus Gittinger <cg@exept.de>
parents: 2294
diff changeset
   709
7ebe79ad61a3 added #removeIdentical:ifAbsent:
Claus Gittinger <cg@exept.de>
parents: 2294
diff changeset
   710
    dstIndex := 1.
7ebe79ad61a3 added #removeIdentical:ifAbsent:
Claus Gittinger <cg@exept.de>
parents: 2294
diff changeset
   711
    any := false.
7ebe79ad61a3 added #removeIdentical:ifAbsent:
Claus Gittinger <cg@exept.de>
parents: 2294
diff changeset
   712
    sz := self size.
7ebe79ad61a3 added #removeIdentical:ifAbsent:
Claus Gittinger <cg@exept.de>
parents: 2294
diff changeset
   713
    1 to:sz do:[:srcIndex |
2363
57cc0807827a checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2347
diff changeset
   714
        el := self at:srcIndex.
57cc0807827a checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2347
diff changeset
   715
        (anElement == el) ifTrue:[
2346
7ebe79ad61a3 added #removeIdentical:ifAbsent:
Claus Gittinger <cg@exept.de>
parents: 2294
diff changeset
   716
            any := true
7ebe79ad61a3 added #removeIdentical:ifAbsent:
Claus Gittinger <cg@exept.de>
parents: 2294
diff changeset
   717
        ] ifFalse:[
7ebe79ad61a3 added #removeIdentical:ifAbsent:
Claus Gittinger <cg@exept.de>
parents: 2294
diff changeset
   718
            (dstIndex ~~ srcIndex) ifTrue:[
2363
57cc0807827a checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2347
diff changeset
   719
                self at:dstIndex put:el
2346
7ebe79ad61a3 added #removeIdentical:ifAbsent:
Claus Gittinger <cg@exept.de>
parents: 2294
diff changeset
   720
            ].
7ebe79ad61a3 added #removeIdentical:ifAbsent:
Claus Gittinger <cg@exept.de>
parents: 2294
diff changeset
   721
            dstIndex := dstIndex + 1
7ebe79ad61a3 added #removeIdentical:ifAbsent:
Claus Gittinger <cg@exept.de>
parents: 2294
diff changeset
   722
        ]
7ebe79ad61a3 added #removeIdentical:ifAbsent:
Claus Gittinger <cg@exept.de>
parents: 2294
diff changeset
   723
    ].
7ebe79ad61a3 added #removeIdentical:ifAbsent:
Claus Gittinger <cg@exept.de>
parents: 2294
diff changeset
   724
    any ifTrue:[
7ebe79ad61a3 added #removeIdentical:ifAbsent:
Claus Gittinger <cg@exept.de>
parents: 2294
diff changeset
   725
        self grow:dstIndex - 1.
7ebe79ad61a3 added #removeIdentical:ifAbsent:
Claus Gittinger <cg@exept.de>
parents: 2294
diff changeset
   726
        ^ anElement
7ebe79ad61a3 added #removeIdentical:ifAbsent:
Claus Gittinger <cg@exept.de>
parents: 2294
diff changeset
   727
    ].
7ebe79ad61a3 added #removeIdentical:ifAbsent:
Claus Gittinger <cg@exept.de>
parents: 2294
diff changeset
   728
    ^ aBlock value
7ebe79ad61a3 added #removeIdentical:ifAbsent:
Claus Gittinger <cg@exept.de>
parents: 2294
diff changeset
   729
7ebe79ad61a3 added #removeIdentical:ifAbsent:
Claus Gittinger <cg@exept.de>
parents: 2294
diff changeset
   730
    "
2347
b79cdb6b553e added #removeIdentical:ifAbsent:
Claus Gittinger <cg@exept.de>
parents: 2346
diff changeset
   731
     #(1.0 2.0 3.0 4.0 5.0) remove:5 ifAbsent:[#oops]         
2346
7ebe79ad61a3 added #removeIdentical:ifAbsent:
Claus Gittinger <cg@exept.de>
parents: 2294
diff changeset
   732
     #(1.0 2.0 3.0 4.0 5.0) removeIdentical:5 ifAbsent:[#oops]
7ebe79ad61a3 added #removeIdentical:ifAbsent:
Claus Gittinger <cg@exept.de>
parents: 2294
diff changeset
   733
    "
7ebe79ad61a3 added #removeIdentical:ifAbsent:
Claus Gittinger <cg@exept.de>
parents: 2294
diff changeset
   734
2363
57cc0807827a checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2347
diff changeset
   735
    "Modified: 8.2.1997 / 16:26:49 / cg"
2346
7ebe79ad61a3 added #removeIdentical:ifAbsent:
Claus Gittinger <cg@exept.de>
parents: 2294
diff changeset
   736
!
7ebe79ad61a3 added #removeIdentical:ifAbsent:
Claus Gittinger <cg@exept.de>
parents: 2294
diff changeset
   737
602
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
   738
removeIndex:index
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
   739
    "remove the argument stored at index. Return the receiver.
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
   740
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
   741
     Notice, that this is modifies the receiver NOT a copy.
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
   742
     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
   743
     due to the grow:-message, which is inefficient for fixed size 
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
   744
     collections (i.e. for Strings and Arrays it is not recommened)."
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
   745
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
   746
    self removeFromIndex:index toIndex:index
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
   747
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
   748
    "
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
   749
     #(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
   750
     #(1 2 3 4 5) asOrderedCollection removeIndex:6
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
   751
     #($a $b $c $d $e $f $g) removeIndex:3
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
   752
    "
77
6c38ca59927f *** empty log message ***
claus
parents: 69
diff changeset
   753
!
6c38ca59927f *** empty log message ***
claus
parents: 69
diff changeset
   754
602
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
   755
removeLast
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
   756
    "remove the last element of the receiver and return it.
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
   757
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
   758
     Notice, that this is modifies the receiver NOT a copy.
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
   759
     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
   760
     due to the grow:-message, which is inefficient for fixed size
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
   761
     collections (i.e. for Strings and Arrays it is not recommened)."
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
   762
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
   763
    ^ self removeAtIndex:(self size) 
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
   764
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
   765
    "
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
   766
     |a|
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
   767
     a := #(1 2 3 4 5 6).
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
   768
     a removeLast.
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
   769
     a   
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
   770
    "
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
   771
! !
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
   772
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
   773
!SequenceableCollection methodsFor:'comparing'!
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
   774
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
   775
= aCollection
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
   776
    "return true if the receiver and aCollection represent collections
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
   777
     with equal contents."
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
   778
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
   779
    |index "{ Class: SmallInteger }"
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
   780
     stop  "{ Class: SmallInteger }" |
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
    (aCollection == self) ifTrue:[^true].
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
   783
    (aCollection isSequenceable) ifFalse:[^false].
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
   784
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
   785
    stop := self size.
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
   786
    stop == (aCollection size) ifFalse:[^false].
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
    index := 1.
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
   789
    [index <= stop] whileTrue:[
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
   790
	(self at:index) = (aCollection at:index) ifFalse:[^false].
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
   791
	index := index + 1
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
   792
    ].
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
   793
    ^ true
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
   794
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
   795
    "
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
   796
     #(1 2 3 4 5) = #(1 2 3 4 5)                        
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
   797
     #($1 $2 $3 $4 $5) = #(1 2 3 4 5)                   
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
   798
     #($1 $2 $3 $4 $5) = '12345'                       
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
   799
     #($1 $2 $3 $4 $5) = '54321' asSortedCollection   
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
!
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
   802
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
   803
endsWith:aCollection
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
   804
    "return true, if the receivers last elements match those
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
   805
     of aCollection"
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
   806
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
   807
    |index1 "{ Class: SmallInteger }"
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
   808
     index2 "{ Class: SmallInteger }" 
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
   809
     stop   "{ Class: SmallInteger }" 
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
   810
     sz     "{ Class: SmallInteger }"|
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
   811
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
   812
    (aCollection == self) ifTrue:[^ true].
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
   813
    (aCollection isSequenceable) ifFalse:[^ false].
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
    stop := aCollection size.
77
6c38ca59927f *** empty log message ***
claus
parents: 69
diff changeset
   816
    sz := self size.
602
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
   817
    stop > sz ifTrue:[^false].
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
   818
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
   819
    index1 := sz.
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
   820
    index2 := stop.
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
   821
    [index2 > 0] whileTrue:[
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
   822
	(self at:index1) = (aCollection at:index2) ifFalse:[^ false].
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
   823
	index1 := index1 - 1.
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
   824
	index2 := index2 - 1
77
6c38ca59927f *** empty log message ***
claus
parents: 69
diff changeset
   825
    ].
602
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
   826
    ^ true
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
   827
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
   828
    "
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
   829
     'abcde' endsWith:#($d $e)
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
   830
     #[1 2 3 4] endsWith:#(3 4)    
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
   831
     #(1 2 3 4) asOrderedCollection endsWith:#(3 4)
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
   832
    "
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
   833
!
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
   834
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
   835
hash
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
   836
    "return a hash key for the receiver"
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
   837
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
   838
    "this hash is stupid - but for larger collections, the hashing
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
   839
     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
   840
     Time will show ..."
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
   841
3653
cc018fcae490 added #copyReplaceAll:with:
Claus Gittinger <cg@exept.de>
parents: 3645
diff changeset
   842
    |mySize|
cc018fcae490 added #copyReplaceAll:with:
Claus Gittinger <cg@exept.de>
parents: 3645
diff changeset
   843
cc018fcae490 added #copyReplaceAll:with:
Claus Gittinger <cg@exept.de>
parents: 3645
diff changeset
   844
    mySize := self size.
cc018fcae490 added #copyReplaceAll:with:
Claus Gittinger <cg@exept.de>
parents: 3645
diff changeset
   845
    mySize == 0 ifTrue:[^ 0].
cc018fcae490 added #copyReplaceAll:with:
Claus Gittinger <cg@exept.de>
parents: 3645
diff changeset
   846
    ^ ((self at:1) hash times:mySize) bitAnd:16r3FFFFFFF
602
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
   847
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
   848
    "
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
   849
     #(1 2 3 4 5) hash
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
   850
     #(1 2 3 4 5.0) asOrderedCollection hash
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
   851
    "
3653
cc018fcae490 added #copyReplaceAll:with:
Claus Gittinger <cg@exept.de>
parents: 3645
diff changeset
   852
cc018fcae490 added #copyReplaceAll:with:
Claus Gittinger <cg@exept.de>
parents: 3645
diff changeset
   853
    "Modified: / 27.3.1998 / 17:33:49 / cg"
602
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
   854
!
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
   855
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
   856
startsWith:aCollection
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
   857
    "return true, if the receivers first elements match those
4389
3655a0fea430 definite (true) return for zero-length arg in #startsWith:
Claus Gittinger <cg@exept.de>
parents: 4382
diff changeset
   858
     of aCollection
3655a0fea430 definite (true) return for zero-length arg in #startsWith:
Claus Gittinger <cg@exept.de>
parents: 4382
diff changeset
   859
     If the argument is empty, true is returned."
602
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
   860
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
   861
    |index "{ Class: SmallInteger }"
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
   862
     stop  "{ Class: SmallInteger }" |
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
   863
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
   864
    (aCollection == self) ifTrue:[^true].
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
   865
    (aCollection isSequenceable) ifFalse:[^false].
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
   866
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
   867
    stop := aCollection size.
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
   868
    stop > self size ifTrue:[^false].
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
   869
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
   870
    index := 1.
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
   871
    [index <= stop] whileTrue:[
4389
3655a0fea430 definite (true) return for zero-length arg in #startsWith:
Claus Gittinger <cg@exept.de>
parents: 4382
diff changeset
   872
        (self at:index) = (aCollection at:index) ifFalse:[^false].
3655a0fea430 definite (true) return for zero-length arg in #startsWith:
Claus Gittinger <cg@exept.de>
parents: 4382
diff changeset
   873
        index := index + 1
602
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
   874
    ].
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
   875
    ^ true
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
   876
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
   877
    "
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
   878
     'abcde' startsWith:#($a $b $c)
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
   879
     #[1 2 3 4] startsWith:#(1 2 3)
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
   880
     #(1 2 3 4) asOrderedCollection startsWith:#(1 2 3)
4389
3655a0fea430 definite (true) return for zero-length arg in #startsWith:
Claus Gittinger <cg@exept.de>
parents: 4382
diff changeset
   881
     #(1 2 3 4) asOrderedCollection startsWith:#()   
602
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
   882
    "
13
62303f84ff5f *** empty log message ***
claus
parents: 5
diff changeset
   883
! !
62303f84ff5f *** empty log message ***
claus
parents: 5
diff changeset
   884
260
cefb485445a7 *** empty log message ***
claus
parents: 252
diff changeset
   885
!SequenceableCollection methodsFor:'converting'!
cefb485445a7 *** empty log message ***
claus
parents: 252
diff changeset
   886
1413
4788a0d3d6e2 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1395
diff changeset
   887
asStringCollection
4788a0d3d6e2 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1395
diff changeset
   888
    "return a new string collection containing the elements;
4788a0d3d6e2 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1395
diff changeset
   889
     these ought to be strings. (i.e. String or Text instances)"
4788a0d3d6e2 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1395
diff changeset
   890
4788a0d3d6e2 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1395
diff changeset
   891
    |newColl sz|
4788a0d3d6e2 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1395
diff changeset
   892
4788a0d3d6e2 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1395
diff changeset
   893
    sz := self size.
4788a0d3d6e2 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1395
diff changeset
   894
    newColl := (StringCollection new:sz) grow:sz.
4788a0d3d6e2 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1395
diff changeset
   895
    newColl replaceFrom:1 to:sz with:self startingAt:1.
4788a0d3d6e2 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1395
diff changeset
   896
    ^ newColl
4788a0d3d6e2 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1395
diff changeset
   897
4788a0d3d6e2 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1395
diff changeset
   898
    "Created: 18.5.1996 / 13:53:55 / cg"
4788a0d3d6e2 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1395
diff changeset
   899
    "Modified: 18.5.1996 / 14:00:16 / cg"
4788a0d3d6e2 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1395
diff changeset
   900
!
4788a0d3d6e2 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1395
diff changeset
   901
1188
a9efdd724afc more asString methods
ca
parents: 1159
diff changeset
   902
asStringWith:sepChar
a9efdd724afc more asString methods
ca
parents: 1159
diff changeset
   903
    "return a string generated by concatenating my elements 
a9efdd724afc more asString methods
ca
parents: 1159
diff changeset
   904
     (which must be strings or nil) and embedding sepChar characters in between.
a9efdd724afc more asString methods
ca
parents: 1159
diff changeset
   905
     Nil entries and empty strings are counted as empty lines."
a9efdd724afc more asString methods
ca
parents: 1159
diff changeset
   906
a9efdd724afc more asString methods
ca
parents: 1159
diff changeset
   907
    ^ self asStringWith:sepChar from:1 to:(self size)
1413
4788a0d3d6e2 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1395
diff changeset
   908
4788a0d3d6e2 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1395
diff changeset
   909
    "
4788a0d3d6e2 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1395
diff changeset
   910
     #('hello' 'world' 'foo' 'bar' 'baz') asStringWith:$;
4788a0d3d6e2 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1395
diff changeset
   911
    "
4788a0d3d6e2 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1395
diff changeset
   912
4788a0d3d6e2 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1395
diff changeset
   913
    "Modified: 18.5.1996 / 15:28:14 / cg"
1188
a9efdd724afc more asString methods
ca
parents: 1159
diff changeset
   914
!
a9efdd724afc more asString methods
ca
parents: 1159
diff changeset
   915
a9efdd724afc more asString methods
ca
parents: 1159
diff changeset
   916
asStringWith:sepCharacter from:firstLine to:lastLine
a9efdd724afc more asString methods
ca
parents: 1159
diff changeset
   917
    "return part of myself as a string with embedded sepCharacters.
a9efdd724afc more asString methods
ca
parents: 1159
diff changeset
   918
     My elements must be strings or nil; nil entries and empty strings are
a9efdd724afc more asString methods
ca
parents: 1159
diff changeset
   919
     taken as empty lines."
a9efdd724afc more asString methods
ca
parents: 1159
diff changeset
   920
a9efdd724afc more asString methods
ca
parents: 1159
diff changeset
   921
    ^ self 
a9efdd724afc more asString methods
ca
parents: 1159
diff changeset
   922
        asStringWith:sepCharacter 
a9efdd724afc more asString methods
ca
parents: 1159
diff changeset
   923
        from:firstLine 
a9efdd724afc more asString methods
ca
parents: 1159
diff changeset
   924
        to:lastLine
a9efdd724afc more asString methods
ca
parents: 1159
diff changeset
   925
        compressTabs:false
a9efdd724afc more asString methods
ca
parents: 1159
diff changeset
   926
        final:nil
a9efdd724afc more asString methods
ca
parents: 1159
diff changeset
   927
    "
a9efdd724afc more asString methods
ca
parents: 1159
diff changeset
   928
     creating entries for searchpath:
a9efdd724afc more asString methods
ca
parents: 1159
diff changeset
   929
a9efdd724afc more asString methods
ca
parents: 1159
diff changeset
   930
     #('foo' 'bar' 'baz' '/foo/bar') asStringWith:$;   
a9efdd724afc more asString methods
ca
parents: 1159
diff changeset
   931
a9efdd724afc more asString methods
ca
parents: 1159
diff changeset
   932
     #('foo' 'bar' 'baz' '/foo/bar') asStringWith:$: from:1 to:3   
a9efdd724afc more asString methods
ca
parents: 1159
diff changeset
   933
    "
a9efdd724afc more asString methods
ca
parents: 1159
diff changeset
   934
a9efdd724afc more asString methods
ca
parents: 1159
diff changeset
   935
    "Modified: 23.2.1996 / 15:28:55 / cg"
a9efdd724afc more asString methods
ca
parents: 1159
diff changeset
   936
!
a9efdd724afc more asString methods
ca
parents: 1159
diff changeset
   937
260
cefb485445a7 *** empty log message ***
claus
parents: 252
diff changeset
   938
asStringWith:sepCharacter from:firstLine to:lastLine compressTabs:compressTabs final:endCharacter
1395
f324be2221e3 asStringWith:... handles emphasized text
Claus Gittinger <cg@exept.de>
parents: 1385
diff changeset
   939
    "return part of myself as a string or text with embedded sepCharacters.
263
e0195b4ad1ac *** empty log message ***
claus
parents: 260
diff changeset
   940
     My elements must be strings or nil; nil entries and empty strings are
260
cefb485445a7 *** empty log message ***
claus
parents: 252
diff changeset
   941
     taken as empty lines.
cefb485445a7 *** empty log message ***
claus
parents: 252
diff changeset
   942
     If the argument compressTabs is true, leading spaces are converted
cefb485445a7 *** empty log message ***
claus
parents: 252
diff changeset
   943
     to tab-characters (8col tabs). The last line is followed by a final
3602
dd53d372c250 added #asStringWithoutEmphasis...
Claus Gittinger <cg@exept.de>
parents: 3482
diff changeset
   944
     character (if non-nil)."
dd53d372c250 added #asStringWithoutEmphasis...
Claus Gittinger <cg@exept.de>
parents: 3482
diff changeset
   945
dd53d372c250 added #asStringWithoutEmphasis...
Claus Gittinger <cg@exept.de>
parents: 3482
diff changeset
   946
    ^ self
dd53d372c250 added #asStringWithoutEmphasis...
Claus Gittinger <cg@exept.de>
parents: 3482
diff changeset
   947
        asStringWith:sepCharacter 
dd53d372c250 added #asStringWithoutEmphasis...
Claus Gittinger <cg@exept.de>
parents: 3482
diff changeset
   948
        from:firstLine 
dd53d372c250 added #asStringWithoutEmphasis...
Claus Gittinger <cg@exept.de>
parents: 3482
diff changeset
   949
        to:lastLine 
dd53d372c250 added #asStringWithoutEmphasis...
Claus Gittinger <cg@exept.de>
parents: 3482
diff changeset
   950
        compressTabs:compressTabs 
dd53d372c250 added #asStringWithoutEmphasis...
Claus Gittinger <cg@exept.de>
parents: 3482
diff changeset
   951
        final:endCharacter 
dd53d372c250 added #asStringWithoutEmphasis...
Claus Gittinger <cg@exept.de>
parents: 3482
diff changeset
   952
        withEmphasis:true
dd53d372c250 added #asStringWithoutEmphasis...
Claus Gittinger <cg@exept.de>
parents: 3482
diff changeset
   953
dd53d372c250 added #asStringWithoutEmphasis...
Claus Gittinger <cg@exept.de>
parents: 3482
diff changeset
   954
    "Modified: / 17.6.1998 / 12:31:19 / cg"
dd53d372c250 added #asStringWithoutEmphasis...
Claus Gittinger <cg@exept.de>
parents: 3482
diff changeset
   955
!
dd53d372c250 added #asStringWithoutEmphasis...
Claus Gittinger <cg@exept.de>
parents: 3482
diff changeset
   956
dd53d372c250 added #asStringWithoutEmphasis...
Claus Gittinger <cg@exept.de>
parents: 3482
diff changeset
   957
asStringWith:sepCharacter from:firstLine to:lastLine compressTabs:compressTabs final:endCharacter withEmphasis:withEmphasis
dd53d372c250 added #asStringWithoutEmphasis...
Claus Gittinger <cg@exept.de>
parents: 3482
diff changeset
   958
    "return part of myself as a string or text with embedded sepCharacters.
dd53d372c250 added #asStringWithoutEmphasis...
Claus Gittinger <cg@exept.de>
parents: 3482
diff changeset
   959
     My elements must be strings or nil; nil entries and empty strings are
dd53d372c250 added #asStringWithoutEmphasis...
Claus Gittinger <cg@exept.de>
parents: 3482
diff changeset
   960
     taken as empty lines.
dd53d372c250 added #asStringWithoutEmphasis...
Claus Gittinger <cg@exept.de>
parents: 3482
diff changeset
   961
     If the argument compressTabs is true, leading spaces are converted
dd53d372c250 added #asStringWithoutEmphasis...
Claus Gittinger <cg@exept.de>
parents: 3482
diff changeset
   962
     to tab-characters (8col tabs). The last line is followed by a final
260
cefb485445a7 *** empty log message ***
claus
parents: 252
diff changeset
   963
     character (if non-nil).
3602
dd53d372c250 added #asStringWithoutEmphasis...
Claus Gittinger <cg@exept.de>
parents: 3482
diff changeset
   964
     The withEmphais argument controls if the returned string should preserve
dd53d372c250 added #asStringWithoutEmphasis...
Claus Gittinger <cg@exept.de>
parents: 3482
diff changeset
   965
     any emphasis. If false, a plain string is returned.
260
cefb485445a7 *** empty log message ***
claus
parents: 252
diff changeset
   966
     This method is tuned for big collections, in not creating many
263
e0195b4ad1ac *** empty log message ***
claus
parents: 260
diff changeset
   967
     intermediate strings (has linear runtime). For very small collections
e0195b4ad1ac *** empty log message ***
claus
parents: 260
diff changeset
   968
     and small strings, it may be faster to use the comma , operation."
260
cefb485445a7 *** empty log message ***
claus
parents: 252
diff changeset
   969
293
31df3850e98c *** empty log message ***
claus
parents: 282
diff changeset
   970
    |idx1        "{ Class:SmallInteger }"
31df3850e98c *** empty log message ***
claus
parents: 282
diff changeset
   971
     idx2        "{ Class:SmallInteger }"
31df3850e98c *** empty log message ***
claus
parents: 282
diff changeset
   972
     totalLength "{ Class:SmallInteger }"
260
cefb485445a7 *** empty log message ***
claus
parents: 252
diff changeset
   973
     pos         "{ Class:SmallInteger }"
1003
c82f2dcf5611 care for embedded 16bit strings when concatenating a stringCollection
Claus Gittinger <cg@exept.de>
parents: 929
diff changeset
   974
     newString lineString spaces idx nTabs sepCnt
1536
29d45204ceed tuned #asStringWith:... if any Text lines with emphasis are involved.
Claus Gittinger <cg@exept.de>
parents: 1495
diff changeset
   975
     any16Bit stringClass needEmphasis newRuns c
29d45204ceed tuned #asStringWith:... if any Text lines with emphasis are involved.
Claus Gittinger <cg@exept.de>
parents: 1495
diff changeset
   976
     thisLen anyTab|
260
cefb485445a7 *** empty log message ***
claus
parents: 252
diff changeset
   977
cefb485445a7 *** empty log message ***
claus
parents: 252
diff changeset
   978
    "
cefb485445a7 *** empty log message ***
claus
parents: 252
diff changeset
   979
     first accumulate the size of the string, to avoid
cefb485445a7 *** empty log message ***
claus
parents: 252
diff changeset
   980
     countless reallocations. If tabs are compressed,
cefb485445a7 *** empty log message ***
claus
parents: 252
diff changeset
   981
     the size computed is not exact, but gives an upper bound ...
1413
4788a0d3d6e2 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1395
diff changeset
   982
     On the fly, look if a 16bit string or emphasized text is needed.
260
cefb485445a7 *** empty log message ***
claus
parents: 252
diff changeset
   983
    "
1395
f324be2221e3 asStringWith:... handles emphasized text
Claus Gittinger <cg@exept.de>
parents: 1385
diff changeset
   984
    any16Bit := needEmphasis := false.
1015
a564efc63383 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1003
diff changeset
   985
    stringClass := String.
a564efc63383 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1003
diff changeset
   986
260
cefb485445a7 *** empty log message ***
claus
parents: 252
diff changeset
   987
    totalLength := 0.
cefb485445a7 *** empty log message ***
claus
parents: 252
diff changeset
   988
    sepCnt := sepCharacter notNil ifTrue:[1] ifFalse:[0].
cefb485445a7 *** empty log message ***
claus
parents: 252
diff changeset
   989
293
31df3850e98c *** empty log message ***
claus
parents: 282
diff changeset
   990
    idx1 := firstLine.
31df3850e98c *** empty log message ***
claus
parents: 282
diff changeset
   991
    idx2 := lastLine.
31df3850e98c *** empty log message ***
claus
parents: 282
diff changeset
   992
    idx1 to:idx2 do:[:lineIndex |
1395
f324be2221e3 asStringWith:... handles emphasized text
Claus Gittinger <cg@exept.de>
parents: 1385
diff changeset
   993
        lineString := self at:lineIndex.
f324be2221e3 asStringWith:... handles emphasized text
Claus Gittinger <cg@exept.de>
parents: 1385
diff changeset
   994
f324be2221e3 asStringWith:... handles emphasized text
Claus Gittinger <cg@exept.de>
parents: 1385
diff changeset
   995
        lineString isNil ifTrue:[
f324be2221e3 asStringWith:... handles emphasized text
Claus Gittinger <cg@exept.de>
parents: 1385
diff changeset
   996
            totalLength := totalLength + sepCnt
f324be2221e3 asStringWith:... handles emphasized text
Claus Gittinger <cg@exept.de>
parents: 1385
diff changeset
   997
        ] ifFalse: [
3602
dd53d372c250 added #asStringWithoutEmphasis...
Claus Gittinger <cg@exept.de>
parents: 3482
diff changeset
   998
            withEmphasis ifTrue:[
dd53d372c250 added #asStringWithoutEmphasis...
Claus Gittinger <cg@exept.de>
parents: 3482
diff changeset
   999
                lineString hasChangeOfEmphasis ifTrue:[
dd53d372c250 added #asStringWithoutEmphasis...
Claus Gittinger <cg@exept.de>
parents: 3482
diff changeset
  1000
                    needEmphasis := true
dd53d372c250 added #asStringWithoutEmphasis...
Claus Gittinger <cg@exept.de>
parents: 3482
diff changeset
  1001
                ].
dd53d372c250 added #asStringWithoutEmphasis...
Claus Gittinger <cg@exept.de>
parents: 3482
diff changeset
  1002
                (lineString bitsPerCharacter == 16) ifTrue:[
dd53d372c250 added #asStringWithoutEmphasis...
Claus Gittinger <cg@exept.de>
parents: 3482
diff changeset
  1003
                    any16Bit := true.
dd53d372c250 added #asStringWithoutEmphasis...
Claus Gittinger <cg@exept.de>
parents: 3482
diff changeset
  1004
                    stringClass := lineString class
dd53d372c250 added #asStringWithoutEmphasis...
Claus Gittinger <cg@exept.de>
parents: 3482
diff changeset
  1005
                ].
1395
f324be2221e3 asStringWith:... handles emphasized text
Claus Gittinger <cg@exept.de>
parents: 1385
diff changeset
  1006
            ].
f324be2221e3 asStringWith:... handles emphasized text
Claus Gittinger <cg@exept.de>
parents: 1385
diff changeset
  1007
            totalLength := totalLength + lineString size + sepCnt
f324be2221e3 asStringWith:... handles emphasized text
Claus Gittinger <cg@exept.de>
parents: 1385
diff changeset
  1008
        ].
260
cefb485445a7 *** empty log message ***
claus
parents: 252
diff changeset
  1009
    ].
cefb485445a7 *** empty log message ***
claus
parents: 252
diff changeset
  1010
    endCharacter isNil ifTrue:[
1673
eea933dbf42d care for empty collection in #asStringWith:...
Claus Gittinger <cg@exept.de>
parents: 1537
diff changeset
  1011
        totalLength := totalLength - 1.
eea933dbf42d care for empty collection in #asStringWith:...
Claus Gittinger <cg@exept.de>
parents: 1537
diff changeset
  1012
        totalLength < 0 ifTrue:[^ ''].
260
cefb485445a7 *** empty log message ***
claus
parents: 252
diff changeset
  1013
    ].
cefb485445a7 *** empty log message ***
claus
parents: 252
diff changeset
  1014
    spaces := '        '.
1016
9588a8d5a64e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1015
diff changeset
  1015
    newString := stringClass new:totalLength.
1536
29d45204ceed tuned #asStringWith:... if any Text lines with emphasis are involved.
Claus Gittinger <cg@exept.de>
parents: 1495
diff changeset
  1016
1395
f324be2221e3 asStringWith:... handles emphasized text
Claus Gittinger <cg@exept.de>
parents: 1385
diff changeset
  1017
    needEmphasis ifTrue:[
1536
29d45204ceed tuned #asStringWith:... if any Text lines with emphasis are involved.
Claus Gittinger <cg@exept.de>
parents: 1495
diff changeset
  1018
        newRuns := RunArray new.
1395
f324be2221e3 asStringWith:... handles emphasized text
Claus Gittinger <cg@exept.de>
parents: 1385
diff changeset
  1019
    ].
260
cefb485445a7 *** empty log message ***
claus
parents: 252
diff changeset
  1020
cefb485445a7 *** empty log message ***
claus
parents: 252
diff changeset
  1021
    "
cefb485445a7 *** empty log message ***
claus
parents: 252
diff changeset
  1022
     now, replace ...
1536
29d45204ceed tuned #asStringWith:... if any Text lines with emphasis are involved.
Claus Gittinger <cg@exept.de>
parents: 1495
diff changeset
  1023
     Be careful with runArrays:
29d45204ceed tuned #asStringWith:... if any Text lines with emphasis are involved.
Claus Gittinger <cg@exept.de>
parents: 1495
diff changeset
  1024
        replacing individual elements is VERY expensive.
29d45204ceed tuned #asStringWith:... if any Text lines with emphasis are involved.
Claus Gittinger <cg@exept.de>
parents: 1495
diff changeset
  1025
        Therefore, create a new runArray from scratch.
260
cefb485445a7 *** empty log message ***
claus
parents: 252
diff changeset
  1026
    "
cefb485445a7 *** empty log message ***
claus
parents: 252
diff changeset
  1027
    pos := 1.
293
31df3850e98c *** empty log message ***
claus
parents: 282
diff changeset
  1028
    idx1 to:idx2 do:[:lineIndex |
1395
f324be2221e3 asStringWith:... handles emphasized text
Claus Gittinger <cg@exept.de>
parents: 1385
diff changeset
  1029
        lineString := self at:lineIndex.
f324be2221e3 asStringWith:... handles emphasized text
Claus Gittinger <cg@exept.de>
parents: 1385
diff changeset
  1030
        thisLen := lineString size.
f324be2221e3 asStringWith:... handles emphasized text
Claus Gittinger <cg@exept.de>
parents: 1385
diff changeset
  1031
        thisLen ~~ 0 ifTrue:[
3602
dd53d372c250 added #asStringWithoutEmphasis...
Claus Gittinger <cg@exept.de>
parents: 3482
diff changeset
  1032
            withEmphasis ifFalse:[
dd53d372c250 added #asStringWithoutEmphasis...
Claus Gittinger <cg@exept.de>
parents: 3482
diff changeset
  1033
                lineString := lineString string.
dd53d372c250 added #asStringWithoutEmphasis...
Claus Gittinger <cg@exept.de>
parents: 3482
diff changeset
  1034
            ].
dd53d372c250 added #asStringWithoutEmphasis...
Claus Gittinger <cg@exept.de>
parents: 3482
diff changeset
  1035
1536
29d45204ceed tuned #asStringWith:... if any Text lines with emphasis are involved.
Claus Gittinger <cg@exept.de>
parents: 1495
diff changeset
  1036
            (anyTab := compressTabs) ifTrue:[
1395
f324be2221e3 asStringWith:... handles emphasized text
Claus Gittinger <cg@exept.de>
parents: 1385
diff changeset
  1037
                "
f324be2221e3 asStringWith:... handles emphasized text
Claus Gittinger <cg@exept.de>
parents: 1385
diff changeset
  1038
                 mhmh: could use withTabs from String-class here,
f324be2221e3 asStringWith:... handles emphasized text
Claus Gittinger <cg@exept.de>
parents: 1385
diff changeset
  1039
                 but we should avoid creating too many temporary strings
f324be2221e3 asStringWith:... handles emphasized text
Claus Gittinger <cg@exept.de>
parents: 1385
diff changeset
  1040
                 (especially, since this method is typically used when converting
f324be2221e3 asStringWith:... handles emphasized text
Claus Gittinger <cg@exept.de>
parents: 1385
diff changeset
  1041
                 big texts such as when saving in the filebrowser ...).
f324be2221e3 asStringWith:... handles emphasized text
Claus Gittinger <cg@exept.de>
parents: 1385
diff changeset
  1042
                 Therefore, we convert tabs inline here doing a direct replace
f324be2221e3 asStringWith:... handles emphasized text
Claus Gittinger <cg@exept.de>
parents: 1385
diff changeset
  1043
                 in newString."
f324be2221e3 asStringWith:... handles emphasized text
Claus Gittinger <cg@exept.de>
parents: 1385
diff changeset
  1044
f324be2221e3 asStringWith:... handles emphasized text
Claus Gittinger <cg@exept.de>
parents: 1385
diff changeset
  1045
                idx := lineString findFirst:[:c | (c ~~ Character space)].
f324be2221e3 asStringWith:... handles emphasized text
Claus Gittinger <cg@exept.de>
parents: 1385
diff changeset
  1046
                nTabs := (idx-1) // 8.
f324be2221e3 asStringWith:... handles emphasized text
Claus Gittinger <cg@exept.de>
parents: 1385
diff changeset
  1047
                nTabs ~~ 0 ifTrue:[
1536
29d45204ceed tuned #asStringWith:... if any Text lines with emphasis are involved.
Claus Gittinger <cg@exept.de>
parents: 1495
diff changeset
  1048
                    anyTab := true
29d45204ceed tuned #asStringWith:... if any Text lines with emphasis are involved.
Claus Gittinger <cg@exept.de>
parents: 1495
diff changeset
  1049
                ]
29d45204ceed tuned #asStringWith:... if any Text lines with emphasis are involved.
Claus Gittinger <cg@exept.de>
parents: 1495
diff changeset
  1050
            ].
29d45204ceed tuned #asStringWith:... if any Text lines with emphasis are involved.
Claus Gittinger <cg@exept.de>
parents: 1495
diff changeset
  1051
            anyTab ifTrue:[
29d45204ceed tuned #asStringWith:... if any Text lines with emphasis are involved.
Claus Gittinger <cg@exept.de>
parents: 1495
diff changeset
  1052
                "any tabs"
29d45204ceed tuned #asStringWith:... if any Text lines with emphasis are involved.
Claus Gittinger <cg@exept.de>
parents: 1495
diff changeset
  1053
29d45204ceed tuned #asStringWith:... if any Text lines with emphasis are involved.
Claus Gittinger <cg@exept.de>
parents: 1495
diff changeset
  1054
                idx := nTabs * 8 + 1.   "/ index of first copied character in string
29d45204ceed tuned #asStringWith:... if any Text lines with emphasis are involved.
Claus Gittinger <cg@exept.de>
parents: 1495
diff changeset
  1055
29d45204ceed tuned #asStringWith:... if any Text lines with emphasis are involved.
Claus Gittinger <cg@exept.de>
parents: 1495
diff changeset
  1056
                newString atAll:(pos to:pos+nTabs-1) put:(Character tab).
29d45204ceed tuned #asStringWith:... if any Text lines with emphasis are involved.
Claus Gittinger <cg@exept.de>
parents: 1495
diff changeset
  1057
                newRuns notNil ifTrue:[
29d45204ceed tuned #asStringWith:... if any Text lines with emphasis are involved.
Claus Gittinger <cg@exept.de>
parents: 1495
diff changeset
  1058
                    newRuns add:nil withOccurrences:nTabs
1395
f324be2221e3 asStringWith:... handles emphasized text
Claus Gittinger <cg@exept.de>
parents: 1385
diff changeset
  1059
                ].
1536
29d45204ceed tuned #asStringWith:... if any Text lines with emphasis are involved.
Claus Gittinger <cg@exept.de>
parents: 1495
diff changeset
  1060
                pos := pos + nTabs.
29d45204ceed tuned #asStringWith:... if any Text lines with emphasis are involved.
Claus Gittinger <cg@exept.de>
parents: 1495
diff changeset
  1061
29d45204ceed tuned #asStringWith:... if any Text lines with emphasis are involved.
Claus Gittinger <cg@exept.de>
parents: 1495
diff changeset
  1062
                newString replaceFrom:pos with:lineString startingAt:idx.
29d45204ceed tuned #asStringWith:... if any Text lines with emphasis are involved.
Claus Gittinger <cg@exept.de>
parents: 1495
diff changeset
  1063
                newRuns notNil ifTrue:[
29d45204ceed tuned #asStringWith:... if any Text lines with emphasis are involved.
Claus Gittinger <cg@exept.de>
parents: 1495
diff changeset
  1064
                    lineString hasChangeOfEmphasis ifTrue:[
2860
760052935b5a oops - asStringWith: was wrong
Claus Gittinger <cg@exept.de>
parents: 2610
diff changeset
  1065
                        idx to:lineString size do:[:pos |
1536
29d45204ceed tuned #asStringWith:... if any Text lines with emphasis are involved.
Claus Gittinger <cg@exept.de>
parents: 1495
diff changeset
  1066
                            newRuns add:(lineString emphasisAt:pos)
29d45204ceed tuned #asStringWith:... if any Text lines with emphasis are involved.
Claus Gittinger <cg@exept.de>
parents: 1495
diff changeset
  1067
                        ]    
29d45204ceed tuned #asStringWith:... if any Text lines with emphasis are involved.
Claus Gittinger <cg@exept.de>
parents: 1495
diff changeset
  1068
                    ] ifFalse:[
29d45204ceed tuned #asStringWith:... if any Text lines with emphasis are involved.
Claus Gittinger <cg@exept.de>
parents: 1495
diff changeset
  1069
                        newRuns add:nil withOccurrences:(lineString size - idx + 1)
29d45204ceed tuned #asStringWith:... if any Text lines with emphasis are involved.
Claus Gittinger <cg@exept.de>
parents: 1495
diff changeset
  1070
                    ]
29d45204ceed tuned #asStringWith:... if any Text lines with emphasis are involved.
Claus Gittinger <cg@exept.de>
parents: 1495
diff changeset
  1071
                ].
29d45204ceed tuned #asStringWith:... if any Text lines with emphasis are involved.
Claus Gittinger <cg@exept.de>
parents: 1495
diff changeset
  1072
                pos := pos + thisLen - (nTabs * 8).
1395
f324be2221e3 asStringWith:... handles emphasized text
Claus Gittinger <cg@exept.de>
parents: 1385
diff changeset
  1073
            ] ifFalse:[
f324be2221e3 asStringWith:... handles emphasized text
Claus Gittinger <cg@exept.de>
parents: 1385
diff changeset
  1074
                newString replaceFrom:pos with:lineString.
1536
29d45204ceed tuned #asStringWith:... if any Text lines with emphasis are involved.
Claus Gittinger <cg@exept.de>
parents: 1495
diff changeset
  1075
29d45204ceed tuned #asStringWith:... if any Text lines with emphasis are involved.
Claus Gittinger <cg@exept.de>
parents: 1495
diff changeset
  1076
                newRuns notNil ifTrue:[
29d45204ceed tuned #asStringWith:... if any Text lines with emphasis are involved.
Claus Gittinger <cg@exept.de>
parents: 1495
diff changeset
  1077
                    lineString hasChangeOfEmphasis ifTrue:[
29d45204ceed tuned #asStringWith:... if any Text lines with emphasis are involved.
Claus Gittinger <cg@exept.de>
parents: 1495
diff changeset
  1078
                        newRuns addAll:(lineString emphasis)
29d45204ceed tuned #asStringWith:... if any Text lines with emphasis are involved.
Claus Gittinger <cg@exept.de>
parents: 1495
diff changeset
  1079
                    ] ifFalse:[
29d45204ceed tuned #asStringWith:... if any Text lines with emphasis are involved.
Claus Gittinger <cg@exept.de>
parents: 1495
diff changeset
  1080
                        newRuns add:nil withOccurrences:lineString size
29d45204ceed tuned #asStringWith:... if any Text lines with emphasis are involved.
Claus Gittinger <cg@exept.de>
parents: 1495
diff changeset
  1081
                    ]
29d45204ceed tuned #asStringWith:... if any Text lines with emphasis are involved.
Claus Gittinger <cg@exept.de>
parents: 1495
diff changeset
  1082
                ].
29d45204ceed tuned #asStringWith:... if any Text lines with emphasis are involved.
Claus Gittinger <cg@exept.de>
parents: 1495
diff changeset
  1083
                pos := pos + thisLen.
29d45204ceed tuned #asStringWith:... if any Text lines with emphasis are involved.
Claus Gittinger <cg@exept.de>
parents: 1495
diff changeset
  1084
            ].
1395
f324be2221e3 asStringWith:... handles emphasized text
Claus Gittinger <cg@exept.de>
parents: 1385
diff changeset
  1085
        ].
1536
29d45204ceed tuned #asStringWith:... if any Text lines with emphasis are involved.
Claus Gittinger <cg@exept.de>
parents: 1495
diff changeset
  1086
29d45204ceed tuned #asStringWith:... if any Text lines with emphasis are involved.
Claus Gittinger <cg@exept.de>
parents: 1495
diff changeset
  1087
        lineIndex ~~ lastLine ifTrue:[
29d45204ceed tuned #asStringWith:... if any Text lines with emphasis are involved.
Claus Gittinger <cg@exept.de>
parents: 1495
diff changeset
  1088
            c := sepCharacter
29d45204ceed tuned #asStringWith:... if any Text lines with emphasis are involved.
Claus Gittinger <cg@exept.de>
parents: 1495
diff changeset
  1089
        ] ifFalse:[
29d45204ceed tuned #asStringWith:... if any Text lines with emphasis are involved.
Claus Gittinger <cg@exept.de>
parents: 1495
diff changeset
  1090
            c := endCharacter
29d45204ceed tuned #asStringWith:... if any Text lines with emphasis are involved.
Claus Gittinger <cg@exept.de>
parents: 1495
diff changeset
  1091
        ].
29d45204ceed tuned #asStringWith:... if any Text lines with emphasis are involved.
Claus Gittinger <cg@exept.de>
parents: 1495
diff changeset
  1092
29d45204ceed tuned #asStringWith:... if any Text lines with emphasis are involved.
Claus Gittinger <cg@exept.de>
parents: 1495
diff changeset
  1093
        c notNil ifTrue:[
29d45204ceed tuned #asStringWith:... if any Text lines with emphasis are involved.
Claus Gittinger <cg@exept.de>
parents: 1495
diff changeset
  1094
            newString at:pos put:c.
29d45204ceed tuned #asStringWith:... if any Text lines with emphasis are involved.
Claus Gittinger <cg@exept.de>
parents: 1495
diff changeset
  1095
            newRuns notNil ifTrue:[
29d45204ceed tuned #asStringWith:... if any Text lines with emphasis are involved.
Claus Gittinger <cg@exept.de>
parents: 1495
diff changeset
  1096
                newRuns add:nil.
29d45204ceed tuned #asStringWith:... if any Text lines with emphasis are involved.
Claus Gittinger <cg@exept.de>
parents: 1495
diff changeset
  1097
            ].
1395
f324be2221e3 asStringWith:... handles emphasized text
Claus Gittinger <cg@exept.de>
parents: 1385
diff changeset
  1098
            pos := pos + 1
1536
29d45204ceed tuned #asStringWith:... if any Text lines with emphasis are involved.
Claus Gittinger <cg@exept.de>
parents: 1495
diff changeset
  1099
        ].
260
cefb485445a7 *** empty log message ***
claus
parents: 252
diff changeset
  1100
    ].
cefb485445a7 *** empty log message ***
claus
parents: 252
diff changeset
  1101
cefb485445a7 *** empty log message ***
claus
parents: 252
diff changeset
  1102
    "
cefb485445a7 *** empty log message ***
claus
parents: 252
diff changeset
  1103
     in case of tab compression, the result has to be
cefb485445a7 *** empty log message ***
claus
parents: 252
diff changeset
  1104
     cut to size ... sorry
cefb485445a7 *** empty log message ***
claus
parents: 252
diff changeset
  1105
    "
cefb485445a7 *** empty log message ***
claus
parents: 252
diff changeset
  1106
    pos ~~ totalLength ifTrue:[
1536
29d45204ceed tuned #asStringWith:... if any Text lines with emphasis are involved.
Claus Gittinger <cg@exept.de>
parents: 1495
diff changeset
  1107
        newString := newString copyTo:(pos - 1)
260
cefb485445a7 *** empty log message ***
claus
parents: 252
diff changeset
  1108
    ].
1536
29d45204ceed tuned #asStringWith:... if any Text lines with emphasis are involved.
Claus Gittinger <cg@exept.de>
parents: 1495
diff changeset
  1109
29d45204ceed tuned #asStringWith:... if any Text lines with emphasis are involved.
Claus Gittinger <cg@exept.de>
parents: 1495
diff changeset
  1110
    newRuns notNil ifTrue:[
29d45204ceed tuned #asStringWith:... if any Text lines with emphasis are involved.
Claus Gittinger <cg@exept.de>
parents: 1495
diff changeset
  1111
        newString := Text string:newString runs:newRuns.
29d45204ceed tuned #asStringWith:... if any Text lines with emphasis are involved.
Claus Gittinger <cg@exept.de>
parents: 1495
diff changeset
  1112
    ].
29d45204ceed tuned #asStringWith:... if any Text lines with emphasis are involved.
Claus Gittinger <cg@exept.de>
parents: 1495
diff changeset
  1113
260
cefb485445a7 *** empty log message ***
claus
parents: 252
diff changeset
  1114
    ^ newString
cefb485445a7 *** empty log message ***
claus
parents: 252
diff changeset
  1115
cefb485445a7 *** empty log message ***
claus
parents: 252
diff changeset
  1116
    "
cefb485445a7 *** empty log message ***
claus
parents: 252
diff changeset
  1117
     creating entries for searchpath:
cefb485445a7 *** empty log message ***
claus
parents: 252
diff changeset
  1118
1395
f324be2221e3 asStringWith:... handles emphasized text
Claus Gittinger <cg@exept.de>
parents: 1385
diff changeset
  1119
       #('foo' 'bar' 'baz' '/foo/bar') 
f324be2221e3 asStringWith:... handles emphasized text
Claus Gittinger <cg@exept.de>
parents: 1385
diff changeset
  1120
          asStringWith:$: 
f324be2221e3 asStringWith:... handles emphasized text
Claus Gittinger <cg@exept.de>
parents: 1385
diff changeset
  1121
          from:1 to:4 
f324be2221e3 asStringWith:... handles emphasized text
Claus Gittinger <cg@exept.de>
parents: 1385
diff changeset
  1122
          compressTabs:false 
f324be2221e3 asStringWith:... handles emphasized text
Claus Gittinger <cg@exept.de>
parents: 1385
diff changeset
  1123
          final:nil 
260
cefb485445a7 *** empty log message ***
claus
parents: 252
diff changeset
  1124
cefb485445a7 *** empty log message ***
claus
parents: 252
diff changeset
  1125
     with trailing colon:
cefb485445a7 *** empty log message ***
claus
parents: 252
diff changeset
  1126
1395
f324be2221e3 asStringWith:... handles emphasized text
Claus Gittinger <cg@exept.de>
parents: 1385
diff changeset
  1127
       #('foo' 'bar' 'baz' '/foo/bar') 
f324be2221e3 asStringWith:... handles emphasized text
Claus Gittinger <cg@exept.de>
parents: 1385
diff changeset
  1128
          asStringWith:$: 
f324be2221e3 asStringWith:... handles emphasized text
Claus Gittinger <cg@exept.de>
parents: 1385
diff changeset
  1129
          from:1 to:4 
f324be2221e3 asStringWith:... handles emphasized text
Claus Gittinger <cg@exept.de>
parents: 1385
diff changeset
  1130
          compressTabs:false 
f324be2221e3 asStringWith:... handles emphasized text
Claus Gittinger <cg@exept.de>
parents: 1385
diff changeset
  1131
          final:$: 
260
cefb485445a7 *** empty log message ***
claus
parents: 252
diff changeset
  1132
cefb485445a7 *** empty log message ***
claus
parents: 252
diff changeset
  1133
     concatenating all elements:
cefb485445a7 *** empty log message ***
claus
parents: 252
diff changeset
  1134
1395
f324be2221e3 asStringWith:... handles emphasized text
Claus Gittinger <cg@exept.de>
parents: 1385
diff changeset
  1135
       #('foo' 'bar' 'baz') 
f324be2221e3 asStringWith:... handles emphasized text
Claus Gittinger <cg@exept.de>
parents: 1385
diff changeset
  1136
          asStringWith:nil 
f324be2221e3 asStringWith:... handles emphasized text
Claus Gittinger <cg@exept.de>
parents: 1385
diff changeset
  1137
          from:1 to:3 
f324be2221e3 asStringWith:... handles emphasized text
Claus Gittinger <cg@exept.de>
parents: 1385
diff changeset
  1138
          compressTabs:false 
f324be2221e3 asStringWith:... handles emphasized text
Claus Gittinger <cg@exept.de>
parents: 1385
diff changeset
  1139
          final:nil 
260
cefb485445a7 *** empty log message ***
claus
parents: 252
diff changeset
  1140
cefb485445a7 *** empty log message ***
claus
parents: 252
diff changeset
  1141
     creating a string from a collection of lines:
cefb485445a7 *** empty log message ***
claus
parents: 252
diff changeset
  1142
1395
f324be2221e3 asStringWith:... handles emphasized text
Claus Gittinger <cg@exept.de>
parents: 1385
diff changeset
  1143
       #('foo' 'bar' 'baz') 
f324be2221e3 asStringWith:... handles emphasized text
Claus Gittinger <cg@exept.de>
parents: 1385
diff changeset
  1144
          asStringWith:(Character cr) 
f324be2221e3 asStringWith:... handles emphasized text
Claus Gittinger <cg@exept.de>
parents: 1385
diff changeset
  1145
          from:1 to:3 
f324be2221e3 asStringWith:... handles emphasized text
Claus Gittinger <cg@exept.de>
parents: 1385
diff changeset
  1146
          compressTabs:false 
f324be2221e3 asStringWith:... handles emphasized text
Claus Gittinger <cg@exept.de>
parents: 1385
diff changeset
  1147
          final:(Character cr) 
f324be2221e3 asStringWith:... handles emphasized text
Claus Gittinger <cg@exept.de>
parents: 1385
diff changeset
  1148
f324be2221e3 asStringWith:... handles emphasized text
Claus Gittinger <cg@exept.de>
parents: 1385
diff changeset
  1149
     creating a text from a collection of mixed texts and strings:
f324be2221e3 asStringWith:... handles emphasized text
Claus Gittinger <cg@exept.de>
parents: 1385
diff changeset
  1150
f324be2221e3 asStringWith:... handles emphasized text
Claus Gittinger <cg@exept.de>
parents: 1385
diff changeset
  1151
       (Array
f324be2221e3 asStringWith:... handles emphasized text
Claus Gittinger <cg@exept.de>
parents: 1385
diff changeset
  1152
            with:'foo'
f324be2221e3 asStringWith:... handles emphasized text
Claus Gittinger <cg@exept.de>
parents: 1385
diff changeset
  1153
            with:('bar' asText allBold)
f324be2221e3 asStringWith:... handles emphasized text
Claus Gittinger <cg@exept.de>
parents: 1385
diff changeset
  1154
            with:'baz'
f324be2221e3 asStringWith:... handles emphasized text
Claus Gittinger <cg@exept.de>
parents: 1385
diff changeset
  1155
            with:('baz2' asText emphasizeAllWith:#italic)
f324be2221e3 asStringWith:... handles emphasized text
Claus Gittinger <cg@exept.de>
parents: 1385
diff changeset
  1156
       ) 
f324be2221e3 asStringWith:... handles emphasized text
Claus Gittinger <cg@exept.de>
parents: 1385
diff changeset
  1157
          asStringWith:(Character cr) 
f324be2221e3 asStringWith:... handles emphasized text
Claus Gittinger <cg@exept.de>
parents: 1385
diff changeset
  1158
          from:1 to:4 
f324be2221e3 asStringWith:... handles emphasized text
Claus Gittinger <cg@exept.de>
parents: 1385
diff changeset
  1159
          compressTabs:false 
f324be2221e3 asStringWith:... handles emphasized text
Claus Gittinger <cg@exept.de>
parents: 1385
diff changeset
  1160
          final:(Character cr) 
260
cefb485445a7 *** empty log message ***
claus
parents: 252
diff changeset
  1161
    "
1003
c82f2dcf5611 care for embedded 16bit strings when concatenating a stringCollection
Claus Gittinger <cg@exept.de>
parents: 929
diff changeset
  1162
3602
dd53d372c250 added #asStringWithoutEmphasis...
Claus Gittinger <cg@exept.de>
parents: 3482
diff changeset
  1163
    "Created: / 17.6.1998 / 12:30:32 / cg"
dd53d372c250 added #asStringWithoutEmphasis...
Claus Gittinger <cg@exept.de>
parents: 3482
diff changeset
  1164
    "Modified: / 17.6.1998 / 12:31:59 / cg"
379
5b5a130ccd09 revision added
claus
parents: 375
diff changeset
  1165
!
5b5a130ccd09 revision added
claus
parents: 375
diff changeset
  1166
602
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  1167
asStringWithCRs
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  1168
    "return a string generated by concatenating my elements 
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  1169
     (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
  1170
     Nil entries and empty strings are counted as empty lines."
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  1171
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  1172
    ^ self asStringWithCRsFrom:1 to:(self size)
1413
4788a0d3d6e2 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1395
diff changeset
  1173
4788a0d3d6e2 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1395
diff changeset
  1174
    "
4788a0d3d6e2 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1395
diff changeset
  1175
     #('hello' 'world' 'foo' 'bar' 'baz') asStringWithCRs 
4788a0d3d6e2 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1395
diff changeset
  1176
4788a0d3d6e2 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1395
diff changeset
  1177
     (OrderedCollection new
4788a0d3d6e2 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1395
diff changeset
  1178
        add:'hello'; 
4788a0d3d6e2 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1395
diff changeset
  1179
        add:'world';
4788a0d3d6e2 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1395
diff changeset
  1180
        add:'foo';
4788a0d3d6e2 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1395
diff changeset
  1181
        add:('bar' asText allBold);
4788a0d3d6e2 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1395
diff changeset
  1182
        yourself) asStringWithCRs
1421
7224371d514c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1413
diff changeset
  1183
1422
9a0b792f2953 showCr: -> showCR:
Claus Gittinger <cg@exept.de>
parents: 1421
diff changeset
  1184
     Transcript showCR:
1421
7224371d514c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1413
diff changeset
  1185
         (OrderedCollection new
7224371d514c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1413
diff changeset
  1186
            add:'hello'; 
7224371d514c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1413
diff changeset
  1187
            add:'world';
7224371d514c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1413
diff changeset
  1188
            add:'foo';
7224371d514c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1413
diff changeset
  1189
            add:('bar' asText allBold);
7224371d514c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1413
diff changeset
  1190
            yourself) asStringWithCRs
1413
4788a0d3d6e2 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1395
diff changeset
  1191
    "
4788a0d3d6e2 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1395
diff changeset
  1192
1421
7224371d514c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1413
diff changeset
  1193
    "Modified: 18.5.1996 / 16:43:47 / cg"
602
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  1194
!
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  1195
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  1196
asStringWithCRsFrom:firstLine to:lastLine
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  1197
    "return a string generated by concatenating some of my elements 
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  1198
     (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
  1199
     Nil entries and empty strings are counted as empty lines."
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  1200
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  1201
    ^ self asStringWithCRsFrom:firstLine to:lastLine compressTabs:false withCR:true
1421
7224371d514c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1413
diff changeset
  1202
7224371d514c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1413
diff changeset
  1203
    "
7224371d514c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1413
diff changeset
  1204
     #('hello' 'world' 'foo' 'bar' 'baz') asStringWithCRsFrom:2 to:4 
7224371d514c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1413
diff changeset
  1205
7224371d514c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1413
diff changeset
  1206
    "
7224371d514c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1413
diff changeset
  1207
7224371d514c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1413
diff changeset
  1208
    "Modified: 18.5.1996 / 16:50:55 / cg"
602
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
asStringWithCRsFrom:firstLine to:lastLine compressTabs:compressTabs
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  1212
    "return part of myself as a string with embedded cr's.
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  1213
     My elements must be strings or nil.
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  1214
     If the argument compressTabs is true, leading spaces are converted
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  1215
     to tab-characters (8col tabs).
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  1216
     Nil entries and empty strings are taken as empty lines."
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  1217
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  1218
    ^ self asStringWithCRsFrom:firstLine to:lastLine compressTabs:compressTabs withCR:true
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
asStringWithCRsFrom:firstLine to:lastLine compressTabs:compressTabs withCR:withCR
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  1222
    "return part of myself as a string with embedded cr's.
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  1223
     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
  1224
     taken as empty lines.
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  1225
     If the argument compressTabs is true, leading spaces are converted
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  1226
     to tab-characters (8col tabs). WithCR controls whether the last line
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  1227
     should be followed by a cr or not."
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
    ^ self asStringWith:(Character cr)
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  1230
		   from:firstLine 
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  1231
		     to:lastLine 
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  1232
	   compressTabs:compressTabs 
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  1233
		  final:(withCR ifTrue:[Character cr] ifFalse:[nil])
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  1234
!
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  1235
379
5b5a130ccd09 revision added
claus
parents: 375
diff changeset
  1236
decodeAsLiteralArray
1245
c8afea3d5af0 commentary
Claus Gittinger <cg@exept.de>
parents: 1188
diff changeset
  1237
    "given a literalEncoding in the receiver,
c8afea3d5af0 commentary
Claus Gittinger <cg@exept.de>
parents: 1188
diff changeset
  1238
     create & return the corresponding object.
c8afea3d5af0 commentary
Claus Gittinger <cg@exept.de>
parents: 1188
diff changeset
  1239
     The inverse operation to #literalArrayEncoding."
c8afea3d5af0 commentary
Claus Gittinger <cg@exept.de>
parents: 1188
diff changeset
  1240
2165
9ef030343739 added #zeroIndex for protocol completeness (ST-80)
Claus Gittinger <cg@exept.de>
parents: 2069
diff changeset
  1241
    |clsName cls|
9ef030343739 added #zeroIndex for protocol completeness (ST-80)
Claus Gittinger <cg@exept.de>
parents: 2069
diff changeset
  1242
9ef030343739 added #zeroIndex for protocol completeness (ST-80)
Claus Gittinger <cg@exept.de>
parents: 2069
diff changeset
  1243
    clsName := self first.
9ef030343739 added #zeroIndex for protocol completeness (ST-80)
Claus Gittinger <cg@exept.de>
parents: 2069
diff changeset
  1244
    cls := Smalltalk at:clsName ifAbsent:nil.
379
5b5a130ccd09 revision added
claus
parents: 375
diff changeset
  1245
    cls isNil ifTrue:[
4197
8ae90a572914 raise a special signal, when a literalencodings class
Claus Gittinger <cg@exept.de>
parents: 4154
diff changeset
  1246
        ^ MissingClassInLiteralArrayErrorSignal 
8ae90a572914 raise a special signal, when a literalencodings class
Claus Gittinger <cg@exept.de>
parents: 4154
diff changeset
  1247
                raiseRequestWith:clsName errorString:('unknown class in spec: ' , clsName)
379
5b5a130ccd09 revision added
claus
parents: 375
diff changeset
  1248
    ].
2371
280aa91ff41e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2363
diff changeset
  1249
    ^ cls decodeFromLiteralArray:self.
379
5b5a130ccd09 revision added
claus
parents: 375
diff changeset
  1250
5b5a130ccd09 revision added
claus
parents: 375
diff changeset
  1251
    "
5b5a130ccd09 revision added
claus
parents: 375
diff changeset
  1252
     #(Point 10 20) decodeAsLiteralArray  
5b5a130ccd09 revision added
claus
parents: 375
diff changeset
  1253
     #(Rectangle 100 200 400 500) decodeAsLiteralArray 
2417
64115b76cd15 commentary
Claus Gittinger <cg@exept.de>
parents: 2413
diff changeset
  1254
     #(#MenuItem #rawLabel: 'right' #value: #right) decodeAsLiteralArray 
379
5b5a130ccd09 revision added
claus
parents: 375
diff changeset
  1255
    "
1245
c8afea3d5af0 commentary
Claus Gittinger <cg@exept.de>
parents: 1188
diff changeset
  1256
4197
8ae90a572914 raise a special signal, when a literalencodings class
Claus Gittinger <cg@exept.de>
parents: 4154
diff changeset
  1257
    "Modified: / 18.5.1999 / 14:51:58 / cg"
422
claus
parents: 384
diff changeset
  1258
!
claus
parents: 384
diff changeset
  1259
claus
parents: 384
diff changeset
  1260
literalArrayEncoding
1245
c8afea3d5af0 commentary
Claus Gittinger <cg@exept.de>
parents: 1188
diff changeset
  1261
    "encode myself as an array literal, from which a copy of the receiver
c8afea3d5af0 commentary
Claus Gittinger <cg@exept.de>
parents: 1188
diff changeset
  1262
     can be reconstructed with #decodeAsLiteralArray."
c8afea3d5af0 commentary
Claus Gittinger <cg@exept.de>
parents: 1188
diff changeset
  1263
4382
900e9acf2cbb oops - the last one was not good.
Claus Gittinger <cg@exept.de>
parents: 4381
diff changeset
  1264
    ^ (self collect:[:el | el literalArrayEncoding]) asArray
422
claus
parents: 384
diff changeset
  1265
claus
parents: 384
diff changeset
  1266
    "
claus
parents: 384
diff changeset
  1267
     (Array with:(Color red:50 green:50 blue:50)
1245
c8afea3d5af0 commentary
Claus Gittinger <cg@exept.de>
parents: 1188
diff changeset
  1268
            with:(1 @ 2)
422
claus
parents: 384
diff changeset
  1269
     ) literalArrayEncoding   
claus
parents: 384
diff changeset
  1270
    "
1245
c8afea3d5af0 commentary
Claus Gittinger <cg@exept.de>
parents: 1188
diff changeset
  1271
c8afea3d5af0 commentary
Claus Gittinger <cg@exept.de>
parents: 1188
diff changeset
  1272
    "Modified: 22.4.1996 / 13:00:56 / cg"
260
cefb485445a7 *** empty log message ***
claus
parents: 252
diff changeset
  1273
! !
cefb485445a7 *** empty log message ***
claus
parents: 252
diff changeset
  1274
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1275
!SequenceableCollection methodsFor:'copying'!
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1276
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1277
, aCollection
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1278
    "return a new collection formed from concatenating the receiver with
44
b262907c93ea *** empty log message ***
claus
parents: 42
diff changeset
  1279
     the argument. The class of the new collection is determined by the
b262907c93ea *** empty log message ***
claus
parents: 42
diff changeset
  1280
     receivers class, so mixing classes is possible, if the second collections
b262907c93ea *** empty log message ***
claus
parents: 42
diff changeset
  1281
     elements can be stored into instances of the receivers class."
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1282
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1283
    |newCollection 
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1284
     mySize    "{ Class: SmallInteger }"
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1285
     newSize   "{ Class: SmallInteger }"
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1286
     otherSize "{ Class: SmallInteger }"
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1287
     dstIndex  "{ Class: SmallInteger }"|
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1288
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1289
    mySize := self size.
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1290
    otherSize := aCollection size.
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1291
    newSize := mySize + otherSize.
202
40ca7cc6fb9c *** empty log message ***
claus
parents: 186
diff changeset
  1292
252
  1293
    newCollection := self copyEmptyAndGrow:newSize.   "must grow, otherwise replace fails"
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1294
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1295
    newCollection replaceFrom:1 to:mySize with:self startingAt:1.
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1296
    dstIndex := mySize + 1.
202
40ca7cc6fb9c *** empty log message ***
claus
parents: 186
diff changeset
  1297
    aCollection isSequenceable ifTrue:[
40ca7cc6fb9c *** empty log message ***
claus
parents: 186
diff changeset
  1298
	"
40ca7cc6fb9c *** empty log message ***
claus
parents: 186
diff changeset
  1299
	 yes, aCollection has indexed elements
40ca7cc6fb9c *** empty log message ***
claus
parents: 186
diff changeset
  1300
	"
159
514c749165c3 *** empty log message ***
claus
parents: 118
diff changeset
  1301
	newCollection replaceFrom:dstIndex to:newSize
514c749165c3 *** empty log message ***
claus
parents: 118
diff changeset
  1302
			     with:aCollection startingAt:1.
514c749165c3 *** empty log message ***
claus
parents: 118
diff changeset
  1303
	^ newCollection
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1304
    ] ifFalse:[
202
40ca7cc6fb9c *** empty log message ***
claus
parents: 186
diff changeset
  1305
	"
40ca7cc6fb9c *** empty log message ***
claus
parents: 186
diff changeset
  1306
	 no, enumerate aCollection
40ca7cc6fb9c *** empty log message ***
claus
parents: 186
diff changeset
  1307
	"
159
514c749165c3 *** empty log message ***
claus
parents: 118
diff changeset
  1308
	aCollection do:[:element |
514c749165c3 *** empty log message ***
claus
parents: 118
diff changeset
  1309
	    newCollection at:dstIndex put:element.
514c749165c3 *** empty log message ***
claus
parents: 118
diff changeset
  1310
	    dstIndex := dstIndex + 1
514c749165c3 *** empty log message ***
claus
parents: 118
diff changeset
  1311
	]
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1312
    ].
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1313
    ^ newCollection
44
b262907c93ea *** empty log message ***
claus
parents: 42
diff changeset
  1314
95
d22739a0c6e9 *** empty log message ***
claus
parents: 88
diff changeset
  1315
    "
d22739a0c6e9 *** empty log message ***
claus
parents: 88
diff changeset
  1316
     #($a $b $c) , #(1 2 3)
d22739a0c6e9 *** empty log message ***
claus
parents: 88
diff changeset
  1317
     #($a $b $c) , '123'
d22739a0c6e9 *** empty log message ***
claus
parents: 88
diff changeset
  1318
     'abc' , '123'
d22739a0c6e9 *** empty log message ***
claus
parents: 88
diff changeset
  1319
     'abc' , #($q $w $e $r $t $y) asSortedCollection
d22739a0c6e9 *** empty log message ***
claus
parents: 88
diff changeset
  1320
     'abc' , #(1 2 3 4 5)"  "-- will fail, since strings cannot store integers
d22739a0c6e9 *** empty log message ***
claus
parents: 88
diff changeset
  1321
     'abc' asArray , #(1 2 3 4 5)
d22739a0c6e9 *** empty log message ***
claus
parents: 88
diff changeset
  1322
    "
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1323
!
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1324
602
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  1325
copyFirst:count
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  1326
    "return a new collection consisting of the receivers first count
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  1327
     elements - this is just a rename of copyTo: - for compatibility."
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
    ^ self copyFrom:1 to:count
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  1330
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  1331
    "
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  1332
     #($a $b $c $d $e $f $g) copyFirst:5
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  1333
     '1234567890' copyFirst:4
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  1334
    "
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  1335
!
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
copyFrom:start
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  1338
    "return a new collection consisting of receivers elements
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  1339
     from start to the end of the collection"
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  1340
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  1341
    ^ self copyFrom:start to:(self size)
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  1342
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  1343
    "
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  1344
     #($a $b $c $d $e $f $g) copyFrom:2
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  1345
     '1234567890' copyFrom:2
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  1346
    "
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  1347
!
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  1348
2413
a3f91741d7ba added #replaceFrom:count:* methods
Claus Gittinger <cg@exept.de>
parents: 2411
diff changeset
  1349
copyFrom:start count:numberOfElements
a3f91741d7ba added #replaceFrom:count:* methods
Claus Gittinger <cg@exept.de>
parents: 2411
diff changeset
  1350
    "return a new collection consisting of numberOfElements elements
a3f91741d7ba added #replaceFrom:count:* methods
Claus Gittinger <cg@exept.de>
parents: 2411
diff changeset
  1351
     extracted from the receiver starting at index start
a3f91741d7ba added #replaceFrom:count:* methods
Claus Gittinger <cg@exept.de>
parents: 2411
diff changeset
  1352
     (i.e. extract a slice)"
a3f91741d7ba added #replaceFrom:count:* methods
Claus Gittinger <cg@exept.de>
parents: 2411
diff changeset
  1353
a3f91741d7ba added #replaceFrom:count:* methods
Claus Gittinger <cg@exept.de>
parents: 2411
diff changeset
  1354
    ^ self
a3f91741d7ba added #replaceFrom:count:* methods
Claus Gittinger <cg@exept.de>
parents: 2411
diff changeset
  1355
        copyFrom:start
a3f91741d7ba added #replaceFrom:count:* methods
Claus Gittinger <cg@exept.de>
parents: 2411
diff changeset
  1356
        to:(start + numberOfElements - 1)
a3f91741d7ba added #replaceFrom:count:* methods
Claus Gittinger <cg@exept.de>
parents: 2411
diff changeset
  1357
a3f91741d7ba added #replaceFrom:count:* methods
Claus Gittinger <cg@exept.de>
parents: 2411
diff changeset
  1358
    "
a3f91741d7ba added #replaceFrom:count:* methods
Claus Gittinger <cg@exept.de>
parents: 2411
diff changeset
  1359
     #($a $b $c $d $e $f $g) copyFrom:2 count:3 
a3f91741d7ba added #replaceFrom:count:* methods
Claus Gittinger <cg@exept.de>
parents: 2411
diff changeset
  1360
     '1234567890' copyFrom:2 count:5    
a3f91741d7ba added #replaceFrom:count:* methods
Claus Gittinger <cg@exept.de>
parents: 2411
diff changeset
  1361
    "
a3f91741d7ba added #replaceFrom:count:* methods
Claus Gittinger <cg@exept.de>
parents: 2411
diff changeset
  1362
a3f91741d7ba added #replaceFrom:count:* methods
Claus Gittinger <cg@exept.de>
parents: 2411
diff changeset
  1363
    "Modified: 20.2.1997 / 14:23:01 / cg"
a3f91741d7ba added #replaceFrom:count:* methods
Claus Gittinger <cg@exept.de>
parents: 2411
diff changeset
  1364
!
a3f91741d7ba added #replaceFrom:count:* methods
Claus Gittinger <cg@exept.de>
parents: 2411
diff changeset
  1365
602
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  1366
copyFrom:start to:stop
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  1367
    "return a new collection consisting of receivers elements
4403
eb4379909671 comment
Claus Gittinger <cg@exept.de>
parents: 4402
diff changeset
  1368
     between start and stop.
eb4379909671 comment
Claus Gittinger <cg@exept.de>
parents: 4402
diff changeset
  1369
     Returns an empty collection in some situations"
602
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
    |newCollection newSize|
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  1372
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  1373
    newSize := stop - start + 1.
4402
7c19502120b7 care for bad startIndex in #copyFrom:to:
Claus Gittinger <cg@exept.de>
parents: 4389
diff changeset
  1374
    newSize < 0 ifTrue:[
7c19502120b7 care for bad startIndex in #copyFrom:to:
Claus Gittinger <cg@exept.de>
parents: 4389
diff changeset
  1375
        newSize := 0
7c19502120b7 care for bad startIndex in #copyFrom:to:
Claus Gittinger <cg@exept.de>
parents: 4389
diff changeset
  1376
    ].
602
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  1377
    newCollection := self copyEmptyAndGrow:newSize.
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  1378
    newCollection replaceFrom:1 to:newSize with:self startingAt:start.
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  1379
    ^ newCollection
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  1380
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  1381
    "
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  1382
     #($a $b $c $d $e $f $g) copyFrom:2 to:5
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  1383
     '1234567890' copyFrom:2 to:5
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  1384
    "
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
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  1387
copyLast:count
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  1388
    "return a new collection consisting of the receivers last count
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  1389
     elements."
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
    |sz|
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  1392
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  1393
    sz := self size.
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  1394
    ^ self copyFrom:(sz - count + 1) to:sz
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
    "
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  1397
     #($a $b $c $d $e $f $g) copyLast:5
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  1398
     '1234567890' copyLast:4
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  1399
    "
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
3653
cc018fcae490 added #copyReplaceAll:with:
Claus Gittinger <cg@exept.de>
parents: 3645
diff changeset
  1402
copyReplaceAll:oldElement with:newElement
cc018fcae490 added #copyReplaceAll:with:
Claus Gittinger <cg@exept.de>
parents: 3645
diff changeset
  1403
    "return a copy of the receiver, where all elements equal to oldElement
cc018fcae490 added #copyReplaceAll:with:
Claus Gittinger <cg@exept.de>
parents: 3645
diff changeset
  1404
     have been replaced by newElement."
cc018fcae490 added #copyReplaceAll:with:
Claus Gittinger <cg@exept.de>
parents: 3645
diff changeset
  1405
cc018fcae490 added #copyReplaceAll:with:
Claus Gittinger <cg@exept.de>
parents: 3645
diff changeset
  1406
    ^ self copy replaceAll:oldElement with:newElement
cc018fcae490 added #copyReplaceAll:with:
Claus Gittinger <cg@exept.de>
parents: 3645
diff changeset
  1407
cc018fcae490 added #copyReplaceAll:with:
Claus Gittinger <cg@exept.de>
parents: 3645
diff changeset
  1408
    "
cc018fcae490 added #copyReplaceAll:with:
Claus Gittinger <cg@exept.de>
parents: 3645
diff changeset
  1409
     #(1 2 1 2 1 2 1 2 1 2) copyReplaceAll:1 with:99 
cc018fcae490 added #copyReplaceAll:with:
Claus Gittinger <cg@exept.de>
parents: 3645
diff changeset
  1410
     'hello world' copyReplaceAll:$l with:$*         
cc018fcae490 added #copyReplaceAll:with:
Claus Gittinger <cg@exept.de>
parents: 3645
diff changeset
  1411
    "
cc018fcae490 added #copyReplaceAll:with:
Claus Gittinger <cg@exept.de>
parents: 3645
diff changeset
  1412
cc018fcae490 added #copyReplaceAll:with:
Claus Gittinger <cg@exept.de>
parents: 3645
diff changeset
  1413
    "Modified: / 18.7.1998 / 22:52:17 / cg"
cc018fcae490 added #copyReplaceAll:with:
Claus Gittinger <cg@exept.de>
parents: 3645
diff changeset
  1414
!
cc018fcae490 added #copyReplaceAll:with:
Claus Gittinger <cg@exept.de>
parents: 3645
diff changeset
  1415
3992
549eefe16a28 added #copyReplaceAll:withAll:
Claus Gittinger <cg@exept.de>
parents: 3887
diff changeset
  1416
copyReplaceAll:oldObject withAll:aCollection
549eefe16a28 added #copyReplaceAll:withAll:
Claus Gittinger <cg@exept.de>
parents: 3887
diff changeset
  1417
    "return a copy, where all oldObjects are replaced by all
549eefe16a28 added #copyReplaceAll:withAll:
Claus Gittinger <cg@exept.de>
parents: 3887
diff changeset
  1418
     elements from aCollection (i.e. sliced in).
549eefe16a28 added #copyReplaceAll:withAll:
Claus Gittinger <cg@exept.de>
parents: 3887
diff changeset
  1419
     Non-destructive; returns a new collection.
549eefe16a28 added #copyReplaceAll:withAll:
Claus Gittinger <cg@exept.de>
parents: 3887
diff changeset
  1420
     The implementation here is a general-purpose one;
549eefe16a28 added #copyReplaceAll:withAll:
Claus Gittinger <cg@exept.de>
parents: 3887
diff changeset
  1421
     and should be redefined in String, if heavily used."
549eefe16a28 added #copyReplaceAll:withAll:
Claus Gittinger <cg@exept.de>
parents: 3887
diff changeset
  1422
549eefe16a28 added #copyReplaceAll:withAll:
Claus Gittinger <cg@exept.de>
parents: 3887
diff changeset
  1423
    |s i|
549eefe16a28 added #copyReplaceAll:withAll:
Claus Gittinger <cg@exept.de>
parents: 3887
diff changeset
  1424
549eefe16a28 added #copyReplaceAll:withAll:
Claus Gittinger <cg@exept.de>
parents: 3887
diff changeset
  1425
    s := WriteStream on:self species new.
549eefe16a28 added #copyReplaceAll:withAll:
Claus Gittinger <cg@exept.de>
parents: 3887
diff changeset
  1426
    self do:[:el |
549eefe16a28 added #copyReplaceAll:withAll:
Claus Gittinger <cg@exept.de>
parents: 3887
diff changeset
  1427
        el = oldObject ifTrue:[
549eefe16a28 added #copyReplaceAll:withAll:
Claus Gittinger <cg@exept.de>
parents: 3887
diff changeset
  1428
            aCollection do:[:el2 |
549eefe16a28 added #copyReplaceAll:withAll:
Claus Gittinger <cg@exept.de>
parents: 3887
diff changeset
  1429
                s nextPut:el2
549eefe16a28 added #copyReplaceAll:withAll:
Claus Gittinger <cg@exept.de>
parents: 3887
diff changeset
  1430
            ]
549eefe16a28 added #copyReplaceAll:withAll:
Claus Gittinger <cg@exept.de>
parents: 3887
diff changeset
  1431
        ] ifFalse:[
549eefe16a28 added #copyReplaceAll:withAll:
Claus Gittinger <cg@exept.de>
parents: 3887
diff changeset
  1432
            s nextPut:el
549eefe16a28 added #copyReplaceAll:withAll:
Claus Gittinger <cg@exept.de>
parents: 3887
diff changeset
  1433
        ]
549eefe16a28 added #copyReplaceAll:withAll:
Claus Gittinger <cg@exept.de>
parents: 3887
diff changeset
  1434
    ].
549eefe16a28 added #copyReplaceAll:withAll:
Claus Gittinger <cg@exept.de>
parents: 3887
diff changeset
  1435
    ^ s contents
549eefe16a28 added #copyReplaceAll:withAll:
Claus Gittinger <cg@exept.de>
parents: 3887
diff changeset
  1436
549eefe16a28 added #copyReplaceAll:withAll:
Claus Gittinger <cg@exept.de>
parents: 3887
diff changeset
  1437
    "
549eefe16a28 added #copyReplaceAll:withAll:
Claus Gittinger <cg@exept.de>
parents: 3887
diff changeset
  1438
     args:    oldObject  : <object>
549eefe16a28 added #copyReplaceAll:withAll:
Claus Gittinger <cg@exept.de>
parents: 3887
diff changeset
  1439
              newObject  : <collection>
549eefe16a28 added #copyReplaceAll:withAll:
Claus Gittinger <cg@exept.de>
parents: 3887
diff changeset
  1440
549eefe16a28 added #copyReplaceAll:withAll:
Claus Gittinger <cg@exept.de>
parents: 3887
diff changeset
  1441
     returns: newCollection
549eefe16a28 added #copyReplaceAll:withAll:
Claus Gittinger <cg@exept.de>
parents: 3887
diff changeset
  1442
    "
549eefe16a28 added #copyReplaceAll:withAll:
Claus Gittinger <cg@exept.de>
parents: 3887
diff changeset
  1443
549eefe16a28 added #copyReplaceAll:withAll:
Claus Gittinger <cg@exept.de>
parents: 3887
diff changeset
  1444
    "
549eefe16a28 added #copyReplaceAll:withAll:
Claus Gittinger <cg@exept.de>
parents: 3887
diff changeset
  1445
     '123123abc123' copyReplaceAll:$1 withAll:'one'    
549eefe16a28 added #copyReplaceAll:withAll:
Claus Gittinger <cg@exept.de>
parents: 3887
diff changeset
  1446
     #(1 2 3 4 1 2 3 4) copyReplaceAll:1 withAll:'one' 
549eefe16a28 added #copyReplaceAll:withAll:
Claus Gittinger <cg@exept.de>
parents: 3887
diff changeset
  1447
    "
549eefe16a28 added #copyReplaceAll:withAll:
Claus Gittinger <cg@exept.de>
parents: 3887
diff changeset
  1448
549eefe16a28 added #copyReplaceAll:withAll:
Claus Gittinger <cg@exept.de>
parents: 3887
diff changeset
  1449
!
549eefe16a28 added #copyReplaceAll:withAll:
Claus Gittinger <cg@exept.de>
parents: 3887
diff changeset
  1450
602
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  1451
copyReplaceFrom:startIndex to:endIndex with:aCollection
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  1452
    "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
  1453
     endIndex have been replaced by the elements of aCollection"
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  1454
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  1455
    |newColl sz replSize|
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
    replSize := aCollection size.
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  1458
    sz := self size - (endIndex - startIndex + 1) + replSize.
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  1459
    newColl := self copyEmptyAndGrow:sz.
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  1460
    newColl replaceFrom:1 to:(startIndex - 1) with:self.
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  1461
    newColl replaceFrom:startIndex with:aCollection.
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  1462
    newColl replaceFrom:(startIndex + replSize) with:self startingAt:(endIndex + 1).
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  1463
    ^ newColl
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  1464
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  1465
    "
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  1466
     #(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
  1467
     'hello world' copyReplaceFrom:6 to:6 with:' there, '  
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  1468
    "
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  1469
!
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  1470
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  1471
copyReplaceFrom:startIndex with:aCollection
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  1472
    "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
  1473
     the end have been replaced by the elements of aCollection"
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  1474
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  1475
    ^ self copyReplaceFrom:startIndex to:(self size) with:aCollection
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  1476
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  1477
    "
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  1478
     #(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
  1479
     'hello world' copyReplaceFrom:7 with:'smalltalk fan'  
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  1480
    "
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  1481
!
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  1482
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  1483
copyThrough:element
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  1484
    "return a new collection consisting of the receiver elements
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  1485
     up-to (AND including) the first occurence of element."
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  1486
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  1487
    |idx|
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  1488
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  1489
    idx := self indexOf:element.
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  1490
    idx == 0 ifTrue:[^ nil].    "question: is this ok?"
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  1491
    ^ self copyFrom:1 to:idx
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  1492
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  1493
    "
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  1494
     #($a $b $c $d $e $f $g) copyThrough:$d
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  1495
     '1234567890' copyThrough:$5
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  1496
     '1234567890' copyThrough:$a
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  1497
     '1234567890' copyThrough:$1
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  1498
    "
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  1499
!
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  1500
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  1501
copyTo:stop
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  1502
    "return a new collection consisting of receivers elements
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  1503
     from 1 up to (including) index stop"
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  1504
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  1505
    ^ self copyFrom:1 to:stop
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  1506
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  1507
    "
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  1508
     #($a $b $c $d $e $f $g) copyTo:5
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  1509
     '1234567890' copyTo:4
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  1510
    "
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  1511
!
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  1512
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  1513
copyUpTo:element
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  1514
    "return a new collection consisting of the receiver elements
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  1515
     up-to (but excluding) the first occurence of element;
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  1516
     or to the end, if element is not included"
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  1517
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  1518
    |idx|
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  1519
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  1520
    idx := self indexOf:element.
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  1521
    idx == 0 ifTrue:[^ self copy].    "question: is this ok?"
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  1522
    idx == 1 ifTrue:[^ self copyEmpty].
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  1523
    ^ self copyFrom:1 to:(idx-1)
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
    "
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  1526
     #($a $b $c $d $e $f $g) copyUpTo:$d
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  1527
     '1234567890' copyUpTo:$5
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  1528
     '1234567890' copyUpTo:$a
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  1529
     '1234567890' copyUpTo:$1
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  1530
     '123456789' copyUpTo:$0
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  1531
    "
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
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1534
copyWith:newElement
233
98f588af201a comments
claus
parents: 202
diff changeset
  1535
    "return a new collection containing the receivers elements
98f588af201a comments
claus
parents: 202
diff changeset
  1536
     and the single new element, newElement. 
98f588af201a comments
claus
parents: 202
diff changeset
  1537
     This is different from concatentation, which expects another collection
98f588af201a comments
claus
parents: 202
diff changeset
  1538
     as argument, but equivalent to copy-and-addLast."
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1539
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1540
    |newCollection mySize newSize|
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1541
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1542
    mySize := self size.
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1543
    newSize := mySize + 1.
252
  1544
    newCollection := self copyEmptyAndGrow:newSize.
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1545
    newCollection replaceFrom:1 to:mySize with:self startingAt:1.
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1546
    newCollection at:newSize put:newElement.
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1547
    ^newCollection
44
b262907c93ea *** empty log message ***
claus
parents: 42
diff changeset
  1548
95
d22739a0c6e9 *** empty log message ***
claus
parents: 88
diff changeset
  1549
    "
d22739a0c6e9 *** empty log message ***
claus
parents: 88
diff changeset
  1550
     #(1 2 3 4 5) copyWith:$a
d22739a0c6e9 *** empty log message ***
claus
parents: 88
diff changeset
  1551
     'abcdefg' copyWith:$h
d22739a0c6e9 *** empty log message ***
claus
parents: 88
diff changeset
  1552
     'abcdefg' copyWith:'123'   -- will fail: string cannot be stored into string
d22739a0c6e9 *** empty log message ***
claus
parents: 88
diff changeset
  1553
     'abcdefg' copyWith:1       -- will fail: integer cannot be stored into string
d22739a0c6e9 *** empty log message ***
claus
parents: 88
diff changeset
  1554
    "
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1555
!
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1556
61
claus
parents: 44
diff changeset
  1557
copyWithout:elementToSkip
claus
parents: 44
diff changeset
  1558
    "return a new collection consisting of a copy of the receiver, with
claus
parents: 44
diff changeset
  1559
     ALL elements equal to elementToSkip are left out.
claus
parents: 44
diff changeset
  1560
     No error is reported, if elementToSkip is not in the collection."
claus
parents: 44
diff changeset
  1561
293
31df3850e98c *** empty log message ***
claus
parents: 282
diff changeset
  1562
    |n         "{ Class: SmallInteger }"
31df3850e98c *** empty log message ***
claus
parents: 282
diff changeset
  1563
     sz        "{ Class: SmallInteger }"
31df3850e98c *** empty log message ***
claus
parents: 282
diff changeset
  1564
     srcIndex  "{ Class: SmallInteger }"
31df3850e98c *** empty log message ***
claus
parents: 282
diff changeset
  1565
     dstIndex  "{ Class: SmallInteger }"
31df3850e98c *** empty log message ***
claus
parents: 282
diff changeset
  1566
     skipIndex "{ Class: SmallInteger }"
31df3850e98c *** empty log message ***
claus
parents: 282
diff changeset
  1567
     copy l|
61
claus
parents: 44
diff changeset
  1568
claus
parents: 44
diff changeset
  1569
    "the code below may look like overkill, 
claus
parents: 44
diff changeset
  1570
     however, for big collections its better to move data
claus
parents: 44
diff changeset
  1571
     around in big chunks"
claus
parents: 44
diff changeset
  1572
claus
parents: 44
diff changeset
  1573
    n := self occurrencesOf:elementToSkip.
claus
parents: 44
diff changeset
  1574
    n == 0 ifTrue:[^ self copy].
claus
parents: 44
diff changeset
  1575
claus
parents: 44
diff changeset
  1576
    sz := self size.
252
  1577
    copy := self copyEmptyAndGrow:(sz - n).
61
claus
parents: 44
diff changeset
  1578
claus
parents: 44
diff changeset
  1579
    srcIndex := 1.
claus
parents: 44
diff changeset
  1580
    dstIndex := 1.
claus
parents: 44
diff changeset
  1581
claus
parents: 44
diff changeset
  1582
    n timesRepeat:[
159
514c749165c3 *** empty log message ***
claus
parents: 118
diff changeset
  1583
	skipIndex := self indexOf:elementToSkip startingAt:srcIndex.
514c749165c3 *** empty log message ***
claus
parents: 118
diff changeset
  1584
	l := skipIndex - srcIndex.
514c749165c3 *** empty log message ***
claus
parents: 118
diff changeset
  1585
	l ~~ 0 ifTrue:[
514c749165c3 *** empty log message ***
claus
parents: 118
diff changeset
  1586
	    copy replaceFrom:dstIndex to:(dstIndex + l - 1) 
514c749165c3 *** empty log message ***
claus
parents: 118
diff changeset
  1587
			with:self startingAt:srcIndex.
514c749165c3 *** empty log message ***
claus
parents: 118
diff changeset
  1588
	    dstIndex := dstIndex + l
514c749165c3 *** empty log message ***
claus
parents: 118
diff changeset
  1589
	].
514c749165c3 *** empty log message ***
claus
parents: 118
diff changeset
  1590
	srcIndex := skipIndex + 1
61
claus
parents: 44
diff changeset
  1591
    ].
claus
parents: 44
diff changeset
  1592
    l := sz - srcIndex.
claus
parents: 44
diff changeset
  1593
    copy replaceFrom:dstIndex to:(dstIndex + l)
159
514c749165c3 *** empty log message ***
claus
parents: 118
diff changeset
  1594
		with:self startingAt:srcIndex.
61
claus
parents: 44
diff changeset
  1595
    ^ copy
claus
parents: 44
diff changeset
  1596
95
d22739a0c6e9 *** empty log message ***
claus
parents: 88
diff changeset
  1597
    "
d22739a0c6e9 *** empty log message ***
claus
parents: 88
diff changeset
  1598
     #($a $b $c $d $e $f $g) copyWithout:$d
d22739a0c6e9 *** empty log message ***
claus
parents: 88
diff changeset
  1599
     #($a $b $c $d $e $f $g) copyWithout:$a
d22739a0c6e9 *** empty log message ***
claus
parents: 88
diff changeset
  1600
     #($a $b $c $d $e $f $g) copyWithout:$g
202
40ca7cc6fb9c *** empty log message ***
claus
parents: 186
diff changeset
  1601
     'abcdefghi' copyWithout:$h    
40ca7cc6fb9c *** empty log message ***
claus
parents: 186
diff changeset
  1602
     'abcdefg' copyWithout:$h       
95
d22739a0c6e9 *** empty log message ***
claus
parents: 88
diff changeset
  1603
     #($a $b $c $a $a $d $e $a $f $g) copyWithout:$a
d22739a0c6e9 *** empty log message ***
claus
parents: 88
diff changeset
  1604
     #($a $b $c $d $e $f $g) copyWithout:$x
d22739a0c6e9 *** empty log message ***
claus
parents: 88
diff changeset
  1605
     #(90 80 70 60 50) copyWithout:70
d22739a0c6e9 *** empty log message ***
claus
parents: 88
diff changeset
  1606
     #(90 80 70 80 60 45 80 50) copyWithout:80
d22739a0c6e9 *** empty log message ***
claus
parents: 88
diff changeset
  1607
    "
61
claus
parents: 44
diff changeset
  1608
!
claus
parents: 44
diff changeset
  1609
602
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  1610
copyWithoutFirst:elementToSkip
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  1611
    "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
  1612
     without the first elementToSkip, if it was present. 
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  1613
     No error is reported, if elementToSkip is not in the collection."
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  1614
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  1615
    |copy skipIndex sz|
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  1616
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  1617
    skipIndex := self indexOf:elementToSkip startingAt:1.
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  1618
    (skipIndex == 0) ifTrue:[^ self copy].
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  1619
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  1620
    sz := self size - 1.
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  1621
    copy := self copyEmptyAndGrow:sz.
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  1622
    copy replaceFrom:1 to:(skipIndex - 1) with:self startingAt:1.
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  1623
    copy replaceFrom:skipIndex to:sz with:self startingAt:(skipIndex + 1).
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  1624
    ^ copy
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  1625
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  1626
    "
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  1627
     #($a $b $c $d $e $f $g) copyWithoutFirst:$d
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  1628
     #($a $b $c $d $e $f $g) copyWithoutFirst:$x
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  1629
     #(90 80 70 60 50) copyWithoutFirst:70
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  1630
     #(90 80 70 80 60 45 80 50) copyWithoutFirst:80
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  1631
    "
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  1632
!
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  1633
61
claus
parents: 44
diff changeset
  1634
copyWithoutIndex:omitIndex
claus
parents: 44
diff changeset
  1635
    "return a new collection consisting of receivers elements
claus
parents: 44
diff changeset
  1636
     without the argument stored at omitIndex"
claus
parents: 44
diff changeset
  1637
claus
parents: 44
diff changeset
  1638
    |copy sz|
claus
parents: 44
diff changeset
  1639
202
40ca7cc6fb9c *** empty log message ***
claus
parents: 186
diff changeset
  1640
    sz := self size - 1.
252
  1641
    copy := self copyEmptyAndGrow:sz.
293
31df3850e98c *** empty log message ***
claus
parents: 282
diff changeset
  1642
    copy replaceFrom:1 to:(omitIndex - 1) with:self startingAt:1.
31df3850e98c *** empty log message ***
claus
parents: 282
diff changeset
  1643
    copy replaceFrom:omitIndex to:sz with:self startingAt:(omitIndex + 1).
61
claus
parents: 44
diff changeset
  1644
    ^ copy
claus
parents: 44
diff changeset
  1645
95
d22739a0c6e9 *** empty log message ***
claus
parents: 88
diff changeset
  1646
    "
d22739a0c6e9 *** empty log message ***
claus
parents: 88
diff changeset
  1647
     #(1 2 3 4 5 6 7 8 9 0) copyWithoutIndex:3
d22739a0c6e9 *** empty log message ***
claus
parents: 88
diff changeset
  1648
     'abcdefghijkl' copyWithoutIndex:5
d22739a0c6e9 *** empty log message ***
claus
parents: 88
diff changeset
  1649
    "
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1650
!
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1651
202
40ca7cc6fb9c *** empty log message ***
claus
parents: 186
diff changeset
  1652
copyWithoutLast:count
40ca7cc6fb9c *** empty log message ***
claus
parents: 186
diff changeset
  1653
    "return a new collection consisting of the receivers elements
40ca7cc6fb9c *** empty log message ***
claus
parents: 186
diff changeset
  1654
     except the last count elements."
40ca7cc6fb9c *** empty log message ***
claus
parents: 186
diff changeset
  1655
40ca7cc6fb9c *** empty log message ***
claus
parents: 186
diff changeset
  1656
    |sz|
40ca7cc6fb9c *** empty log message ***
claus
parents: 186
diff changeset
  1657
40ca7cc6fb9c *** empty log message ***
claus
parents: 186
diff changeset
  1658
    sz := self size.
40ca7cc6fb9c *** empty log message ***
claus
parents: 186
diff changeset
  1659
    ^ self copyTo:(sz - count)
40ca7cc6fb9c *** empty log message ***
claus
parents: 186
diff changeset
  1660
40ca7cc6fb9c *** empty log message ***
claus
parents: 186
diff changeset
  1661
    "
40ca7cc6fb9c *** empty log message ***
claus
parents: 186
diff changeset
  1662
     #($a $b $c $d $e $f $g) copyWithoutLast:5 
40ca7cc6fb9c *** empty log message ***
claus
parents: 186
diff changeset
  1663
     '1234567890' copyWithoutLast:4 
40ca7cc6fb9c *** empty log message ***
claus
parents: 186
diff changeset
  1664
    "
602
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  1665
! !
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  1666
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  1667
!SequenceableCollection methodsFor:'enumerating'!
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
collect:aBlock
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  1670
    "evaluate the argument, aBlock for every element in the collection
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  1671
     and return a collection of the results"
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  1672
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  1673
    |newCollection
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  1674
     sz  "{ Class:SmallInteger }"|
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  1675
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  1676
    sz := self size.
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  1677
    newCollection := self copyEmptyAndGrow:sz.
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  1678
    1 to:sz do:[:index |
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  1679
	newCollection at:index put:(aBlock value:(self at:index)).
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  1680
    ].
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  1681
    ^ newCollection
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  1682
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  1683
    "
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  1684
     #(one two three four five six) collect:[:element | element asUppercase]  
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  1685
     #(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
  1686
     (1 to:9) collect:[:element | element * element]   
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  1687
    "
202
40ca7cc6fb9c *** empty log message ***
claus
parents: 186
diff changeset
  1688
!
40ca7cc6fb9c *** empty log message ***
claus
parents: 186
diff changeset
  1689
602
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  1690
do:aBlock
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  1691
    "evaluate the argument, aBlock for every element in the collection."
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
    |stop "{ Class:SmallInteger }"|
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  1694
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  1695
    stop := self size.
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  1696
    1 to:stop do:[:index |
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  1697
	aBlock value:(self at:index).
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  1698
    ]
2927
1434c3d7f78a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2881
diff changeset
  1699
602
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  1700
    "
1422
9a0b792f2953 showCr: -> showCR:
Claus Gittinger <cg@exept.de>
parents: 1421
diff changeset
  1701
     #(one two three four five six) do:[:element | Transcript showCR:element]
602
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
!
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  1704
2927
1434c3d7f78a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2881
diff changeset
  1705
do:aBlock separatedBy:sepBlock
1434c3d7f78a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2881
diff changeset
  1706
    "evaluate the argument, aBlock for every element in the collection.
1434c3d7f78a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2881
diff changeset
  1707
     Between each element (i.e. not before the first element and not after the
1434c3d7f78a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2881
diff changeset
  1708
     last element), evaluate sepBlock.
1434c3d7f78a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2881
diff changeset
  1709
     This supports printing of collections with elements separated by some
1434c3d7f78a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2881
diff changeset
  1710
     string."
1434c3d7f78a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2881
diff changeset
  1711
1434c3d7f78a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2881
diff changeset
  1712
    |stop "{ Class:SmallInteger }"|
1434c3d7f78a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2881
diff changeset
  1713
1434c3d7f78a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2881
diff changeset
  1714
    stop := self size.
1434c3d7f78a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2881
diff changeset
  1715
    stop < 1 ifTrue:[^ self].
1434c3d7f78a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2881
diff changeset
  1716
    aBlock value:(self at:1).
1434c3d7f78a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2881
diff changeset
  1717
    2 to:stop do:[:index |
1434c3d7f78a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2881
diff changeset
  1718
	sepBlock value.
1434c3d7f78a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2881
diff changeset
  1719
	aBlock value:(self at:index)
1434c3d7f78a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2881
diff changeset
  1720
    ].
1434c3d7f78a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2881
diff changeset
  1721
1434c3d7f78a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2881
diff changeset
  1722
    "
1434c3d7f78a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2881
diff changeset
  1723
     #(one two three four five six)
1434c3d7f78a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2881
diff changeset
  1724
	do:[:each | Transcript show:each]
1434c3d7f78a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2881
diff changeset
  1725
	separatedBy:[Transcript show:' , ']
1434c3d7f78a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2881
diff changeset
  1726
    "
1434c3d7f78a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2881
diff changeset
  1727
!
3003
0f66385bbbd2 replaceAny / replaceAll
Claus Gittinger <cg@exept.de>
parents: 2980
diff changeset
  1728
3044
a0bbac91639b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3037
diff changeset
  1729
doWithIndex:aBlock
a0bbac91639b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3037
diff changeset
  1730
    "Squeak compatibility; like keysAndValuesDo:, but passes
a0bbac91639b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3037
diff changeset
  1731
     the index as second argument."
a0bbac91639b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3037
diff changeset
  1732
a0bbac91639b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3037
diff changeset
  1733
    self keysAndValuesDo:[:index :value |
a0bbac91639b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3037
diff changeset
  1734
        aBlock value:value value:index
a0bbac91639b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3037
diff changeset
  1735
    ].
a0bbac91639b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3037
diff changeset
  1736
a0bbac91639b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3037
diff changeset
  1737
    "Created: 17.10.1997 / 12:33:10 / cg"
a0bbac91639b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3037
diff changeset
  1738
!
a0bbac91639b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3037
diff changeset
  1739
602
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  1740
from:startIndex do:aBlock
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  1741
    "evaluate the argument, aBlock for the elements starting with the
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  1742
     element at startIndex to the end."
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  1743
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  1744
    ^ self from:startIndex to:self size do:aBlock
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1745
95
d22739a0c6e9 *** empty log message ***
claus
parents: 88
diff changeset
  1746
    "
2927
1434c3d7f78a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2881
diff changeset
  1747
     #(one two three four five six) 
1434c3d7f78a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2881
diff changeset
  1748
	from:3 
1434c3d7f78a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2881
diff changeset
  1749
	do:[:element | Transcript showCR:element]
602
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  1750
    "
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  1751
!
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  1752
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  1753
from:start to:stop collect:aBlock
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  1754
    "evaluate the argument, aBlock for the elements indexed by start
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  1755
     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
  1756
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  1757
    |newCollection sz
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  1758
     idx  "{ Class:SmallInteger }"|
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  1759
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  1760
    sz := stop - start + 1.
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  1761
    newCollection := self copyEmptyAndGrow:sz.
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  1762
    idx := 1.
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  1763
    start to:stop do:[:index |
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  1764
	newCollection at:idx put:(aBlock value:(self at:index)).
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  1765
	idx := idx + 1
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  1766
    ].
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  1767
    ^ newCollection
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  1768
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  1769
    "
2927
1434c3d7f78a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2881
diff changeset
  1770
     #(one two three four five six) 
1434c3d7f78a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2881
diff changeset
  1771
	from:2 
1434c3d7f78a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2881
diff changeset
  1772
	to:4 
1434c3d7f78a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2881
diff changeset
  1773
	collect:[:element | element asUppercase]  
602
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  1774
    "
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  1775
!
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  1776
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  1777
from:index1 to:index2 do:aBlock
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  1778
    "evaluate the argument, aBlock for the elements with index index1 to
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  1779
     index2 in the collection"
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  1780
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  1781
    |start "{ Class:SmallInteger }"
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  1782
     stop  "{ Class:SmallInteger }" |
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  1783
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  1784
    start := index1.
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  1785
    stop := index2.
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  1786
    start to:stop do:[:index |
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  1787
	aBlock value:(self at:index).
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  1788
    ]
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  1789
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  1790
    "
2927
1434c3d7f78a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2881
diff changeset
  1791
     #(one two three four five six) 
1434c3d7f78a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2881
diff changeset
  1792
	from:3 
1434c3d7f78a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2881
diff changeset
  1793
	to:5 
1434c3d7f78a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2881
diff changeset
  1794
	do:[:element | Transcript showCR:element]
602
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  1795
    "
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  1796
!
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  1797
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  1798
from:index1 to:index2 reverseDo:aBlock
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  1799
    "evaluate the argument, aBlock for the elements with index index1 to
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  1800
     index2 in the collection. Step in reverse order"
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  1801
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  1802
    |start "{ Class:SmallInteger }"
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  1803
     stop  "{ Class:SmallInteger }" |
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  1804
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  1805
    start := index1.
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  1806
    stop := index2.
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  1807
    stop to:start by:-1 do:[:index |
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  1808
	aBlock value:(self at:index).
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  1809
    ]
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  1810
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  1811
    "
2927
1434c3d7f78a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2881
diff changeset
  1812
     #(one two three four five six) 
1434c3d7f78a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2881
diff changeset
  1813
	from:3 
1434c3d7f78a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2881
diff changeset
  1814
	to:5 
1434c3d7f78a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2881
diff changeset
  1815
	reverseDo:[:element | Transcript showCR:element]
95
d22739a0c6e9 *** empty log message ***
claus
parents: 88
diff changeset
  1816
    "
61
claus
parents: 44
diff changeset
  1817
!
claus
parents: 44
diff changeset
  1818
602
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  1819
keysAndValuesDo:aTwoArgBlock
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  1820
    "evaluate the argument, aBlock for every element in the collection,
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  1821
     passing both index and element as arguments."
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  1822
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  1823
    |stop  "{ Class:SmallInteger }"|
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  1824
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  1825
    stop := self size.
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  1826
    1 to:stop do:[:index |
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  1827
	aTwoArgBlock value:index value:(self at:index).
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  1828
    ]
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  1829
    "
2927
1434c3d7f78a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2881
diff changeset
  1830
     #(one two three four five six) 
1434c3d7f78a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2881
diff changeset
  1831
	keysAndValuesDo:[:key :element | 
1434c3d7f78a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2881
diff changeset
  1832
			    Transcript show:key; space; showCR:element
1434c3d7f78a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2881
diff changeset
  1833
			]
602
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  1834
    "
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  1835
!
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  1836
1359
5ff95f3f0baf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1289
diff changeset
  1837
keysAndValuesReverseDo:aTwoArgBlock
5ff95f3f0baf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1289
diff changeset
  1838
    "evaluate the argument, aBlock in reverse order, for every element 
5ff95f3f0baf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1289
diff changeset
  1839
     in the collection, passing both index and element as arguments."
5ff95f3f0baf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1289
diff changeset
  1840
5ff95f3f0baf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1289
diff changeset
  1841
    |stop  "{ Class:SmallInteger }"|
5ff95f3f0baf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1289
diff changeset
  1842
5ff95f3f0baf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1289
diff changeset
  1843
    stop := self size.
5ff95f3f0baf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1289
diff changeset
  1844
    stop to:1 by:-1 do:[:index |
5ff95f3f0baf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1289
diff changeset
  1845
        aTwoArgBlock value:index value:(self at:index).
5ff95f3f0baf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1289
diff changeset
  1846
    ]
5ff95f3f0baf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1289
diff changeset
  1847
5ff95f3f0baf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1289
diff changeset
  1848
    "
5ff95f3f0baf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1289
diff changeset
  1849
     #(one two three four five six) 
2927
1434c3d7f78a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2881
diff changeset
  1850
        keysAndValuesReverseDo:[:key :element | 
1434c3d7f78a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2881
diff changeset
  1851
				    Transcript show:key; space; showCR:element
1434c3d7f78a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2881
diff changeset
  1852
			       ]
1359
5ff95f3f0baf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1289
diff changeset
  1853
    "
5ff95f3f0baf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1289
diff changeset
  1854
5ff95f3f0baf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1289
diff changeset
  1855
    "Modified: 9.5.1996 / 00:57:23 / cg"
5ff95f3f0baf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1289
diff changeset
  1856
!
5ff95f3f0baf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1289
diff changeset
  1857
602
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  1858
nonNilElementsDo:aBlock
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  1859
    "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
  1860
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  1861
    |stop "{ Class:SmallInteger }"
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  1862
     element|
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  1863
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  1864
    stop := self size.
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  1865
    1 to:stop do:[:index |
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  1866
	(element := self at:index) notNil ifTrue:[
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  1867
	    aBlock value:element.
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  1868
	]
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  1869
    ]
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  1870
    "
1422
9a0b792f2953 showCr: -> showCR:
Claus Gittinger <cg@exept.de>
parents: 1421
diff changeset
  1871
     #(one nil three nil five nil seven) nonNilElementsDo:[:element | Transcript showCR:element]
602
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  1872
    "
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  1873
!
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  1874
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  1875
pairWiseCollect:aBlock
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  1876
    "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
  1877
     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
  1878
     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
  1879
     is not a multiple of 2.
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  1880
     Collect the results and return a new collection containing those."
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  1881
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  1882
    |stop newCollection dstIdx "{ Class:SmallInteger }"|
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  1883
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  1884
    stop := self size.
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  1885
    newCollection := self copyEmptyAndGrow:stop // 2.
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  1886
    dstIdx := 1.
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  1887
    1 to:stop by:2 do:[:index |
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  1888
	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
  1889
	dstIdx := dstIdx + 1
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  1890
    ].
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  1891
    ^ newCollection
44
b262907c93ea *** empty log message ***
claus
parents: 42
diff changeset
  1892
95
d22739a0c6e9 *** empty log message ***
claus
parents: 88
diff changeset
  1893
    "
602
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  1894
     #(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
  1895
     pairWiseCollect:[:num :sym | sym->num] 
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  1896
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  1897
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  1898
     #(1 1  1 2  1 3  1 4  1 5) 
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  1899
     pairWiseCollect:[:x :y | x@y] 
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  1900
    "
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  1901
!
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  1902
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  1903
pairWiseDo:aBlock
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  1904
    "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
  1905
     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
  1906
     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
  1907
     is not a multiple of 2."
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  1908
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  1909
    |stop "{ Class:SmallInteger }"|
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  1910
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  1911
    stop := self size.
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  1912
    1 to:stop by:2 do:[:index |
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  1913
	aBlock value:(self at:index) value:(self at:index+1).
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  1914
    ]
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  1915
    "
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  1916
     #(1 one 2 two 3 three 4 four 5 five 6 six) 
1422
9a0b792f2953 showCr: -> showCR:
Claus Gittinger <cg@exept.de>
parents: 1421
diff changeset
  1917
     pairWiseDo:[:num :sym | Transcript show:num; show:' is: '; showCR:sym]
602
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  1918
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  1919
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  1920
     #(1 1  1 2  1 3  1 4  1 5) 
1422
9a0b792f2953 showCr: -> showCR:
Claus Gittinger <cg@exept.de>
parents: 1421
diff changeset
  1921
     pairWiseDo:[:x :y | Transcript showCR:x@y]
95
d22739a0c6e9 *** empty log message ***
claus
parents: 88
diff changeset
  1922
    "
61
claus
parents: 44
diff changeset
  1923
!
claus
parents: 44
diff changeset
  1924
602
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  1925
reverseDo:aBlock
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  1926
    "evaluate the argument, aBlock for every element in the collection
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  1927
     in reverse order"
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  1928
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  1929
    |sz  "{ Class:SmallInteger }"|
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  1930
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  1931
    sz := self size.
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  1932
    sz to:1 by:-1 do:[:index |
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  1933
	aBlock value:(self at:index).
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  1934
    ]
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
    "
1422
9a0b792f2953 showCr: -> showCR:
Claus Gittinger <cg@exept.de>
parents: 1421
diff changeset
  1937
     #(one two three four five six) reverseDo:[:element | Transcript showCR:element]
602
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
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  1941
select:aBlock
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  1942
    "evaluate the argument, aBlock for every element in the collection
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  1943
     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
  1944
     true"
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
    |element newColl species needCopy
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  1947
     sz  "{ Class:SmallInteger }"|
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  1948
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  1949
    sz := self size.
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  1950
    species := self species.
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  1951
    species growIsCheap ifFalse:[
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  1952
	newColl := OrderedCollection new:sz.
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  1953
	needCopy := true
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  1954
    ] ifTrue:[
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  1955
	newColl := self copyEmpty:sz.
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  1956
	needCopy := false
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  1957
    ].
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  1958
    1 to:sz do:[:index |
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  1959
	element := self at:index.
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  1960
	(aBlock value:element) ifTrue:[
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  1961
	    newColl add:element
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  1962
	].
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  1963
    ].
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  1964
    needCopy ifTrue:[
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  1965
	newColl := (species withAll:newColl) postCopyFrom:self
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  1966
    ].
61
claus
parents: 44
diff changeset
  1967
    ^ newColl
claus
parents: 44
diff changeset
  1968
95
d22739a0c6e9 *** empty log message ***
claus
parents: 88
diff changeset
  1969
    "
602
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  1970
     #(one two three four five six) select:[:element | element startsWith:'f']   
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  1971
     #(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
  1972
     (#(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
  1973
     (1 to:9) select:[:element | element odd]   
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  1974
     (Smalltalk allClasses) select:[:class | class name startsWith:'S']   
95
d22739a0c6e9 *** empty log message ***
claus
parents: 88
diff changeset
  1975
    "
186
a4c3032fc825 *** empty log message ***
claus
parents: 159
diff changeset
  1976
!
a4c3032fc825 *** empty log message ***
claus
parents: 159
diff changeset
  1977
602
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  1978
with:aSequenceableCollection do:aTwoArgBlock
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  1979
    "evaluate the argument, aBlock for successive elements from
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  1980
     each the receiver and the argument, aSequenceableCollection.
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  1981
     The second argument, aBlock must be a two-argument block.
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  1982
     The collection argument must implement access via a numeric key."
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  1983
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  1984
    |stop  "{ Class: SmallInteger }" |
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  1985
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  1986
    stop := self size.
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  1987
    1 to:stop do:[:index |
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  1988
	aTwoArgBlock value:(self at:index) value:(aSequenceableCollection at:index).
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  1989
    ]
186
a4c3032fc825 *** empty log message ***
claus
parents: 159
diff changeset
  1990
    "
1422
9a0b792f2953 showCr: -> showCR:
Claus Gittinger <cg@exept.de>
parents: 1421
diff changeset
  1991
     #(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
  1992
    "
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1993
! !
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1994
4154
6938d9274ee4 category rename
Claus Gittinger <cg@exept.de>
parents: 3992
diff changeset
  1995
!SequenceableCollection methodsFor:'filling & replacing'!
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1996
602
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  1997
atAllPut:anObject
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  1998
    "replace all elements of the collection by the argument, anObject.
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  1999
     Notice: This operation modifies the receiver, NOT a copy;
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  2000
     therefore the change may affect all others referencing the receiver."
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  2001
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  2002
    self from:1 to:(self size) put:anObject
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  2003
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  2004
    "
3468
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  2005
     args:    anObject : <object>
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  2006
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  2007
     returns: self
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  2008
    "
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  2009
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  2010
    "
602
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  2011
     (Array new:10) atAllPut:1
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  2012
     (String new:10) atAllPut:$a
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  2013
    "
3468
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  2014
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  2015
    "Modified: / 20.5.1998 / 15:14:11 / cg"
602
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
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  2018
from:index1 to:index2 put:anObject
a27a279701f8 Initial revision
claus
parents:
diff changeset
  2019
    "replace the elements from index1 to index2 of the collection
44
b262907c93ea *** empty log message ***
claus
parents: 42
diff changeset
  2020
     by the argument, anObject.
b262907c93ea *** empty log message ***
claus
parents: 42
diff changeset
  2021
     Notice: This operation modifies the receiver, NOT a copy;
b262907c93ea *** empty log message ***
claus
parents: 42
diff changeset
  2022
     therefore the change may affect all others referencing the receiver."
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  2023
a27a279701f8 Initial revision
claus
parents:
diff changeset
  2024
    |index "{ Class: SmallInteger }"
a27a279701f8 Initial revision
claus
parents:
diff changeset
  2025
     end   "{ Class: SmallInteger }"|
a27a279701f8 Initial revision
claus
parents:
diff changeset
  2026
a27a279701f8 Initial revision
claus
parents:
diff changeset
  2027
    index := index1.
a27a279701f8 Initial revision
claus
parents:
diff changeset
  2028
    end := index2.
a27a279701f8 Initial revision
claus
parents:
diff changeset
  2029
    [index <= end] whileTrue:[
3468
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  2030
        self at:index put:anObject.
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  2031
        index := index + 1
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  2032
    ]
44
b262907c93ea *** empty log message ***
claus
parents: 42
diff changeset
  2033
95
d22739a0c6e9 *** empty log message ***
claus
parents: 88
diff changeset
  2034
    "
3468
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  2035
     args:    index1    : <integer>
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  2036
              index2    : <integer>
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  2037
              anObject  : <object>
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  2038
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  2039
     returns: self
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  2040
    "
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  2041
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  2042
    "
95
d22739a0c6e9 *** empty log message ***
claus
parents: 88
diff changeset
  2043
     #(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
  2044
     'abcdefghijkl' from:3 to:6 put:$X
d22739a0c6e9 *** empty log message ***
claus
parents: 88
diff changeset
  2045
    "
3468
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  2046
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  2047
    "Modified: / 20.5.1998 / 15:16:52 / cg"
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  2048
!
a27a279701f8 Initial revision
claus
parents:
diff changeset
  2049
3003
0f66385bbbd2 replaceAny / replaceAll
Claus Gittinger <cg@exept.de>
parents: 2980
diff changeset
  2050
replaceAll:oldObject by:newObject
0f66385bbbd2 replaceAny / replaceAll
Claus Gittinger <cg@exept.de>
parents: 2980
diff changeset
  2051
    "backward ST/X compatibility: an alias for #replaceAll:with:.
0f66385bbbd2 replaceAny / replaceAll
Claus Gittinger <cg@exept.de>
parents: 2980
diff changeset
  2052
     Pleace do no longer use this one;
0f66385bbbd2 replaceAny / replaceAll
Claus Gittinger <cg@exept.de>
parents: 2980
diff changeset
  2053
     instead use #replaceAll:with: for ST-80 compatibility."
0f66385bbbd2 replaceAny / replaceAll
Claus Gittinger <cg@exept.de>
parents: 2980
diff changeset
  2054
3468
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  2055
    self obsoleteMethodWarning:'use #replaceAll:with:'.
3003
0f66385bbbd2 replaceAny / replaceAll
Claus Gittinger <cg@exept.de>
parents: 2980
diff changeset
  2056
    ^ self replaceAll:oldObject with:newObject
0f66385bbbd2 replaceAny / replaceAll
Claus Gittinger <cg@exept.de>
parents: 2980
diff changeset
  2057
3468
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  2058
    "
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  2059
     args:    oldObject  : <object>
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  2060
              newObject  : <object>
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  2061
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  2062
     returns: self
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  2063
    "
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  2064
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  2065
    "Modified: / 20.5.1998 / 15:16:28 / cg"
3003
0f66385bbbd2 replaceAny / replaceAll
Claus Gittinger <cg@exept.de>
parents: 2980
diff changeset
  2066
!
0f66385bbbd2 replaceAny / replaceAll
Claus Gittinger <cg@exept.de>
parents: 2980
diff changeset
  2067
0f66385bbbd2 replaceAny / replaceAll
Claus Gittinger <cg@exept.de>
parents: 2980
diff changeset
  2068
replaceAll:oldObject by:newObject from:startIndex to:stopIndex
0f66385bbbd2 replaceAny / replaceAll
Claus Gittinger <cg@exept.de>
parents: 2980
diff changeset
  2069
    "backward ST/X compatibility: an alias for #replaceAll:with:from:to:.
3468
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  2070
     Please do no longer use this one;
3003
0f66385bbbd2 replaceAny / replaceAll
Claus Gittinger <cg@exept.de>
parents: 2980
diff changeset
  2071
     instead use #replaceAll:with:from:to: for ST-80 compatibility."
0f66385bbbd2 replaceAny / replaceAll
Claus Gittinger <cg@exept.de>
parents: 2980
diff changeset
  2072
3468
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  2073
    self obsoleteMethodWarning:'use #replaceAll:with:from:to:'.
3003
0f66385bbbd2 replaceAny / replaceAll
Claus Gittinger <cg@exept.de>
parents: 2980
diff changeset
  2074
    ^ self replaceAll:oldObject with:newObject from:startIndex to:stopIndex
3468
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  2075
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  2076
    "
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  2077
     args:    oldObject  : <object>
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  2078
              newObject  : <object>
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  2079
              startIndex : <integer>
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  2080
              stopIndex  : <integer>
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  2081
        
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  2082
     returns: self
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  2083
    "
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  2084
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  2085
    "Modified: / 20.5.1998 / 15:16:02 / cg"
3003
0f66385bbbd2 replaceAny / replaceAll
Claus Gittinger <cg@exept.de>
parents: 2980
diff changeset
  2086
!
0f66385bbbd2 replaceAny / replaceAll
Claus Gittinger <cg@exept.de>
parents: 2980
diff changeset
  2087
2927
1434c3d7f78a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2881
diff changeset
  2088
replaceAll:oldObject with:newObject
44
b262907c93ea *** empty log message ***
claus
parents: 42
diff changeset
  2089
    "replace all oldObjects by newObject in the receiver.
3468
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  2090
44
b262907c93ea *** empty log message ***
claus
parents: 42
diff changeset
  2091
     Notice: This operation modifies the receiver, NOT a copy;
b262907c93ea *** empty log message ***
claus
parents: 42
diff changeset
  2092
     therefore the change may affect all others referencing the receiver."
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  2093
3468
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  2094
    ^ self 
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  2095
        replaceAll:oldObject 
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  2096
        with:newObject 
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  2097
        from:1 
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  2098
        to:self size
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  2099
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  2100
    "
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  2101
     args:    oldObject  : <object>
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  2102
              newObject  : <object>
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  2103
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  2104
     returns: self
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  2105
    "
362
claus
parents: 360
diff changeset
  2106
claus
parents: 360
diff changeset
  2107
    "
2980
a662ffcfad1d *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2927
diff changeset
  2108
     '123123abc123' replaceAll:$1 with:$*  
a662ffcfad1d *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2927
diff changeset
  2109
     #(1 2 3 4 1 2 3 4) copy replaceAll:1 with:'one' 
362
claus
parents: 360
diff changeset
  2110
    "
3468
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  2111
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  2112
    "Modified: / 20.5.1998 / 15:26:10 / cg"
362
claus
parents: 360
diff changeset
  2113
!
293
31df3850e98c *** empty log message ***
claus
parents: 282
diff changeset
  2114
2927
1434c3d7f78a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2881
diff changeset
  2115
replaceAll:oldObject with:newObject from:startIndex to:stopIndex
362
claus
parents: 360
diff changeset
  2116
    "replace all oldObjects found between startIndex and endIndex,
claus
parents: 360
diff changeset
  2117
     by newObject in the receiver.
3468
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  2118
362
claus
parents: 360
diff changeset
  2119
     Notice: This operation modifies the receiver, NOT a copy;
claus
parents: 360
diff changeset
  2120
     therefore the change may affect all others referencing the receiver."
claus
parents: 360
diff changeset
  2121
claus
parents: 360
diff changeset
  2122
    |start "{ Class: SmallInteger }"
claus
parents: 360
diff changeset
  2123
     stop  "{ Class: SmallInteger }"|
claus
parents: 360
diff changeset
  2124
claus
parents: 360
diff changeset
  2125
    start := startIndex.
claus
parents: 360
diff changeset
  2126
    stop := stopIndex.
claus
parents: 360
diff changeset
  2127
    startIndex to:stopIndex do:[:index |
3468
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  2128
        (self at:index) = oldObject ifTrue:[
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  2129
            self at:index put:newObject
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  2130
        ]
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  2131
    ]
44
b262907c93ea *** empty log message ***
claus
parents: 42
diff changeset
  2132
95
d22739a0c6e9 *** empty log message ***
claus
parents: 88
diff changeset
  2133
    "
3468
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  2134
     args:    oldObject  : <object>
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  2135
              newObject  : <object>
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  2136
              startIndex : <integer>
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  2137
              stopIndex  : <integer> 
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  2138
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  2139
     returns: self
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  2140
    "
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  2141
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  2142
    "
2980
a662ffcfad1d *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2927
diff changeset
  2143
     '123123abc123' replaceAll:$1 with:$*
a662ffcfad1d *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2927
diff changeset
  2144
     '123123abc123' replaceAll:$1 with:$* from:1 to:6
a662ffcfad1d *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2927
diff changeset
  2145
     #(1 2 3 4 1 2 3 4) replaceAll:1 with:'one' from:1 to:4
95
d22739a0c6e9 *** empty log message ***
claus
parents: 88
diff changeset
  2146
    "
3468
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  2147
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  2148
    "Modified: / 20.5.1998 / 15:23:10 / cg"
95
d22739a0c6e9 *** empty log message ***
claus
parents: 88
diff changeset
  2149
!
d22739a0c6e9 *** empty log message ***
claus
parents: 88
diff changeset
  2150
3003
0f66385bbbd2 replaceAny / replaceAll
Claus Gittinger <cg@exept.de>
parents: 2980
diff changeset
  2151
replaceAny:aCollection by:newObject
0f66385bbbd2 replaceAny / replaceAll
Claus Gittinger <cg@exept.de>
parents: 2980
diff changeset
  2152
    "backward ST/X compatibility; alias for #replaceAny:with:.
2927
1434c3d7f78a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2881
diff changeset
  2153
     Pleace do no longer use this one;
3003
0f66385bbbd2 replaceAny / replaceAll
Claus Gittinger <cg@exept.de>
parents: 2980
diff changeset
  2154
     instead use #replaceAny:with: for naming consistence."
0f66385bbbd2 replaceAny / replaceAll
Claus Gittinger <cg@exept.de>
parents: 2980
diff changeset
  2155
3468
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  2156
    self obsoleteMethodWarning:'use #replaceAny:with:'.
3003
0f66385bbbd2 replaceAny / replaceAll
Claus Gittinger <cg@exept.de>
parents: 2980
diff changeset
  2157
    ^ self replaceAny:aCollection with:newObject from:1 to:self size 
0f66385bbbd2 replaceAny / replaceAll
Claus Gittinger <cg@exept.de>
parents: 2980
diff changeset
  2158
0f66385bbbd2 replaceAny / replaceAll
Claus Gittinger <cg@exept.de>
parents: 2980
diff changeset
  2159
    "
3468
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  2160
     args:    aCollection    : <colleciton of <object> >
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  2161
              newObject      : <object>
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  2162
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  2163
     returns: self
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  2164
    "
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  2165
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  2166
    "
3003
0f66385bbbd2 replaceAny / replaceAll
Claus Gittinger <cg@exept.de>
parents: 2980
diff changeset
  2167
     '123123abc123' replaceAny:#($1 $2) with:$*
0f66385bbbd2 replaceAny / replaceAll
Claus Gittinger <cg@exept.de>
parents: 2980
diff changeset
  2168
     #('foo' 'bar' 'foo' 'baz' foo 1 2 3) replaceAny:#(foo 1) with:'*'
0f66385bbbd2 replaceAny / replaceAll
Claus Gittinger <cg@exept.de>
parents: 2980
diff changeset
  2169
    "
0f66385bbbd2 replaceAny / replaceAll
Claus Gittinger <cg@exept.de>
parents: 2980
diff changeset
  2170
3468
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  2171
    "Modified: / 20.5.1998 / 15:17:51 / cg"
602
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  2172
!
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  2173
3003
0f66385bbbd2 replaceAny / replaceAll
Claus Gittinger <cg@exept.de>
parents: 2980
diff changeset
  2174
replaceAny:aCollection by:newObject from:startIndex to:stopIndex
0f66385bbbd2 replaceAny / replaceAll
Claus Gittinger <cg@exept.de>
parents: 2980
diff changeset
  2175
    "backward ST/X compatibility; alias for #replaceAny:with:from:to:.
2927
1434c3d7f78a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2881
diff changeset
  2176
     Pleace do no longer use this one;
3003
0f66385bbbd2 replaceAny / replaceAll
Claus Gittinger <cg@exept.de>
parents: 2980
diff changeset
  2177
     instead use #replaceAny:with:from:to: for naming consistence."
0f66385bbbd2 replaceAny / replaceAll
Claus Gittinger <cg@exept.de>
parents: 2980
diff changeset
  2178
    
3468
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  2179
    self obsoleteMethodWarning:'use #replaceAny:with:from:to:'.
3003
0f66385bbbd2 replaceAny / replaceAll
Claus Gittinger <cg@exept.de>
parents: 2980
diff changeset
  2180
    ^ self replaceAny:aCollection with:newObject from:startIndex to:stopIndex 
0f66385bbbd2 replaceAny / replaceAll
Claus Gittinger <cg@exept.de>
parents: 2980
diff changeset
  2181
0f66385bbbd2 replaceAny / replaceAll
Claus Gittinger <cg@exept.de>
parents: 2980
diff changeset
  2182
    "
3468
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  2183
     args:    aCollection    : <colleciton of <object> >
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  2184
              newObject      : <object>
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  2185
              startIndex     : <integer>
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  2186
              stopIndex     : <integer>
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  2187
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  2188
     returns: self
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  2189
    "
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  2190
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  2191
    "
3003
0f66385bbbd2 replaceAny / replaceAll
Claus Gittinger <cg@exept.de>
parents: 2980
diff changeset
  2192
     '123123abc123' replaceAny:#($1 $2) with:$* from:1 to:6      
0f66385bbbd2 replaceAny / replaceAll
Claus Gittinger <cg@exept.de>
parents: 2980
diff changeset
  2193
     #('foo' 'bar' 'foo' 'baz' foo 1 2 3) replaceAny:#(foo 1) with:'*'  
0f66385bbbd2 replaceAny / replaceAll
Claus Gittinger <cg@exept.de>
parents: 2980
diff changeset
  2194
    "
0f66385bbbd2 replaceAny / replaceAll
Claus Gittinger <cg@exept.de>
parents: 2980
diff changeset
  2195
3468
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  2196
    "Modified: / 20.5.1998 / 15:18:16 / cg"
2927
1434c3d7f78a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2881
diff changeset
  2197
!
1434c3d7f78a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2881
diff changeset
  2198
1434c3d7f78a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2881
diff changeset
  2199
replaceAny:aCollection with:newObject
1434c3d7f78a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2881
diff changeset
  2200
    "replace all elements, which are in aCollection, by newObject.
3468
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  2201
2927
1434c3d7f78a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2881
diff changeset
  2202
     Notice: This operation modifies the receiver, NOT a copy;
1434c3d7f78a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2881
diff changeset
  2203
     therefore the change may affect all others referencing the receiver."
1434c3d7f78a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2881
diff changeset
  2204
3468
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  2205
    ^ self 
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  2206
        replaceAny:aCollection 
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  2207
        with:newObject 
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  2208
        from:1 
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  2209
        to:self size
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  2210
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  2211
    "
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  2212
     args:    aCollection    : <colleciton of <object> >
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  2213
              newObject      : <object>
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  2214
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  2215
     returns: self
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  2216
    "
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  2217
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  2218
    "Modified: / 20.5.1998 / 15:25:58 / cg"
602
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  2219
!
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  2220
2927
1434c3d7f78a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2881
diff changeset
  2221
replaceAny:aCollection with:newObject from:startIndex to:stopIndex
362
claus
parents: 360
diff changeset
  2222
    "replace all elements within a range,
claus
parents: 360
diff changeset
  2223
     which are in contained in aCollection by newObject.
3468
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  2224
362
claus
parents: 360
diff changeset
  2225
     Notice: This operation modifies the receiver, NOT a copy;
claus
parents: 360
diff changeset
  2226
     therefore the change may affect all others referencing the receiver."
claus
parents: 360
diff changeset
  2227
claus
parents: 360
diff changeset
  2228
    |start "{ Class: SmallInteger }"
claus
parents: 360
diff changeset
  2229
     stop "{ Class: SmallInteger }"|
claus
parents: 360
diff changeset
  2230
claus
parents: 360
diff changeset
  2231
    start := startIndex.
claus
parents: 360
diff changeset
  2232
    stop := stopIndex.
claus
parents: 360
diff changeset
  2233
    startIndex to:stopIndex do:[:index |
3468
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  2234
        (aCollection includes:(self at:index)) ifTrue:[
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  2235
            self at:index put:newObject
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  2236
        ]
95
d22739a0c6e9 *** empty log message ***
claus
parents: 88
diff changeset
  2237
    ]
d22739a0c6e9 *** empty log message ***
claus
parents: 88
diff changeset
  2238
d22739a0c6e9 *** empty log message ***
claus
parents: 88
diff changeset
  2239
    "
3468
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  2240
     args:    aCollection    : <colleciton of <object> >
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  2241
              newObject      : <object>
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  2242
              startIndex     : <integer>
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  2243
              stopIndex      : <integer>
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  2244
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  2245
     returns: self
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  2246
    "
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  2247
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  2248
    "
2927
1434c3d7f78a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2881
diff changeset
  2249
     '123123abc123' replaceAny:#($1 $2) with:$* from:1 to:6      
1434c3d7f78a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2881
diff changeset
  2250
     #('foo' 'bar' 'foo' 'baz' foo 1 2 3) replaceAny:#(foo 1) with:'*'  
95
d22739a0c6e9 *** empty log message ***
claus
parents: 88
diff changeset
  2251
    "
3468
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  2252
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  2253
    "Modified: / 20.5.1998 / 15:22:43 / cg"
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  2254
!
a27a279701f8 Initial revision
claus
parents:
diff changeset
  2255
3468
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  2256
replaceFrom:startIndex count:numberOfElements with:replacementCollection
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  2257
    "replace numberOfElements elements in the receiver from startIndex,
2413
a3f91741d7ba added #replaceFrom:count:* methods
Claus Gittinger <cg@exept.de>
parents: 2411
diff changeset
  2258
     with elements taken from replacementCollection starting at 1.
3468
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  2259
2413
a3f91741d7ba added #replaceFrom:count:* methods
Claus Gittinger <cg@exept.de>
parents: 2411
diff changeset
  2260
     Notice: This operation modifies the receiver, NOT a copy;
a3f91741d7ba added #replaceFrom:count:* methods
Claus Gittinger <cg@exept.de>
parents: 2411
diff changeset
  2261
     therefore the change may affect all others referencing the receiver."
a3f91741d7ba added #replaceFrom:count:* methods
Claus Gittinger <cg@exept.de>
parents: 2411
diff changeset
  2262
3468
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  2263
    ^ self 
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  2264
        replaceFrom:startIndex
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  2265
        to:(startIndex + numberOfElements - 1)
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  2266
        with:replacementCollection
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  2267
        startingAt:1
2413
a3f91741d7ba added #replaceFrom:count:* methods
Claus Gittinger <cg@exept.de>
parents: 2411
diff changeset
  2268
a3f91741d7ba added #replaceFrom:count:* methods
Claus Gittinger <cg@exept.de>
parents: 2411
diff changeset
  2269
    "
a3f91741d7ba added #replaceFrom:count:* methods
Claus Gittinger <cg@exept.de>
parents: 2411
diff changeset
  2270
     '1234567890' replaceFrom:5 count:3 with:'abcdef'  
a3f91741d7ba added #replaceFrom:count:* methods
Claus Gittinger <cg@exept.de>
parents: 2411
diff changeset
  2271
     #($a $b $c $d $e) replaceFrom:2 count:2 with:'12345'
a3f91741d7ba added #replaceFrom:count:* methods
Claus Gittinger <cg@exept.de>
parents: 2411
diff changeset
  2272
    "
a3f91741d7ba added #replaceFrom:count:* methods
Claus Gittinger <cg@exept.de>
parents: 2411
diff changeset
  2273
3468
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  2274
    "Modified: / 20.5.1998 / 15:25:46 / cg"
2413
a3f91741d7ba added #replaceFrom:count:* methods
Claus Gittinger <cg@exept.de>
parents: 2411
diff changeset
  2275
!
a3f91741d7ba added #replaceFrom:count:* methods
Claus Gittinger <cg@exept.de>
parents: 2411
diff changeset
  2276
3468
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  2277
replaceFrom:startIndex count:numberOfElementsToReplace with:replacementCollection startingAt:repStartIndex
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  2278
    "replace numberOfElementsToReplace elements in the receiver from startIndex,
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  2279
     with elements taken from replacementCollection starting at repStartIndex.
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  2280
2413
a3f91741d7ba added #replaceFrom:count:* methods
Claus Gittinger <cg@exept.de>
parents: 2411
diff changeset
  2281
     Notice: This operation modifies the receiver, NOT a copy;
a3f91741d7ba added #replaceFrom:count:* methods
Claus Gittinger <cg@exept.de>
parents: 2411
diff changeset
  2282
     therefore the change may affect all others referencing the receiver."
a3f91741d7ba added #replaceFrom:count:* methods
Claus Gittinger <cg@exept.de>
parents: 2411
diff changeset
  2283
a3f91741d7ba added #replaceFrom:count:* methods
Claus Gittinger <cg@exept.de>
parents: 2411
diff changeset
  2284
    ^ self
3468
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  2285
        replaceFrom:startIndex
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  2286
        to:(startIndex + numberOfElementsToReplace - 1)
2413
a3f91741d7ba added #replaceFrom:count:* methods
Claus Gittinger <cg@exept.de>
parents: 2411
diff changeset
  2287
        with:replacementCollection
3468
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  2288
        startingAt:repStartIndex
2413
a3f91741d7ba added #replaceFrom:count:* methods
Claus Gittinger <cg@exept.de>
parents: 2411
diff changeset
  2289
a3f91741d7ba added #replaceFrom:count:* methods
Claus Gittinger <cg@exept.de>
parents: 2411
diff changeset
  2290
    "
a3f91741d7ba added #replaceFrom:count:* methods
Claus Gittinger <cg@exept.de>
parents: 2411
diff changeset
  2291
     '1234567890' replaceFrom:5 count:3 with:'abcdef' startingAt:3  
a3f91741d7ba added #replaceFrom:count:* methods
Claus Gittinger <cg@exept.de>
parents: 2411
diff changeset
  2292
     #($a $b $c $d $e) replaceFrom:2 count:3 with:'12345' startingAt:4 
a3f91741d7ba added #replaceFrom:count:* methods
Claus Gittinger <cg@exept.de>
parents: 2411
diff changeset
  2293
     #($a $b $c $d $e) asOrderedCollection replaceFrom:2 count:3 with:'12345' startingAt:4 
a3f91741d7ba added #replaceFrom:count:* methods
Claus Gittinger <cg@exept.de>
parents: 2411
diff changeset
  2294
    "
a3f91741d7ba added #replaceFrom:count:* methods
Claus Gittinger <cg@exept.de>
parents: 2411
diff changeset
  2295
3468
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  2296
    "Modified: / 20.5.1998 / 15:22:22 / cg"
2413
a3f91741d7ba added #replaceFrom:count:* methods
Claus Gittinger <cg@exept.de>
parents: 2411
diff changeset
  2297
!
a3f91741d7ba added #replaceFrom:count:* methods
Claus Gittinger <cg@exept.de>
parents: 2411
diff changeset
  2298
3468
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  2299
replaceFrom:startIndex to:stopIndex with:replacementCollection
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  2300
    "replace elements in the receiver between index startIndex and stopIndex,
44
b262907c93ea *** empty log message ***
claus
parents: 42
diff changeset
  2301
     with elements taken from replacementCollection starting at 1.
3468
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  2302
44
b262907c93ea *** empty log message ***
claus
parents: 42
diff changeset
  2303
     Notice: This operation modifies the receiver, NOT a copy;
b262907c93ea *** empty log message ***
claus
parents: 42
diff changeset
  2304
     therefore the change may affect all others referencing the receiver."
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  2305
3468
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  2306
    ^ self 
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  2307
        replaceFrom:startIndex
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  2308
        to:stopIndex
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  2309
        with:replacementCollection
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  2310
        startingAt:1
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  2311
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  2312
    "
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  2313
     args:    startIndex            : <integer>
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  2314
              stopIndex             : <integer>
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  2315
              replacementCollection : <colleciton of <object> >
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  2316
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  2317
     returns: self
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  2318
    "
61
claus
parents: 44
diff changeset
  2319
95
d22739a0c6e9 *** empty log message ***
claus
parents: 88
diff changeset
  2320
    "
d22739a0c6e9 *** empty log message ***
claus
parents: 88
diff changeset
  2321
     '1234567890' replaceFrom:5 to:7 with:'abcdef'
d22739a0c6e9 *** empty log message ***
claus
parents: 88
diff changeset
  2322
     #($a $b $c $d $e) replaceFrom:2 to:3 with:'12345'
d22739a0c6e9 *** empty log message ***
claus
parents: 88
diff changeset
  2323
    "
3468
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  2324
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  2325
    "Modified: / 20.5.1998 / 15:25:37 / cg"
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  2326
!
a27a279701f8 Initial revision
claus
parents:
diff changeset
  2327
3468
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  2328
replaceFrom:startIndex to:stopIndex with:replacementCollection startingAt:repStartIndex
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  2329
    "replace elements in the receiver between index startIndex and stopIndex,
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  2330
     with elements  taken from replacementCollection starting at repStartIndex.
3234
4cc58bc6a8ed comment
Claus Gittinger <cg@exept.de>
parents: 3055
diff changeset
  2331
     Return the receiver.
3468
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  2332
44
b262907c93ea *** empty log message ***
claus
parents: 42
diff changeset
  2333
     Notice: This operation modifies the receiver, NOT a copy;
b262907c93ea *** empty log message ***
claus
parents: 42
diff changeset
  2334
     therefore the change may affect all others referencing the receiver."
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  2335
a27a279701f8 Initial revision
claus
parents:
diff changeset
  2336
    |srcIndex "{ Class: SmallInteger }"
a27a279701f8 Initial revision
claus
parents:
diff changeset
  2337
     dstIndex "{ Class: SmallInteger }"
a27a279701f8 Initial revision
claus
parents:
diff changeset
  2338
     end      "{ Class: SmallInteger }" |
a27a279701f8 Initial revision
claus
parents:
diff changeset
  2339
3468
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  2340
    (repStartIndex < startIndex) ifTrue:[
3234
4cc58bc6a8ed comment
Claus Gittinger <cg@exept.de>
parents: 3055
diff changeset
  2341
        " must do reverse copy "
3468
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  2342
        srcIndex := repStartIndex + (stopIndex - startIndex).
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  2343
        dstIndex := stopIndex.
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  2344
        end := startIndex.
3234
4cc58bc6a8ed comment
Claus Gittinger <cg@exept.de>
parents: 3055
diff changeset
  2345
        [dstIndex >= end] whileTrue:[
4cc58bc6a8ed comment
Claus Gittinger <cg@exept.de>
parents: 3055
diff changeset
  2346
            self at:dstIndex put:(replacementCollection at:srcIndex).
4cc58bc6a8ed comment
Claus Gittinger <cg@exept.de>
parents: 3055
diff changeset
  2347
            srcIndex := srcIndex - 1.
4cc58bc6a8ed comment
Claus Gittinger <cg@exept.de>
parents: 3055
diff changeset
  2348
            dstIndex := dstIndex - 1
4cc58bc6a8ed comment
Claus Gittinger <cg@exept.de>
parents: 3055
diff changeset
  2349
        ].
4cc58bc6a8ed comment
Claus Gittinger <cg@exept.de>
parents: 3055
diff changeset
  2350
        ^ self
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  2351
    ].
a27a279701f8 Initial revision
claus
parents:
diff changeset
  2352
3468
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  2353
    srcIndex := repStartIndex.
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  2354
    dstIndex := startIndex.
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  2355
    end := stopIndex.
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  2356
    [dstIndex <= end] whileTrue:[
3234
4cc58bc6a8ed comment
Claus Gittinger <cg@exept.de>
parents: 3055
diff changeset
  2357
        self at:dstIndex put:(replacementCollection at:srcIndex).
4cc58bc6a8ed comment
Claus Gittinger <cg@exept.de>
parents: 3055
diff changeset
  2358
        srcIndex := srcIndex + 1.
4cc58bc6a8ed comment
Claus Gittinger <cg@exept.de>
parents: 3055
diff changeset
  2359
        dstIndex := dstIndex + 1
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  2360
    ]
61
claus
parents: 44
diff changeset
  2361
95
d22739a0c6e9 *** empty log message ***
claus
parents: 88
diff changeset
  2362
    "
3468
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  2363
     args:    startIndex            : <integer>
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  2364
              stopIndex             : <integer>
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  2365
              replacementCollection : <colleciton of <object> >
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  2366
              repStartIndex         : <integer>
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  2367
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  2368
     returns: self
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  2369
    "
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  2370
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  2371
    "
282
94f5c3a6230d *** empty log message ***
claus
parents: 266
diff changeset
  2372
     '1234567890' replaceFrom:5 to:7 with:'abcdef' startingAt:3  
94f5c3a6230d *** empty log message ***
claus
parents: 266
diff changeset
  2373
     #($a $b $c $d $e) replaceFrom:2 to:3 with:'12345' startingAt:4 
94f5c3a6230d *** empty log message ***
claus
parents: 266
diff changeset
  2374
     #($a $b $c $d $e) asOrderedCollection replaceFrom:2 to:3 with:'12345' startingAt:4 
94f5c3a6230d *** empty log message ***
claus
parents: 266
diff changeset
  2375
94f5c3a6230d *** empty log message ***
claus
parents: 266
diff changeset
  2376
     |c|
94f5c3a6230d *** empty log message ***
claus
parents: 266
diff changeset
  2377
     c := #($a $b $c $d $e) asOrderedCollection.
94f5c3a6230d *** empty log message ***
claus
parents: 266
diff changeset
  2378
     c replaceFrom:2 to:3 with:c startingAt:4  
94f5c3a6230d *** empty log message ***
claus
parents: 266
diff changeset
  2379
94f5c3a6230d *** empty log message ***
claus
parents: 266
diff changeset
  2380
     |c|
94f5c3a6230d *** empty log message ***
claus
parents: 266
diff changeset
  2381
     c := #($a $b $c $d $e) asOrderedCollection.
94f5c3a6230d *** empty log message ***
claus
parents: 266
diff changeset
  2382
     c replaceFrom:4 to:5 with:c startingAt:2  
95
d22739a0c6e9 *** empty log message ***
claus
parents: 88
diff changeset
  2383
    "
3234
4cc58bc6a8ed comment
Claus Gittinger <cg@exept.de>
parents: 3055
diff changeset
  2384
3468
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  2385
    "Modified: / 20.5.1998 / 15:23:21 / cg"
61
claus
parents: 44
diff changeset
  2386
!
claus
parents: 44
diff changeset
  2387
3468
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  2388
replaceFrom:startIndex with:replacementCollection
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  2389
    "replace elements in the receiver starting at startIndex,
602
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  2390
     with elements taken from replacementCollection starting at 1
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  2391
     to the end of replacementCollection.
3468
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  2392
602
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  2393
     Notice: This operation modifies the receiver, NOT a copy;
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  2394
     therefore the change may affect all others referencing the receiver."
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  2395
3468
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  2396
    ^ self 
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  2397
        replaceFrom:startIndex 
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  2398
        to:(startIndex + replacementCollection size - 1)
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  2399
        with:replacementCollection
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  2400
        startingAt:1
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  2401
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  2402
    "
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  2403
     args:    startIndex            : <integer>
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  2404
              replacementCollection : <colleciton of <object> >
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  2405
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  2406
     returns: self
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  2407
    "
602
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  2408
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  2409
    "
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  2410
     '1234567890' replaceFrom:5 with:'abc'
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  2411
     #($a $b $c $d $e) replaceFrom:2 with:'123'
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  2412
    "
3468
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  2413
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  2414
    "Modified: / 20.5.1998 / 15:25:27 / cg"
602
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  2415
!
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  2416
3468
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  2417
replaceFrom:startIndex with:replacementCollection startingAt:repStartIndex
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  2418
    "replace elements in the receiver starting at startIndex,
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  2419
     with elements taken from replacementCollection starting at repStartIndex
602
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  2420
     to the end of replacementCollection.
3468
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  2421
602
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  2422
     Notice: This operation modifies the receiver, NOT a copy;
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  2423
     therefore the change may affect all others referencing the receiver."
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  2424
3468
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  2425
    ^ self 
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  2426
        replaceFrom:startIndex 
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  2427
        to:(startIndex + replacementCollection size - repStartIndex)
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  2428
        with:replacementCollection
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  2429
        startingAt:repStartIndex
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  2430
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  2431
    "
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  2432
     args:    startIndex            : <integer>
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  2433
              replacementCollection : <colleciton of <object> >
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  2434
              offset                : <integer>
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  2435
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  2436
     returns: self
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  2437
    "
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  2438
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  2439
    "
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  2440
     '1234567890' replaceFrom:5 with:'abcdef' startingAt:3  
602
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  2441
     #($a $b $c $d $e) replaceFrom:2 with:'12345' startingAt:4
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  2442
    "
3468
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  2443
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  2444
    "Modified: / 20.5.1998 / 15:25:18 / cg"
602
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  2445
!
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  2446
61
claus
parents: 44
diff changeset
  2447
startingAt:sourceStart replaceElementsIn:destColl from:destStartIndex to:destEndIndex
claus
parents: 44
diff changeset
  2448
    "replace elements in destColl with elements from the receiver.
3468
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  2449
61
claus
parents: 44
diff changeset
  2450
     Notice: This operation modifies the destination collection, NOT a copy;
claus
parents: 44
diff changeset
  2451
     therefore the change may affect all others referencing this object."
claus
parents: 44
diff changeset
  2452
3468
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  2453
    destColl 
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  2454
        replaceFrom:destStartIndex 
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  2455
        to:destEndIndex 
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  2456
        with:self 
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  2457
        startingAt:sourceStart
61
claus
parents: 44
diff changeset
  2458
claus
parents: 44
diff changeset
  2459
    "
claus
parents: 44
diff changeset
  2460
     |s|
claus
parents: 44
diff changeset
  2461
     s := 'abcdefghijklmnop'.
claus
parents: 44
diff changeset
  2462
     '1234567890' startingAt:1 replaceElementsIn:s from:1 to:3.
claus
parents: 44
diff changeset
  2463
     s'123defghijklmnop'
claus
parents: 44
diff changeset
  2464
    "
3468
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  2465
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  2466
    "Modified: / 20.5.1998 / 15:25:08 / cg"
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  2467
! !
a27a279701f8 Initial revision
claus
parents:
diff changeset
  2468
2069
f6183117f922 comments
Claus Gittinger <cg@exept.de>
parents: 1673
diff changeset
  2469
!SequenceableCollection methodsFor:'private sorting helpers'!
f6183117f922 comments
Claus Gittinger <cg@exept.de>
parents: 1673
diff changeset
  2470
f6183117f922 comments
Claus Gittinger <cg@exept.de>
parents: 1673
diff changeset
  2471
quickSortFrom:inBegin to:inEnd
f6183117f922 comments
Claus Gittinger <cg@exept.de>
parents: 1673
diff changeset
  2472
    "actual quicksort worker for sort-message"
f6183117f922 comments
Claus Gittinger <cg@exept.de>
parents: 1673
diff changeset
  2473
f6183117f922 comments
Claus Gittinger <cg@exept.de>
parents: 1673
diff changeset
  2474
    |begin   "{ Class: SmallInteger }"
f6183117f922 comments
Claus Gittinger <cg@exept.de>
parents: 1673
diff changeset
  2475
     end     "{ Class: SmallInteger }"
f6183117f922 comments
Claus Gittinger <cg@exept.de>
parents: 1673
diff changeset
  2476
     b       "{ Class: SmallInteger }"
f6183117f922 comments
Claus Gittinger <cg@exept.de>
parents: 1673
diff changeset
  2477
     e       "{ Class: SmallInteger }"
f6183117f922 comments
Claus Gittinger <cg@exept.de>
parents: 1673
diff changeset
  2478
     middleElement temp1 temp2 |
f6183117f922 comments
Claus Gittinger <cg@exept.de>
parents: 1673
diff changeset
  2479
f6183117f922 comments
Claus Gittinger <cg@exept.de>
parents: 1673
diff changeset
  2480
    begin := inBegin.   "/ this also does a type-check
f6183117f922 comments
Claus Gittinger <cg@exept.de>
parents: 1673
diff changeset
  2481
    end := inEnd.
f6183117f922 comments
Claus Gittinger <cg@exept.de>
parents: 1673
diff changeset
  2482
f6183117f922 comments
Claus Gittinger <cg@exept.de>
parents: 1673
diff changeset
  2483
    b := begin.
f6183117f922 comments
Claus Gittinger <cg@exept.de>
parents: 1673
diff changeset
  2484
    e := end.
f6183117f922 comments
Claus Gittinger <cg@exept.de>
parents: 1673
diff changeset
  2485
    middleElement := self at:((b + e) // 2).
f6183117f922 comments
Claus Gittinger <cg@exept.de>
parents: 1673
diff changeset
  2486
f6183117f922 comments
Claus Gittinger <cg@exept.de>
parents: 1673
diff changeset
  2487
    [b < e] whileTrue:[
f6183117f922 comments
Claus Gittinger <cg@exept.de>
parents: 1673
diff changeset
  2488
	[b < end and:[(self at:b) < middleElement]] whileTrue:[b := b + 1].
f6183117f922 comments
Claus Gittinger <cg@exept.de>
parents: 1673
diff changeset
  2489
	[e > begin and:[middleElement < (self at:e)]] whileTrue:[e := e - 1].
f6183117f922 comments
Claus Gittinger <cg@exept.de>
parents: 1673
diff changeset
  2490
f6183117f922 comments
Claus Gittinger <cg@exept.de>
parents: 1673
diff changeset
  2491
	(b <= e) ifTrue:[
f6183117f922 comments
Claus Gittinger <cg@exept.de>
parents: 1673
diff changeset
  2492
	    (b == e) ifFalse:[
f6183117f922 comments
Claus Gittinger <cg@exept.de>
parents: 1673
diff changeset
  2493
		temp1 := self at:b. temp2 := self at:e. 
f6183117f922 comments
Claus Gittinger <cg@exept.de>
parents: 1673
diff changeset
  2494
		self at:b put:temp2. self at:e put:temp1
f6183117f922 comments
Claus Gittinger <cg@exept.de>
parents: 1673
diff changeset
  2495
	    ].
f6183117f922 comments
Claus Gittinger <cg@exept.de>
parents: 1673
diff changeset
  2496
	    b := b + 1.
f6183117f922 comments
Claus Gittinger <cg@exept.de>
parents: 1673
diff changeset
  2497
	    e := e - 1
f6183117f922 comments
Claus Gittinger <cg@exept.de>
parents: 1673
diff changeset
  2498
	]
f6183117f922 comments
Claus Gittinger <cg@exept.de>
parents: 1673
diff changeset
  2499
    ].
f6183117f922 comments
Claus Gittinger <cg@exept.de>
parents: 1673
diff changeset
  2500
    (begin < e) ifTrue:[self quickSortFrom:begin to:e].
f6183117f922 comments
Claus Gittinger <cg@exept.de>
parents: 1673
diff changeset
  2501
    (b < end) ifTrue:[self quickSortFrom:b to:end]
f6183117f922 comments
Claus Gittinger <cg@exept.de>
parents: 1673
diff changeset
  2502
!
f6183117f922 comments
Claus Gittinger <cg@exept.de>
parents: 1673
diff changeset
  2503
f6183117f922 comments
Claus Gittinger <cg@exept.de>
parents: 1673
diff changeset
  2504
quickSortFrom:inBegin to:inEnd sortBlock:sortBlock
f6183117f922 comments
Claus Gittinger <cg@exept.de>
parents: 1673
diff changeset
  2505
    "actual quicksort worker for sort:-message"
f6183117f922 comments
Claus Gittinger <cg@exept.de>
parents: 1673
diff changeset
  2506
f6183117f922 comments
Claus Gittinger <cg@exept.de>
parents: 1673
diff changeset
  2507
    |begin   "{ Class: SmallInteger }"
f6183117f922 comments
Claus Gittinger <cg@exept.de>
parents: 1673
diff changeset
  2508
     end     "{ Class: SmallInteger }"
f6183117f922 comments
Claus Gittinger <cg@exept.de>
parents: 1673
diff changeset
  2509
     b       "{ Class: SmallInteger }"
f6183117f922 comments
Claus Gittinger <cg@exept.de>
parents: 1673
diff changeset
  2510
     e       "{ Class: SmallInteger }"
f6183117f922 comments
Claus Gittinger <cg@exept.de>
parents: 1673
diff changeset
  2511
     middleElement temp1 temp2 |
f6183117f922 comments
Claus Gittinger <cg@exept.de>
parents: 1673
diff changeset
  2512
f6183117f922 comments
Claus Gittinger <cg@exept.de>
parents: 1673
diff changeset
  2513
    begin := inBegin.   "/ this also does a type-check
f6183117f922 comments
Claus Gittinger <cg@exept.de>
parents: 1673
diff changeset
  2514
    end := inEnd.
f6183117f922 comments
Claus Gittinger <cg@exept.de>
parents: 1673
diff changeset
  2515
f6183117f922 comments
Claus Gittinger <cg@exept.de>
parents: 1673
diff changeset
  2516
    b := begin.
f6183117f922 comments
Claus Gittinger <cg@exept.de>
parents: 1673
diff changeset
  2517
    e := end.
f6183117f922 comments
Claus Gittinger <cg@exept.de>
parents: 1673
diff changeset
  2518
    middleElement := self at:((b + e) // 2).
f6183117f922 comments
Claus Gittinger <cg@exept.de>
parents: 1673
diff changeset
  2519
f6183117f922 comments
Claus Gittinger <cg@exept.de>
parents: 1673
diff changeset
  2520
    [b < e] whileTrue:[
f6183117f922 comments
Claus Gittinger <cg@exept.de>
parents: 1673
diff changeset
  2521
	[b < end and:[sortBlock value:(self at:b) value:middleElement]] whileTrue:[b := b + 1].
f6183117f922 comments
Claus Gittinger <cg@exept.de>
parents: 1673
diff changeset
  2522
	[e > begin and:[sortBlock value:middleElement value:(self at:e)]] whileTrue:[e := e - 1].
f6183117f922 comments
Claus Gittinger <cg@exept.de>
parents: 1673
diff changeset
  2523
f6183117f922 comments
Claus Gittinger <cg@exept.de>
parents: 1673
diff changeset
  2524
	(b <= e) ifTrue:[
f6183117f922 comments
Claus Gittinger <cg@exept.de>
parents: 1673
diff changeset
  2525
	    (b == e) ifFalse:[
f6183117f922 comments
Claus Gittinger <cg@exept.de>
parents: 1673
diff changeset
  2526
		temp1 := self at:b. temp2 := self at:e. 
f6183117f922 comments
Claus Gittinger <cg@exept.de>
parents: 1673
diff changeset
  2527
		self at:b put:temp2. self at:e put:temp1
f6183117f922 comments
Claus Gittinger <cg@exept.de>
parents: 1673
diff changeset
  2528
	    ].
f6183117f922 comments
Claus Gittinger <cg@exept.de>
parents: 1673
diff changeset
  2529
	    b := b + 1.
f6183117f922 comments
Claus Gittinger <cg@exept.de>
parents: 1673
diff changeset
  2530
	    e := e - 1
f6183117f922 comments
Claus Gittinger <cg@exept.de>
parents: 1673
diff changeset
  2531
	]
f6183117f922 comments
Claus Gittinger <cg@exept.de>
parents: 1673
diff changeset
  2532
    ].
f6183117f922 comments
Claus Gittinger <cg@exept.de>
parents: 1673
diff changeset
  2533
    (begin < e) ifTrue:[self quickSortFrom:begin to:e sortBlock:sortBlock].
f6183117f922 comments
Claus Gittinger <cg@exept.de>
parents: 1673
diff changeset
  2534
    (b < end) ifTrue:[self quickSortFrom:b to:end sortBlock:sortBlock]
f6183117f922 comments
Claus Gittinger <cg@exept.de>
parents: 1673
diff changeset
  2535
!
f6183117f922 comments
Claus Gittinger <cg@exept.de>
parents: 1673
diff changeset
  2536
3055
0832fba4c740 support 3-arg sort, passing a collationPolicy
Claus Gittinger <cg@exept.de>
parents: 3044
diff changeset
  2537
quickSortFrom:inBegin to:inEnd sortBlock:sortBlock policy:p
0832fba4c740 support 3-arg sort, passing a collationPolicy
Claus Gittinger <cg@exept.de>
parents: 3044
diff changeset
  2538
    "actual quicksort worker for sort:-message"
0832fba4c740 support 3-arg sort, passing a collationPolicy
Claus Gittinger <cg@exept.de>
parents: 3044
diff changeset
  2539
0832fba4c740 support 3-arg sort, passing a collationPolicy
Claus Gittinger <cg@exept.de>
parents: 3044
diff changeset
  2540
    |begin   "{ Class: SmallInteger }"
0832fba4c740 support 3-arg sort, passing a collationPolicy
Claus Gittinger <cg@exept.de>
parents: 3044
diff changeset
  2541
     end     "{ Class: SmallInteger }"
0832fba4c740 support 3-arg sort, passing a collationPolicy
Claus Gittinger <cg@exept.de>
parents: 3044
diff changeset
  2542
     b       "{ Class: SmallInteger }"
0832fba4c740 support 3-arg sort, passing a collationPolicy
Claus Gittinger <cg@exept.de>
parents: 3044
diff changeset
  2543
     e       "{ Class: SmallInteger }"
0832fba4c740 support 3-arg sort, passing a collationPolicy
Claus Gittinger <cg@exept.de>
parents: 3044
diff changeset
  2544
     middleElement temp1 temp2 |
0832fba4c740 support 3-arg sort, passing a collationPolicy
Claus Gittinger <cg@exept.de>
parents: 3044
diff changeset
  2545
0832fba4c740 support 3-arg sort, passing a collationPolicy
Claus Gittinger <cg@exept.de>
parents: 3044
diff changeset
  2546
    begin := inBegin.   "/ this also does a type-check
0832fba4c740 support 3-arg sort, passing a collationPolicy
Claus Gittinger <cg@exept.de>
parents: 3044
diff changeset
  2547
    end := inEnd.
0832fba4c740 support 3-arg sort, passing a collationPolicy
Claus Gittinger <cg@exept.de>
parents: 3044
diff changeset
  2548
0832fba4c740 support 3-arg sort, passing a collationPolicy
Claus Gittinger <cg@exept.de>
parents: 3044
diff changeset
  2549
    b := begin.
0832fba4c740 support 3-arg sort, passing a collationPolicy
Claus Gittinger <cg@exept.de>
parents: 3044
diff changeset
  2550
    e := end.
0832fba4c740 support 3-arg sort, passing a collationPolicy
Claus Gittinger <cg@exept.de>
parents: 3044
diff changeset
  2551
    middleElement := self at:((b + e) // 2).
0832fba4c740 support 3-arg sort, passing a collationPolicy
Claus Gittinger <cg@exept.de>
parents: 3044
diff changeset
  2552
0832fba4c740 support 3-arg sort, passing a collationPolicy
Claus Gittinger <cg@exept.de>
parents: 3044
diff changeset
  2553
    [b < e] whileTrue:[
0832fba4c740 support 3-arg sort, passing a collationPolicy
Claus Gittinger <cg@exept.de>
parents: 3044
diff changeset
  2554
        [b < end and:[sortBlock value:p value:(self at:b) value:middleElement]] whileTrue:[b := b + 1].
0832fba4c740 support 3-arg sort, passing a collationPolicy
Claus Gittinger <cg@exept.de>
parents: 3044
diff changeset
  2555
        [e > begin and:[sortBlock value:p value:middleElement value:(self at:e)]] whileTrue:[e := e - 1].
0832fba4c740 support 3-arg sort, passing a collationPolicy
Claus Gittinger <cg@exept.de>
parents: 3044
diff changeset
  2556
0832fba4c740 support 3-arg sort, passing a collationPolicy
Claus Gittinger <cg@exept.de>
parents: 3044
diff changeset
  2557
        (b <= e) ifTrue:[
0832fba4c740 support 3-arg sort, passing a collationPolicy
Claus Gittinger <cg@exept.de>
parents: 3044
diff changeset
  2558
            (b == e) ifFalse:[
0832fba4c740 support 3-arg sort, passing a collationPolicy
Claus Gittinger <cg@exept.de>
parents: 3044
diff changeset
  2559
                temp1 := self at:b. temp2 := self at:e. 
0832fba4c740 support 3-arg sort, passing a collationPolicy
Claus Gittinger <cg@exept.de>
parents: 3044
diff changeset
  2560
                self at:b put:temp2. self at:e put:temp1
0832fba4c740 support 3-arg sort, passing a collationPolicy
Claus Gittinger <cg@exept.de>
parents: 3044
diff changeset
  2561
            ].
0832fba4c740 support 3-arg sort, passing a collationPolicy
Claus Gittinger <cg@exept.de>
parents: 3044
diff changeset
  2562
            b := b + 1.
0832fba4c740 support 3-arg sort, passing a collationPolicy
Claus Gittinger <cg@exept.de>
parents: 3044
diff changeset
  2563
            e := e - 1
0832fba4c740 support 3-arg sort, passing a collationPolicy
Claus Gittinger <cg@exept.de>
parents: 3044
diff changeset
  2564
        ]
0832fba4c740 support 3-arg sort, passing a collationPolicy
Claus Gittinger <cg@exept.de>
parents: 3044
diff changeset
  2565
    ].
0832fba4c740 support 3-arg sort, passing a collationPolicy
Claus Gittinger <cg@exept.de>
parents: 3044
diff changeset
  2566
    (begin < e) ifTrue:[self quickSortFrom:begin to:e sortBlock:sortBlock policy:p].
0832fba4c740 support 3-arg sort, passing a collationPolicy
Claus Gittinger <cg@exept.de>
parents: 3044
diff changeset
  2567
    (b < end) ifTrue:[self quickSortFrom:b to:end sortBlock:sortBlock policy:p]
0832fba4c740 support 3-arg sort, passing a collationPolicy
Claus Gittinger <cg@exept.de>
parents: 3044
diff changeset
  2568
0832fba4c740 support 3-arg sort, passing a collationPolicy
Claus Gittinger <cg@exept.de>
parents: 3044
diff changeset
  2569
    "Created: / 27.10.1997 / 19:57:12 / cg"
0832fba4c740 support 3-arg sort, passing a collationPolicy
Claus Gittinger <cg@exept.de>
parents: 3044
diff changeset
  2570
!
0832fba4c740 support 3-arg sort, passing a collationPolicy
Claus Gittinger <cg@exept.de>
parents: 3044
diff changeset
  2571
2069
f6183117f922 comments
Claus Gittinger <cg@exept.de>
parents: 1673
diff changeset
  2572
quickSortFrom:inBegin to:inEnd sortBlock:sortBlock with:aCollection
f6183117f922 comments
Claus Gittinger <cg@exept.de>
parents: 1673
diff changeset
  2573
    "actual quicksort worker for sort:with:-message"
f6183117f922 comments
Claus Gittinger <cg@exept.de>
parents: 1673
diff changeset
  2574
f6183117f922 comments
Claus Gittinger <cg@exept.de>
parents: 1673
diff changeset
  2575
    |begin   "{ Class: SmallInteger }"
f6183117f922 comments
Claus Gittinger <cg@exept.de>
parents: 1673
diff changeset
  2576
     end     "{ Class: SmallInteger }"
f6183117f922 comments
Claus Gittinger <cg@exept.de>
parents: 1673
diff changeset
  2577
     b       "{ Class: SmallInteger }"
f6183117f922 comments
Claus Gittinger <cg@exept.de>
parents: 1673
diff changeset
  2578
     e       "{ Class: SmallInteger }"
f6183117f922 comments
Claus Gittinger <cg@exept.de>
parents: 1673
diff changeset
  2579
     middleElement temp1 temp2 |
f6183117f922 comments
Claus Gittinger <cg@exept.de>
parents: 1673
diff changeset
  2580
f6183117f922 comments
Claus Gittinger <cg@exept.de>
parents: 1673
diff changeset
  2581
    begin := inBegin.   "/ this also does a type-check
f6183117f922 comments
Claus Gittinger <cg@exept.de>
parents: 1673
diff changeset
  2582
    end := inEnd.
f6183117f922 comments
Claus Gittinger <cg@exept.de>
parents: 1673
diff changeset
  2583
f6183117f922 comments
Claus Gittinger <cg@exept.de>
parents: 1673
diff changeset
  2584
    b := begin.
f6183117f922 comments
Claus Gittinger <cg@exept.de>
parents: 1673
diff changeset
  2585
    e := end.
f6183117f922 comments
Claus Gittinger <cg@exept.de>
parents: 1673
diff changeset
  2586
    middleElement := self at:((b + e) // 2).
f6183117f922 comments
Claus Gittinger <cg@exept.de>
parents: 1673
diff changeset
  2587
f6183117f922 comments
Claus Gittinger <cg@exept.de>
parents: 1673
diff changeset
  2588
    [b < e] whileTrue:[
f6183117f922 comments
Claus Gittinger <cg@exept.de>
parents: 1673
diff changeset
  2589
        [b < end and:[sortBlock value:(self at:b) value:middleElement]] whileTrue:[b := b + 1].
f6183117f922 comments
Claus Gittinger <cg@exept.de>
parents: 1673
diff changeset
  2590
        [e > begin and:[sortBlock value:middleElement value:(self at:e)]] whileTrue:[e := e - 1].
f6183117f922 comments
Claus Gittinger <cg@exept.de>
parents: 1673
diff changeset
  2591
f6183117f922 comments
Claus Gittinger <cg@exept.de>
parents: 1673
diff changeset
  2592
        (b <= e) ifTrue:[
f6183117f922 comments
Claus Gittinger <cg@exept.de>
parents: 1673
diff changeset
  2593
            (b == e) ifFalse:[
f6183117f922 comments
Claus Gittinger <cg@exept.de>
parents: 1673
diff changeset
  2594
                temp1 := self at:b. temp2 := self at:e. 
f6183117f922 comments
Claus Gittinger <cg@exept.de>
parents: 1673
diff changeset
  2595
                self at:b put:temp2. self at:e put:temp1.
f6183117f922 comments
Claus Gittinger <cg@exept.de>
parents: 1673
diff changeset
  2596
                temp1 := aCollection at:b. temp2 := aCollection at:e. 
f6183117f922 comments
Claus Gittinger <cg@exept.de>
parents: 1673
diff changeset
  2597
                aCollection at:b put:temp2. aCollection at:e put:temp1
f6183117f922 comments
Claus Gittinger <cg@exept.de>
parents: 1673
diff changeset
  2598
            ].
f6183117f922 comments
Claus Gittinger <cg@exept.de>
parents: 1673
diff changeset
  2599
            b := b + 1.
f6183117f922 comments
Claus Gittinger <cg@exept.de>
parents: 1673
diff changeset
  2600
            e := e - 1
f6183117f922 comments
Claus Gittinger <cg@exept.de>
parents: 1673
diff changeset
  2601
        ]
f6183117f922 comments
Claus Gittinger <cg@exept.de>
parents: 1673
diff changeset
  2602
    ].
f6183117f922 comments
Claus Gittinger <cg@exept.de>
parents: 1673
diff changeset
  2603
    (begin < e) ifTrue:[self quickSortFrom:begin to:e sortBlock:sortBlock with:aCollection].
f6183117f922 comments
Claus Gittinger <cg@exept.de>
parents: 1673
diff changeset
  2604
    (b < end) ifTrue:[self quickSortFrom:b to:end sortBlock:sortBlock with:aCollection]
f6183117f922 comments
Claus Gittinger <cg@exept.de>
parents: 1673
diff changeset
  2605
f6183117f922 comments
Claus Gittinger <cg@exept.de>
parents: 1673
diff changeset
  2606
    "Modified: 5.1.1997 / 18:12:36 / cg"
f6183117f922 comments
Claus Gittinger <cg@exept.de>
parents: 1673
diff changeset
  2607
!
f6183117f922 comments
Claus Gittinger <cg@exept.de>
parents: 1673
diff changeset
  2608
f6183117f922 comments
Claus Gittinger <cg@exept.de>
parents: 1673
diff changeset
  2609
quickSortFrom:inBegin to:inEnd with:aCollection
f6183117f922 comments
Claus Gittinger <cg@exept.de>
parents: 1673
diff changeset
  2610
    "actual quicksort worker for sortWith-message"
f6183117f922 comments
Claus Gittinger <cg@exept.de>
parents: 1673
diff changeset
  2611
f6183117f922 comments
Claus Gittinger <cg@exept.de>
parents: 1673
diff changeset
  2612
    |begin   "{ Class: SmallInteger }"
f6183117f922 comments
Claus Gittinger <cg@exept.de>
parents: 1673
diff changeset
  2613
     end     "{ Class: SmallInteger }"
f6183117f922 comments
Claus Gittinger <cg@exept.de>
parents: 1673
diff changeset
  2614
     b       "{ Class: SmallInteger }"
f6183117f922 comments
Claus Gittinger <cg@exept.de>
parents: 1673
diff changeset
  2615
     e       "{ Class: SmallInteger }"
f6183117f922 comments
Claus Gittinger <cg@exept.de>
parents: 1673
diff changeset
  2616
     middleElement temp1 temp2 |
f6183117f922 comments
Claus Gittinger <cg@exept.de>
parents: 1673
diff changeset
  2617
f6183117f922 comments
Claus Gittinger <cg@exept.de>
parents: 1673
diff changeset
  2618
    begin := inBegin.   "/ this also does a type-check
f6183117f922 comments
Claus Gittinger <cg@exept.de>
parents: 1673
diff changeset
  2619
    end := inEnd.
f6183117f922 comments
Claus Gittinger <cg@exept.de>
parents: 1673
diff changeset
  2620
f6183117f922 comments
Claus Gittinger <cg@exept.de>
parents: 1673
diff changeset
  2621
    b := begin.
f6183117f922 comments
Claus Gittinger <cg@exept.de>
parents: 1673
diff changeset
  2622
    e := end.
f6183117f922 comments
Claus Gittinger <cg@exept.de>
parents: 1673
diff changeset
  2623
    middleElement := self at:((b + e) // 2).
f6183117f922 comments
Claus Gittinger <cg@exept.de>
parents: 1673
diff changeset
  2624
f6183117f922 comments
Claus Gittinger <cg@exept.de>
parents: 1673
diff changeset
  2625
    [b < e] whileTrue:[
f6183117f922 comments
Claus Gittinger <cg@exept.de>
parents: 1673
diff changeset
  2626
	[b < end and:[(self at:b) < middleElement]] whileTrue:[b := b + 1].
f6183117f922 comments
Claus Gittinger <cg@exept.de>
parents: 1673
diff changeset
  2627
	[e > begin and:[middleElement < (self at:e)]] whileTrue:[e := e - 1].
f6183117f922 comments
Claus Gittinger <cg@exept.de>
parents: 1673
diff changeset
  2628
f6183117f922 comments
Claus Gittinger <cg@exept.de>
parents: 1673
diff changeset
  2629
	(b <= e) ifTrue:[
f6183117f922 comments
Claus Gittinger <cg@exept.de>
parents: 1673
diff changeset
  2630
	    (b == e) ifFalse:[
f6183117f922 comments
Claus Gittinger <cg@exept.de>
parents: 1673
diff changeset
  2631
		temp1 := self at:b. temp2 := self at:e. 
f6183117f922 comments
Claus Gittinger <cg@exept.de>
parents: 1673
diff changeset
  2632
		self at:b put:temp2. self at:e put:temp1.
f6183117f922 comments
Claus Gittinger <cg@exept.de>
parents: 1673
diff changeset
  2633
		temp1 := aCollection at:b. temp2 := aCollection at:e. 
f6183117f922 comments
Claus Gittinger <cg@exept.de>
parents: 1673
diff changeset
  2634
		aCollection at:b put:temp2. aCollection at:e put:temp1
f6183117f922 comments
Claus Gittinger <cg@exept.de>
parents: 1673
diff changeset
  2635
	    ].
f6183117f922 comments
Claus Gittinger <cg@exept.de>
parents: 1673
diff changeset
  2636
	    b := b + 1.
f6183117f922 comments
Claus Gittinger <cg@exept.de>
parents: 1673
diff changeset
  2637
	    e := e - 1
f6183117f922 comments
Claus Gittinger <cg@exept.de>
parents: 1673
diff changeset
  2638
	]
f6183117f922 comments
Claus Gittinger <cg@exept.de>
parents: 1673
diff changeset
  2639
    ].
f6183117f922 comments
Claus Gittinger <cg@exept.de>
parents: 1673
diff changeset
  2640
    (begin < e) ifTrue:[self quickSortFrom:begin to:e with:aCollection].
f6183117f922 comments
Claus Gittinger <cg@exept.de>
parents: 1673
diff changeset
  2641
    (b < end) ifTrue:[self quickSortFrom:b to:end with:aCollection]
2881
452f9154d0dc comments; added #randomizedQuickSort.
Claus Gittinger <cg@exept.de>
parents: 2860
diff changeset
  2642
!
452f9154d0dc comments; added #randomizedQuickSort.
Claus Gittinger <cg@exept.de>
parents: 2860
diff changeset
  2643
452f9154d0dc comments; added #randomizedQuickSort.
Claus Gittinger <cg@exept.de>
parents: 2860
diff changeset
  2644
randomizedQuickSortFrom:inBegin to:inEnd sortBlock:sortBlock with:aCollection
452f9154d0dc comments; added #randomizedQuickSort.
Claus Gittinger <cg@exept.de>
parents: 2860
diff changeset
  2645
    "actual randomizedQuicksort worker for sort:with:-message.
452f9154d0dc comments; added #randomizedQuickSort.
Claus Gittinger <cg@exept.de>
parents: 2860
diff changeset
  2646
     This exchanges a random element within the partition, to avoid
452f9154d0dc comments; added #randomizedQuickSort.
Claus Gittinger <cg@exept.de>
parents: 2860
diff changeset
  2647
     the worst case O-square situation of quickSort.
452f9154d0dc comments; added #randomizedQuickSort.
Claus Gittinger <cg@exept.de>
parents: 2860
diff changeset
  2648
452f9154d0dc comments; added #randomizedQuickSort.
Claus Gittinger <cg@exept.de>
parents: 2860
diff changeset
  2649
     Notice, that this method has a much worse best- and average case
452f9154d0dc comments; added #randomizedQuickSort.
Claus Gittinger <cg@exept.de>
parents: 2860
diff changeset
  2650
     runTime, due to the random number generation.
452f9154d0dc comments; added #randomizedQuickSort.
Claus Gittinger <cg@exept.de>
parents: 2860
diff changeset
  2651
     The worst case of quickSort is encountered, if the choosen pivot
452f9154d0dc comments; added #randomizedQuickSort.
Claus Gittinger <cg@exept.de>
parents: 2860
diff changeset
  2652
     element lies at either end of the partition, so that a split
452f9154d0dc comments; added #randomizedQuickSort.
Claus Gittinger <cg@exept.de>
parents: 2860
diff changeset
  2653
     creates partitions of size 1 and (n-1).
452f9154d0dc comments; added #randomizedQuickSort.
Claus Gittinger <cg@exept.de>
parents: 2860
diff changeset
  2654
     Since the middle element is choosen, this worst case is very unlikely
452f9154d0dc comments; added #randomizedQuickSort.
Claus Gittinger <cg@exept.de>
parents: 2860
diff changeset
  2655
     to be encountered."
452f9154d0dc comments; added #randomizedQuickSort.
Claus Gittinger <cg@exept.de>
parents: 2860
diff changeset
  2656
452f9154d0dc comments; added #randomizedQuickSort.
Claus Gittinger <cg@exept.de>
parents: 2860
diff changeset
  2657
    |begin   "{ Class: SmallInteger }"
452f9154d0dc comments; added #randomizedQuickSort.
Claus Gittinger <cg@exept.de>
parents: 2860
diff changeset
  2658
     end     "{ Class: SmallInteger }"
452f9154d0dc comments; added #randomizedQuickSort.
Claus Gittinger <cg@exept.de>
parents: 2860
diff changeset
  2659
     b       "{ Class: SmallInteger }"
452f9154d0dc comments; added #randomizedQuickSort.
Claus Gittinger <cg@exept.de>
parents: 2860
diff changeset
  2660
     e       "{ Class: SmallInteger }"
452f9154d0dc comments; added #randomizedQuickSort.
Claus Gittinger <cg@exept.de>
parents: 2860
diff changeset
  2661
     rnd     "{ Class: SmallInteger }"
452f9154d0dc comments; added #randomizedQuickSort.
Claus Gittinger <cg@exept.de>
parents: 2860
diff changeset
  2662
     middleElement temp1 temp2 |
452f9154d0dc comments; added #randomizedQuickSort.
Claus Gittinger <cg@exept.de>
parents: 2860
diff changeset
  2663
452f9154d0dc comments; added #randomizedQuickSort.
Claus Gittinger <cg@exept.de>
parents: 2860
diff changeset
  2664
    begin := inBegin.   "/ this also does a type-check
452f9154d0dc comments; added #randomizedQuickSort.
Claus Gittinger <cg@exept.de>
parents: 2860
diff changeset
  2665
    end := inEnd.
452f9154d0dc comments; added #randomizedQuickSort.
Claus Gittinger <cg@exept.de>
parents: 2860
diff changeset
  2666
452f9154d0dc comments; added #randomizedQuickSort.
Claus Gittinger <cg@exept.de>
parents: 2860
diff changeset
  2667
    b := begin.
452f9154d0dc comments; added #randomizedQuickSort.
Claus Gittinger <cg@exept.de>
parents: 2860
diff changeset
  2668
    e := end.
452f9154d0dc comments; added #randomizedQuickSort.
Claus Gittinger <cg@exept.de>
parents: 2860
diff changeset
  2669
452f9154d0dc comments; added #randomizedQuickSort.
Claus Gittinger <cg@exept.de>
parents: 2860
diff changeset
  2670
    "/ randomize that partition
452f9154d0dc comments; added #randomizedQuickSort.
Claus Gittinger <cg@exept.de>
parents: 2860
diff changeset
  2671
    "/ by exchanging the first element with any random
452f9154d0dc comments; added #randomizedQuickSort.
Claus Gittinger <cg@exept.de>
parents: 2860
diff changeset
  2672
    "/ element.
452f9154d0dc comments; added #randomizedQuickSort.
Claus Gittinger <cg@exept.de>
parents: 2860
diff changeset
  2673
    rnd := Random nextIntegerBetween:b and:e.
452f9154d0dc comments; added #randomizedQuickSort.
Claus Gittinger <cg@exept.de>
parents: 2860
diff changeset
  2674
    temp1 := self at:b. temp2 := self at:rnd.
452f9154d0dc comments; added #randomizedQuickSort.
Claus Gittinger <cg@exept.de>
parents: 2860
diff changeset
  2675
    self at:b put:temp2. self at:rnd put:temp1.
452f9154d0dc comments; added #randomizedQuickSort.
Claus Gittinger <cg@exept.de>
parents: 2860
diff changeset
  2676
    aCollection notNil ifTrue:[
452f9154d0dc comments; added #randomizedQuickSort.
Claus Gittinger <cg@exept.de>
parents: 2860
diff changeset
  2677
        temp1 := aCollection at:b. temp2 := aCollection at:rnd. 
452f9154d0dc comments; added #randomizedQuickSort.
Claus Gittinger <cg@exept.de>
parents: 2860
diff changeset
  2678
        aCollection at:b put:temp2. aCollection at:rnd put:temp1
452f9154d0dc comments; added #randomizedQuickSort.
Claus Gittinger <cg@exept.de>
parents: 2860
diff changeset
  2679
    ].
452f9154d0dc comments; added #randomizedQuickSort.
Claus Gittinger <cg@exept.de>
parents: 2860
diff changeset
  2680
452f9154d0dc comments; added #randomizedQuickSort.
Claus Gittinger <cg@exept.de>
parents: 2860
diff changeset
  2681
    "/
452f9154d0dc comments; added #randomizedQuickSort.
Claus Gittinger <cg@exept.de>
parents: 2860
diff changeset
  2682
    "/ now proceed as usual
452f9154d0dc comments; added #randomizedQuickSort.
Claus Gittinger <cg@exept.de>
parents: 2860
diff changeset
  2683
    "/
452f9154d0dc comments; added #randomizedQuickSort.
Claus Gittinger <cg@exept.de>
parents: 2860
diff changeset
  2684
    middleElement := self at:((b + e) // 2).
452f9154d0dc comments; added #randomizedQuickSort.
Claus Gittinger <cg@exept.de>
parents: 2860
diff changeset
  2685
452f9154d0dc comments; added #randomizedQuickSort.
Claus Gittinger <cg@exept.de>
parents: 2860
diff changeset
  2686
    [b < e] whileTrue:[
452f9154d0dc comments; added #randomizedQuickSort.
Claus Gittinger <cg@exept.de>
parents: 2860
diff changeset
  2687
        [b < end and:[sortBlock value:(self at:b) value:middleElement]] whileTrue:[b := b + 1].
452f9154d0dc comments; added #randomizedQuickSort.
Claus Gittinger <cg@exept.de>
parents: 2860
diff changeset
  2688
        [e > begin and:[sortBlock value:middleElement value:(self at:e)]] whileTrue:[e := e - 1].
452f9154d0dc comments; added #randomizedQuickSort.
Claus Gittinger <cg@exept.de>
parents: 2860
diff changeset
  2689
452f9154d0dc comments; added #randomizedQuickSort.
Claus Gittinger <cg@exept.de>
parents: 2860
diff changeset
  2690
        (b <= e) ifTrue:[
452f9154d0dc comments; added #randomizedQuickSort.
Claus Gittinger <cg@exept.de>
parents: 2860
diff changeset
  2691
            (b == e) ifFalse:[
452f9154d0dc comments; added #randomizedQuickSort.
Claus Gittinger <cg@exept.de>
parents: 2860
diff changeset
  2692
                temp1 := self at:b. temp2 := self at:e. 
452f9154d0dc comments; added #randomizedQuickSort.
Claus Gittinger <cg@exept.de>
parents: 2860
diff changeset
  2693
                self at:b put:temp2. self at:e put:temp1.
452f9154d0dc comments; added #randomizedQuickSort.
Claus Gittinger <cg@exept.de>
parents: 2860
diff changeset
  2694
                aCollection notNil ifTrue:[
452f9154d0dc comments; added #randomizedQuickSort.
Claus Gittinger <cg@exept.de>
parents: 2860
diff changeset
  2695
                    temp1 := aCollection at:b. temp2 := aCollection at:e. 
452f9154d0dc comments; added #randomizedQuickSort.
Claus Gittinger <cg@exept.de>
parents: 2860
diff changeset
  2696
                    aCollection at:b put:temp2. aCollection at:e put:temp1
452f9154d0dc comments; added #randomizedQuickSort.
Claus Gittinger <cg@exept.de>
parents: 2860
diff changeset
  2697
                ].
452f9154d0dc comments; added #randomizedQuickSort.
Claus Gittinger <cg@exept.de>
parents: 2860
diff changeset
  2698
            ].
452f9154d0dc comments; added #randomizedQuickSort.
Claus Gittinger <cg@exept.de>
parents: 2860
diff changeset
  2699
            b := b + 1.
452f9154d0dc comments; added #randomizedQuickSort.
Claus Gittinger <cg@exept.de>
parents: 2860
diff changeset
  2700
            e := e - 1
452f9154d0dc comments; added #randomizedQuickSort.
Claus Gittinger <cg@exept.de>
parents: 2860
diff changeset
  2701
        ]
452f9154d0dc comments; added #randomizedQuickSort.
Claus Gittinger <cg@exept.de>
parents: 2860
diff changeset
  2702
    ].
452f9154d0dc comments; added #randomizedQuickSort.
Claus Gittinger <cg@exept.de>
parents: 2860
diff changeset
  2703
    (begin < e) ifTrue:[self randomizedQuickSortFrom:begin to:e sortBlock:sortBlock with:aCollection].
452f9154d0dc comments; added #randomizedQuickSort.
Claus Gittinger <cg@exept.de>
parents: 2860
diff changeset
  2704
    (b < end) ifTrue:[self randomizedQuickSortFrom:b to:end sortBlock:sortBlock with:aCollection]
452f9154d0dc comments; added #randomizedQuickSort.
Claus Gittinger <cg@exept.de>
parents: 2860
diff changeset
  2705
452f9154d0dc comments; added #randomizedQuickSort.
Claus Gittinger <cg@exept.de>
parents: 2860
diff changeset
  2706
    "Created: 21.8.1997 / 18:13:35 / cg"
452f9154d0dc comments; added #randomizedQuickSort.
Claus Gittinger <cg@exept.de>
parents: 2860
diff changeset
  2707
    "Modified: 21.8.1997 / 18:34:31 / cg"
452f9154d0dc comments; added #randomizedQuickSort.
Claus Gittinger <cg@exept.de>
parents: 2860
diff changeset
  2708
!
452f9154d0dc comments; added #randomizedQuickSort.
Claus Gittinger <cg@exept.de>
parents: 2860
diff changeset
  2709
452f9154d0dc comments; added #randomizedQuickSort.
Claus Gittinger <cg@exept.de>
parents: 2860
diff changeset
  2710
randomizedQuickSortFrom:inBegin to:inEnd with:aCollection
452f9154d0dc comments; added #randomizedQuickSort.
Claus Gittinger <cg@exept.de>
parents: 2860
diff changeset
  2711
    "actual randomizedQuicksort worker for randomizedSort:-message.
452f9154d0dc comments; added #randomizedQuickSort.
Claus Gittinger <cg@exept.de>
parents: 2860
diff changeset
  2712
     This exchanges a random element within the partition, to avoid
452f9154d0dc comments; added #randomizedQuickSort.
Claus Gittinger <cg@exept.de>
parents: 2860
diff changeset
  2713
     the worst case O-square situation of quickSort.
452f9154d0dc comments; added #randomizedQuickSort.
Claus Gittinger <cg@exept.de>
parents: 2860
diff changeset
  2714
452f9154d0dc comments; added #randomizedQuickSort.
Claus Gittinger <cg@exept.de>
parents: 2860
diff changeset
  2715
     Notice, that this method has a much worse best- and average case
452f9154d0dc comments; added #randomizedQuickSort.
Claus Gittinger <cg@exept.de>
parents: 2860
diff changeset
  2716
     runTime, due to the random number generation.
452f9154d0dc comments; added #randomizedQuickSort.
Claus Gittinger <cg@exept.de>
parents: 2860
diff changeset
  2717
     The worst case of quickSort is encountered, if the choosen pivot
452f9154d0dc comments; added #randomizedQuickSort.
Claus Gittinger <cg@exept.de>
parents: 2860
diff changeset
  2718
     element lies at either end of the partition, so that a split
452f9154d0dc comments; added #randomizedQuickSort.
Claus Gittinger <cg@exept.de>
parents: 2860
diff changeset
  2719
     creates partitions of size 1 and (n-1).
452f9154d0dc comments; added #randomizedQuickSort.
Claus Gittinger <cg@exept.de>
parents: 2860
diff changeset
  2720
     Since the middle element is choosen, this worst case is very unlikely
452f9154d0dc comments; added #randomizedQuickSort.
Claus Gittinger <cg@exept.de>
parents: 2860
diff changeset
  2721
     to be encountered."
452f9154d0dc comments; added #randomizedQuickSort.
Claus Gittinger <cg@exept.de>
parents: 2860
diff changeset
  2722
452f9154d0dc comments; added #randomizedQuickSort.
Claus Gittinger <cg@exept.de>
parents: 2860
diff changeset
  2723
    |begin   "{ Class: SmallInteger }"
452f9154d0dc comments; added #randomizedQuickSort.
Claus Gittinger <cg@exept.de>
parents: 2860
diff changeset
  2724
     end     "{ Class: SmallInteger }"
452f9154d0dc comments; added #randomizedQuickSort.
Claus Gittinger <cg@exept.de>
parents: 2860
diff changeset
  2725
     b       "{ Class: SmallInteger }"
452f9154d0dc comments; added #randomizedQuickSort.
Claus Gittinger <cg@exept.de>
parents: 2860
diff changeset
  2726
     e       "{ Class: SmallInteger }"
452f9154d0dc comments; added #randomizedQuickSort.
Claus Gittinger <cg@exept.de>
parents: 2860
diff changeset
  2727
     rnd     "{ Class: SmallInteger }"
452f9154d0dc comments; added #randomizedQuickSort.
Claus Gittinger <cg@exept.de>
parents: 2860
diff changeset
  2728
     middleElement temp1 temp2 |
452f9154d0dc comments; added #randomizedQuickSort.
Claus Gittinger <cg@exept.de>
parents: 2860
diff changeset
  2729
452f9154d0dc comments; added #randomizedQuickSort.
Claus Gittinger <cg@exept.de>
parents: 2860
diff changeset
  2730
    begin := inBegin.   "/ this also does a type-check
452f9154d0dc comments; added #randomizedQuickSort.
Claus Gittinger <cg@exept.de>
parents: 2860
diff changeset
  2731
    end := inEnd.
452f9154d0dc comments; added #randomizedQuickSort.
Claus Gittinger <cg@exept.de>
parents: 2860
diff changeset
  2732
452f9154d0dc comments; added #randomizedQuickSort.
Claus Gittinger <cg@exept.de>
parents: 2860
diff changeset
  2733
    b := begin.
452f9154d0dc comments; added #randomizedQuickSort.
Claus Gittinger <cg@exept.de>
parents: 2860
diff changeset
  2734
    e := end.
452f9154d0dc comments; added #randomizedQuickSort.
Claus Gittinger <cg@exept.de>
parents: 2860
diff changeset
  2735
452f9154d0dc comments; added #randomizedQuickSort.
Claus Gittinger <cg@exept.de>
parents: 2860
diff changeset
  2736
    "/ randomize that partition
452f9154d0dc comments; added #randomizedQuickSort.
Claus Gittinger <cg@exept.de>
parents: 2860
diff changeset
  2737
    "/ by exchanging the first element with any random
452f9154d0dc comments; added #randomizedQuickSort.
Claus Gittinger <cg@exept.de>
parents: 2860
diff changeset
  2738
    "/ element.
452f9154d0dc comments; added #randomizedQuickSort.
Claus Gittinger <cg@exept.de>
parents: 2860
diff changeset
  2739
    rnd := Random nextIntegerBetween:b and:e.
452f9154d0dc comments; added #randomizedQuickSort.
Claus Gittinger <cg@exept.de>
parents: 2860
diff changeset
  2740
    temp1 := self at:b. temp2 := self at:rnd.
452f9154d0dc comments; added #randomizedQuickSort.
Claus Gittinger <cg@exept.de>
parents: 2860
diff changeset
  2741
    self at:b put:temp2. self at:rnd put:temp1.
452f9154d0dc comments; added #randomizedQuickSort.
Claus Gittinger <cg@exept.de>
parents: 2860
diff changeset
  2742
    aCollection notNil ifTrue:[
452f9154d0dc comments; added #randomizedQuickSort.
Claus Gittinger <cg@exept.de>
parents: 2860
diff changeset
  2743
        temp1 := aCollection at:b. temp2 := aCollection at:rnd. 
452f9154d0dc comments; added #randomizedQuickSort.
Claus Gittinger <cg@exept.de>
parents: 2860
diff changeset
  2744
        aCollection at:b put:temp2. aCollection at:rnd put:temp1
452f9154d0dc comments; added #randomizedQuickSort.
Claus Gittinger <cg@exept.de>
parents: 2860
diff changeset
  2745
    ].
452f9154d0dc comments; added #randomizedQuickSort.
Claus Gittinger <cg@exept.de>
parents: 2860
diff changeset
  2746
452f9154d0dc comments; added #randomizedQuickSort.
Claus Gittinger <cg@exept.de>
parents: 2860
diff changeset
  2747
    "/
452f9154d0dc comments; added #randomizedQuickSort.
Claus Gittinger <cg@exept.de>
parents: 2860
diff changeset
  2748
    "/ now proceed as usual
452f9154d0dc comments; added #randomizedQuickSort.
Claus Gittinger <cg@exept.de>
parents: 2860
diff changeset
  2749
    "/
452f9154d0dc comments; added #randomizedQuickSort.
Claus Gittinger <cg@exept.de>
parents: 2860
diff changeset
  2750
    middleElement := self at:((b + e) // 2).
452f9154d0dc comments; added #randomizedQuickSort.
Claus Gittinger <cg@exept.de>
parents: 2860
diff changeset
  2751
452f9154d0dc comments; added #randomizedQuickSort.
Claus Gittinger <cg@exept.de>
parents: 2860
diff changeset
  2752
    [b < e] whileTrue:[
452f9154d0dc comments; added #randomizedQuickSort.
Claus Gittinger <cg@exept.de>
parents: 2860
diff changeset
  2753
        [b < end and:[(self at:b) < middleElement]] whileTrue:[b := b + 1].
452f9154d0dc comments; added #randomizedQuickSort.
Claus Gittinger <cg@exept.de>
parents: 2860
diff changeset
  2754
        [e > begin and:[middleElement < (self at:e)]] whileTrue:[e := e - 1].
452f9154d0dc comments; added #randomizedQuickSort.
Claus Gittinger <cg@exept.de>
parents: 2860
diff changeset
  2755
452f9154d0dc comments; added #randomizedQuickSort.
Claus Gittinger <cg@exept.de>
parents: 2860
diff changeset
  2756
        (b <= e) ifTrue:[
452f9154d0dc comments; added #randomizedQuickSort.
Claus Gittinger <cg@exept.de>
parents: 2860
diff changeset
  2757
            (b == e) ifFalse:[
452f9154d0dc comments; added #randomizedQuickSort.
Claus Gittinger <cg@exept.de>
parents: 2860
diff changeset
  2758
                temp1 := self at:b. temp2 := self at:e. 
452f9154d0dc comments; added #randomizedQuickSort.
Claus Gittinger <cg@exept.de>
parents: 2860
diff changeset
  2759
                self at:b put:temp2. self at:e put:temp1.
452f9154d0dc comments; added #randomizedQuickSort.
Claus Gittinger <cg@exept.de>
parents: 2860
diff changeset
  2760
                aCollection notNil ifTrue:[
452f9154d0dc comments; added #randomizedQuickSort.
Claus Gittinger <cg@exept.de>
parents: 2860
diff changeset
  2761
                    temp1 := aCollection at:b. temp2 := aCollection at:e. 
452f9154d0dc comments; added #randomizedQuickSort.
Claus Gittinger <cg@exept.de>
parents: 2860
diff changeset
  2762
                    aCollection at:b put:temp2. aCollection at:e put:temp1
452f9154d0dc comments; added #randomizedQuickSort.
Claus Gittinger <cg@exept.de>
parents: 2860
diff changeset
  2763
                ].
452f9154d0dc comments; added #randomizedQuickSort.
Claus Gittinger <cg@exept.de>
parents: 2860
diff changeset
  2764
            ].
452f9154d0dc comments; added #randomizedQuickSort.
Claus Gittinger <cg@exept.de>
parents: 2860
diff changeset
  2765
            b := b + 1.
452f9154d0dc comments; added #randomizedQuickSort.
Claus Gittinger <cg@exept.de>
parents: 2860
diff changeset
  2766
            e := e - 1
452f9154d0dc comments; added #randomizedQuickSort.
Claus Gittinger <cg@exept.de>
parents: 2860
diff changeset
  2767
        ]
452f9154d0dc comments; added #randomizedQuickSort.
Claus Gittinger <cg@exept.de>
parents: 2860
diff changeset
  2768
    ].
452f9154d0dc comments; added #randomizedQuickSort.
Claus Gittinger <cg@exept.de>
parents: 2860
diff changeset
  2769
    (begin < e) ifTrue:[self randomizedQuickSortFrom:begin to:e with:aCollection].
452f9154d0dc comments; added #randomizedQuickSort.
Claus Gittinger <cg@exept.de>
parents: 2860
diff changeset
  2770
    (b < end) ifTrue:[self randomizedQuickSortFrom:b to:end with:aCollection]
452f9154d0dc comments; added #randomizedQuickSort.
Claus Gittinger <cg@exept.de>
parents: 2860
diff changeset
  2771
452f9154d0dc comments; added #randomizedQuickSort.
Claus Gittinger <cg@exept.de>
parents: 2860
diff changeset
  2772
    "Modified: 21.8.1997 / 18:30:19 / cg"
452f9154d0dc comments; added #randomizedQuickSort.
Claus Gittinger <cg@exept.de>
parents: 2860
diff changeset
  2773
    "Created: 21.8.1997 / 18:34:23 / cg"
2069
f6183117f922 comments
Claus Gittinger <cg@exept.de>
parents: 1673
diff changeset
  2774
! !
f6183117f922 comments
Claus Gittinger <cg@exept.de>
parents: 1673
diff changeset
  2775
602
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  2776
!SequenceableCollection methodsFor:'queries'!
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  2777
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  2778
firstIndex
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  2779
    "return the first elements index"
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  2780
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  2781
    ^ 1
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  2782
!
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  2783
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  2784
isSequenceable
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  2785
    "return true, if the receiver is some kind of sequenceableCollection"
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  2786
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  2787
    ^ true
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  2788
!
a27a279701f8 Initial revision
claus
parents:
diff changeset
  2789
602
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  2790
isSequenceableCollection
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  2791
    "OBSOLETE: use isSequenceable for ST-80 compatibility.
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  2792
     This method is a historic leftover and will be removed."
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  2793
3435
04c06b559fa6 isSequenceableCollection is now obsolete;
Claus Gittinger <cg@exept.de>
parents: 3408
diff changeset
  2794
    self obsoleteMethodWarning:'use #isSequenceable'.
602
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  2795
    ^ true
3435
04c06b559fa6 isSequenceableCollection is now obsolete;
Claus Gittinger <cg@exept.de>
parents: 3408
diff changeset
  2796
04c06b559fa6 isSequenceableCollection is now obsolete;
Claus Gittinger <cg@exept.de>
parents: 3408
diff changeset
  2797
    "Modified: / 8.5.1998 / 21:27:18 / cg"
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  2798
!
a27a279701f8 Initial revision
claus
parents:
diff changeset
  2799
602
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  2800
keys
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  2801
    "return a collection with all keys in the Smalltalk dictionary"
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  2802
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  2803
    |sz|
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  2804
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  2805
    sz := self size.
602
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  2806
    sz == 0 ifTrue:[
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  2807
	^ #()
61
claus
parents: 44
diff changeset
  2808
    ].
602
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  2809
    ^ 1 to:sz
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  2810
!
a27a279701f8 Initial revision
claus
parents:
diff changeset
  2811
602
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  2812
lastIndex
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  2813
    "return the last elements index"
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  2814
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  2815
    ^ self size
61
claus
parents: 44
diff changeset
  2816
!
claus
parents: 44
diff changeset
  2817
602
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  2818
size
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  2819
    "return the number of elements in the collection.
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  2820
     concrete implementations must define this"
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  2821
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  2822
    ^ self subclassResponsibility
2165
9ef030343739 added #zeroIndex for protocol completeness (ST-80)
Claus Gittinger <cg@exept.de>
parents: 2069
diff changeset
  2823
!
9ef030343739 added #zeroIndex for protocol completeness (ST-80)
Claus Gittinger <cg@exept.de>
parents: 2069
diff changeset
  2824
9ef030343739 added #zeroIndex for protocol completeness (ST-80)
Claus Gittinger <cg@exept.de>
parents: 2069
diff changeset
  2825
zeroIndex
9ef030343739 added #zeroIndex for protocol completeness (ST-80)
Claus Gittinger <cg@exept.de>
parents: 2069
diff changeset
  2826
    "return the index value which is returned when nothing
9ef030343739 added #zeroIndex for protocol completeness (ST-80)
Claus Gittinger <cg@exept.de>
parents: 2069
diff changeset
  2827
     is found in an indexOf* kind of search.
9ef030343739 added #zeroIndex for protocol completeness (ST-80)
Claus Gittinger <cg@exept.de>
parents: 2069
diff changeset
  2828
     ST-compatibility"
9ef030343739 added #zeroIndex for protocol completeness (ST-80)
Claus Gittinger <cg@exept.de>
parents: 2069
diff changeset
  2829
9ef030343739 added #zeroIndex for protocol completeness (ST-80)
Claus Gittinger <cg@exept.de>
parents: 2069
diff changeset
  2830
    ^ 0
9ef030343739 added #zeroIndex for protocol completeness (ST-80)
Claus Gittinger <cg@exept.de>
parents: 2069
diff changeset
  2831
9ef030343739 added #zeroIndex for protocol completeness (ST-80)
Claus Gittinger <cg@exept.de>
parents: 2069
diff changeset
  2832
    "Created: 14.2.1997 / 16:13:03 / cg"
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  2833
! !
a27a279701f8 Initial revision
claus
parents:
diff changeset
  2834
4402
7c19502120b7 care for bad startIndex in #copyFrom:to:
Claus Gittinger <cg@exept.de>
parents: 4389
diff changeset
  2835
!SequenceableCollection methodsFor:'queries - asn1'!
7c19502120b7 care for bad startIndex in #copyFrom:to:
Claus Gittinger <cg@exept.de>
parents: 4389
diff changeset
  2836
7c19502120b7 care for bad startIndex in #copyFrom:to:
Claus Gittinger <cg@exept.de>
parents: 4389
diff changeset
  2837
asn1Type
7c19502120b7 care for bad startIndex in #copyFrom:to:
Claus Gittinger <cg@exept.de>
parents: 4389
diff changeset
  2838
    ^ OSI::ASN1_SEQUENCE primitiveType
7c19502120b7 care for bad startIndex in #copyFrom:to:
Claus Gittinger <cg@exept.de>
parents: 4389
diff changeset
  2839
7c19502120b7 care for bad startIndex in #copyFrom:to:
Claus Gittinger <cg@exept.de>
parents: 4389
diff changeset
  2840
7c19502120b7 care for bad startIndex in #copyFrom:to:
Claus Gittinger <cg@exept.de>
parents: 4389
diff changeset
  2841
7c19502120b7 care for bad startIndex in #copyFrom:to:
Claus Gittinger <cg@exept.de>
parents: 4389
diff changeset
  2842
! !
7c19502120b7 care for bad startIndex in #copyFrom:to:
Claus Gittinger <cg@exept.de>
parents: 4389
diff changeset
  2843
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  2844
!SequenceableCollection methodsFor:'searching'!
a27a279701f8 Initial revision
claus
parents:
diff changeset
  2845
a27a279701f8 Initial revision
claus
parents:
diff changeset
  2846
detect:aBlock ifNone:exceptionBlock
a27a279701f8 Initial revision
claus
parents:
diff changeset
  2847
    "find the first element, for which evaluation of the argument, aBlock
a27a279701f8 Initial revision
claus
parents:
diff changeset
  2848
     return true; if none does so, return the evaluation of exceptionBlock
a27a279701f8 Initial revision
claus
parents:
diff changeset
  2849
a27a279701f8 Initial revision
claus
parents:
diff changeset
  2850
    reimplemented here for speed"
a27a279701f8 Initial revision
claus
parents:
diff changeset
  2851
32
ee1a621c696c *** empty log message ***
claus
parents: 13
diff changeset
  2852
    |stop  "{ Class: SmallInteger }"
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  2853
     element|
a27a279701f8 Initial revision
claus
parents:
diff changeset
  2854
32
ee1a621c696c *** empty log message ***
claus
parents: 13
diff changeset
  2855
    stop := self size.
ee1a621c696c *** empty log message ***
claus
parents: 13
diff changeset
  2856
    1 to:stop do:[:index |
159
514c749165c3 *** empty log message ***
claus
parents: 118
diff changeset
  2857
	element := self at:index.
514c749165c3 *** empty log message ***
claus
parents: 118
diff changeset
  2858
	(aBlock value:element) ifTrue:[
514c749165c3 *** empty log message ***
claus
parents: 118
diff changeset
  2859
	    ^ element
514c749165c3 *** empty log message ***
claus
parents: 118
diff changeset
  2860
	].
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  2861
    ].
a27a279701f8 Initial revision
claus
parents:
diff changeset
  2862
    ^ exceptionBlock value
159
514c749165c3 *** empty log message ***
claus
parents: 118
diff changeset
  2863
514c749165c3 *** empty log message ***
claus
parents: 118
diff changeset
  2864
    "
514c749165c3 *** empty log message ***
claus
parents: 118
diff changeset
  2865
     #(11 12 13 14) detect:[:n | n odd] ifNone:['sorry']    
514c749165c3 *** empty log message ***
claus
parents: 118
diff changeset
  2866
     #(12 14 16 18) detect:[:n | n odd] ifNone:['sorry']     
514c749165c3 *** empty log message ***
claus
parents: 118
diff changeset
  2867
    "
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  2868
!
a27a279701f8 Initial revision
claus
parents:
diff changeset
  2869
3887
c3c86dcca908 added #detect:startingAt:
Claus Gittinger <cg@exept.de>
parents: 3764
diff changeset
  2870
detect:aBlock startingAt:startIndex
c3c86dcca908 added #detect:startingAt:
Claus Gittinger <cg@exept.de>
parents: 3764
diff changeset
  2871
    "find the first element, for which evaluation of the argument, aBlock
c3c86dcca908 added #detect:startingAt:
Claus Gittinger <cg@exept.de>
parents: 3764
diff changeset
  2872
     return true, starting the search with startIndex.
c3c86dcca908 added #detect:startingAt:
Claus Gittinger <cg@exept.de>
parents: 3764
diff changeset
  2873
     If none does so, report an error"
c3c86dcca908 added #detect:startingAt:
Claus Gittinger <cg@exept.de>
parents: 3764
diff changeset
  2874
c3c86dcca908 added #detect:startingAt:
Claus Gittinger <cg@exept.de>
parents: 3764
diff changeset
  2875
    ^ self detect:aBlock startingAt:startIndex ifNone:[self errorNotFound]
c3c86dcca908 added #detect:startingAt:
Claus Gittinger <cg@exept.de>
parents: 3764
diff changeset
  2876
c3c86dcca908 added #detect:startingAt:
Claus Gittinger <cg@exept.de>
parents: 3764
diff changeset
  2877
    "
c3c86dcca908 added #detect:startingAt:
Claus Gittinger <cg@exept.de>
parents: 3764
diff changeset
  2878
     #(11 12 13 14) detect:[:n | n odd] startingAt:3    
c3c86dcca908 added #detect:startingAt:
Claus Gittinger <cg@exept.de>
parents: 3764
diff changeset
  2879
     #(12 14 16 18) detect:[:n | n odd] startingAt:3     
c3c86dcca908 added #detect:startingAt:
Claus Gittinger <cg@exept.de>
parents: 3764
diff changeset
  2880
    "
c3c86dcca908 added #detect:startingAt:
Claus Gittinger <cg@exept.de>
parents: 3764
diff changeset
  2881
c3c86dcca908 added #detect:startingAt:
Claus Gittinger <cg@exept.de>
parents: 3764
diff changeset
  2882
    "Created: / 21.10.1998 / 18:47:28 / cg"
c3c86dcca908 added #detect:startingAt:
Claus Gittinger <cg@exept.de>
parents: 3764
diff changeset
  2883
!
c3c86dcca908 added #detect:startingAt:
Claus Gittinger <cg@exept.de>
parents: 3764
diff changeset
  2884
c3c86dcca908 added #detect:startingAt:
Claus Gittinger <cg@exept.de>
parents: 3764
diff changeset
  2885
detect:aBlock startingAt:startIndex ifNone:exceptionBlock
c3c86dcca908 added #detect:startingAt:
Claus Gittinger <cg@exept.de>
parents: 3764
diff changeset
  2886
    "find the first element, for which evaluation of the argument, aBlock
c3c86dcca908 added #detect:startingAt:
Claus Gittinger <cg@exept.de>
parents: 3764
diff changeset
  2887
     return true, starting the search with startIndex.
c3c86dcca908 added #detect:startingAt:
Claus Gittinger <cg@exept.de>
parents: 3764
diff changeset
  2888
     If none does so, return the evaluation of exceptionBlock
c3c86dcca908 added #detect:startingAt:
Claus Gittinger <cg@exept.de>
parents: 3764
diff changeset
  2889
c3c86dcca908 added #detect:startingAt:
Claus Gittinger <cg@exept.de>
parents: 3764
diff changeset
  2890
    reimplemented here for speed"
c3c86dcca908 added #detect:startingAt:
Claus Gittinger <cg@exept.de>
parents: 3764
diff changeset
  2891
c3c86dcca908 added #detect:startingAt:
Claus Gittinger <cg@exept.de>
parents: 3764
diff changeset
  2892
    |stop  "{ Class: SmallInteger }"
c3c86dcca908 added #detect:startingAt:
Claus Gittinger <cg@exept.de>
parents: 3764
diff changeset
  2893
     element|
c3c86dcca908 added #detect:startingAt:
Claus Gittinger <cg@exept.de>
parents: 3764
diff changeset
  2894
c3c86dcca908 added #detect:startingAt:
Claus Gittinger <cg@exept.de>
parents: 3764
diff changeset
  2895
    stop := self size.
c3c86dcca908 added #detect:startingAt:
Claus Gittinger <cg@exept.de>
parents: 3764
diff changeset
  2896
    startIndex to:stop do:[:index |
c3c86dcca908 added #detect:startingAt:
Claus Gittinger <cg@exept.de>
parents: 3764
diff changeset
  2897
        element := self at:index.
c3c86dcca908 added #detect:startingAt:
Claus Gittinger <cg@exept.de>
parents: 3764
diff changeset
  2898
        (aBlock value:element) ifTrue:[
c3c86dcca908 added #detect:startingAt:
Claus Gittinger <cg@exept.de>
parents: 3764
diff changeset
  2899
            ^ element
c3c86dcca908 added #detect:startingAt:
Claus Gittinger <cg@exept.de>
parents: 3764
diff changeset
  2900
        ].
c3c86dcca908 added #detect:startingAt:
Claus Gittinger <cg@exept.de>
parents: 3764
diff changeset
  2901
    ].
c3c86dcca908 added #detect:startingAt:
Claus Gittinger <cg@exept.de>
parents: 3764
diff changeset
  2902
    ^ exceptionBlock value
c3c86dcca908 added #detect:startingAt:
Claus Gittinger <cg@exept.de>
parents: 3764
diff changeset
  2903
c3c86dcca908 added #detect:startingAt:
Claus Gittinger <cg@exept.de>
parents: 3764
diff changeset
  2904
    "
c3c86dcca908 added #detect:startingAt:
Claus Gittinger <cg@exept.de>
parents: 3764
diff changeset
  2905
     #(11 12 13 14) detect:[:n | n odd] startingAt:3 ifNone:['sorry']    
c3c86dcca908 added #detect:startingAt:
Claus Gittinger <cg@exept.de>
parents: 3764
diff changeset
  2906
     #(12 14 16 18) detect:[:n | n odd] startingAt:3 ifNone:['sorry']     
c3c86dcca908 added #detect:startingAt:
Claus Gittinger <cg@exept.de>
parents: 3764
diff changeset
  2907
    "
c3c86dcca908 added #detect:startingAt:
Claus Gittinger <cg@exept.de>
parents: 3764
diff changeset
  2908
c3c86dcca908 added #detect:startingAt:
Claus Gittinger <cg@exept.de>
parents: 3764
diff changeset
  2909
    "Created: / 21.10.1998 / 18:46:01 / cg"
c3c86dcca908 added #detect:startingAt:
Claus Gittinger <cg@exept.de>
parents: 3764
diff changeset
  2910
!
c3c86dcca908 added #detect:startingAt:
Claus Gittinger <cg@exept.de>
parents: 3764
diff changeset
  2911
602
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  2912
findFirst:aBlock
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  2913
    "find the first element, for which evaluation of the argument, aBlock
3887
c3c86dcca908 added #detect:startingAt:
Claus Gittinger <cg@exept.de>
parents: 3764
diff changeset
  2914
     returns true; return its index or 0 if none detected.
c3c86dcca908 added #detect:startingAt:
Claus Gittinger <cg@exept.de>
parents: 3764
diff changeset
  2915
     This is much like #detect, however, here an INDEX is returned,
c3c86dcca908 added #detect:startingAt:
Claus Gittinger <cg@exept.de>
parents: 3764
diff changeset
  2916
     while #detect returns the element."
602
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  2917
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  2918
    |stop  "{ Class: SmallInteger }" |
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  2919
32
ee1a621c696c *** empty log message ***
claus
parents: 13
diff changeset
  2920
    stop := self size.
602
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  2921
    1 to:stop do:[:index |
3887
c3c86dcca908 added #detect:startingAt:
Claus Gittinger <cg@exept.de>
parents: 3764
diff changeset
  2922
        (aBlock value:(self at:index)) ifTrue:[^ index].
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  2923
    ].
a27a279701f8 Initial revision
claus
parents:
diff changeset
  2924
    ^ 0
159
514c749165c3 *** empty log message ***
claus
parents: 118
diff changeset
  2925
95
d22739a0c6e9 *** empty log message ***
claus
parents: 88
diff changeset
  2926
    "
602
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  2927
     #(1 2 3 4 5 6) findFirst:[:x | (x >= 3)]
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  2928
     #(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
  2929
     #(1 2 3 4 5 6) findFirst:[:x | (x >= 8)]           
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  2930
     'one.two.three' findFirst:[:c | (c == $.)]
95
d22739a0c6e9 *** empty log message ***
claus
parents: 88
diff changeset
  2931
    "
3887
c3c86dcca908 added #detect:startingAt:
Claus Gittinger <cg@exept.de>
parents: 3764
diff changeset
  2932
c3c86dcca908 added #detect:startingAt:
Claus Gittinger <cg@exept.de>
parents: 3764
diff changeset
  2933
    "Modified: / 21.10.1998 / 18:48:10 / cg"
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  2934
!
a27a279701f8 Initial revision
claus
parents:
diff changeset
  2935
929
674de4c05dcb added findFirst:startingAt: and findLast:startingAt:
Claus Gittinger <cg@exept.de>
parents: 911
diff changeset
  2936
findFirst:aBlock startingAt:startIndex
674de4c05dcb added findFirst:startingAt: and findLast:startingAt:
Claus Gittinger <cg@exept.de>
parents: 911
diff changeset
  2937
    "find the first element, for which evaluation of the argument, aBlock
3887
c3c86dcca908 added #detect:startingAt:
Claus Gittinger <cg@exept.de>
parents: 3764
diff changeset
  2938
     returns true; return its index or 0 if none detected.
c3c86dcca908 added #detect:startingAt:
Claus Gittinger <cg@exept.de>
parents: 3764
diff changeset
  2939
     This is much like #detect:startingAt:, however, here an INDEX is returned,
c3c86dcca908 added #detect:startingAt:
Claus Gittinger <cg@exept.de>
parents: 3764
diff changeset
  2940
     while #detect returns the element."
929
674de4c05dcb added findFirst:startingAt: and findLast:startingAt:
Claus Gittinger <cg@exept.de>
parents: 911
diff changeset
  2941
674de4c05dcb added findFirst:startingAt: and findLast:startingAt:
Claus Gittinger <cg@exept.de>
parents: 911
diff changeset
  2942
    |start "{ Class: SmallInteger }"
674de4c05dcb added findFirst:startingAt: and findLast:startingAt:
Claus Gittinger <cg@exept.de>
parents: 911
diff changeset
  2943
     stop  "{ Class: SmallInteger }" |
674de4c05dcb added findFirst:startingAt: and findLast:startingAt:
Claus Gittinger <cg@exept.de>
parents: 911
diff changeset
  2944
674de4c05dcb added findFirst:startingAt: and findLast:startingAt:
Claus Gittinger <cg@exept.de>
parents: 911
diff changeset
  2945
    start := startIndex. "/ as a compiler hint
674de4c05dcb added findFirst:startingAt: and findLast:startingAt:
Claus Gittinger <cg@exept.de>
parents: 911
diff changeset
  2946
    stop := self size.
674de4c05dcb added findFirst:startingAt: and findLast:startingAt:
Claus Gittinger <cg@exept.de>
parents: 911
diff changeset
  2947
    start to:stop do:[:index |
3887
c3c86dcca908 added #detect:startingAt:
Claus Gittinger <cg@exept.de>
parents: 3764
diff changeset
  2948
        (aBlock value:(self at:index)) ifTrue:[^ index].
929
674de4c05dcb added findFirst:startingAt: and findLast:startingAt:
Claus Gittinger <cg@exept.de>
parents: 911
diff changeset
  2949
    ].
674de4c05dcb added findFirst:startingAt: and findLast:startingAt:
Claus Gittinger <cg@exept.de>
parents: 911
diff changeset
  2950
    ^ 0
674de4c05dcb added findFirst:startingAt: and findLast:startingAt:
Claus Gittinger <cg@exept.de>
parents: 911
diff changeset
  2951
674de4c05dcb added findFirst:startingAt: and findLast:startingAt:
Claus Gittinger <cg@exept.de>
parents: 911
diff changeset
  2952
    "
674de4c05dcb added findFirst:startingAt: and findLast:startingAt:
Claus Gittinger <cg@exept.de>
parents: 911
diff changeset
  2953
     #(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
  2954
     'one.two.three' findFirst:[:c | (c == $.)] startingAt:5
674de4c05dcb added findFirst:startingAt: and findLast:startingAt:
Claus Gittinger <cg@exept.de>
parents: 911
diff changeset
  2955
    "
3887
c3c86dcca908 added #detect:startingAt:
Claus Gittinger <cg@exept.de>
parents: 3764
diff changeset
  2956
c3c86dcca908 added #detect:startingAt:
Claus Gittinger <cg@exept.de>
parents: 3764
diff changeset
  2957
    "Modified: / 21.10.1998 / 18:48:22 / cg"
929
674de4c05dcb added findFirst:startingAt: and findLast:startingAt:
Claus Gittinger <cg@exept.de>
parents: 911
diff changeset
  2958
!
674de4c05dcb added findFirst:startingAt: and findLast:startingAt:
Claus Gittinger <cg@exept.de>
parents: 911
diff changeset
  2959
602
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  2960
findLast:aBlock
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  2961
    "find the last element, for which evaluation of the argument, aBlock
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  2962
     returns true; return its index or 0 if none detected."
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  2963
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  2964
    |start "{ Class: SmallInteger }"|
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  2965
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  2966
    start := self size.
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  2967
    start to:1 by:-1 do:[:index |
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  2968
	(aBlock value:(self at:index)) ifTrue:[^ index].
252
  2969
    ].
  2970
    ^ 0
  2971
  2972
    "
602
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  2973
     #(1 99 3 99 5 6) findLast:[:x | (x == 99)]
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  2974
     'one.two.three' findLast:[:c | (c == $.)]
252
  2975
    "
  2976
!
  2977
929
674de4c05dcb added findFirst:startingAt: and findLast:startingAt:
Claus Gittinger <cg@exept.de>
parents: 911
diff changeset
  2978
findLast:aBlock startingAt:startIndex
674de4c05dcb added findFirst:startingAt: and findLast:startingAt:
Claus Gittinger <cg@exept.de>
parents: 911
diff changeset
  2979
    "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
  2980
     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
  2981
674de4c05dcb added findFirst:startingAt: and findLast:startingAt:
Claus Gittinger <cg@exept.de>
parents: 911
diff changeset
  2982
    |start "{ Class: SmallInteger }"|
674de4c05dcb added findFirst:startingAt: and findLast:startingAt:
Claus Gittinger <cg@exept.de>
parents: 911
diff changeset
  2983
674de4c05dcb added findFirst:startingAt: and findLast:startingAt:
Claus Gittinger <cg@exept.de>
parents: 911
diff changeset
  2984
    start := startIndex.
674de4c05dcb added findFirst:startingAt: and findLast:startingAt:
Claus Gittinger <cg@exept.de>
parents: 911
diff changeset
  2985
    start to:1 by:-1 do:[:index |
674de4c05dcb added findFirst:startingAt: and findLast:startingAt:
Claus Gittinger <cg@exept.de>
parents: 911
diff changeset
  2986
	(aBlock value:(self at:index)) ifTrue:[^ index].
674de4c05dcb added findFirst:startingAt: and findLast:startingAt:
Claus Gittinger <cg@exept.de>
parents: 911
diff changeset
  2987
    ].
674de4c05dcb added findFirst:startingAt: and findLast:startingAt:
Claus Gittinger <cg@exept.de>
parents: 911
diff changeset
  2988
    ^ 0
674de4c05dcb added findFirst:startingAt: and findLast:startingAt:
Claus Gittinger <cg@exept.de>
parents: 911
diff changeset
  2989
674de4c05dcb added findFirst:startingAt: and findLast:startingAt:
Claus Gittinger <cg@exept.de>
parents: 911
diff changeset
  2990
    "
674de4c05dcb added findFirst:startingAt: and findLast:startingAt:
Claus Gittinger <cg@exept.de>
parents: 911
diff changeset
  2991
     #(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
  2992
     'one.two.three' findLast:[:c | (c == $.)] startingAt:7
674de4c05dcb added findFirst:startingAt: and findLast:startingAt:
Claus Gittinger <cg@exept.de>
parents: 911
diff changeset
  2993
    "
674de4c05dcb added findFirst:startingAt: and findLast:startingAt:
Claus Gittinger <cg@exept.de>
parents: 911
diff changeset
  2994
!
674de4c05dcb added findFirst:startingAt: and findLast:startingAt:
Claus Gittinger <cg@exept.de>
parents: 911
diff changeset
  2995
159
514c749165c3 *** empty log message ***
claus
parents: 118
diff changeset
  2996
indexOfAny:aCollection
514c749165c3 *** empty log message ***
claus
parents: 118
diff changeset
  2997
    "search the collection for an element in aCollection.
514c749165c3 *** empty log message ***
claus
parents: 118
diff changeset
  2998
     if found, return the index otherwise return 0.
514c749165c3 *** empty log message ***
claus
parents: 118
diff changeset
  2999
     The comparison is done using = 
514c749165c3 *** empty log message ***
claus
parents: 118
diff changeset
  3000
     (i.e. equality test - not identity test).
514c749165c3 *** empty log message ***
claus
parents: 118
diff changeset
  3001
514c749165c3 *** empty log message ***
claus
parents: 118
diff changeset
  3002
     Notice, that for big collections, the runtime of this search
514c749165c3 *** empty log message ***
claus
parents: 118
diff changeset
  3003
     grows proportional to size(receiver) * size(aCollection).
514c749165c3 *** empty log message ***
claus
parents: 118
diff changeset
  3004
     You may think about using other mechanisms (Sets, Dictionaries etc)."
514c749165c3 *** empty log message ***
claus
parents: 118
diff changeset
  3005
514c749165c3 *** empty log message ***
claus
parents: 118
diff changeset
  3006
    ^ self indexOfAny:aCollection startingAt:1
514c749165c3 *** empty log message ***
claus
parents: 118
diff changeset
  3007
514c749165c3 *** empty log message ***
claus
parents: 118
diff changeset
  3008
    "
514c749165c3 *** empty log message ***
claus
parents: 118
diff changeset
  3009
     #(10 20 30 40 50 60 70) indexOfAny:#(40 30 50)
514c749165c3 *** empty log message ***
claus
parents: 118
diff changeset
  3010
     #(10 20 30 40 50 60 70) indexOfAny:#(40.0 30.0 50)
514c749165c3 *** empty log message ***
claus
parents: 118
diff changeset
  3011
    "
514c749165c3 *** empty log message ***
claus
parents: 118
diff changeset
  3012
!
514c749165c3 *** empty log message ***
claus
parents: 118
diff changeset
  3013
514c749165c3 *** empty log message ***
claus
parents: 118
diff changeset
  3014
indexOfAny:aCollection startingAt:start
514c749165c3 *** empty log message ***
claus
parents: 118
diff changeset
  3015
    "search the collection for an element in aCollection,
514c749165c3 *** empty log message ***
claus
parents: 118
diff changeset
  3016
     starting the search at index start;
514c749165c3 *** empty log message ***
claus
parents: 118
diff changeset
  3017
     if found, return the index otherwise return 0.
514c749165c3 *** empty log message ***
claus
parents: 118
diff changeset
  3018
     The comparison is done using = 
514c749165c3 *** empty log message ***
claus
parents: 118
diff changeset
  3019
     (i.e. equality test - not identity test).
514c749165c3 *** empty log message ***
claus
parents: 118
diff changeset
  3020
514c749165c3 *** empty log message ***
claus
parents: 118
diff changeset
  3021
     Notice, that for big collections, the runtime of this search
514c749165c3 *** empty log message ***
claus
parents: 118
diff changeset
  3022
     grows proportional to size(receiver) * size(aCollection).
514c749165c3 *** empty log message ***
claus
parents: 118
diff changeset
  3023
     You may think about using other mechanisms (Sets, Dictionaries etc)."
514c749165c3 *** empty log message ***
claus
parents: 118
diff changeset
  3024
514c749165c3 *** empty log message ***
claus
parents: 118
diff changeset
  3025
514c749165c3 *** empty log message ***
claus
parents: 118
diff changeset
  3026
    |startIndex "{ Class: SmallInteger }"
514c749165c3 *** empty log message ***
claus
parents: 118
diff changeset
  3027
     stop       "{ Class: SmallInteger }" |
514c749165c3 *** empty log message ***
claus
parents: 118
diff changeset
  3028
514c749165c3 *** empty log message ***
claus
parents: 118
diff changeset
  3029
    startIndex := start.
514c749165c3 *** empty log message ***
claus
parents: 118
diff changeset
  3030
    stop := self size.
514c749165c3 *** empty log message ***
claus
parents: 118
diff changeset
  3031
    startIndex to:stop do:[:index |
514c749165c3 *** empty log message ***
claus
parents: 118
diff changeset
  3032
	(aCollection includes:(self at:index)) ifTrue:[^ index].
514c749165c3 *** empty log message ***
claus
parents: 118
diff changeset
  3033
    ].
514c749165c3 *** empty log message ***
claus
parents: 118
diff changeset
  3034
    ^ 0
514c749165c3 *** empty log message ***
claus
parents: 118
diff changeset
  3035
    "
514c749165c3 *** empty log message ***
claus
parents: 118
diff changeset
  3036
     #(10 20 30 40 10 20 30 40) indexOfAny:#(40 50 30) startingAt:5  
514c749165c3 *** empty log message ***
claus
parents: 118
diff changeset
  3037
     #(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
  3038
    "
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  3039
!
a27a279701f8 Initial revision
claus
parents:
diff changeset
  3040
518
5372a8875432 added indexOfAny:startingAt:ifAbsent:
Claus Gittinger <cg@exept.de>
parents: 424
diff changeset
  3041
indexOfAny:aCollection startingAt:start ifAbsent:exceptionBlock
5372a8875432 added indexOfAny:startingAt:ifAbsent:
Claus Gittinger <cg@exept.de>
parents: 424
diff changeset
  3042
    "search the collection for an element in aCollection,
5372a8875432 added indexOfAny:startingAt:ifAbsent:
Claus Gittinger <cg@exept.de>
parents: 424
diff changeset
  3043
     starting the search at index start;
5372a8875432 added indexOfAny:startingAt:ifAbsent:
Claus Gittinger <cg@exept.de>
parents: 424
diff changeset
  3044
     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
  3045
     The comparison is done using = 
5372a8875432 added indexOfAny:startingAt:ifAbsent:
Claus Gittinger <cg@exept.de>
parents: 424
diff changeset
  3046
     (i.e. equality test - not identity test).
5372a8875432 added indexOfAny:startingAt:ifAbsent:
Claus Gittinger <cg@exept.de>
parents: 424
diff changeset
  3047
5372a8875432 added indexOfAny:startingAt:ifAbsent:
Claus Gittinger <cg@exept.de>
parents: 424
diff changeset
  3048
     Notice, that for big collections, the runtime of this search
5372a8875432 added indexOfAny:startingAt:ifAbsent:
Claus Gittinger <cg@exept.de>
parents: 424
diff changeset
  3049
     grows proportional to size(receiver) * size(aCollection).
5372a8875432 added indexOfAny:startingAt:ifAbsent:
Claus Gittinger <cg@exept.de>
parents: 424
diff changeset
  3050
     You may think about using other mechanisms (Sets, Dictionaries etc)."
5372a8875432 added indexOfAny:startingAt:ifAbsent:
Claus Gittinger <cg@exept.de>
parents: 424
diff changeset
  3051
5372a8875432 added indexOfAny:startingAt:ifAbsent:
Claus Gittinger <cg@exept.de>
parents: 424
diff changeset
  3052
5372a8875432 added indexOfAny:startingAt:ifAbsent:
Claus Gittinger <cg@exept.de>
parents: 424
diff changeset
  3053
    |val|
5372a8875432 added indexOfAny:startingAt:ifAbsent:
Claus Gittinger <cg@exept.de>
parents: 424
diff changeset
  3054
5372a8875432 added indexOfAny:startingAt:ifAbsent:
Claus Gittinger <cg@exept.de>
parents: 424
diff changeset
  3055
    val := self indexOfAny:aCollection startingAt:start .
5372a8875432 added indexOfAny:startingAt:ifAbsent:
Claus Gittinger <cg@exept.de>
parents: 424
diff changeset
  3056
    val == 0 ifTrue:[^ exceptionBlock value].
5372a8875432 added indexOfAny:startingAt:ifAbsent:
Claus Gittinger <cg@exept.de>
parents: 424
diff changeset
  3057
    ^ val.
5372a8875432 added indexOfAny:startingAt:ifAbsent:
Claus Gittinger <cg@exept.de>
parents: 424
diff changeset
  3058
5372a8875432 added indexOfAny:startingAt:ifAbsent:
Claus Gittinger <cg@exept.de>
parents: 424
diff changeset
  3059
    "
5372a8875432 added indexOfAny:startingAt:ifAbsent:
Claus Gittinger <cg@exept.de>
parents: 424
diff changeset
  3060
     #(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
  3061
     #(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
  3062
     #(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
  3063
    "
5372a8875432 added indexOfAny:startingAt:ifAbsent:
Claus Gittinger <cg@exept.de>
parents: 424
diff changeset
  3064
!
5372a8875432 added indexOfAny:startingAt:ifAbsent:
Claus Gittinger <cg@exept.de>
parents: 424
diff changeset
  3065
4338
326f43992dcd added #indexOfAnyOf:* for squeak compatibility.
Claus Gittinger <cg@exept.de>
parents: 4303
diff changeset
  3066
indexOfAnyOf:aCollection
326f43992dcd added #indexOfAnyOf:* for squeak compatibility.
Claus Gittinger <cg@exept.de>
parents: 4303
diff changeset
  3067
    "squeak compatibility: same as #indexOfAny:"
326f43992dcd added #indexOfAnyOf:* for squeak compatibility.
Claus Gittinger <cg@exept.de>
parents: 4303
diff changeset
  3068
326f43992dcd added #indexOfAnyOf:* for squeak compatibility.
Claus Gittinger <cg@exept.de>
parents: 4303
diff changeset
  3069
    ^ self indexOfAny:aCollection
326f43992dcd added #indexOfAnyOf:* for squeak compatibility.
Claus Gittinger <cg@exept.de>
parents: 4303
diff changeset
  3070
326f43992dcd added #indexOfAnyOf:* for squeak compatibility.
Claus Gittinger <cg@exept.de>
parents: 4303
diff changeset
  3071
    "
326f43992dcd added #indexOfAnyOf:* for squeak compatibility.
Claus Gittinger <cg@exept.de>
parents: 4303
diff changeset
  3072
     #(10 20 30 40 50 60 70) indexOfAnyOf:#(40 30 50)
326f43992dcd added #indexOfAnyOf:* for squeak compatibility.
Claus Gittinger <cg@exept.de>
parents: 4303
diff changeset
  3073
     #(10 20 30 40 50 60 70) indexOfAnyOf:#(40.0 30.0 50)
326f43992dcd added #indexOfAnyOf:* for squeak compatibility.
Claus Gittinger <cg@exept.de>
parents: 4303
diff changeset
  3074
    "
326f43992dcd added #indexOfAnyOf:* for squeak compatibility.
Claus Gittinger <cg@exept.de>
parents: 4303
diff changeset
  3075
!
326f43992dcd added #indexOfAnyOf:* for squeak compatibility.
Claus Gittinger <cg@exept.de>
parents: 4303
diff changeset
  3076
326f43992dcd added #indexOfAnyOf:* for squeak compatibility.
Claus Gittinger <cg@exept.de>
parents: 4303
diff changeset
  3077
indexOfAnyOf:aCollection startingAt:start 
326f43992dcd added #indexOfAnyOf:* for squeak compatibility.
Claus Gittinger <cg@exept.de>
parents: 4303
diff changeset
  3078
    "squeak compatibility: same as #indexOfAny:startingAt:"
326f43992dcd added #indexOfAnyOf:* for squeak compatibility.
Claus Gittinger <cg@exept.de>
parents: 4303
diff changeset
  3079
326f43992dcd added #indexOfAnyOf:* for squeak compatibility.
Claus Gittinger <cg@exept.de>
parents: 4303
diff changeset
  3080
    ^ self indexOfAny:aCollection startingAt:start
326f43992dcd added #indexOfAnyOf:* for squeak compatibility.
Claus Gittinger <cg@exept.de>
parents: 4303
diff changeset
  3081
326f43992dcd added #indexOfAnyOf:* for squeak compatibility.
Claus Gittinger <cg@exept.de>
parents: 4303
diff changeset
  3082
    "
326f43992dcd added #indexOfAnyOf:* for squeak compatibility.
Claus Gittinger <cg@exept.de>
parents: 4303
diff changeset
  3083
     #(10 20 30 40 50 60 70) indexOfAnyOf:#(40 30 50)     startingAt:2
326f43992dcd added #indexOfAnyOf:* for squeak compatibility.
Claus Gittinger <cg@exept.de>
parents: 4303
diff changeset
  3084
     #(10 20 30 40 50 60 70) indexOfAnyOf:#(40.0 30.0 50) startingAt:2
326f43992dcd added #indexOfAnyOf:* for squeak compatibility.
Claus Gittinger <cg@exept.de>
parents: 4303
diff changeset
  3085
    "
326f43992dcd added #indexOfAnyOf:* for squeak compatibility.
Claus Gittinger <cg@exept.de>
parents: 4303
diff changeset
  3086
!
326f43992dcd added #indexOfAnyOf:* for squeak compatibility.
Claus Gittinger <cg@exept.de>
parents: 4303
diff changeset
  3087
326f43992dcd added #indexOfAnyOf:* for squeak compatibility.
Claus Gittinger <cg@exept.de>
parents: 4303
diff changeset
  3088
indexOfAnyOf:aCollection startingAt:start ifAbsent:exceptionBlock
326f43992dcd added #indexOfAnyOf:* for squeak compatibility.
Claus Gittinger <cg@exept.de>
parents: 4303
diff changeset
  3089
    "squeak compatibility: same as #indexOfAny:startingAt:ifAbsent:"
326f43992dcd added #indexOfAnyOf:* for squeak compatibility.
Claus Gittinger <cg@exept.de>
parents: 4303
diff changeset
  3090
326f43992dcd added #indexOfAnyOf:* for squeak compatibility.
Claus Gittinger <cg@exept.de>
parents: 4303
diff changeset
  3091
    ^ self indexOfAny:aCollection startingAt:start ifAbsent:exceptionBlock
326f43992dcd added #indexOfAnyOf:* for squeak compatibility.
Claus Gittinger <cg@exept.de>
parents: 4303
diff changeset
  3092
326f43992dcd added #indexOfAnyOf:* for squeak compatibility.
Claus Gittinger <cg@exept.de>
parents: 4303
diff changeset
  3093
!
326f43992dcd added #indexOfAnyOf:* for squeak compatibility.
Claus Gittinger <cg@exept.de>
parents: 4303
diff changeset
  3094
368
a3c21a89ec37 *** empty log message ***
claus
parents: 362
diff changeset
  3095
indexOfSubCollection:aCollection
a3c21a89ec37 *** empty log message ***
claus
parents: 362
diff changeset
  3096
    "find a subcollection. 
a3c21a89ec37 *** empty log message ***
claus
parents: 362
diff changeset
  3097
     If found, return the index; if not found, return 0."
a3c21a89ec37 *** empty log message ***
claus
parents: 362
diff changeset
  3098
1145
a094d90e11bf dont use [0] blocks - use 0 constant instead
Claus Gittinger <cg@exept.de>
parents: 1016
diff changeset
  3099
    ^ self indexOfSubCollection:aCollection startingAt:1 ifAbsent:0
368
a3c21a89ec37 *** empty log message ***
claus
parents: 362
diff changeset
  3100
a3c21a89ec37 *** empty log message ***
claus
parents: 362
diff changeset
  3101
    "
a3c21a89ec37 *** empty log message ***
claus
parents: 362
diff changeset
  3102
     #(1 2 3 4 5 6 7) indexOfSubCollection:#()  
a3c21a89ec37 *** empty log message ***
claus
parents: 362
diff changeset
  3103
     #(1 2 3 4 5 6 7) indexOfSubCollection:#(1)      
a3c21a89ec37 *** empty log message ***
claus
parents: 362
diff changeset
  3104
     #(1 2 3 4 5 6 7) indexOfSubCollection:#(1 2 3 4) 
a3c21a89ec37 *** empty log message ***
claus
parents: 362
diff changeset
  3105
     #(1 2 3 4 5 6 7) indexOfSubCollection:#(2 3 5)   
a3c21a89ec37 *** empty log message ***
claus
parents: 362
diff changeset
  3106
     #(1 2 3 2 3 4 5) indexOfSubCollection:#(2 3 4)  
a3c21a89ec37 *** empty log message ***
claus
parents: 362
diff changeset
  3107
     #(1 2 3 4 5 6 7) indexOfSubCollection:#(5 6 7)  
a3c21a89ec37 *** empty log message ***
claus
parents: 362
diff changeset
  3108
     #(1 2 3 4 5 6 7) indexOfSubCollection:#(5 6 8)  
a3c21a89ec37 *** empty log message ***
claus
parents: 362
diff changeset
  3109
     #(1 2 3 4 5 6 7) indexOfSubCollection:#(5 6 7 8)  
a3c21a89ec37 *** empty log message ***
claus
parents: 362
diff changeset
  3110
    "
a3c21a89ec37 *** empty log message ***
claus
parents: 362
diff changeset
  3111
!
a3c21a89ec37 *** empty log message ***
claus
parents: 362
diff changeset
  3112
602
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  3113
indexOfSubCollection:aCollection ifAbsent:exceptionBlock
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  3114
    "find a subcollection. If found, return the index;
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  3115
     if not found, return the result of evaluating exceptionBlock."
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  3116
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  3117
    ^ self indexOfSubCollection:aCollection startingAt:1 ifAbsent:exceptionBlock
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  3118
!
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  3119
368
a3c21a89ec37 *** empty log message ***
claus
parents: 362
diff changeset
  3120
indexOfSubCollection:aCollection startingAt:startIndex
a3c21a89ec37 *** empty log message ***
claus
parents: 362
diff changeset
  3121
    "find a subcollection starting at index. 
a3c21a89ec37 *** empty log message ***
claus
parents: 362
diff changeset
  3122
     If found, return the index; if not found, return 0."
a3c21a89ec37 *** empty log message ***
claus
parents: 362
diff changeset
  3123
1145
a094d90e11bf dont use [0] blocks - use 0 constant instead
Claus Gittinger <cg@exept.de>
parents: 1016
diff changeset
  3124
    ^ self indexOfSubCollection:aCollection startingAt:startIndex ifAbsent:0
368
a3c21a89ec37 *** empty log message ***
claus
parents: 362
diff changeset
  3125
!
a3c21a89ec37 *** empty log message ***
claus
parents: 362
diff changeset
  3126
a3c21a89ec37 *** empty log message ***
claus
parents: 362
diff changeset
  3127
indexOfSubCollection:aCollection startingAt:startIndex ifAbsent:exceptionBlock
a3c21a89ec37 *** empty log message ***
claus
parents: 362
diff changeset
  3128
    "find a subcollection, starting at index. If found, return the index;
a3c21a89ec37 *** empty log message ***
claus
parents: 362
diff changeset
  3129
     if not found, return the result of evaluating exceptionBlock.
a3c21a89ec37 *** empty log message ***
claus
parents: 362
diff changeset
  3130
     This is a q&d hack - not very efficient"
a3c21a89ec37 *** empty log message ***
claus
parents: 362
diff changeset
  3131
a3c21a89ec37 *** empty log message ***
claus
parents: 362
diff changeset
  3132
    |same first 
a3c21a89ec37 *** empty log message ***
claus
parents: 362
diff changeset
  3133
     mySize     "{Class: SmallInteger }"
a3c21a89ec37 *** empty log message ***
claus
parents: 362
diff changeset
  3134
     checkIndex "{Class: SmallInteger }"
a3c21a89ec37 *** empty log message ***
claus
parents: 362
diff changeset
  3135
     cmpIndex   "{Class: SmallInteger }"
a3c21a89ec37 *** empty log message ***
claus
parents: 362
diff changeset
  3136
     sz         "{Class: SmallInteger }"|
a3c21a89ec37 *** empty log message ***
claus
parents: 362
diff changeset
  3137
a3c21a89ec37 *** empty log message ***
claus
parents: 362
diff changeset
  3138
    mySize := self size.
a3c21a89ec37 *** empty log message ***
claus
parents: 362
diff changeset
  3139
    sz := aCollection size.
a3c21a89ec37 *** empty log message ***
claus
parents: 362
diff changeset
  3140
    sz == 0 ifTrue:[^ exceptionBlock value].
a3c21a89ec37 *** empty log message ***
claus
parents: 362
diff changeset
  3141
    first := aCollection at:1.
a3c21a89ec37 *** empty log message ***
claus
parents: 362
diff changeset
  3142
a3c21a89ec37 *** empty log message ***
claus
parents: 362
diff changeset
  3143
    checkIndex := startIndex - 1.    
a3c21a89ec37 *** empty log message ***
claus
parents: 362
diff changeset
  3144
    [true] whileTrue:[
a3c21a89ec37 *** empty log message ***
claus
parents: 362
diff changeset
  3145
	checkIndex := self indexOf:first startingAt:checkIndex+1.
a3c21a89ec37 *** empty log message ***
claus
parents: 362
diff changeset
  3146
	checkIndex == 0 ifTrue:[^ exceptionBlock value].
a3c21a89ec37 *** empty log message ***
claus
parents: 362
diff changeset
  3147
a3c21a89ec37 *** empty log message ***
claus
parents: 362
diff changeset
  3148
	(checkIndex + sz - 1) > mySize ifTrue:[
a3c21a89ec37 *** empty log message ***
claus
parents: 362
diff changeset
  3149
	    ^ 0
a3c21a89ec37 *** empty log message ***
claus
parents: 362
diff changeset
  3150
	].
a3c21a89ec37 *** empty log message ***
claus
parents: 362
diff changeset
  3151
	same := true.
a3c21a89ec37 *** empty log message ***
claus
parents: 362
diff changeset
  3152
	cmpIndex := 1.
a3c21a89ec37 *** empty log message ***
claus
parents: 362
diff changeset
  3153
	[same and:[cmpIndex <= sz]] whileTrue:[
a3c21a89ec37 *** empty log message ***
claus
parents: 362
diff changeset
  3154
	    (self at:checkIndex + cmpIndex - 1) = (aCollection at:cmpIndex) ifFalse:[
a3c21a89ec37 *** empty log message ***
claus
parents: 362
diff changeset
  3155
		same := false
a3c21a89ec37 *** empty log message ***
claus
parents: 362
diff changeset
  3156
	    ] ifTrue:[
a3c21a89ec37 *** empty log message ***
claus
parents: 362
diff changeset
  3157
		cmpIndex := cmpIndex + 1
a3c21a89ec37 *** empty log message ***
claus
parents: 362
diff changeset
  3158
	    ]
a3c21a89ec37 *** empty log message ***
claus
parents: 362
diff changeset
  3159
	].
a3c21a89ec37 *** empty log message ***
claus
parents: 362
diff changeset
  3160
	same ifTrue:[^ checkIndex].
a3c21a89ec37 *** empty log message ***
claus
parents: 362
diff changeset
  3161
    ]    
a3c21a89ec37 *** empty log message ***
claus
parents: 362
diff changeset
  3162
a3c21a89ec37 *** empty log message ***
claus
parents: 362
diff changeset
  3163
    "
a3c21a89ec37 *** empty log message ***
claus
parents: 362
diff changeset
  3164
     #(1 2 3 4 5 6 7) indexOfSubCollection:#()  startingAt:2 
a3c21a89ec37 *** empty log message ***
claus
parents: 362
diff changeset
  3165
     #(1 2 3 4 5 6 7) indexOfSubCollection:#(1) startingAt:2     
a3c21a89ec37 *** empty log message ***
claus
parents: 362
diff changeset
  3166
     #(1 2 1 2 1 2 3) indexOfSubCollection:#(1 2 3) startingAt:2 
a3c21a89ec37 *** empty log message ***
claus
parents: 362
diff changeset
  3167
     #(1 2 1 2 1 2 3) indexOfSubCollection:#(1 2)   startingAt:2  
a3c21a89ec37 *** empty log message ***
claus
parents: 362
diff changeset
  3168
     #(1 2 1 2 1 2 3) indexOfSubCollection:#(1 2)   startingAt:3  
a3c21a89ec37 *** empty log message ***
claus
parents: 362
diff changeset
  3169
     #(1 2 1 2 1 2 3) indexOfSubCollection:#(1 2)   startingAt:4 
a3c21a89ec37 *** empty log message ***
claus
parents: 362
diff changeset
  3170
    "
602
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  3171
!
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  3172
3452
95d66fc71059 added #lastIndexOfSubCollection family of methods.
Claus Gittinger <cg@exept.de>
parents: 3435
diff changeset
  3173
lastIndexOfSubCollection:aCollection
95d66fc71059 added #lastIndexOfSubCollection family of methods.
Claus Gittinger <cg@exept.de>
parents: 3435
diff changeset
  3174
    "find a subcollection from the end. 
95d66fc71059 added #lastIndexOfSubCollection family of methods.
Claus Gittinger <cg@exept.de>
parents: 3435
diff changeset
  3175
     If found, return the index; if not found, return 0."
95d66fc71059 added #lastIndexOfSubCollection family of methods.
Claus Gittinger <cg@exept.de>
parents: 3435
diff changeset
  3176
95d66fc71059 added #lastIndexOfSubCollection family of methods.
Claus Gittinger <cg@exept.de>
parents: 3435
diff changeset
  3177
    ^ self lastIndexOfSubCollection:aCollection startingAt:self size ifAbsent:0
95d66fc71059 added #lastIndexOfSubCollection family of methods.
Claus Gittinger <cg@exept.de>
parents: 3435
diff changeset
  3178
95d66fc71059 added #lastIndexOfSubCollection family of methods.
Claus Gittinger <cg@exept.de>
parents: 3435
diff changeset
  3179
    "Created: / 16.5.1998 / 20:08:55 / cg"
95d66fc71059 added #lastIndexOfSubCollection family of methods.
Claus Gittinger <cg@exept.de>
parents: 3435
diff changeset
  3180
    "Modified: / 16.5.1998 / 20:12:37 / cg"
95d66fc71059 added #lastIndexOfSubCollection family of methods.
Claus Gittinger <cg@exept.de>
parents: 3435
diff changeset
  3181
!
95d66fc71059 added #lastIndexOfSubCollection family of methods.
Claus Gittinger <cg@exept.de>
parents: 3435
diff changeset
  3182
95d66fc71059 added #lastIndexOfSubCollection family of methods.
Claus Gittinger <cg@exept.de>
parents: 3435
diff changeset
  3183
lastIndexOfSubCollection:aCollection ifAbsent:exceptionBlock
95d66fc71059 added #lastIndexOfSubCollection family of methods.
Claus Gittinger <cg@exept.de>
parents: 3435
diff changeset
  3184
    "find a subcollection from the end. If found, return the index;
95d66fc71059 added #lastIndexOfSubCollection family of methods.
Claus Gittinger <cg@exept.de>
parents: 3435
diff changeset
  3185
     if not found, return the result of evaluating exceptionBlock."
95d66fc71059 added #lastIndexOfSubCollection family of methods.
Claus Gittinger <cg@exept.de>
parents: 3435
diff changeset
  3186
95d66fc71059 added #lastIndexOfSubCollection family of methods.
Claus Gittinger <cg@exept.de>
parents: 3435
diff changeset
  3187
    ^ self lastIndexOfSubCollection:aCollection startingAt:self size ifAbsent:exceptionBlock
95d66fc71059 added #lastIndexOfSubCollection family of methods.
Claus Gittinger <cg@exept.de>
parents: 3435
diff changeset
  3188
95d66fc71059 added #lastIndexOfSubCollection family of methods.
Claus Gittinger <cg@exept.de>
parents: 3435
diff changeset
  3189
    "Created: / 16.5.1998 / 20:09:08 / cg"
95d66fc71059 added #lastIndexOfSubCollection family of methods.
Claus Gittinger <cg@exept.de>
parents: 3435
diff changeset
  3190
    "Modified: / 16.5.1998 / 20:12:39 / cg"
95d66fc71059 added #lastIndexOfSubCollection family of methods.
Claus Gittinger <cg@exept.de>
parents: 3435
diff changeset
  3191
!
95d66fc71059 added #lastIndexOfSubCollection family of methods.
Claus Gittinger <cg@exept.de>
parents: 3435
diff changeset
  3192
95d66fc71059 added #lastIndexOfSubCollection family of methods.
Claus Gittinger <cg@exept.de>
parents: 3435
diff changeset
  3193
lastIndexOfSubCollection:aCollection startingAt:startIndex
95d66fc71059 added #lastIndexOfSubCollection family of methods.
Claus Gittinger <cg@exept.de>
parents: 3435
diff changeset
  3194
    "find a subcollection from the end starting at index. 
95d66fc71059 added #lastIndexOfSubCollection family of methods.
Claus Gittinger <cg@exept.de>
parents: 3435
diff changeset
  3195
     If found, return the index; if not found, return 0."
95d66fc71059 added #lastIndexOfSubCollection family of methods.
Claus Gittinger <cg@exept.de>
parents: 3435
diff changeset
  3196
95d66fc71059 added #lastIndexOfSubCollection family of methods.
Claus Gittinger <cg@exept.de>
parents: 3435
diff changeset
  3197
    ^ self lastIndexOfSubCollection:aCollection startingAt:startIndex ifAbsent:0
95d66fc71059 added #lastIndexOfSubCollection family of methods.
Claus Gittinger <cg@exept.de>
parents: 3435
diff changeset
  3198
95d66fc71059 added #lastIndexOfSubCollection family of methods.
Claus Gittinger <cg@exept.de>
parents: 3435
diff changeset
  3199
    "Created: / 16.5.1998 / 20:09:23 / cg"
95d66fc71059 added #lastIndexOfSubCollection family of methods.
Claus Gittinger <cg@exept.de>
parents: 3435
diff changeset
  3200
!
95d66fc71059 added #lastIndexOfSubCollection family of methods.
Claus Gittinger <cg@exept.de>
parents: 3435
diff changeset
  3201
95d66fc71059 added #lastIndexOfSubCollection family of methods.
Claus Gittinger <cg@exept.de>
parents: 3435
diff changeset
  3202
lastIndexOfSubCollection:aCollection startingAt:startIndex ifAbsent:exceptionBlock
95d66fc71059 added #lastIndexOfSubCollection family of methods.
Claus Gittinger <cg@exept.de>
parents: 3435
diff changeset
  3203
    "find a subcollection from the end, starting at index. If found, return the index;
95d66fc71059 added #lastIndexOfSubCollection family of methods.
Claus Gittinger <cg@exept.de>
parents: 3435
diff changeset
  3204
     if not found, return the result of evaluating exceptionBlock.
95d66fc71059 added #lastIndexOfSubCollection family of methods.
Claus Gittinger <cg@exept.de>
parents: 3435
diff changeset
  3205
     This is a q&d hack - not very efficient"
95d66fc71059 added #lastIndexOfSubCollection family of methods.
Claus Gittinger <cg@exept.de>
parents: 3435
diff changeset
  3206
95d66fc71059 added #lastIndexOfSubCollection family of methods.
Claus Gittinger <cg@exept.de>
parents: 3435
diff changeset
  3207
    |same last 
95d66fc71059 added #lastIndexOfSubCollection family of methods.
Claus Gittinger <cg@exept.de>
parents: 3435
diff changeset
  3208
     mySize     "{Class: SmallInteger }"
95d66fc71059 added #lastIndexOfSubCollection family of methods.
Claus Gittinger <cg@exept.de>
parents: 3435
diff changeset
  3209
     checkIndex "{Class: SmallInteger }"
95d66fc71059 added #lastIndexOfSubCollection family of methods.
Claus Gittinger <cg@exept.de>
parents: 3435
diff changeset
  3210
     cmpIndex   "{Class: SmallInteger }"
95d66fc71059 added #lastIndexOfSubCollection family of methods.
Claus Gittinger <cg@exept.de>
parents: 3435
diff changeset
  3211
     sz         "{Class: SmallInteger }"|
95d66fc71059 added #lastIndexOfSubCollection family of methods.
Claus Gittinger <cg@exept.de>
parents: 3435
diff changeset
  3212
95d66fc71059 added #lastIndexOfSubCollection family of methods.
Claus Gittinger <cg@exept.de>
parents: 3435
diff changeset
  3213
    mySize := self size.
95d66fc71059 added #lastIndexOfSubCollection family of methods.
Claus Gittinger <cg@exept.de>
parents: 3435
diff changeset
  3214
    sz := aCollection size.
95d66fc71059 added #lastIndexOfSubCollection family of methods.
Claus Gittinger <cg@exept.de>
parents: 3435
diff changeset
  3215
    sz == 0 ifTrue:[^ exceptionBlock value].
95d66fc71059 added #lastIndexOfSubCollection family of methods.
Claus Gittinger <cg@exept.de>
parents: 3435
diff changeset
  3216
    last := aCollection at:sz.
95d66fc71059 added #lastIndexOfSubCollection family of methods.
Claus Gittinger <cg@exept.de>
parents: 3435
diff changeset
  3217
95d66fc71059 added #lastIndexOfSubCollection family of methods.
Claus Gittinger <cg@exept.de>
parents: 3435
diff changeset
  3218
    checkIndex := startIndex + sz.    
95d66fc71059 added #lastIndexOfSubCollection family of methods.
Claus Gittinger <cg@exept.de>
parents: 3435
diff changeset
  3219
    checkIndex >  mySize ifTrue:[
95d66fc71059 added #lastIndexOfSubCollection family of methods.
Claus Gittinger <cg@exept.de>
parents: 3435
diff changeset
  3220
        checkIndex := mySize + 1
95d66fc71059 added #lastIndexOfSubCollection family of methods.
Claus Gittinger <cg@exept.de>
parents: 3435
diff changeset
  3221
    ].
95d66fc71059 added #lastIndexOfSubCollection family of methods.
Claus Gittinger <cg@exept.de>
parents: 3435
diff changeset
  3222
    [true] whileTrue:[
95d66fc71059 added #lastIndexOfSubCollection family of methods.
Claus Gittinger <cg@exept.de>
parents: 3435
diff changeset
  3223
        checkIndex := self lastIndexOf:last startingAt:checkIndex-1.
95d66fc71059 added #lastIndexOfSubCollection family of methods.
Claus Gittinger <cg@exept.de>
parents: 3435
diff changeset
  3224
        checkIndex == 0 ifTrue:[^ exceptionBlock value].
95d66fc71059 added #lastIndexOfSubCollection family of methods.
Claus Gittinger <cg@exept.de>
parents: 3435
diff changeset
  3225
95d66fc71059 added #lastIndexOfSubCollection family of methods.
Claus Gittinger <cg@exept.de>
parents: 3435
diff changeset
  3226
        (checkIndex - sz + 1) < 1 ifTrue:[
95d66fc71059 added #lastIndexOfSubCollection family of methods.
Claus Gittinger <cg@exept.de>
parents: 3435
diff changeset
  3227
            ^ 0
95d66fc71059 added #lastIndexOfSubCollection family of methods.
Claus Gittinger <cg@exept.de>
parents: 3435
diff changeset
  3228
        ].
95d66fc71059 added #lastIndexOfSubCollection family of methods.
Claus Gittinger <cg@exept.de>
parents: 3435
diff changeset
  3229
        same := true.
95d66fc71059 added #lastIndexOfSubCollection family of methods.
Claus Gittinger <cg@exept.de>
parents: 3435
diff changeset
  3230
        cmpIndex := 1.
95d66fc71059 added #lastIndexOfSubCollection family of methods.
Claus Gittinger <cg@exept.de>
parents: 3435
diff changeset
  3231
        [same and:[cmpIndex <= sz]] whileTrue:[
95d66fc71059 added #lastIndexOfSubCollection family of methods.
Claus Gittinger <cg@exept.de>
parents: 3435
diff changeset
  3232
            (self at:checkIndex - sz + cmpIndex) = (aCollection at:cmpIndex) ifFalse:[
95d66fc71059 added #lastIndexOfSubCollection family of methods.
Claus Gittinger <cg@exept.de>
parents: 3435
diff changeset
  3233
                same := false
95d66fc71059 added #lastIndexOfSubCollection family of methods.
Claus Gittinger <cg@exept.de>
parents: 3435
diff changeset
  3234
            ] ifTrue:[
95d66fc71059 added #lastIndexOfSubCollection family of methods.
Claus Gittinger <cg@exept.de>
parents: 3435
diff changeset
  3235
                cmpIndex := cmpIndex + 1
95d66fc71059 added #lastIndexOfSubCollection family of methods.
Claus Gittinger <cg@exept.de>
parents: 3435
diff changeset
  3236
            ]
95d66fc71059 added #lastIndexOfSubCollection family of methods.
Claus Gittinger <cg@exept.de>
parents: 3435
diff changeset
  3237
        ].
95d66fc71059 added #lastIndexOfSubCollection family of methods.
Claus Gittinger <cg@exept.de>
parents: 3435
diff changeset
  3238
        same ifTrue:[^ checkIndex - sz + 1].
95d66fc71059 added #lastIndexOfSubCollection family of methods.
Claus Gittinger <cg@exept.de>
parents: 3435
diff changeset
  3239
    ]    
95d66fc71059 added #lastIndexOfSubCollection family of methods.
Claus Gittinger <cg@exept.de>
parents: 3435
diff changeset
  3240
95d66fc71059 added #lastIndexOfSubCollection family of methods.
Claus Gittinger <cg@exept.de>
parents: 3435
diff changeset
  3241
    "
95d66fc71059 added #lastIndexOfSubCollection family of methods.
Claus Gittinger <cg@exept.de>
parents: 3435
diff changeset
  3242
     #(1 2 3 4 5 6 7) lastIndexOfSubCollection:#()  startingAt:2  
95d66fc71059 added #lastIndexOfSubCollection family of methods.
Claus Gittinger <cg@exept.de>
parents: 3435
diff changeset
  3243
     #(1 2 3 4 5 6 7) lastIndexOfSubCollection:#(1)  
95d66fc71059 added #lastIndexOfSubCollection family of methods.
Claus Gittinger <cg@exept.de>
parents: 3435
diff changeset
  3244
     #(1 2 3 4 5 6 7) lastIndexOfSubCollection:#(1) startingAt:4     
95d66fc71059 added #lastIndexOfSubCollection family of methods.
Claus Gittinger <cg@exept.de>
parents: 3435
diff changeset
  3245
     #(1 3 1 2 1 3 3) lastIndexOfSubCollection:#(1 2 3)  
95d66fc71059 added #lastIndexOfSubCollection family of methods.
Claus Gittinger <cg@exept.de>
parents: 3435
diff changeset
  3246
     #(1 2 1 2 1 2 3) lastIndexOfSubCollection:#(1 2 3) startingAt:2 
95d66fc71059 added #lastIndexOfSubCollection family of methods.
Claus Gittinger <cg@exept.de>
parents: 3435
diff changeset
  3247
     #(1 2 1 2 1 2 3) lastIndexOfSubCollection:#(1 2 3) 
95d66fc71059 added #lastIndexOfSubCollection family of methods.
Claus Gittinger <cg@exept.de>
parents: 3435
diff changeset
  3248
     #(1 2 1 2 1 2 3) lastIndexOfSubCollection:#(1 2)  
95d66fc71059 added #lastIndexOfSubCollection family of methods.
Claus Gittinger <cg@exept.de>
parents: 3435
diff changeset
  3249
     #(1 2 1 2 1 2 3) lastIndexOfSubCollection:#(1 2)   startingAt:5 
95d66fc71059 added #lastIndexOfSubCollection family of methods.
Claus Gittinger <cg@exept.de>
parents: 3435
diff changeset
  3250
     #(1 2 1 2 1 2 3) lastIndexOfSubCollection:#(1 2)   startingAt:4 
95d66fc71059 added #lastIndexOfSubCollection family of methods.
Claus Gittinger <cg@exept.de>
parents: 3435
diff changeset
  3251
    "
95d66fc71059 added #lastIndexOfSubCollection family of methods.
Claus Gittinger <cg@exept.de>
parents: 3435
diff changeset
  3252
95d66fc71059 added #lastIndexOfSubCollection family of methods.
Claus Gittinger <cg@exept.de>
parents: 3435
diff changeset
  3253
    "Modified: / 16.5.1998 / 20:21:46 / cg"
3468
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  3254
! !
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  3255
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  3256
!SequenceableCollection methodsFor:'searching - equality'!
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  3257
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  3258
includes:anElement
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  3259
    "return true if the collection contains anElement; false otherwise.
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  3260
     Comparison is done using equality compare (i.e. =).
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  3261
     See #includesIdentical: if identity is asked for."
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  3262
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  3263
    ((self indexOf:anElement startingAt:1) == 0) ifTrue:[^ false].
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  3264
    ^ true
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  3265
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  3266
    "
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  3267
     args:    anElement : <object> 
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  3268
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  3269
     returns: true  - if found
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  3270
              false - if not found
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  3271
    "
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  3272
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  3273
    "
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  3274
     #(10 20 30 40 50 60 70) includes:99      
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  3275
     #(10 20 30 40 50 60 70) includes:40     
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  3276
     #(10 20 30 40 50 60 70) includes:40.0    
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  3277
    "
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  3278
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  3279
    "Modified: / 20.5.1998 / 15:00:23 / cg"
3452
95d66fc71059 added #lastIndexOfSubCollection family of methods.
Claus Gittinger <cg@exept.de>
parents: 3435
diff changeset
  3280
!
95d66fc71059 added #lastIndexOfSubCollection family of methods.
Claus Gittinger <cg@exept.de>
parents: 3435
diff changeset
  3281
3468
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  3282
indexOf:anElement
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  3283
    "search the collection for anElement;
602
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  3284
     if found, return the index otherwise return 0.
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  3285
     The comparison is done using = 
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  3286
     (i.e. equality test - not identity test)."
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  3287
3468
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  3288
    ^ self indexOf:anElement startingAt:1
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  3289
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  3290
    "
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  3291
     args:    anElement : <object>
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  3292
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  3293
     returns: elementIndex - if found
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  3294
              0            - if not found
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  3295
    "
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  3296
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  3297
    "
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  3298
     #(10 20 30 40 50 60 70) indexOf:40
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  3299
     #(10 20 30 40 50 60 70) indexOf:40.0
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  3300
    "
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  3301
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  3302
    "Modified: / 20.5.1998 / 14:59:55 / cg"
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  3303
!
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  3304
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  3305
indexOf:anElement ifAbsent:exceptionBlock
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  3306
    "search the collection for anElement;
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  3307
     if found, return the index otherwise return the value of the
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  3308
     exceptionBlock.
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  3309
     The comparison is done using = 
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  3310
     (i.e. equality test - not identity test)."
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  3311
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  3312
    |index|
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  3313
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  3314
    index := self indexOf:anElement startingAt:1.
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  3315
    (index == 0) ifTrue:[^ exceptionBlock value].
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  3316
    ^ index
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  3317
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  3318
    "
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  3319
     args:    anElement      : <object>
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  3320
              exceptionBlock : <valueImplementor>
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  3321
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  3322
     returns: elementIndex         - if found
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  3323
              exceptionBlock value - if not found
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  3324
    "
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  3325
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  3326
    "
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  3327
     #(10 20 30 40 10 20 30 40) indexOf:40   ifAbsent:['none'] 
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  3328
     #(10 20 30 40 10 20 30 40) indexOf:40.0 ifAbsent:['none'] 
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  3329
     #(10 20 30 40 10 20 30 40) indexOf:35   ifAbsent:['none'] 
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  3330
    "
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  3331
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  3332
    "Modified: / 20.5.1998 / 14:57:35 / cg"
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  3333
!
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  3334
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  3335
indexOf:elementToFind replaceWith:replacement startingAt:start stoppingAt:stop
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  3336
    "search for the first occurence of elementToFind starting at start,
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  3337
     stopping the search at stop. If found, replace the element by replacement
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  3338
     and return the index.
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  3339
     If not found, return 0."
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  3340
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  3341
    |idx|
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  3342
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  3343
    idx := self indexOf:elementToFind startingAt:start.
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  3344
    ((idx > 0) and:[idx <= stop]) ifTrue:[
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  3345
        self at:idx put:replacement.
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  3346
        ^ idx
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  3347
    ].
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  3348
    ^ 0
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  3349
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  3350
    "
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  3351
     args:    elementToFind : <object> 
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  3352
              replacement   : <integer>
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  3353
              start         : <integer>
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  3354
              stop          : <integer>
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  3355
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  3356
     returns: elementIndex - if found (and replaced)
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  3357
              0            - if not found
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  3358
    "
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  3359
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  3360
    "
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  3361
     |a|
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  3362
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  3363
     a := #(10 20 30 40 50 60 70).
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  3364
     (a indexOf:30 replaceWith:nil startingAt:1 stoppingAt:7) printNL.
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  3365
     a printNL.
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  3366
    "
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  3367
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  3368
    "Modified: / 20.5.1998 / 14:59:30 / cg"
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  3369
!
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  3370
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  3371
indexOf:anElement startingAt:start
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  3372
    "search the collection for anElement, starting the search at index start;
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  3373
     if found, return the index otherwise return 0.
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  3374
     The comparison is done using = 
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  3375
     (i.e. equality test - not identity test)."
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  3376
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  3377
    |startIndex "{ Class: SmallInteger }"
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  3378
     stop       "{ Class: SmallInteger }" |
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  3379
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  3380
    startIndex := start.
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  3381
    stop := self size.
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  3382
    startIndex to:stop do:[:index |
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  3383
        anElement = (self at:index) ifTrue:[^ index].
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  3384
    ].
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  3385
    ^ 0
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  3386
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  3387
    "
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  3388
     args:    anElement : <object> 
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  3389
              start     : <integer>
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  3390
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  3391
     returns: elementIndex - if found
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  3392
              0            - if not found
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  3393
    "
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  3394
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  3395
    "
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  3396
     #(10 20 30 40 10 20 30 40) indexOf:40   startingAt:5  
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  3397
     #(10 20 30 40 10 20 30 40) indexOf:40.0 startingAt:5  
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  3398
    "
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  3399
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  3400
    "Modified: / 20.5.1998 / 14:58:49 / cg"
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  3401
!
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  3402
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  3403
indexOf:anElement startingAt:start endingAt:stop
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  3404
    "search the collection for anElement, starting the search at index start;
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  3405
     ending at stop.
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  3406
     If found (within the range), return the index, otherwise return 0.
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  3407
     The comparison is done using = 
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  3408
     (i.e. equality test - not identity test)."
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  3409
602
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  3410
    |startIndex "{ Class: SmallInteger }"
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  3411
     stopIndex  "{ Class: SmallInteger }" |
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  3412
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  3413
    startIndex := start.
3468
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  3414
    stopIndex := self size min:stop.
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  3415
    startIndex to:stopIndex do:[:index |
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  3416
        anElement = (self at:index) ifTrue:[^ index].
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  3417
    ].
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  3418
    ^ 0
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  3419
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  3420
    "
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  3421
     args:    anElement      : <object> 
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  3422
              start          : <integer> 
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  3423
              stop           : <integer> 
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  3424
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  3425
     returns: elementIndex         - if found
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  3426
              exceptionBlock value - if not found
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  3427
    "
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  3428
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  3429
    "
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  3430
     #(10 20 30 40 10 20 30 40) indexOf:40   startingAt:3 endingAt:99  
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  3431
     #(10 20 30 40 10 20 30 40) indexOf:40   startingAt:3 endingAt:5  
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  3432
     #(10 20 30 40 10 20 30 40) indexOf:40   startingAt:1 endingAt:3   
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  3433
     #(10 20 30 40 10 20 30 40) indexOf:40.0 startingAt:5  
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  3434
    "
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  3435
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  3436
    "Created: / 12.4.1996 / 17:37:13 / cg"
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  3437
    "Modified: / 20.5.1998 / 14:58:28 / cg"
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  3438
!
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  3439
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  3440
indexOf:anElement startingAt:start ifAbsent:exceptionBlock
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  3441
    "search the collection for anElement starting the search at index start;
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  3442
     if found, return the index otherwise return the value of the
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  3443
     exceptionBlock.
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  3444
     The comparison is done using = 
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  3445
     (i.e. equality test - not identity test)."
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  3446
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  3447
    |index|
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  3448
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  3449
    index := self indexOf:anElement startingAt:start.
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  3450
    (index == 0) ifTrue:[^ exceptionBlock value].
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  3451
    ^ index
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  3452
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  3453
    "
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  3454
     args:    anElement      : <object> 
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  3455
              start          : <integer> 
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  3456
              exceptionBlock : <valueImplementor>
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  3457
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  3458
     returns: elementIndex         - if found
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  3459
              exceptionBlock value - if not found
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  3460
    "
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  3461
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  3462
    "
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  3463
     #(10 20 30 40 10 20 30 40) indexOf:40   startingAt:5 ifAbsent:['none'] 
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  3464
     #(10 20 30 40 10 20 30 40) indexOf:40.0 startingAt:5 ifAbsent:['none'] 
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  3465
     #(10 20 30 40 10 20 30 40) indexOf:35   startingAt:5 ifAbsent:['none'] 
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  3466
    "
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  3467
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  3468
    "Modified: / 20.5.1998 / 14:58:05 / cg"
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  3469
!
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  3470
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  3471
lastIndexOf:anElement
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  3472
    "search the collection backwards for anElement;
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  3473
     if found, return the index otherwise return 0.
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  3474
     The comparison is done using = 
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  3475
     (i.e. equality test - not identity test)."
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  3476
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  3477
    ^ self lastIndexOf:anElement startingAt:self size 
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  3478
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  3479
    "
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  3480
     args:    anElement      : <object>
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  3481
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  3482
     returns: elementIndex - if found
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  3483
              0            - if not found
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  3484
    "
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  3485
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  3486
    "
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  3487
     #(10 20 30 40 50 60 70) lastIndexOf:40    
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  3488
     #(10 20 30 40 50 60 70) lastIndexOf:40.0  
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  3489
     #(10 20 30 40 50 60 70) lastIndexOf:35    
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  3490
     #(10 20 30 40 50 60 70) lastIndexOf:10    
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  3491
    "
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  3492
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  3493
    "Modified: / 20.5.1998 / 15:02:10 / cg"
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  3494
!
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  3495
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  3496
lastIndexOf:anElement ifAbsent:exceptionBlock
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  3497
    "search the collection backwards for anElement;
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  3498
     if found, return the index otherwise return the value of the
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  3499
     exceptionBlock.
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  3500
     The comparison is done using = 
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  3501
     (i.e. equality test - not identity test)."
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  3502
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  3503
    |index|
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  3504
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  3505
    index := self lastIndexOf:anElement startingAt:self size.
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  3506
    (index == 0) ifTrue:[^ exceptionBlock value].
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  3507
    ^ index
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  3508
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  3509
    "
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  3510
     #(10 20 30 40 10 20 30 40) lastIndexOf:40   ifAbsent:['none'] 
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  3511
     #(10 20 30 40 10 20 30 40) lastIndexOf:40.0 ifAbsent:['none'] 
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  3512
     #(10 20 30 40 10 20 30 40) lastIndexOf:35   ifAbsent:['none'] 
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  3513
     #(10 20 30 40 10 20 30 40) lastIndexOf:10   ifAbsent:['none'] 
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  3514
    "
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  3515
!
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  3516
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  3517
lastIndexOf:anElement startingAt:start
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  3518
    "search the collection backwards for anElement, starting the search at index start;
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  3519
     if found, return the index otherwise return 0.
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  3520
     The comparison is done using = 
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  3521
     (i.e. equality test - not identity test)."
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  3522
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  3523
    |startIndex "{ Class: SmallInteger }"|
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  3524
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  3525
    startIndex := start.
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  3526
    startIndex to:1 by:-1 do:[:index |
602
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  3527
	anElement = (self at:index) ifTrue:[^ index].
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  3528
    ].
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  3529
    ^ 0
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  3530
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  3531
    "
3468
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  3532
     #(10 20 30 40 10 20 30 40) lastIndexOf:40   startingAt:8  
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  3533
     #(10 20 30 40 10 20 30 40) lastIndexOf:40.0 startingAt:8  
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  3534
     #(10 20 30 40 10 20 30 40) lastIndexOf:35   startingAt:8  
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  3535
     #(10 20 30 40 10 20 30 40) lastIndexOf:10   startingAt:8  
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  3536
     #(10 20 30 40 10 20 30 40) lastIndexOf:10   startingAt:4  
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  3537
    "
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  3538
!
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  3539
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  3540
lastIndexOf:anElement startingAt:start ifAbsent:exceptionBlock
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  3541
    "search the collection backwards for anElement starting the search at 
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  3542
     index start; if found, return the index 
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  3543
     otherwise return the value of the exceptionBlock.
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  3544
     The comparison is done using = 
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  3545
     (i.e. equality test - not identity test)."
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  3546
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  3547
    |index|
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  3548
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  3549
    index := self lastIndexOf:anElement startingAt:start.
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  3550
    (index == 0) ifTrue:[^ exceptionBlock value].
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  3551
    ^ index
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  3552
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  3553
    "
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  3554
     #(10 20 30 40 10 20 30 40) lastIndexOf:40   startingAt:8 ifAbsent:['none'] 
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  3555
     #(10 20 30 40 10 20 30 40) lastIndexOf:40.0 startingAt:8 ifAbsent:['none'] 
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  3556
     #(10 20 30 40 10 20 30 40) lastIndexOf:35   startingAt:8 ifAbsent:['none'] 
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  3557
     #(10 20 30 40 10 20 30 40) lastIndexOf:10   startingAt:8 ifAbsent:['none'] 
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  3558
    "
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  3559
!
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  3560
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  3561
nextIndexOf:anElement from:start to:stop
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  3562
    "search the collection for anElement, starting the search at index start,
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  3563
     stopping at:stop;
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  3564
     if found, return the index otherwise return nil.
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  3565
     The comparison is done using = 
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  3566
     (i.e. equality test - not identity test).
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  3567
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  3568
     NOTICE: nil is returned here if the element is not found,
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  3569
             although this is somewhat strange (the indexOf-search
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  3570
             methods return 0), this is done for VW compatibility."
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  3571
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  3572
    |startIndex "{ Class: SmallInteger }"
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  3573
     stopIndex  "{ Class: SmallInteger }" |
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  3574
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  3575
    startIndex := start.
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  3576
    stopIndex :=  stop.
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  3577
    startIndex to:stop do:[:index |
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  3578
        anElement = (self at:index) ifTrue:[^ index].
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  3579
    ].
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  3580
    ^ nil
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  3581
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  3582
    "
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  3583
     args:    anElement : <object>
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  3584
              start     : <integer>
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  3585
              stop      : <integer>
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  3586
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  3587
     returns: elementIndex - if found
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  3588
              nil          - if not found
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  3589
    "
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  3590
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  3591
    "
602
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  3592
     #(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
  3593
     #(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
  3594
     #(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
  3595
    "
3468
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  3596
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  3597
    "Modified: / 20.5.1998 / 15:11:32 / cg"
602
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  3598
!
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  3599
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  3600
nextIndexOf:anElement from:start to:stop ifAbsent:exceptionBlock
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  3601
    "search the collection for anElement, starting the search at index start
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  3602
     and stopping at stop;
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  3603
     if found, return the index otherwise return the value of the
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  3604
     exceptionBlock.
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  3605
     The comparison is done using = 
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  3606
     (i.e. equality test - not identity test)."
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  3607
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  3608
    |index|
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  3609
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  3610
    index := self nextIndexOf:anElement from:start to:stop.
3468
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  3611
    index isNil ifTrue:[^ exceptionBlock value].
602
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  3612
    ^ index
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  3613
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  3614
    "
3468
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  3615
     args:    anElement      : <object>
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  3616
              start          : <integer>
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  3617
              stop           : <integer>
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  3618
              exceptionBlock : <valueImplementor>
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  3619
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  3620
     returns: elementIndex           - if found
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  3621
              valueImplementor value - if not found
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  3622
    "
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  3623
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  3624
    "
602
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  3625
     #(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
  3626
     #(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
  3627
     #(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
  3628
    "
3468
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  3629
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  3630
    "Modified: / 20.5.1998 / 15:12:36 / cg"
2275
882e11d07295 added prevIndexOf:from:to:
Claus Gittinger <cg@exept.de>
parents: 2165
diff changeset
  3631
!
882e11d07295 added prevIndexOf:from:to:
Claus Gittinger <cg@exept.de>
parents: 2165
diff changeset
  3632
882e11d07295 added prevIndexOf:from:to:
Claus Gittinger <cg@exept.de>
parents: 2165
diff changeset
  3633
prevIndexOf:anElement from:startSearchIndex to:endSearchIndex
882e11d07295 added prevIndexOf:from:to:
Claus Gittinger <cg@exept.de>
parents: 2165
diff changeset
  3634
    "search the collection for anElement, starting the search at index start;
882e11d07295 added prevIndexOf:from:to:
Claus Gittinger <cg@exept.de>
parents: 2165
diff changeset
  3635
     ending at stop, going in reverse direction.
3468
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  3636
     If found (within the range), return the index, otherwise return nil.
2275
882e11d07295 added prevIndexOf:from:to:
Claus Gittinger <cg@exept.de>
parents: 2165
diff changeset
  3637
     The comparison is done using = 
3468
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  3638
     (i.e. equality test - not identity test).
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  3639
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  3640
     NOTICE: nil is returned here if the element is not found,
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  3641
             although this is somewhat strange (the indexOf-search
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  3642
             methods return 0), this is done for VW compatibility."
2275
882e11d07295 added prevIndexOf:from:to:
Claus Gittinger <cg@exept.de>
parents: 2165
diff changeset
  3643
882e11d07295 added prevIndexOf:from:to:
Claus Gittinger <cg@exept.de>
parents: 2165
diff changeset
  3644
    |startIndex "{ Class: SmallInteger }"
882e11d07295 added prevIndexOf:from:to:
Claus Gittinger <cg@exept.de>
parents: 2165
diff changeset
  3645
     stopIndex  "{ Class: SmallInteger }" |
882e11d07295 added prevIndexOf:from:to:
Claus Gittinger <cg@exept.de>
parents: 2165
diff changeset
  3646
882e11d07295 added prevIndexOf:from:to:
Claus Gittinger <cg@exept.de>
parents: 2165
diff changeset
  3647
    startIndex := startSearchIndex.
882e11d07295 added prevIndexOf:from:to:
Claus Gittinger <cg@exept.de>
parents: 2165
diff changeset
  3648
    stopIndex := endSearchIndex max:1.
882e11d07295 added prevIndexOf:from:to:
Claus Gittinger <cg@exept.de>
parents: 2165
diff changeset
  3649
    startIndex to:stopIndex by:-1 do:[:index |
882e11d07295 added prevIndexOf:from:to:
Claus Gittinger <cg@exept.de>
parents: 2165
diff changeset
  3650
        anElement = (self at:index) ifTrue:[^ index].
882e11d07295 added prevIndexOf:from:to:
Claus Gittinger <cg@exept.de>
parents: 2165
diff changeset
  3651
    ].
3468
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  3652
    ^ nil
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  3653
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  3654
    "
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  3655
     args:    anElement : <object>
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  3656
              start     : <integer>
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  3657
              stop      : <integer>
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  3658
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  3659
     returns: elementIndex - if found
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  3660
              nil          - if not found
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  3661
    "
2275
882e11d07295 added prevIndexOf:from:to:
Claus Gittinger <cg@exept.de>
parents: 2165
diff changeset
  3662
882e11d07295 added prevIndexOf:from:to:
Claus Gittinger <cg@exept.de>
parents: 2165
diff changeset
  3663
    "
882e11d07295 added prevIndexOf:from:to:
Claus Gittinger <cg@exept.de>
parents: 2165
diff changeset
  3664
     #(10 20 30 40 10 20 30 40) prevIndexOf:40   from:7 to:2  
882e11d07295 added prevIndexOf:from:to:
Claus Gittinger <cg@exept.de>
parents: 2165
diff changeset
  3665
     #(10 20 30 40 10 20 30 40) prevIndexOf:40.0 from:7 to:2  
882e11d07295 added prevIndexOf:from:to:
Claus Gittinger <cg@exept.de>
parents: 2165
diff changeset
  3666
     #(10 20 30 40 10 20 30 40) prevIndexOf:35   from:7 to:5  
882e11d07295 added prevIndexOf:from:to:
Claus Gittinger <cg@exept.de>
parents: 2165
diff changeset
  3667
    "
882e11d07295 added prevIndexOf:from:to:
Claus Gittinger <cg@exept.de>
parents: 2165
diff changeset
  3668
3468
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  3669
    "Modified: / 20.5.1998 / 15:13:27 / cg"
2275
882e11d07295 added prevIndexOf:from:to:
Claus Gittinger <cg@exept.de>
parents: 2165
diff changeset
  3670
!
882e11d07295 added prevIndexOf:from:to:
Claus Gittinger <cg@exept.de>
parents: 2165
diff changeset
  3671
882e11d07295 added prevIndexOf:from:to:
Claus Gittinger <cg@exept.de>
parents: 2165
diff changeset
  3672
prevIndexOf:anElement from:start to:stop ifAbsent:exceptionBlock
882e11d07295 added prevIndexOf:from:to:
Claus Gittinger <cg@exept.de>
parents: 2165
diff changeset
  3673
    "search the collection for anElement, starting the search at index start
882e11d07295 added prevIndexOf:from:to:
Claus Gittinger <cg@exept.de>
parents: 2165
diff changeset
  3674
     and stopping at stop, doing a reverse search;
882e11d07295 added prevIndexOf:from:to:
Claus Gittinger <cg@exept.de>
parents: 2165
diff changeset
  3675
     if found, return the index otherwise return the value of the
882e11d07295 added prevIndexOf:from:to:
Claus Gittinger <cg@exept.de>
parents: 2165
diff changeset
  3676
     exceptionBlock.
882e11d07295 added prevIndexOf:from:to:
Claus Gittinger <cg@exept.de>
parents: 2165
diff changeset
  3677
     The comparison is done using = 
882e11d07295 added prevIndexOf:from:to:
Claus Gittinger <cg@exept.de>
parents: 2165
diff changeset
  3678
     (i.e. equality test - not identity test)."
882e11d07295 added prevIndexOf:from:to:
Claus Gittinger <cg@exept.de>
parents: 2165
diff changeset
  3679
882e11d07295 added prevIndexOf:from:to:
Claus Gittinger <cg@exept.de>
parents: 2165
diff changeset
  3680
    |index|
882e11d07295 added prevIndexOf:from:to:
Claus Gittinger <cg@exept.de>
parents: 2165
diff changeset
  3681
882e11d07295 added prevIndexOf:from:to:
Claus Gittinger <cg@exept.de>
parents: 2165
diff changeset
  3682
    index := self prevIndexOf:anElement from:start to:stop.
882e11d07295 added prevIndexOf:from:to:
Claus Gittinger <cg@exept.de>
parents: 2165
diff changeset
  3683
    (index == 0) ifTrue:[^ exceptionBlock value].
882e11d07295 added prevIndexOf:from:to:
Claus Gittinger <cg@exept.de>
parents: 2165
diff changeset
  3684
    ^ index
882e11d07295 added prevIndexOf:from:to:
Claus Gittinger <cg@exept.de>
parents: 2165
diff changeset
  3685
882e11d07295 added prevIndexOf:from:to:
Claus Gittinger <cg@exept.de>
parents: 2165
diff changeset
  3686
    "
3468
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  3687
     args:    anElement      : <object>
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  3688
              start          : <integer>
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  3689
              stop           : <integer>
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  3690
              exceptionBlock : <valueImplementor>
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  3691
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  3692
     returns: elementIndex           - if found
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  3693
              valueImplementor value - if not found
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  3694
    "
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  3695
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  3696
    "
2275
882e11d07295 added prevIndexOf:from:to:
Claus Gittinger <cg@exept.de>
parents: 2165
diff changeset
  3697
     #(10 20 30 40 10 20 30 40) prevIndexOf:40   from:7 to:2 ifAbsent:['none'] 
882e11d07295 added prevIndexOf:from:to:
Claus Gittinger <cg@exept.de>
parents: 2165
diff changeset
  3698
     #(10 20 30 40 10 20 30 40) prevIndexOf:40.0 from:7 to:2 ifAbsent:['none'] 
882e11d07295 added prevIndexOf:from:to:
Claus Gittinger <cg@exept.de>
parents: 2165
diff changeset
  3699
     #(10 20 30 40 10 20 30 40) prevIndexOf:35   from:7 to:5 ifAbsent:['none'] 
882e11d07295 added prevIndexOf:from:to:
Claus Gittinger <cg@exept.de>
parents: 2165
diff changeset
  3700
    "
882e11d07295 added prevIndexOf:from:to:
Claus Gittinger <cg@exept.de>
parents: 2165
diff changeset
  3701
3468
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  3702
    "Modified: / 20.5.1998 / 15:13:05 / cg"
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  3703
! !
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  3704
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  3705
!SequenceableCollection methodsFor:'searching - identity'!
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  3706
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  3707
identityIndexOf:anElement
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  3708
    "search the collection for anElement using identity compare (i.e. ==);
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  3709
     if found, return the index otherwise return 0."
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  3710
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  3711
    ^ self identityIndexOf:anElement startingAt:1
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  3712
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  3713
    "
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  3714
     args:    anElement : <object>
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  3715
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  3716
     returns: elementIndex - if found
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  3717
              0            - if not found
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  3718
    "
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  3719
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  3720
    "
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  3721
     #(10 20 30 40 50 60 70) identityIndexOf:40
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  3722
     #(10 20 30 40 50 60 70) identityIndexOf:40.0
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  3723
     #(10 20 30 40 50 60 70) indexOf:40.0
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  3724
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  3725
    be careful:
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  3726
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  3727
     #(10 20 30 40.0 50 60 70) indexOf:40.0
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  3728
     #(10 20 30 40.0 50 60 70) identityIndexOf:40.0
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  3729
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  3730
    "
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  3731
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  3732
    "Modified: / 20.5.1998 / 14:57:14 / cg"
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  3733
!
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  3734
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  3735
identityIndexOf:anElement ifAbsent:exceptionBlock
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  3736
    "search the collection for anElement using identity compare (i.e. ==);
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  3737
     if found, return the index otherwise return the value of the
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  3738
     exceptionBlock."
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  3739
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  3740
    |index|
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  3741
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  3742
    index := self identityIndexOf:anElement startingAt:1.
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  3743
    (index == 0) ifTrue:[^ exceptionBlock value].
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  3744
    ^ index
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  3745
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  3746
    "
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  3747
     args:    anElement      : <object>
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  3748
              exceptionBlock : <valueImplementor>
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  3749
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  3750
     returns: elementIndex         - if found
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  3751
              exceptionBlock value - if not found
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  3752
    "
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  3753
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  3754
    "
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  3755
     #(10 20 30 40 50 60 70) identityIndexOf:40  ifAbsent:['none']  
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  3756
     #(10 20 30 40 50 60 70) identityIndexOf:35  ifAbsent:['none']  
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  3757
     #(10 20 30 40 50 60 70) identityIndexOf:40.0 ifAbsent:['none'] 
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  3758
     #(10 20 30 40 50 60 70) indexOf:40.0         ifAbsent:['none'] 
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  3759
    "
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  3760
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  3761
    "Modified: / 20.5.1998 / 14:57:31 / cg"
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  3762
!
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  3763
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  3764
identityIndexOf:anElement startingAt:start
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  3765
    "search the collection for anElement, starting search at index start
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  3766
     using identity compare  (i.e. ==);
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  3767
     if found, return the index otherwise return 0."
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  3768
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  3769
    |startIndex "{ Class: SmallInteger }"
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  3770
     stop       "{ Class: SmallInteger }" |
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  3771
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  3772
    startIndex := start.
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  3773
    stop := self size.
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  3774
    startIndex to:stop do:[:index |
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  3775
        anElement == (self at:index) ifTrue:[^ index].
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  3776
    ].
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  3777
    ^ 0
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  3778
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  3779
    "
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  3780
     args:    anElement : <object>
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  3781
              start     : <integer>
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  3782
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  3783
     returns: elementIndex - if found
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  3784
              0            - if not found
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  3785
    "
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  3786
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  3787
    "
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  3788
     #(10 20 30 40 10 20 30 40) identityIndexOf:40   startingAt:5
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  3789
     #(10 20 30 40 10 20 30 40) identityIndexOf:40.0 startingAt:5
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  3790
     #(10 20 30 40 10 20 30 40) indexOf:40.0         startingAt:5 
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  3791
    "
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  3792
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  3793
    "Modified: / 20.5.1998 / 14:57:09 / cg"
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  3794
!
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  3795
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  3796
identityIndexOf:anElement startingAt:start endingAt:stop
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  3797
    "search the collection for anElement, starting the search at index start;
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  3798
     ending at stop.
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  3799
     If found (within the range), return the index, otherwise return 0.
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  3800
     The comparison is done using = 
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  3801
     (i.e. equality test - not identity test)."
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  3802
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  3803
    |startIndex "{ Class: SmallInteger }"
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  3804
     stopIndex  "{ Class: SmallInteger }" |
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  3805
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  3806
    startIndex := start.
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  3807
    stopIndex := self size min:stop.
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  3808
    startIndex to:stopIndex do:[:index |
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  3809
        anElement == (self at:index) ifTrue:[^ index].
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  3810
    ].
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  3811
    ^ 0
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  3812
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  3813
    "
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  3814
     args:    anElement : <object>
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  3815
              start     : <integer>
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  3816
              stop      : <integer>
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  3817
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  3818
     returns: elementIndex - if found
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  3819
              0            - if not found
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  3820
    "
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  3821
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  3822
    "Created: / 12.4.1996 / 18:23:07 / cg"
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  3823
    "Modified: / 20.5.1998 / 15:00:50 / cg"
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  3824
!
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  3825
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  3826
identityIndexOf:anElement startingAt:start ifAbsent:exceptionBlock
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  3827
    "search the collection for anElement, starting search at index start;
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  3828
     if found, return the index otherwise return the value of the
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  3829
     exceptionBlock.
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  3830
     This one searches for identical objects (i.e. ==)."
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  3831
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  3832
    |index|
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  3833
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  3834
    index := self identityIndexOf:anElement startingAt:start.
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  3835
    (index == 0) ifTrue:[^ exceptionBlock value].
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  3836
    ^ index
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  3837
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  3838
    "
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  3839
     args:    anElement      : <object>
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  3840
              start          : <integer>
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  3841
              exceptionBlock : <valueImplementor>
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  3842
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  3843
     returns: elementIndex         - if found
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  3844
              exceptionBlock value - if not found
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  3845
    "
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  3846
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  3847
    "
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  3848
     #(10 20 30 40 10) identityIndexOf:10 startingAt:3 ifAbsent:['none'] 
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  3849
     #(10 20 30 40 10) identityIndexOf:35 startingAt:3 ifAbsent:['none'] 
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  3850
    "
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  3851
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  3852
    "Modified: / 20.5.1998 / 15:01:23 / cg"
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  3853
!
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  3854
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  3855
includesIdentical:anElement
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  3856
    "return true if the collection contains anElement; false otherwise.
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  3857
     Comparison is done using identity compare (i.e. ==).
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  3858
     See #includes: if equality is asked for."
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  3859
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  3860
    ((self identityIndexOf:anElement startingAt:1) == 0) ifTrue:[^ false].
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  3861
    ^ true
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  3862
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  3863
    "
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  3864
     args:    anElement : <object> 
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  3865
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  3866
     returns: true  - if found
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  3867
              false - if not found
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  3868
    "
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  3869
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  3870
    "
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  3871
     #(10 20 30 40 50 60 70) includesIdentical:40     
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  3872
     #(10 20 30 40 50 60 70) includesIdentical:40.0    
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  3873
     #(10 20 30 40 50 60 70) includes:40     
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  3874
     #(10 20 30 40 50 60 70) includes:40.0    
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  3875
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  3876
     be careful:
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  3877
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  3878
     #(10 20 30 40.0 50 60 70) includes:40.0    
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  3879
     #(10 20 30 40.0 50 60 70) includesIdentical:40.0    
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  3880
    "
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  3881
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  3882
    "Modified: / 20.5.1998 / 15:00:16 / cg"
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  3883
!
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  3884
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  3885
lastIdentityIndexOf:anElement
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  3886
    "search the collection backwards for anElement;
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  3887
     if found, return the index otherwise return 0.
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  3888
     The comparison is done using == 
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  3889
     (i.e. identity test - not equality test)."
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  3890
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  3891
    ^ self lastIdentityIndexOf:anElement startingAt:self size 
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  3892
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  3893
    "
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  3894
     args:    anElement      : <object>
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  3895
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  3896
     returns: elementIndex - if found
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  3897
              0            - if not found
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  3898
    "
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  3899
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  3900
    "
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  3901
     #(10 20 30 40 50 60 70) lastIdentityIndexOf:40    
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  3902
     #(10 20 30 40 50 60 70) lastIdentityIndexOf:40.0  
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  3903
     #(10 20 30 40 50 60 70) lastIdentityIndexOf:35    
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  3904
     #(10 20 30 40 50 60 70) lastIdentityIndexOf:10    
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  3905
    "
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  3906
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  3907
    "Created: / 20.5.1998 / 15:03:06 / cg"
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  3908
!
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  3909
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  3910
lastIdentityIndexOf:anElement ifAbsent:exceptionBlock
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  3911
    "search the collection backwards for anElement;
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  3912
     if found, return the index otherwise return the value of the
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  3913
     exceptionBlock.
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  3914
     The comparison is done using == 
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  3915
     (i.e. identity test - not equality test)."
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  3916
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  3917
    |index|
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  3918
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  3919
    index := self lastIdentityIndexOf:anElement startingAt:self size.
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  3920
    (index == 0) ifTrue:[^ exceptionBlock value].
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  3921
    ^ index
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  3922
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  3923
    "
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  3924
     args:    anElement      : <object>
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  3925
              exceptionBlock : <valueImplementor>
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  3926
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  3927
     returns: elementIndex         - if found
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  3928
              exceptionBlock value - if not found
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  3929
    "
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  3930
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  3931
    "
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  3932
     #(10 20 30 40 10 20 30 40) lastIdentityIndexOf:40   ifAbsent:['none'] 
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  3933
     #(10 20 30 40 10 20 30 40) lastIdentityIndexOf:40.0 ifAbsent:['none'] 
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  3934
     #(10 20 30 40 10 20 30 40) lastIdentityIndexOf:35   ifAbsent:['none'] 
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  3935
     #(10 20 30 40 10 20 30 40) lastIdentityIndexOf:10   ifAbsent:['none'] 
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  3936
    "
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  3937
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  3938
    "Created: / 20.5.1998 / 15:04:46 / cg"
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  3939
    "Modified: / 20.5.1998 / 15:05:53 / cg"
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  3940
!
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  3941
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  3942
lastIdentityIndexOf:anElement startingAt:start
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  3943
    "search the collection backwards for anElement, starting the search at index start;
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  3944
     if found, return the index otherwise return 0.
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  3945
     The comparison is done using == 
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  3946
     (i.e. identity test - not equality test)."
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  3947
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  3948
    |startIndex "{ Class: SmallInteger }"|
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  3949
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  3950
    startIndex := start.
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  3951
    startIndex to:1 by:-1 do:[:index |
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  3952
        anElement == (self at:index) ifTrue:[^ index].
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  3953
    ].
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  3954
    ^ 0
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  3955
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  3956
    "
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  3957
     args:    anElement      : <object>
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  3958
              start          : <integer>
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  3959
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  3960
     returns: elementIndex - if found
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  3961
              0            - if not found
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  3962
    "
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  3963
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  3964
    "
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  3965
     #(10 20 30 40 10 20 30 40) lastIdentityIndexOf:40   startingAt:8  
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  3966
     #(10 20 30 40 10 20 30 40) lastIdentityIndexOf:40.0 startingAt:8  
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  3967
     #(10 20 30 40 10 20 30 40) lastIdentityIndexOf:35   startingAt:8  
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  3968
     #(10 20 30 40 10 20 30 40) lastIdentityIndexOf:10   startingAt:8  
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  3969
     #(10 20 30 40 10 20 30 40) lastIdentityIndexOf:10   startingAt:4  
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  3970
    "
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  3971
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  3972
    "Modified: / 20.5.1998 / 15:06:04 / cg"
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  3973
!
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  3974
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  3975
lastIdentityIndexOf:anElement startingAt:start ifAbsent:exceptionBlock
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  3976
    "search the collection backwards for anElement starting the search at 
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  3977
     index start; if found, return the index 
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  3978
     otherwise return the value of the exceptionBlock.
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  3979
     The comparison is done using == 
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  3980
     (i.e. identity test - not equality test)."
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  3981
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  3982
    |index|
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  3983
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  3984
    index := self lastIdentityIndexOf:anElement startingAt:start.
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  3985
    (index == 0) ifTrue:[^ exceptionBlock value].
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  3986
    ^ index
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  3987
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  3988
    "
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  3989
     args:    anElement      : <object>
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  3990
              start          : <integer>
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  3991
              exceptionBlock : <valueImplementor>
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  3992
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  3993
     returns: elementIndex         - if found
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  3994
              exceptionBlock value - if not found
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  3995
    "
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  3996
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  3997
    "
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  3998
     #(10 20 30 40 10 20 30 40) lastIdentityIndexOf:40   startingAt:8 ifAbsent:['none'] 
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  3999
     #(10 20 30 40 10 20 30 40) lastIdentityIndexOf:40.0 startingAt:8 ifAbsent:['none'] 
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  4000
     #(10 20 30 40 10 20 30 40) lastIdentityIndexOf:35   startingAt:8 ifAbsent:['none'] 
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  4001
     #(10 20 30 40 10 20 30 40) lastIdentityIndexOf:10   startingAt:8 ifAbsent:['none'] 
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  4002
    "
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  4003
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  4004
    "Modified: / 20.5.1998 / 15:06:21 / cg"
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  4005
    "Created: / 20.5.1998 / 15:07:42 / cg"
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  4006
! !
a27a279701f8 Initial revision
claus
parents:
diff changeset
  4007
a27a279701f8 Initial revision
claus
parents:
diff changeset
  4008
!SequenceableCollection methodsFor:'sorting & reordering'!
a27a279701f8 Initial revision
claus
parents:
diff changeset
  4009
2881
452f9154d0dc comments; added #randomizedQuickSort.
Claus Gittinger <cg@exept.de>
parents: 2860
diff changeset
  4010
randomizedSort
452f9154d0dc comments; added #randomizedQuickSort.
Claus Gittinger <cg@exept.de>
parents: 2860
diff changeset
  4011
    "sort the collection inplace. The elements are compared using
452f9154d0dc comments; added #randomizedQuickSort.
Claus Gittinger <cg@exept.de>
parents: 2860
diff changeset
  4012
     '<' i.e. they should offer a magnitude-like protocol.
452f9154d0dc comments; added #randomizedQuickSort.
Claus Gittinger <cg@exept.de>
parents: 2860
diff changeset
  4013
452f9154d0dc comments; added #randomizedQuickSort.
Claus Gittinger <cg@exept.de>
parents: 2860
diff changeset
  4014
     This uses the randomized quicksort algorithm, 
452f9154d0dc comments; added #randomizedQuickSort.
Claus Gittinger <cg@exept.de>
parents: 2860
diff changeset
  4015
     which has a better worstCase behavior than quickSort
452f9154d0dc comments; added #randomizedQuickSort.
Claus Gittinger <cg@exept.de>
parents: 2860
diff changeset
  4016
     (bit worse bestCase & averageCase behavior).
452f9154d0dc comments; added #randomizedQuickSort.
Claus Gittinger <cg@exept.de>
parents: 2860
diff changeset
  4017
     See: Knuth or Cormen,Leiserson,Rivest pg. 163"
452f9154d0dc comments; added #randomizedQuickSort.
Claus Gittinger <cg@exept.de>
parents: 2860
diff changeset
  4018
452f9154d0dc comments; added #randomizedQuickSort.
Claus Gittinger <cg@exept.de>
parents: 2860
diff changeset
  4019
    |stop|
452f9154d0dc comments; added #randomizedQuickSort.
Claus Gittinger <cg@exept.de>
parents: 2860
diff changeset
  4020
452f9154d0dc comments; added #randomizedQuickSort.
Claus Gittinger <cg@exept.de>
parents: 2860
diff changeset
  4021
    stop := self size.
452f9154d0dc comments; added #randomizedQuickSort.
Claus Gittinger <cg@exept.de>
parents: 2860
diff changeset
  4022
    (stop > 1) ifTrue:[
452f9154d0dc comments; added #randomizedQuickSort.
Claus Gittinger <cg@exept.de>
parents: 2860
diff changeset
  4023
        self randomizedQuickSortFrom:1 to:stop sortBlock:[:a :b | a < b] with:nil
452f9154d0dc comments; added #randomizedQuickSort.
Claus Gittinger <cg@exept.de>
parents: 2860
diff changeset
  4024
    ]
452f9154d0dc comments; added #randomizedQuickSort.
Claus Gittinger <cg@exept.de>
parents: 2860
diff changeset
  4025
452f9154d0dc comments; added #randomizedQuickSort.
Claus Gittinger <cg@exept.de>
parents: 2860
diff changeset
  4026
    "Modified: 21.8.1997 / 18:31:21 / cg"
452f9154d0dc comments; added #randomizedQuickSort.
Claus Gittinger <cg@exept.de>
parents: 2860
diff changeset
  4027
!
452f9154d0dc comments; added #randomizedQuickSort.
Claus Gittinger <cg@exept.de>
parents: 2860
diff changeset
  4028
452f9154d0dc comments; added #randomizedQuickSort.
Claus Gittinger <cg@exept.de>
parents: 2860
diff changeset
  4029
randomizedSort:sortBlock
452f9154d0dc comments; added #randomizedQuickSort.
Claus Gittinger <cg@exept.de>
parents: 2860
diff changeset
  4030
    "sort the collection inplace using the 2-arg block sortBlock
452f9154d0dc comments; added #randomizedQuickSort.
Claus Gittinger <cg@exept.de>
parents: 2860
diff changeset
  4031
     for comparison. This allows any sort criteria to be implemented.
452f9154d0dc comments; added #randomizedQuickSort.
Claus Gittinger <cg@exept.de>
parents: 2860
diff changeset
  4032
452f9154d0dc comments; added #randomizedQuickSort.
Claus Gittinger <cg@exept.de>
parents: 2860
diff changeset
  4033
     This uses the randomized quicksort algorithm, 
452f9154d0dc comments; added #randomizedQuickSort.
Claus Gittinger <cg@exept.de>
parents: 2860
diff changeset
  4034
     which has a better worstCase behavior than quickSort
452f9154d0dc comments; added #randomizedQuickSort.
Claus Gittinger <cg@exept.de>
parents: 2860
diff changeset
  4035
     (bit worse bestCase & averageCase behavior).
452f9154d0dc comments; added #randomizedQuickSort.
Claus Gittinger <cg@exept.de>
parents: 2860
diff changeset
  4036
     See: Knuth or Cormen,Leiserson,Rivest pg. 163"
452f9154d0dc comments; added #randomizedQuickSort.
Claus Gittinger <cg@exept.de>
parents: 2860
diff changeset
  4037
452f9154d0dc comments; added #randomizedQuickSort.
Claus Gittinger <cg@exept.de>
parents: 2860
diff changeset
  4038
    |stop|
452f9154d0dc comments; added #randomizedQuickSort.
Claus Gittinger <cg@exept.de>
parents: 2860
diff changeset
  4039
452f9154d0dc comments; added #randomizedQuickSort.
Claus Gittinger <cg@exept.de>
parents: 2860
diff changeset
  4040
    stop := self size.
452f9154d0dc comments; added #randomizedQuickSort.
Claus Gittinger <cg@exept.de>
parents: 2860
diff changeset
  4041
    (stop > 1) ifTrue:[
452f9154d0dc comments; added #randomizedQuickSort.
Claus Gittinger <cg@exept.de>
parents: 2860
diff changeset
  4042
        self randomizedQuickSortFrom:1 to:stop sortBlock:sortBlock with:nil
452f9154d0dc comments; added #randomizedQuickSort.
Claus Gittinger <cg@exept.de>
parents: 2860
diff changeset
  4043
    ]
452f9154d0dc comments; added #randomizedQuickSort.
Claus Gittinger <cg@exept.de>
parents: 2860
diff changeset
  4044
452f9154d0dc comments; added #randomizedQuickSort.
Claus Gittinger <cg@exept.de>
parents: 2860
diff changeset
  4045
    "Created: 21.8.1997 / 18:16:50 / cg"
452f9154d0dc comments; added #randomizedQuickSort.
Claus Gittinger <cg@exept.de>
parents: 2860
diff changeset
  4046
    "Modified: 21.8.1997 / 18:31:24 / cg"
452f9154d0dc comments; added #randomizedQuickSort.
Claus Gittinger <cg@exept.de>
parents: 2860
diff changeset
  4047
!
452f9154d0dc comments; added #randomizedQuickSort.
Claus Gittinger <cg@exept.de>
parents: 2860
diff changeset
  4048
452f9154d0dc comments; added #randomizedQuickSort.
Claus Gittinger <cg@exept.de>
parents: 2860
diff changeset
  4049
randomizedSort:sortBlock with:aCollection
452f9154d0dc comments; added #randomizedQuickSort.
Claus Gittinger <cg@exept.de>
parents: 2860
diff changeset
  4050
    "sort the collection inplace using the 2-arg block sortBlock
452f9154d0dc comments; added #randomizedQuickSort.
Claus Gittinger <cg@exept.de>
parents: 2860
diff changeset
  4051
     for comparison. Also reorder the elements in aCollection.
452f9154d0dc comments; added #randomizedQuickSort.
Claus Gittinger <cg@exept.de>
parents: 2860
diff changeset
  4052
     Use this, when you have a key collection to sort some other collection with.
452f9154d0dc comments; added #randomizedQuickSort.
Claus Gittinger <cg@exept.de>
parents: 2860
diff changeset
  4053
452f9154d0dc comments; added #randomizedQuickSort.
Claus Gittinger <cg@exept.de>
parents: 2860
diff changeset
  4054
     This uses the randomized quicksort algorithm, 
452f9154d0dc comments; added #randomizedQuickSort.
Claus Gittinger <cg@exept.de>
parents: 2860
diff changeset
  4055
     which has a better worstCase behavior than quickSort
452f9154d0dc comments; added #randomizedQuickSort.
Claus Gittinger <cg@exept.de>
parents: 2860
diff changeset
  4056
     (bit worse bestCase & averageCase behavior).
452f9154d0dc comments; added #randomizedQuickSort.
Claus Gittinger <cg@exept.de>
parents: 2860
diff changeset
  4057
     See: Knuth or Cormen,Leiserson,Rivest pg. 163"
452f9154d0dc comments; added #randomizedQuickSort.
Claus Gittinger <cg@exept.de>
parents: 2860
diff changeset
  4058
452f9154d0dc comments; added #randomizedQuickSort.
Claus Gittinger <cg@exept.de>
parents: 2860
diff changeset
  4059
    |stop|
452f9154d0dc comments; added #randomizedQuickSort.
Claus Gittinger <cg@exept.de>
parents: 2860
diff changeset
  4060
452f9154d0dc comments; added #randomizedQuickSort.
Claus Gittinger <cg@exept.de>
parents: 2860
diff changeset
  4061
    stop := self size.
452f9154d0dc comments; added #randomizedQuickSort.
Claus Gittinger <cg@exept.de>
parents: 2860
diff changeset
  4062
    (stop > 1) ifTrue:[
452f9154d0dc comments; added #randomizedQuickSort.
Claus Gittinger <cg@exept.de>
parents: 2860
diff changeset
  4063
        self randomizedQuickSortFrom:1 to:stop sortBlock:sortBlock with:aCollection
452f9154d0dc comments; added #randomizedQuickSort.
Claus Gittinger <cg@exept.de>
parents: 2860
diff changeset
  4064
    ]
452f9154d0dc comments; added #randomizedQuickSort.
Claus Gittinger <cg@exept.de>
parents: 2860
diff changeset
  4065
452f9154d0dc comments; added #randomizedQuickSort.
Claus Gittinger <cg@exept.de>
parents: 2860
diff changeset
  4066
    "Created: 21.8.1997 / 18:20:53 / cg"
452f9154d0dc comments; added #randomizedQuickSort.
Claus Gittinger <cg@exept.de>
parents: 2860
diff changeset
  4067
    "Modified: 21.8.1997 / 18:31:27 / cg"
452f9154d0dc comments; added #randomizedQuickSort.
Claus Gittinger <cg@exept.de>
parents: 2860
diff changeset
  4068
!
452f9154d0dc comments; added #randomizedQuickSort.
Claus Gittinger <cg@exept.de>
parents: 2860
diff changeset
  4069
452f9154d0dc comments; added #randomizedQuickSort.
Claus Gittinger <cg@exept.de>
parents: 2860
diff changeset
  4070
randomizedSortWith:aCollection
452f9154d0dc comments; added #randomizedQuickSort.
Claus Gittinger <cg@exept.de>
parents: 2860
diff changeset
  4071
    "sort the receiver collection inplace, using '<' to compare elements.
452f9154d0dc comments; added #randomizedQuickSort.
Claus Gittinger <cg@exept.de>
parents: 2860
diff changeset
  4072
     Also, the elements of aCollection are reordered with it.
452f9154d0dc comments; added #randomizedQuickSort.
Claus Gittinger <cg@exept.de>
parents: 2860
diff changeset
  4073
     Use this, when you have a key collection to sort another collection with.
452f9154d0dc comments; added #randomizedQuickSort.
Claus Gittinger <cg@exept.de>
parents: 2860
diff changeset
  4074
452f9154d0dc comments; added #randomizedQuickSort.
Claus Gittinger <cg@exept.de>
parents: 2860
diff changeset
  4075
     This uses the randomized quicksort algorithm, 
452f9154d0dc comments; added #randomizedQuickSort.
Claus Gittinger <cg@exept.de>
parents: 2860
diff changeset
  4076
     which has a better worstCase behavior than quickSort
452f9154d0dc comments; added #randomizedQuickSort.
Claus Gittinger <cg@exept.de>
parents: 2860
diff changeset
  4077
     (bit worse bestCase & averageCase behavior).
452f9154d0dc comments; added #randomizedQuickSort.
Claus Gittinger <cg@exept.de>
parents: 2860
diff changeset
  4078
     See: Knuth or Cormen,Leiserson,Rivest pg. 163"
452f9154d0dc comments; added #randomizedQuickSort.
Claus Gittinger <cg@exept.de>
parents: 2860
diff changeset
  4079
452f9154d0dc comments; added #randomizedQuickSort.
Claus Gittinger <cg@exept.de>
parents: 2860
diff changeset
  4080
    |stop|
452f9154d0dc comments; added #randomizedQuickSort.
Claus Gittinger <cg@exept.de>
parents: 2860
diff changeset
  4081
452f9154d0dc comments; added #randomizedQuickSort.
Claus Gittinger <cg@exept.de>
parents: 2860
diff changeset
  4082
    stop := self size.
452f9154d0dc comments; added #randomizedQuickSort.
Claus Gittinger <cg@exept.de>
parents: 2860
diff changeset
  4083
    (stop > 1) ifTrue:[
452f9154d0dc comments; added #randomizedQuickSort.
Claus Gittinger <cg@exept.de>
parents: 2860
diff changeset
  4084
        self randomizedQuickSortFrom:1 to:stop sortBlock:[:a :b | a < b] with:aCollection
452f9154d0dc comments; added #randomizedQuickSort.
Claus Gittinger <cg@exept.de>
parents: 2860
diff changeset
  4085
    ]
452f9154d0dc comments; added #randomizedQuickSort.
Claus Gittinger <cg@exept.de>
parents: 2860
diff changeset
  4086
452f9154d0dc comments; added #randomizedQuickSort.
Claus Gittinger <cg@exept.de>
parents: 2860
diff changeset
  4087
    "Created: 21.8.1997 / 18:22:25 / cg"
452f9154d0dc comments; added #randomizedQuickSort.
Claus Gittinger <cg@exept.de>
parents: 2860
diff changeset
  4088
    "Modified: 21.8.1997 / 18:31:31 / cg"
452f9154d0dc comments; added #randomizedQuickSort.
Claus Gittinger <cg@exept.de>
parents: 2860
diff changeset
  4089
!
452f9154d0dc comments; added #randomizedQuickSort.
Claus Gittinger <cg@exept.de>
parents: 2860
diff changeset
  4090
602
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  4091
reverse
2610
a2ed6babbb0f comment
Claus Gittinger <cg@exept.de>
parents: 2417
diff changeset
  4092
    "destructively reverse the order of the elements inplace"
602
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  4093
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  4094
    |lowIndex "{ Class: SmallInteger }"
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  4095
     hiIndex  "{ Class: SmallInteger }"
929
674de4c05dcb added findFirst:startingAt: and findLast:startingAt:
Claus Gittinger <cg@exept.de>
parents: 911
diff changeset
  4096
     t1 t2|
602
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  4097
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  4098
    hiIndex := self size.
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  4099
    lowIndex := 1.
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  4100
    [lowIndex < hiIndex] whileTrue:[
1495
f0226967f2a2 added a Class: Smallinteger hint
Claus Gittinger <cg@exept.de>
parents: 1422
diff changeset
  4101
	t1 := self at:lowIndex.  t2 := self at:hiIndex.
f0226967f2a2 added a Class: Smallinteger hint
Claus Gittinger <cg@exept.de>
parents: 1422
diff changeset
  4102
	self at:lowIndex put:t2.  self at:hiIndex put:t1.
929
674de4c05dcb added findFirst:startingAt: and findLast:startingAt:
Claus Gittinger <cg@exept.de>
parents: 911
diff changeset
  4103
602
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  4104
	lowIndex := lowIndex + 1.
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  4105
	hiIndex := hiIndex - 1
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  4106
    ]
1495
f0226967f2a2 added a Class: Smallinteger hint
Claus Gittinger <cg@exept.de>
parents: 1422
diff changeset
  4107
69
4564b6328136 *** empty log message ***
claus
parents: 61
diff changeset
  4108
    "
602
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  4109
     #(4 5 6 7 7) reverse
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  4110
     #(1 4 7 10 2 5) asOrderedCollection reverse
69
4564b6328136 *** empty log message ***
claus
parents: 61
diff changeset
  4111
    "
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  4112
!
a27a279701f8 Initial revision
claus
parents:
diff changeset
  4113
a27a279701f8 Initial revision
claus
parents:
diff changeset
  4114
sort
a27a279701f8 Initial revision
claus
parents:
diff changeset
  4115
    "sort the collection inplace. The elements are compared using
2069
f6183117f922 comments
Claus Gittinger <cg@exept.de>
parents: 1673
diff changeset
  4116
     '<' i.e. they should offer a magnitude-like protocol.
2881
452f9154d0dc comments; added #randomizedQuickSort.
Claus Gittinger <cg@exept.de>
parents: 2860
diff changeset
  4117
159
514c749165c3 *** empty log message ***
claus
parents: 118
diff changeset
  4118
     The implementation uses the quicksort algorithm, which may not be
2881
452f9154d0dc comments; added #randomizedQuickSort.
Claus Gittinger <cg@exept.de>
parents: 2860
diff changeset
  4119
     the best possible for all situations (quickSort has O-square worst
452f9154d0dc comments; added #randomizedQuickSort.
Claus Gittinger <cg@exept.de>
parents: 2860
diff changeset
  4120
     case behavior). See also #randomizedSort for a version with better
452f9154d0dc comments; added #randomizedQuickSort.
Claus Gittinger <cg@exept.de>
parents: 2860
diff changeset
  4121
     worstCase behavior (but worse average & bestCase behavior)"
13
62303f84ff5f *** empty log message ***
claus
parents: 5
diff changeset
  4122
32
ee1a621c696c *** empty log message ***
claus
parents: 13
diff changeset
  4123
    |stop|
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  4124
32
ee1a621c696c *** empty log message ***
claus
parents: 13
diff changeset
  4125
    stop := self size.
ee1a621c696c *** empty log message ***
claus
parents: 13
diff changeset
  4126
    (stop > 1) ifTrue:[
2069
f6183117f922 comments
Claus Gittinger <cg@exept.de>
parents: 1673
diff changeset
  4127
        self quickSortFrom:1 to:stop
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  4128
    ]
a27a279701f8 Initial revision
claus
parents:
diff changeset
  4129
95
d22739a0c6e9 *** empty log message ***
claus
parents: 88
diff changeset
  4130
    "
d22739a0c6e9 *** empty log message ***
claus
parents: 88
diff changeset
  4131
     #(1 16 7 98 3 19 4 0) sort
d22739a0c6e9 *** empty log message ***
claus
parents: 88
diff changeset
  4132
d22739a0c6e9 *** empty log message ***
claus
parents: 88
diff changeset
  4133
     |data|
d22739a0c6e9 *** empty log message ***
claus
parents: 88
diff changeset
  4134
     data := Random new next:100000.
d22739a0c6e9 *** empty log message ***
claus
parents: 88
diff changeset
  4135
     'random  ' print. (Time millisecondsToRun:[data sort]) printNL.
d22739a0c6e9 *** empty log message ***
claus
parents: 88
diff changeset
  4136
     'sorted  ' print. (Time millisecondsToRun:[data sort]) printNL.
d22739a0c6e9 *** empty log message ***
claus
parents: 88
diff changeset
  4137
     data reverse. 
d22739a0c6e9 *** empty log message ***
claus
parents: 88
diff changeset
  4138
     'reverse ' print. (Time millisecondsToRun:[data sort]) printNL.
d22739a0c6e9 *** empty log message ***
claus
parents: 88
diff changeset
  4139
    "
2069
f6183117f922 comments
Claus Gittinger <cg@exept.de>
parents: 1673
diff changeset
  4140
2881
452f9154d0dc comments; added #randomizedQuickSort.
Claus Gittinger <cg@exept.de>
parents: 2860
diff changeset
  4141
    "Modified: 21.8.1997 / 18:31:52 / cg"
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  4142
!
a27a279701f8 Initial revision
claus
parents:
diff changeset
  4143
a27a279701f8 Initial revision
claus
parents:
diff changeset
  4144
sort:sortBlock
a27a279701f8 Initial revision
claus
parents:
diff changeset
  4145
    "sort the collection inplace using the 2-arg block sortBlock
2881
452f9154d0dc comments; added #randomizedQuickSort.
Claus Gittinger <cg@exept.de>
parents: 2860
diff changeset
  4146
     for comparison. This allows any sort criteria to be implemented.
452f9154d0dc comments; added #randomizedQuickSort.
Claus Gittinger <cg@exept.de>
parents: 2860
diff changeset
  4147
452f9154d0dc comments; added #randomizedQuickSort.
Claus Gittinger <cg@exept.de>
parents: 2860
diff changeset
  4148
     The implementation uses the quicksort algorithm, which may not be
452f9154d0dc comments; added #randomizedQuickSort.
Claus Gittinger <cg@exept.de>
parents: 2860
diff changeset
  4149
     the best possible for all situations (quickSort has O-square worst
452f9154d0dc comments; added #randomizedQuickSort.
Claus Gittinger <cg@exept.de>
parents: 2860
diff changeset
  4150
     case behavior). See also #randomizedSort: for a version with better
452f9154d0dc comments; added #randomizedQuickSort.
Claus Gittinger <cg@exept.de>
parents: 2860
diff changeset
  4151
     worstCase behavior (but worse average & bestCase behavior)"
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  4152
32
ee1a621c696c *** empty log message ***
claus
parents: 13
diff changeset
  4153
    |stop|
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  4154
32
ee1a621c696c *** empty log message ***
claus
parents: 13
diff changeset
  4155
    stop := self size.
ee1a621c696c *** empty log message ***
claus
parents: 13
diff changeset
  4156
    (stop > 1) ifTrue:[
3055
0832fba4c740 support 3-arg sort, passing a collationPolicy
Claus Gittinger <cg@exept.de>
parents: 3044
diff changeset
  4157
        sortBlock numArgs == 3 ifTrue:[
0832fba4c740 support 3-arg sort, passing a collationPolicy
Claus Gittinger <cg@exept.de>
parents: 3044
diff changeset
  4158
            "/ TODO: pass a collating policy to aBlock
0832fba4c740 support 3-arg sort, passing a collationPolicy
Claus Gittinger <cg@exept.de>
parents: 3044
diff changeset
  4159
            self quickSortFrom:1 to:stop sortBlock:sortBlock policy:(StringCollationPolicy new)
0832fba4c740 support 3-arg sort, passing a collationPolicy
Claus Gittinger <cg@exept.de>
parents: 3044
diff changeset
  4160
        ] ifFalse:[
0832fba4c740 support 3-arg sort, passing a collationPolicy
Claus Gittinger <cg@exept.de>
parents: 3044
diff changeset
  4161
            self quickSortFrom:1 to:stop sortBlock:sortBlock
0832fba4c740 support 3-arg sort, passing a collationPolicy
Claus Gittinger <cg@exept.de>
parents: 3044
diff changeset
  4162
        ]
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  4163
    ]
a27a279701f8 Initial revision
claus
parents:
diff changeset
  4164
95
d22739a0c6e9 *** empty log message ***
claus
parents: 88
diff changeset
  4165
    "
2069
f6183117f922 comments
Claus Gittinger <cg@exept.de>
parents: 1673
diff changeset
  4166
     #(1 16 7 98 3 19 4 0) sort:[:a :b | a < b] 
f6183117f922 comments
Claus Gittinger <cg@exept.de>
parents: 1673
diff changeset
  4167
     #(1 16 7 98 3 19 4 0) sort:[:a :b | a > b] 
f6183117f922 comments
Claus Gittinger <cg@exept.de>
parents: 1673
diff changeset
  4168
     #(1 -1 16 -16 7 -7 98 -98) sort:[:a :b | a < b] 
f6183117f922 comments
Claus Gittinger <cg@exept.de>
parents: 1673
diff changeset
  4169
     #(1 -1 16 -16 7 -7 98 -98) sort:[:a :b | a abs < b abs] 
95
d22739a0c6e9 *** empty log message ***
claus
parents: 88
diff changeset
  4170
    "
2069
f6183117f922 comments
Claus Gittinger <cg@exept.de>
parents: 1673
diff changeset
  4171
3055
0832fba4c740 support 3-arg sort, passing a collationPolicy
Claus Gittinger <cg@exept.de>
parents: 3044
diff changeset
  4172
    "Modified: / 27.10.1997 / 20:03:22 / cg"
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  4173
!
a27a279701f8 Initial revision
claus
parents:
diff changeset
  4174
a27a279701f8 Initial revision
claus
parents:
diff changeset
  4175
sort:sortBlock with:aCollection
a27a279701f8 Initial revision
claus
parents:
diff changeset
  4176
    "sort the collection inplace using the 2-arg block sortBlock
159
514c749165c3 *** empty log message ***
claus
parents: 118
diff changeset
  4177
     for comparison. Also reorder the elements in aCollection.
2881
452f9154d0dc comments; added #randomizedQuickSort.
Claus Gittinger <cg@exept.de>
parents: 2860
diff changeset
  4178
     Use this, when you have a key collection to sort some other collection with.
452f9154d0dc comments; added #randomizedQuickSort.
Claus Gittinger <cg@exept.de>
parents: 2860
diff changeset
  4179
452f9154d0dc comments; added #randomizedQuickSort.
Claus Gittinger <cg@exept.de>
parents: 2860
diff changeset
  4180
     The implementation uses the quicksort algorithm, which may not be
452f9154d0dc comments; added #randomizedQuickSort.
Claus Gittinger <cg@exept.de>
parents: 2860
diff changeset
  4181
     the best possible for all situations (quickSort has O-square worst
452f9154d0dc comments; added #randomizedQuickSort.
Claus Gittinger <cg@exept.de>
parents: 2860
diff changeset
  4182
     case behavior). See also #randomizedSort: for a version with better
452f9154d0dc comments; added #randomizedQuickSort.
Claus Gittinger <cg@exept.de>
parents: 2860
diff changeset
  4183
     worstCase behavior (but worse average & bestCase behavior)"
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  4184
32
ee1a621c696c *** empty log message ***
claus
parents: 13
diff changeset
  4185
    |stop|
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  4186
32
ee1a621c696c *** empty log message ***
claus
parents: 13
diff changeset
  4187
    stop := self size.
ee1a621c696c *** empty log message ***
claus
parents: 13
diff changeset
  4188
    (stop > 1) ifTrue:[
2069
f6183117f922 comments
Claus Gittinger <cg@exept.de>
parents: 1673
diff changeset
  4189
        self quickSortFrom:1 to:stop sortBlock:sortBlock with:aCollection
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  4190
    ]
a27a279701f8 Initial revision
claus
parents:
diff changeset
  4191
69
4564b6328136 *** empty log message ***
claus
parents: 61
diff changeset
  4192
    "
4564b6328136 *** empty log message ***
claus
parents: 61
diff changeset
  4193
     |c1 c2|
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  4194
     c1 := #(1 16 7 9).
a27a279701f8 Initial revision
claus
parents:
diff changeset
  4195
     c2 := #('one' 'sixteen' 'seven' 'nine').
a27a279701f8 Initial revision
claus
parents:
diff changeset
  4196
     c1 sort:[:a :b | a > b] with:c2.
95
d22739a0c6e9 *** empty log message ***
claus
parents: 88
diff changeset
  4197
     c1 printNL.
d22739a0c6e9 *** empty log message ***
claus
parents: 88
diff changeset
  4198
     c2 printNL
69
4564b6328136 *** empty log message ***
claus
parents: 61
diff changeset
  4199
    "
2069
f6183117f922 comments
Claus Gittinger <cg@exept.de>
parents: 1673
diff changeset
  4200
2881
452f9154d0dc comments; added #randomizedQuickSort.
Claus Gittinger <cg@exept.de>
parents: 2860
diff changeset
  4201
    "Modified: 21.8.1997 / 18:32:11 / cg"
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  4202
!
a27a279701f8 Initial revision
claus
parents:
diff changeset
  4203
602
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  4204
sortWith:aCollection
2069
f6183117f922 comments
Claus Gittinger <cg@exept.de>
parents: 1673
diff changeset
  4205
    "sort the receiver collection inplace, using '<' to compare elements.
f6183117f922 comments
Claus Gittinger <cg@exept.de>
parents: 1673
diff changeset
  4206
     Also, the elements of aCollection are reordered with it.
2881
452f9154d0dc comments; added #randomizedQuickSort.
Claus Gittinger <cg@exept.de>
parents: 2860
diff changeset
  4207
     Use this, when you have a key collection to sort another collection with.
452f9154d0dc comments; added #randomizedQuickSort.
Claus Gittinger <cg@exept.de>
parents: 2860
diff changeset
  4208
452f9154d0dc comments; added #randomizedQuickSort.
Claus Gittinger <cg@exept.de>
parents: 2860
diff changeset
  4209
     The implementation uses the quicksort algorithm, which may not be
452f9154d0dc comments; added #randomizedQuickSort.
Claus Gittinger <cg@exept.de>
parents: 2860
diff changeset
  4210
     the best possible for all situations (quickSort has O-square worst
452f9154d0dc comments; added #randomizedQuickSort.
Claus Gittinger <cg@exept.de>
parents: 2860
diff changeset
  4211
     case behavior). See also #randomizedSort: for a version with better
452f9154d0dc comments; added #randomizedQuickSort.
Claus Gittinger <cg@exept.de>
parents: 2860
diff changeset
  4212
     worstCase behavior (but worse average & bestCase behavior)"
602
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  4213
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  4214
    |stop|
356
claus
parents: 348
diff changeset
  4215
claus
parents: 348
diff changeset
  4216
    stop := self size.
602
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  4217
    (stop > 1) ifTrue:[
2069
f6183117f922 comments
Claus Gittinger <cg@exept.de>
parents: 1673
diff changeset
  4218
        self quickSortFrom:1 to:stop with:aCollection
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  4219
    ]
77
6c38ca59927f *** empty log message ***
claus
parents: 69
diff changeset
  4220
2881
452f9154d0dc comments; added #randomizedQuickSort.
Claus Gittinger <cg@exept.de>
parents: 2860
diff changeset
  4221
    "Modified: 21.8.1997 / 18:32:21 / cg"
424
claus
parents: 422
diff changeset
  4222
!
claus
parents: 422
diff changeset
  4223
602
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  4224
topologicalSort:sortBlock
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  4225
    "sort the collection inplace using a sloooow sort algorithm.
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  4226
     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
  4227
     in special situations.
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  4228
     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
  4229
     a>c (for example, to sort classes by inheritance)
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  4230
2881
452f9154d0dc comments; added #randomizedQuickSort.
Claus Gittinger <cg@exept.de>
parents: 2860
diff changeset
  4231
     In all other situations, use #sort; which implements the quicksort algorithm.
77
6c38ca59927f *** empty log message ***
claus
parents: 69
diff changeset
  4232
    "
602
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  4233
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  4234
    |smallestIndex "{ Class: SmallInteger }"
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  4235
     end           "{ Class: SmallInteger }"
1495
f0226967f2a2 added a Class: Smallinteger hint
Claus Gittinger <cg@exept.de>
parents: 1422
diff changeset
  4236
     index2        "{ Class: SmallInteger }"
602
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  4237
     smallest thisOne|
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  4238
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  4239
    "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
  4240
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  4241
    end := self size.
862
007dccfb6cb0 fix topologicalSort:
Stefan Vogel <sv@exept.de>
parents: 628
diff changeset
  4242
    1 to:end-1 do:[:index |
2881
452f9154d0dc comments; added #randomizedQuickSort.
Claus Gittinger <cg@exept.de>
parents: 2860
diff changeset
  4243
        smallest := self at:index.
452f9154d0dc comments; added #randomizedQuickSort.
Claus Gittinger <cg@exept.de>
parents: 2860
diff changeset
  4244
        smallestIndex := index.
452f9154d0dc comments; added #randomizedQuickSort.
Claus Gittinger <cg@exept.de>
parents: 2860
diff changeset
  4245
452f9154d0dc comments; added #randomizedQuickSort.
Claus Gittinger <cg@exept.de>
parents: 2860
diff changeset
  4246
        index2 := index + 1.
452f9154d0dc comments; added #randomizedQuickSort.
Claus Gittinger <cg@exept.de>
parents: 2860
diff changeset
  4247
        [
452f9154d0dc comments; added #randomizedQuickSort.
Claus Gittinger <cg@exept.de>
parents: 2860
diff changeset
  4248
            thisOne := self at:index2.
452f9154d0dc comments; added #randomizedQuickSort.
Claus Gittinger <cg@exept.de>
parents: 2860
diff changeset
  4249
            (index2 ~~ smallestIndex 
452f9154d0dc comments; added #randomizedQuickSort.
Claus Gittinger <cg@exept.de>
parents: 2860
diff changeset
  4250
            and:[sortBlock value:thisOne value:smallest]) ifTrue:[
452f9154d0dc comments; added #randomizedQuickSort.
Claus Gittinger <cg@exept.de>
parents: 2860
diff changeset
  4251
                smallestIndex := index2.
452f9154d0dc comments; added #randomizedQuickSort.
Claus Gittinger <cg@exept.de>
parents: 2860
diff changeset
  4252
                smallest := thisOne.
452f9154d0dc comments; added #randomizedQuickSort.
Claus Gittinger <cg@exept.de>
parents: 2860
diff changeset
  4253
                index2 := index + 1.
452f9154d0dc comments; added #randomizedQuickSort.
Claus Gittinger <cg@exept.de>
parents: 2860
diff changeset
  4254
            ] ifFalse:[
452f9154d0dc comments; added #randomizedQuickSort.
Claus Gittinger <cg@exept.de>
parents: 2860
diff changeset
  4255
                index2 := index2 + 1..
452f9154d0dc comments; added #randomizedQuickSort.
Claus Gittinger <cg@exept.de>
parents: 2860
diff changeset
  4256
            ].
452f9154d0dc comments; added #randomizedQuickSort.
Claus Gittinger <cg@exept.de>
parents: 2860
diff changeset
  4257
        ] doWhile:[index2 <= end].
862
007dccfb6cb0 fix topologicalSort:
Stefan Vogel <sv@exept.de>
parents: 628
diff changeset
  4258
007dccfb6cb0 fix topologicalSort:
Stefan Vogel <sv@exept.de>
parents: 628
diff changeset
  4259
"/        (index + 1) to:end do:[:index2 |
007dccfb6cb0 fix topologicalSort:
Stefan Vogel <sv@exept.de>
parents: 628
diff changeset
  4260
"/            thisOne := self at:index2.
007dccfb6cb0 fix topologicalSort:
Stefan Vogel <sv@exept.de>
parents: 628
diff changeset
  4261
"/            (sortBlock value:thisOne value:smallest) ifTrue:[
007dccfb6cb0 fix topologicalSort:
Stefan Vogel <sv@exept.de>
parents: 628
diff changeset
  4262
"/                smallestIndex := index2.
007dccfb6cb0 fix topologicalSort:
Stefan Vogel <sv@exept.de>
parents: 628
diff changeset
  4263
"/                smallest := thisOne
007dccfb6cb0 fix topologicalSort:
Stefan Vogel <sv@exept.de>
parents: 628
diff changeset
  4264
"/            ].
007dccfb6cb0 fix topologicalSort:
Stefan Vogel <sv@exept.de>
parents: 628
diff changeset
  4265
"/        ].
1495
f0226967f2a2 added a Class: Smallinteger hint
Claus Gittinger <cg@exept.de>
parents: 1422
diff changeset
  4266
2881
452f9154d0dc comments; added #randomizedQuickSort.
Claus Gittinger <cg@exept.de>
parents: 2860
diff changeset
  4267
        (smallestIndex ~~ index) ifTrue:[
452f9154d0dc comments; added #randomizedQuickSort.
Claus Gittinger <cg@exept.de>
parents: 2860
diff changeset
  4268
            thisOne := self at:index.
452f9154d0dc comments; added #randomizedQuickSort.
Claus Gittinger <cg@exept.de>
parents: 2860
diff changeset
  4269
            self at:index put:smallest.
452f9154d0dc comments; added #randomizedQuickSort.
Claus Gittinger <cg@exept.de>
parents: 2860
diff changeset
  4270
            self at:smallestIndex put:thisOne
452f9154d0dc comments; added #randomizedQuickSort.
Claus Gittinger <cg@exept.de>
parents: 2860
diff changeset
  4271
        ].
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  4272
    ]
95
d22739a0c6e9 *** empty log message ***
claus
parents: 88
diff changeset
  4273
77
6c38ca59927f *** empty log message ***
claus
parents: 69
diff changeset
  4274
    "
602
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  4275
     #(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
  4276
     #(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
  4277
     Smalltalk allClasses asArray topologicalSort:[:a :b | b isSubclassOf:a] 
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  4278
     Smalltalk allClasses asArray sort:[:a :b | b isSubclassOf:a] 
77
6c38ca59927f *** empty log message ***
claus
parents: 69
diff changeset
  4279
    "
2881
452f9154d0dc comments; added #randomizedQuickSort.
Claus Gittinger <cg@exept.de>
parents: 2860
diff changeset
  4280
452f9154d0dc comments; added #randomizedQuickSort.
Claus Gittinger <cg@exept.de>
parents: 2860
diff changeset
  4281
    "Modified: 21.8.1997 / 18:30:49 / cg"
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  4282
! !
602
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  4283
2069
f6183117f922 comments
Claus Gittinger <cg@exept.de>
parents: 1673
diff changeset
  4284
!SequenceableCollection class methodsFor:'documentation'!
628
7aa563e4c64a version at the end
Claus Gittinger <cg@exept.de>
parents: 602
diff changeset
  4285
7aa563e4c64a version at the end
Claus Gittinger <cg@exept.de>
parents: 602
diff changeset
  4286
version
4403
eb4379909671 comment
Claus Gittinger <cg@exept.de>
parents: 4402
diff changeset
  4287
    ^ '$Header: /cvs/stx/stx/libbasic/SequenceableCollection.st,v 1.112 1999-07-17 10:21:54 cg Exp $'
628
7aa563e4c64a version at the end
Claus Gittinger <cg@exept.de>
parents: 602
diff changeset
  4288
! !
4197
8ae90a572914 raise a special signal, when a literalencodings class
Claus Gittinger <cg@exept.de>
parents: 4154
diff changeset
  4289
SequenceableCollection initialize!