SequenceableCollection.st
author Stefan Vogel <sv@exept.de>
Tue, 18 Jul 2000 11:07:00 +0200
changeset 5471 a57eeb01c5ab
parent 5446 e5ecc71d3054
child 5489 76788e74329f
permissions -rw-r--r--
General encoding method (#encodeOn:with:)
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
5358
79b21b5a4783 added #isSorted;
Claus Gittinger <cg@exept.de>
parents: 5320
diff changeset
    13
"{ Package: 'stx:libbasic' }"
79b21b5a4783 added #isSorted;
Claus Gittinger <cg@exept.de>
parents: 5320
diff changeset
    14
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
    15
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
    16
	instanceVariableNames:''
4197
8ae90a572914 raise a special signal, when a literalencodings class
Claus Gittinger <cg@exept.de>
parents: 4154
diff changeset
    17
	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
    18
	poolDictionaries:''
8bf5e91a7f68 Use doWhile: instead of whileTrue in topological sort (is compiled to inlined code).
Stefan Vogel <sv@exept.de>
parents: 890
diff changeset
    19
	category:'Collections-Abstract'
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
    20
!
a27a279701f8 Initial revision
claus
parents:
diff changeset
    21
2069
f6183117f922 comments
Claus Gittinger <cg@exept.de>
parents: 1673
diff changeset
    22
!SequenceableCollection class methodsFor:'documentation'!
88
81dacba7a63a *** empty log message ***
claus
parents: 77
diff changeset
    23
81dacba7a63a *** empty log message ***
claus
parents: 77
diff changeset
    24
copyright
81dacba7a63a *** empty log message ***
claus
parents: 77
diff changeset
    25
"
81dacba7a63a *** empty log message ***
claus
parents: 77
diff changeset
    26
 COPYRIGHT (c) 1989 by Claus Gittinger
159
514c749165c3 *** empty log message ***
claus
parents: 118
diff changeset
    27
	      All Rights Reserved
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
    28
88
81dacba7a63a *** empty log message ***
claus
parents: 77
diff changeset
    29
 This software is furnished under a license and may be used
81dacba7a63a *** empty log message ***
claus
parents: 77
diff changeset
    30
 only in accordance with the terms of that license and with the
81dacba7a63a *** empty log message ***
claus
parents: 77
diff changeset
    31
 inclusion of the above copyright notice.   This software may not
81dacba7a63a *** empty log message ***
claus
parents: 77
diff changeset
    32
 be provided or otherwise made available to, or used by, any
81dacba7a63a *** empty log message ***
claus
parents: 77
diff changeset
    33
 other person.  No title to or ownership of the software is
81dacba7a63a *** empty log message ***
claus
parents: 77
diff changeset
    34
 hereby transferred.
81dacba7a63a *** empty log message ***
claus
parents: 77
diff changeset
    35
"
81dacba7a63a *** empty log message ***
claus
parents: 77
diff changeset
    36
!
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
    37
88
81dacba7a63a *** empty log message ***
claus
parents: 77
diff changeset
    38
documentation
81dacba7a63a *** empty log message ***
claus
parents: 77
diff changeset
    39
"
81dacba7a63a *** empty log message ***
claus
parents: 77
diff changeset
    40
    SequenceableCollections have ordered elements which can be accessed via
81dacba7a63a *** empty log message ***
claus
parents: 77
diff changeset
    41
    a numeric index. 
81dacba7a63a *** empty log message ***
claus
parents: 77
diff changeset
    42
    SequenceableCollection is an abstract class - there are no instances of 
1385
Claus Gittinger <cg@exept.de>
parents: 1370
diff changeset
    43
    it in the system. 
Claus Gittinger <cg@exept.de>
parents: 1370
diff changeset
    44
Claus Gittinger <cg@exept.de>
parents: 1370
diff changeset
    45
    The methods found here assume that implementations of (at least)
Claus Gittinger <cg@exept.de>
parents: 1370
diff changeset
    46
    #at:/#at:put: are implemented (which are always found in Object for
Claus Gittinger <cg@exept.de>
parents: 1370
diff changeset
    47
    indexable objects).
Claus Gittinger <cg@exept.de>
parents: 1370
diff changeset
    48
Claus Gittinger <cg@exept.de>
parents: 1370
diff changeset
    49
    For performance, some subclasses redefine more methods, knowing the details
Claus Gittinger <cg@exept.de>
parents: 1370
diff changeset
    50
    of how elements are stored. 
Claus Gittinger <cg@exept.de>
parents: 1370
diff changeset
    51
    Especially, bulk data manipulation (i.e. #replaceFrom:to:with:startingAt:) 
Claus Gittinger <cg@exept.de>
parents: 1370
diff changeset
    52
    and search methods (i.e. #indexOf:startingAt:) are good candidates for this
Claus Gittinger <cg@exept.de>
parents: 1370
diff changeset
    53
    kind of tuneup.
Claus Gittinger <cg@exept.de>
parents: 1370
diff changeset
    54
Claus Gittinger <cg@exept.de>
parents: 1370
diff changeset
    55
    See concrete subclasses (such as OrderedCollection, Array or String).
1289
3abde2c376de checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1245
diff changeset
    56
3abde2c376de checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1245
diff changeset
    57
    [author:]
3abde2c376de checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1245
diff changeset
    58
        Claus Gittinger
1385
Claus Gittinger <cg@exept.de>
parents: 1370
diff changeset
    59
Claus Gittinger <cg@exept.de>
parents: 1370
diff changeset
    60
    [see also:]
Claus Gittinger <cg@exept.de>
parents: 1370
diff changeset
    61
        OrderedCollection Array
Claus Gittinger <cg@exept.de>
parents: 1370
diff changeset
    62
        CharacterArray String
88
81dacba7a63a *** empty log message ***
claus
parents: 77
diff changeset
    63
"
81dacba7a63a *** empty log message ***
claus
parents: 77
diff changeset
    64
! !
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
    65
4197
8ae90a572914 raise a special signal, when a literalencodings class
Claus Gittinger <cg@exept.de>
parents: 4154
diff changeset
    66
!SequenceableCollection class methodsFor:'initialization'!
8ae90a572914 raise a special signal, when a literalencodings class
Claus Gittinger <cg@exept.de>
parents: 4154
diff changeset
    67
8ae90a572914 raise a special signal, when a literalencodings class
Claus Gittinger <cg@exept.de>
parents: 4154
diff changeset
    68
initialize
8ae90a572914 raise a special signal, when a literalencodings class
Claus Gittinger <cg@exept.de>
parents: 4154
diff changeset
    69
    MissingClassInLiteralArrayErrorSignal isNil ifTrue:[
8ae90a572914 raise a special signal, when a literalencodings class
Claus Gittinger <cg@exept.de>
parents: 4154
diff changeset
    70
        MissingClassInLiteralArrayErrorSignal := ErrorSignal newSignalMayProceed:true.
8ae90a572914 raise a special signal, when a literalencodings class
Claus Gittinger <cg@exept.de>
parents: 4154
diff changeset
    71
        MissingClassInLiteralArrayErrorSignal nameClass:self message:#missingClassInLiteralArrayErrorSignal.
8ae90a572914 raise a special signal, when a literalencodings class
Claus Gittinger <cg@exept.de>
parents: 4154
diff changeset
    72
        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
    73
    ]
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
    "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
    76
! !
8ae90a572914 raise a special signal, when a literalencodings class
Claus Gittinger <cg@exept.de>
parents: 4154
diff changeset
    77
2069
f6183117f922 comments
Claus Gittinger <cg@exept.de>
parents: 1673
diff changeset
    78
!SequenceableCollection class methodsFor:'instance creation'!
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
    79
4807
Claus Gittinger <cg@exept.de>
parents: 4788
diff changeset
    80
decodeFromLiteralArray:anArray
Claus Gittinger <cg@exept.de>
parents: 4788
diff changeset
    81
    "create & return a new instance from information encoded in anArray.
Claus Gittinger <cg@exept.de>
parents: 4788
diff changeset
    82
     Redefined for faster creation.
Claus Gittinger <cg@exept.de>
parents: 4788
diff changeset
    83
    "
Claus Gittinger <cg@exept.de>
parents: 4788
diff changeset
    84
    |col|
Claus Gittinger <cg@exept.de>
parents: 4788
diff changeset
    85
    col := self new.
Claus Gittinger <cg@exept.de>
parents: 4788
diff changeset
    86
    anArray from:2 do:[:el| col add:(el decodeAsLiteralArray) ].
Claus Gittinger <cg@exept.de>
parents: 4788
diff changeset
    87
  ^ col
Claus Gittinger <cg@exept.de>
parents: 4788
diff changeset
    88
Claus Gittinger <cg@exept.de>
parents: 4788
diff changeset
    89
!
Claus Gittinger <cg@exept.de>
parents: 4788
diff changeset
    90
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
    91
new:size withAll:element
360
claus
parents: 359
diff changeset
    92
    "return a new collection of size, where all elements are
claus
parents: 359
diff changeset
    93
     initialized to element."
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
    94
a27a279701f8 Initial revision
claus
parents:
diff changeset
    95
    |newCollection|
a27a279701f8 Initial revision
claus
parents:
diff changeset
    96
a27a279701f8 Initial revision
claus
parents:
diff changeset
    97
    newCollection := self new:size.
a27a279701f8 Initial revision
claus
parents:
diff changeset
    98
    newCollection atAllPut:element.
a27a279701f8 Initial revision
claus
parents:
diff changeset
    99
    ^ newCollection
360
claus
parents: 359
diff changeset
   100
!
claus
parents: 359
diff changeset
   101
4303
4a2e5a5cb83d added #newWithConcatenationOfAll: for tune concatenation of
Claus Gittinger <cg@exept.de>
parents: 4197
diff changeset
   102
newWithConcatenationOfAll:aCollectionOfCollections
4a2e5a5cb83d added #newWithConcatenationOfAll: for tune concatenation of
Claus Gittinger <cg@exept.de>
parents: 4197
diff changeset
   103
    "this creates and returns a new collection consisting
4a2e5a5cb83d added #newWithConcatenationOfAll: for tune concatenation of
Claus Gittinger <cg@exept.de>
parents: 4197
diff changeset
   104
     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
   105
     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
   106
     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
   107
     by avoiding repeated garbage allocations.
4a2e5a5cb83d added #newWithConcatenationOfAll: for tune concatenation of
Claus Gittinger <cg@exept.de>
parents: 4197
diff changeset
   108
     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
   109
4a2e5a5cb83d added #newWithConcatenationOfAll: for tune concatenation of
Claus Gittinger <cg@exept.de>
parents: 4197
diff changeset
   110
    |totalSize newColl idx|
4a2e5a5cb83d added #newWithConcatenationOfAll: for tune concatenation of
Claus Gittinger <cg@exept.de>
parents: 4197
diff changeset
   111
4a2e5a5cb83d added #newWithConcatenationOfAll: for tune concatenation of
Claus Gittinger <cg@exept.de>
parents: 4197
diff changeset
   112
    totalSize := aCollectionOfCollections 
4a2e5a5cb83d added #newWithConcatenationOfAll: for tune concatenation of
Claus Gittinger <cg@exept.de>
parents: 4197
diff changeset
   113
                        inject:0
4a2e5a5cb83d added #newWithConcatenationOfAll: for tune concatenation of
Claus Gittinger <cg@exept.de>
parents: 4197
diff changeset
   114
                        into:[:sumSoFar :el | sumSoFar + el size].
4a2e5a5cb83d added #newWithConcatenationOfAll: for tune concatenation of
Claus Gittinger <cg@exept.de>
parents: 4197
diff changeset
   115
    newColl := self new:totalSize.
4a2e5a5cb83d added #newWithConcatenationOfAll: for tune concatenation of
Claus Gittinger <cg@exept.de>
parents: 4197
diff changeset
   116
    idx := 1.
4a2e5a5cb83d added #newWithConcatenationOfAll: for tune concatenation of
Claus Gittinger <cg@exept.de>
parents: 4197
diff changeset
   117
    aCollectionOfCollections do:[:el |
4a2e5a5cb83d added #newWithConcatenationOfAll: for tune concatenation of
Claus Gittinger <cg@exept.de>
parents: 4197
diff changeset
   118
        |sz|
4a2e5a5cb83d added #newWithConcatenationOfAll: for tune concatenation of
Claus Gittinger <cg@exept.de>
parents: 4197
diff changeset
   119
4a2e5a5cb83d added #newWithConcatenationOfAll: for tune concatenation of
Claus Gittinger <cg@exept.de>
parents: 4197
diff changeset
   120
        sz := el size.
4a2e5a5cb83d added #newWithConcatenationOfAll: for tune concatenation of
Claus Gittinger <cg@exept.de>
parents: 4197
diff changeset
   121
        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
   122
        idx := idx + sz
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
    ^ newColl
4a2e5a5cb83d added #newWithConcatenationOfAll: for tune concatenation of
Claus Gittinger <cg@exept.de>
parents: 4197
diff changeset
   125
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
     this method optimizes the following (common) operation:
4a2e5a5cb83d added #newWithConcatenationOfAll: for tune concatenation of
Claus Gittinger <cg@exept.de>
parents: 4197
diff changeset
   128
4a2e5a5cb83d added #newWithConcatenationOfAll: for tune concatenation of
Claus Gittinger <cg@exept.de>
parents: 4197
diff changeset
   129
         |s|
4a2e5a5cb83d added #newWithConcatenationOfAll: for tune concatenation of
Claus Gittinger <cg@exept.de>
parents: 4197
diff changeset
   130
4a2e5a5cb83d added #newWithConcatenationOfAll: for tune concatenation of
Claus Gittinger <cg@exept.de>
parents: 4197
diff changeset
   131
         s := ''.
4a2e5a5cb83d added #newWithConcatenationOfAll: for tune concatenation of
Claus Gittinger <cg@exept.de>
parents: 4197
diff changeset
   132
         #('hello' ' ' 'world' ' ' 'this is ' 'ST/X') do:[:e|
4a2e5a5cb83d added #newWithConcatenationOfAll: for tune concatenation of
Claus Gittinger <cg@exept.de>
parents: 4197
diff changeset
   133
            s := s , e.
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
         s  
4a2e5a5cb83d added #newWithConcatenationOfAll: for tune concatenation of
Claus Gittinger <cg@exept.de>
parents: 4197
diff changeset
   136
4a2e5a5cb83d added #newWithConcatenationOfAll: for tune concatenation of
Claus Gittinger <cg@exept.de>
parents: 4197
diff changeset
   137
     String 
4a2e5a5cb83d added #newWithConcatenationOfAll: for tune concatenation of
Claus Gittinger <cg@exept.de>
parents: 4197
diff changeset
   138
        newWithConcatenationOfAll:#('hello' ' ' 'world' ' ' 'this is ' 'ST/X')
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
     String 
4a2e5a5cb83d added #newWithConcatenationOfAll: for tune concatenation of
Claus Gittinger <cg@exept.de>
parents: 4197
diff changeset
   141
        newWithConcatenationOfAll:#()   
4a2e5a5cb83d added #newWithConcatenationOfAll: for tune concatenation of
Claus Gittinger <cg@exept.de>
parents: 4197
diff changeset
   142
4a2e5a5cb83d added #newWithConcatenationOfAll: for tune concatenation of
Claus Gittinger <cg@exept.de>
parents: 4197
diff changeset
   143
     Array
4a2e5a5cb83d added #newWithConcatenationOfAll: for tune concatenation of
Claus Gittinger <cg@exept.de>
parents: 4197
diff changeset
   144
        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
   145
4a2e5a5cb83d added #newWithConcatenationOfAll: for tune concatenation of
Claus Gittinger <cg@exept.de>
parents: 4197
diff changeset
   146
     timing:
4a2e5a5cb83d added #newWithConcatenationOfAll: for tune concatenation of
Claus Gittinger <cg@exept.de>
parents: 4197
diff changeset
   147
     -------
4a2e5a5cb83d added #newWithConcatenationOfAll: for tune concatenation of
Claus Gittinger <cg@exept.de>
parents: 4197
diff changeset
   148
     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
   149
     for more elements, #newWithConcatenationOfAll: is much faster.
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
     |arr1 arr2 arr3 t|
4a2e5a5cb83d added #newWithConcatenationOfAll: for tune concatenation of
Claus Gittinger <cg@exept.de>
parents: 4197
diff changeset
   152
4a2e5a5cb83d added #newWithConcatenationOfAll: for tune concatenation of
Claus Gittinger <cg@exept.de>
parents: 4197
diff changeset
   153
     arr1 := #('hello' ' ' 'world' ' ' 'this is ' 'ST/X').
4a2e5a5cb83d added #newWithConcatenationOfAll: for tune concatenation of
Claus Gittinger <cg@exept.de>
parents: 4197
diff changeset
   154
     arr2 := Array new:1000 withAll:'hello'.
4a2e5a5cb83d added #newWithConcatenationOfAll: for tune concatenation of
Claus Gittinger <cg@exept.de>
parents: 4197
diff changeset
   155
     arr3 := Array new:10000 withAll:'hello'.
4a2e5a5cb83d added #newWithConcatenationOfAll: for tune concatenation of
Claus Gittinger <cg@exept.de>
parents: 4197
diff changeset
   156
4a2e5a5cb83d added #newWithConcatenationOfAll: for tune concatenation of
Claus Gittinger <cg@exept.de>
parents: 4197
diff changeset
   157
     (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
   158
         t := Time millisecondsToRun:[
4a2e5a5cb83d added #newWithConcatenationOfAll: for tune concatenation of
Claus Gittinger <cg@exept.de>
parents: 4197
diff changeset
   159
            cnt timesRepeat:[
4a2e5a5cb83d added #newWithConcatenationOfAll: for tune concatenation of
Claus Gittinger <cg@exept.de>
parents: 4197
diff changeset
   160
                String 
4a2e5a5cb83d added #newWithConcatenationOfAll: for tune concatenation of
Claus Gittinger <cg@exept.de>
parents: 4197
diff changeset
   161
                    newWithConcatenationOfAll:arr
4a2e5a5cb83d added #newWithConcatenationOfAll: for tune concatenation of
Claus Gittinger <cg@exept.de>
parents: 4197
diff changeset
   162
            ]
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
         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
   165
         Transcript endEntry.
4a2e5a5cb83d added #newWithConcatenationOfAll: for tune concatenation of
Claus Gittinger <cg@exept.de>
parents: 4197
diff changeset
   166
4a2e5a5cb83d added #newWithConcatenationOfAll: for tune concatenation of
Claus Gittinger <cg@exept.de>
parents: 4197
diff changeset
   167
         t := Time millisecondsToRun:[
4a2e5a5cb83d added #newWithConcatenationOfAll: for tune concatenation of
Claus Gittinger <cg@exept.de>
parents: 4197
diff changeset
   168
            cnt timesRepeat:[
4a2e5a5cb83d added #newWithConcatenationOfAll: for tune concatenation of
Claus Gittinger <cg@exept.de>
parents: 4197
diff changeset
   169
                 |s|
4a2e5a5cb83d added #newWithConcatenationOfAll: for tune concatenation of
Claus Gittinger <cg@exept.de>
parents: 4197
diff changeset
   170
4a2e5a5cb83d added #newWithConcatenationOfAll: for tune concatenation of
Claus Gittinger <cg@exept.de>
parents: 4197
diff changeset
   171
                 s := ''.
4a2e5a5cb83d added #newWithConcatenationOfAll: for tune concatenation of
Claus Gittinger <cg@exept.de>
parents: 4197
diff changeset
   172
                 arr do:[:e|
4a2e5a5cb83d added #newWithConcatenationOfAll: for tune concatenation of
Claus Gittinger <cg@exept.de>
parents: 4197
diff changeset
   173
                    s := s , e.
4a2e5a5cb83d added #newWithConcatenationOfAll: for tune concatenation of
Claus Gittinger <cg@exept.de>
parents: 4197
diff changeset
   174
                 ]. 
4a2e5a5cb83d added #newWithConcatenationOfAll: for tune concatenation of
Claus Gittinger <cg@exept.de>
parents: 4197
diff changeset
   175
                 s  
4a2e5a5cb83d added #newWithConcatenationOfAll: for tune concatenation of
Claus Gittinger <cg@exept.de>
parents: 4197
diff changeset
   176
            ]
4a2e5a5cb83d added #newWithConcatenationOfAll: for tune concatenation of
Claus Gittinger <cg@exept.de>
parents: 4197
diff changeset
   177
         ].  
4a2e5a5cb83d added #newWithConcatenationOfAll: for tune concatenation of
Claus Gittinger <cg@exept.de>
parents: 4197
diff changeset
   178
         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
   179
         Transcript endEntry.
4a2e5a5cb83d added #newWithConcatenationOfAll: for tune concatenation of
Claus Gittinger <cg@exept.de>
parents: 4197
diff changeset
   180
     ]
4a2e5a5cb83d added #newWithConcatenationOfAll: for tune concatenation of
Claus Gittinger <cg@exept.de>
parents: 4197
diff changeset
   181
    "
4a2e5a5cb83d added #newWithConcatenationOfAll: for tune concatenation of
Claus Gittinger <cg@exept.de>
parents: 4197
diff changeset
   182
!
4a2e5a5cb83d added #newWithConcatenationOfAll: for tune concatenation of
Claus Gittinger <cg@exept.de>
parents: 4197
diff changeset
   183
360
claus
parents: 359
diff changeset
   184
withSize:size
claus
parents: 359
diff changeset
   185
    "return a new collection of size.
claus
parents: 359
diff changeset
   186
     For variable size collections, this is different from #new:,
claus
parents: 359
diff changeset
   187
     in that #new: creates an empty collection with preallocated size,
claus
parents: 359
diff changeset
   188
     while #withSize: creates a non empty one."
claus
parents: 359
diff changeset
   189
claus
parents: 359
diff changeset
   190
    |newCollection|
claus
parents: 359
diff changeset
   191
claus
parents: 359
diff changeset
   192
    newCollection := self new:size.
claus
parents: 359
diff changeset
   193
    newCollection grow:size.
claus
parents: 359
diff changeset
   194
    ^ newCollection
claus
parents: 359
diff changeset
   195
claus
parents: 359
diff changeset
   196
    "
claus
parents: 359
diff changeset
   197
     (OrderedCollection new:10) inspect.
claus
parents: 359
diff changeset
   198
     (OrderedCollection withSize:10) inspect.
claus
parents: 359
diff changeset
   199
     (Array new:10) inspect.
claus
parents: 359
diff changeset
   200
     (Array withSize:10) inspect.
claus
parents: 359
diff changeset
   201
    "
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   202
! !
a27a279701f8 Initial revision
claus
parents:
diff changeset
   203
5188
ffe7bdb92f71 category renamining
Claus Gittinger <cg@exept.de>
parents: 5153
diff changeset
   204
!SequenceableCollection class methodsFor:'Compatibility - Squeak'!
4370
a1e3b976c7be checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4338
diff changeset
   205
a1e3b976c7be checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4338
diff changeset
   206
streamContents:blockWithArg
a1e3b976c7be checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4338
diff changeset
   207
    |stream|
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
    stream := WriteStream on:(self new:100).
a1e3b976c7be checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4338
diff changeset
   210
    blockWithArg value:stream.
a1e3b976c7be checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4338
diff changeset
   211
    ^ stream contents
a1e3b976c7be checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4338
diff changeset
   212
a1e3b976c7be checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4338
diff changeset
   213
! !
a1e3b976c7be checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4338
diff changeset
   214
5188
ffe7bdb92f71 category renamining
Claus Gittinger <cg@exept.de>
parents: 5153
diff changeset
   215
!SequenceableCollection class methodsFor:'Signal constants'!
ffe7bdb92f71 category renamining
Claus Gittinger <cg@exept.de>
parents: 5153
diff changeset
   216
ffe7bdb92f71 category renamining
Claus Gittinger <cg@exept.de>
parents: 5153
diff changeset
   217
missingClassInLiteralArrayErrorSignal
ffe7bdb92f71 category renamining
Claus Gittinger <cg@exept.de>
parents: 5153
diff changeset
   218
    ^ MissingClassInLiteralArrayErrorSignal
ffe7bdb92f71 category renamining
Claus Gittinger <cg@exept.de>
parents: 5153
diff changeset
   219
ffe7bdb92f71 category renamining
Claus Gittinger <cg@exept.de>
parents: 5153
diff changeset
   220
    "Created: / 18.5.1999 / 14:50:04 / cg"
ffe7bdb92f71 category renamining
Claus Gittinger <cg@exept.de>
parents: 5153
diff changeset
   221
! !
ffe7bdb92f71 category renamining
Claus Gittinger <cg@exept.de>
parents: 5153
diff changeset
   222
4414
dcf1a565095b checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4403
diff changeset
   223
!SequenceableCollection methodsFor:'Compatibility - Squeak'!
dcf1a565095b checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4403
diff changeset
   224
dcf1a565095b checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4403
diff changeset
   225
atPin: index 
dcf1a565095b checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4403
diff changeset
   226
    "Return the index'th element of me if possible.
dcf1a565095b checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4403
diff changeset
   227
     Return the first or last element if index is out of bounds."
dcf1a565095b checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4403
diff changeset
   228
dcf1a565095b checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4403
diff changeset
   229
    index < 1 ifTrue:[^ self first].
dcf1a565095b checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4403
diff changeset
   230
    index > self size ifTrue:[^ self last].
dcf1a565095b checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4403
diff changeset
   231
    ^ self at:index
dcf1a565095b checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4403
diff changeset
   232
dcf1a565095b checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4403
diff changeset
   233
    "
dcf1a565095b checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4403
diff changeset
   234
     #(1 2 3) atPin:4    
dcf1a565095b checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4403
diff changeset
   235
     #(1 2 3) atPin:0    
dcf1a565095b checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4403
diff changeset
   236
     #(1 2 3) atPin:1    
dcf1a565095b checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4403
diff changeset
   237
     #(1 2 3) atPin:3    
dcf1a565095b checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4403
diff changeset
   238
    "
4459
a0466230c74b checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4414
diff changeset
   239
!
a0466230c74b checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4414
diff changeset
   240
a0466230c74b checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4414
diff changeset
   241
atRandom 
a0466230c74b checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4414
diff changeset
   242
    "Return any random element from the receiver"
a0466230c74b checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4414
diff changeset
   243
a0466230c74b checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4414
diff changeset
   244
    |max idx|
a0466230c74b checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4414
diff changeset
   245
a0466230c74b checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4414
diff changeset
   246
    (max := self size) == 0 ifTrue:[
a0466230c74b checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4414
diff changeset
   247
        self emptyCollectionError
a0466230c74b checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4414
diff changeset
   248
    ].
a0466230c74b checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4414
diff changeset
   249
    idx := Random nextIntegerBetween:1 and:max.
a0466230c74b checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4414
diff changeset
   250
    ^ self at:idx
a0466230c74b checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4414
diff changeset
   251
a0466230c74b checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4414
diff changeset
   252
    "
a0466230c74b checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4414
diff changeset
   253
     #(1 2 3) atRandom  
a0466230c74b checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4414
diff changeset
   254
    "
4975
598ff2d009c1 added #atWrap:
Claus Gittinger <cg@exept.de>
parents: 4856
diff changeset
   255
!
598ff2d009c1 added #atWrap:
Claus Gittinger <cg@exept.de>
parents: 4856
diff changeset
   256
598ff2d009c1 added #atWrap:
Claus Gittinger <cg@exept.de>
parents: 4856
diff changeset
   257
atWrap:index 
598ff2d009c1 added #atWrap:
Claus Gittinger <cg@exept.de>
parents: 4856
diff changeset
   258
    "Return the index'th element of me if possible.
598ff2d009c1 added #atWrap:
Claus Gittinger <cg@exept.de>
parents: 4856
diff changeset
   259
     Wrap the index modulu the receivers size if it is out of bounds."
598ff2d009c1 added #atWrap:
Claus Gittinger <cg@exept.de>
parents: 4856
diff changeset
   260
598ff2d009c1 added #atWrap:
Claus Gittinger <cg@exept.de>
parents: 4856
diff changeset
   261
    ^ self at:((index - 1) \\ (self size)) + 1
598ff2d009c1 added #atWrap:
Claus Gittinger <cg@exept.de>
parents: 4856
diff changeset
   262
598ff2d009c1 added #atWrap:
Claus Gittinger <cg@exept.de>
parents: 4856
diff changeset
   263
    "
598ff2d009c1 added #atWrap:
Claus Gittinger <cg@exept.de>
parents: 4856
diff changeset
   264
     #(1 2 3) atWrap:1    
598ff2d009c1 added #atWrap:
Claus Gittinger <cg@exept.de>
parents: 4856
diff changeset
   265
     #(1 2 3) atWrap:2    
598ff2d009c1 added #atWrap:
Claus Gittinger <cg@exept.de>
parents: 4856
diff changeset
   266
     #(1 2 3) atWrap:3    
598ff2d009c1 added #atWrap:
Claus Gittinger <cg@exept.de>
parents: 4856
diff changeset
   267
     #(1 2 3) atWrap:4    
598ff2d009c1 added #atWrap:
Claus Gittinger <cg@exept.de>
parents: 4856
diff changeset
   268
     #(1 2 3) atWrap:5    
598ff2d009c1 added #atWrap:
Claus Gittinger <cg@exept.de>
parents: 4856
diff changeset
   269
     #(1 2 3) atWrap:6    
598ff2d009c1 added #atWrap:
Claus Gittinger <cg@exept.de>
parents: 4856
diff changeset
   270
     #(1 2 3) atWrap:7    
598ff2d009c1 added #atWrap:
Claus Gittinger <cg@exept.de>
parents: 4856
diff changeset
   271
     #(1 2 3) atWrap:0    
598ff2d009c1 added #atWrap:
Claus Gittinger <cg@exept.de>
parents: 4856
diff changeset
   272
     #(1 2 3) atWrap:-1    
598ff2d009c1 added #atWrap:
Claus Gittinger <cg@exept.de>
parents: 4856
diff changeset
   273
    "
5372
6c78e7ad3d5c added #beginsWith::
Claus Gittinger <cg@exept.de>
parents: 5358
diff changeset
   274
!
6c78e7ad3d5c added #beginsWith::
Claus Gittinger <cg@exept.de>
parents: 5358
diff changeset
   275
6c78e7ad3d5c added #beginsWith::
Claus Gittinger <cg@exept.de>
parents: 5358
diff changeset
   276
beginsWith:aCollection
6c78e7ad3d5c added #beginsWith::
Claus Gittinger <cg@exept.de>
parents: 5358
diff changeset
   277
    "same as #startsWith: - sigh"
6c78e7ad3d5c added #beginsWith::
Claus Gittinger <cg@exept.de>
parents: 5358
diff changeset
   278
6c78e7ad3d5c added #beginsWith::
Claus Gittinger <cg@exept.de>
parents: 5358
diff changeset
   279
    ^ self startsWith:aCollection
4414
dcf1a565095b checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4403
diff changeset
   280
! !
dcf1a565095b checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4403
diff changeset
   281
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   282
!SequenceableCollection methodsFor:'accessing'!
a27a279701f8 Initial revision
claus
parents:
diff changeset
   283
1366
531162d17aaa lifted #after: / #before:
Claus Gittinger <cg@exept.de>
parents: 1359
diff changeset
   284
after:anObject
531162d17aaa lifted #after: / #before:
Claus Gittinger <cg@exept.de>
parents: 1359
diff changeset
   285
    "return the element, after anObject.
5231
df6dd43af1c5 comments;
Claus Gittinger <cg@exept.de>
parents: 5220
diff changeset
   286
     If anObject is not in the receiver, report an error;
df6dd43af1c5 comments;
Claus Gittinger <cg@exept.de>
parents: 5220
diff changeset
   287
     if anObject is the last in the receiver, return nil.
1366
531162d17aaa lifted #after: / #before:
Claus Gittinger <cg@exept.de>
parents: 1359
diff changeset
   288
     This depends on #after:ifAbsent: being implemented in a concrete class."
531162d17aaa lifted #after: / #before:
Claus Gittinger <cg@exept.de>
parents: 1359
diff changeset
   289
531162d17aaa lifted #after: / #before:
Claus Gittinger <cg@exept.de>
parents: 1359
diff changeset
   290
    ^ self after:anObject ifAbsent:[self errorValueNotFound:anObject]
531162d17aaa lifted #after: / #before:
Claus Gittinger <cg@exept.de>
parents: 1359
diff changeset
   291
531162d17aaa lifted #after: / #before:
Claus Gittinger <cg@exept.de>
parents: 1359
diff changeset
   292
    "
531162d17aaa lifted #after: / #before:
Claus Gittinger <cg@exept.de>
parents: 1359
diff changeset
   293
     #(4 3 2 1) asOrderedCollection after:3. 
531162d17aaa lifted #after: / #before:
Claus Gittinger <cg@exept.de>
parents: 1359
diff changeset
   294
     #(4 3 2 1) asOrderedCollection after:5 
531162d17aaa lifted #after: / #before:
Claus Gittinger <cg@exept.de>
parents: 1359
diff changeset
   295
     #(4 3 2 1) asOrderedCollection after:1 
531162d17aaa lifted #after: / #before:
Claus Gittinger <cg@exept.de>
parents: 1359
diff changeset
   296
    "
531162d17aaa lifted #after: / #before:
Claus Gittinger <cg@exept.de>
parents: 1359
diff changeset
   297
531162d17aaa lifted #after: / #before:
Claus Gittinger <cg@exept.de>
parents: 1359
diff changeset
   298
    "Created: 10.5.1996 / 13:59:29 / cg"
531162d17aaa lifted #after: / #before:
Claus Gittinger <cg@exept.de>
parents: 1359
diff changeset
   299
    "Modified: 10.5.1996 / 14:03:33 / cg"
531162d17aaa lifted #after: / #before:
Claus Gittinger <cg@exept.de>
parents: 1359
diff changeset
   300
!
531162d17aaa lifted #after: / #before:
Claus Gittinger <cg@exept.de>
parents: 1359
diff changeset
   301
531162d17aaa lifted #after: / #before:
Claus Gittinger <cg@exept.de>
parents: 1359
diff changeset
   302
after:anObject ifAbsent:exceptionBlock
5231
df6dd43af1c5 comments;
Claus Gittinger <cg@exept.de>
parents: 5220
diff changeset
   303
    "return the element, after anObject. 
df6dd43af1c5 comments;
Claus Gittinger <cg@exept.de>
parents: 5220
diff changeset
   304
     If anObject is the last in the receiver, return nil.
df6dd43af1c5 comments;
Claus Gittinger <cg@exept.de>
parents: 5220
diff changeset
   305
     If there is no such element (anObject is not found),
1366
531162d17aaa lifted #after: / #before:
Claus Gittinger <cg@exept.de>
parents: 1359
diff changeset
   306
     return the value from exceptionBlock."
531162d17aaa lifted #after: / #before:
Claus Gittinger <cg@exept.de>
parents: 1359
diff changeset
   307
531162d17aaa lifted #after: / #before:
Claus Gittinger <cg@exept.de>
parents: 1359
diff changeset
   308
    ^ self subclassResponsibility
531162d17aaa lifted #after: / #before:
Claus Gittinger <cg@exept.de>
parents: 1359
diff changeset
   309
5231
df6dd43af1c5 comments;
Claus Gittinger <cg@exept.de>
parents: 5220
diff changeset
   310
    "
df6dd43af1c5 comments;
Claus Gittinger <cg@exept.de>
parents: 5220
diff changeset
   311
     #(4 3 2 1) asOrderedCollection after:3 ifAbsent:nil. 
df6dd43af1c5 comments;
Claus Gittinger <cg@exept.de>
parents: 5220
diff changeset
   312
     #(4 3 2 1) asOrderedCollection after:5 ifAbsent:nil. 
df6dd43af1c5 comments;
Claus Gittinger <cg@exept.de>
parents: 5220
diff changeset
   313
     #(4 3 2 1) asOrderedCollection after:5. 
df6dd43af1c5 comments;
Claus Gittinger <cg@exept.de>
parents: 5220
diff changeset
   314
    "
df6dd43af1c5 comments;
Claus Gittinger <cg@exept.de>
parents: 5220
diff changeset
   315
1366
531162d17aaa lifted #after: / #before:
Claus Gittinger <cg@exept.de>
parents: 1359
diff changeset
   316
!
531162d17aaa lifted #after: / #before:
Claus Gittinger <cg@exept.de>
parents: 1359
diff changeset
   317
32
ee1a621c696c *** empty log message ***
claus
parents: 13
diff changeset
   318
at:index ifAbsent:exceptionBlock
61
claus
parents: 44
diff changeset
   319
    "return the element at index if valid. 
claus
parents: 44
diff changeset
   320
     If the index is invalid, return the result of evaluating 
302
1f76060d58a4 *** empty log message ***
claus
parents: 293
diff changeset
   321
     the exceptionblock.
1f76060d58a4 *** empty log message ***
claus
parents: 293
diff changeset
   322
     NOTICE: 
5231
df6dd43af1c5 comments;
Claus Gittinger <cg@exept.de>
parents: 5220
diff changeset
   323
        in ST-80, this message is only defined for Dictionaries,
df6dd43af1c5 comments;
Claus Gittinger <cg@exept.de>
parents: 5220
diff changeset
   324
        however, having a common protocol with indexed collections
df6dd43af1c5 comments;
Claus Gittinger <cg@exept.de>
parents: 5220
diff changeset
   325
        often simplifies things."
32
ee1a621c696c *** empty log message ***
claus
parents: 13
diff changeset
   326
ee1a621c696c *** empty log message ***
claus
parents: 13
diff changeset
   327
    ((index < 1) or:[index > self size]) ifTrue:[
5231
df6dd43af1c5 comments;
Claus Gittinger <cg@exept.de>
parents: 5220
diff changeset
   328
        ^ exceptionBlock value
32
ee1a621c696c *** empty log message ***
claus
parents: 13
diff changeset
   329
    ].
ee1a621c696c *** empty log message ***
claus
parents: 13
diff changeset
   330
    ^ self at:index
ee1a621c696c *** empty log message ***
claus
parents: 13
diff changeset
   331
95
d22739a0c6e9 *** empty log message ***
claus
parents: 88
diff changeset
   332
    "
d22739a0c6e9 *** empty log message ***
claus
parents: 88
diff changeset
   333
     #(1 2 3) at:4 ifAbsent:['no such index']
302
1f76060d58a4 *** empty log message ***
claus
parents: 293
diff changeset
   334
     #(1 2 3) asOrderedCollection at:4 ifAbsent:['no such index'] 
5231
df6dd43af1c5 comments;
Claus Gittinger <cg@exept.de>
parents: 5220
diff changeset
   335
     #(1 2 3) at:4 ifAbsent:['no such index']  
302
1f76060d58a4 *** empty log message ***
claus
parents: 293
diff changeset
   336
95
d22739a0c6e9 *** empty log message ***
claus
parents: 88
diff changeset
   337
     (Dictionary with:(#foo -> #bar)
5231
df6dd43af1c5 comments;
Claus Gittinger <cg@exept.de>
parents: 5220
diff changeset
   338
                 with:(#frob -> #baz)) 
df6dd43af1c5 comments;
Claus Gittinger <cg@exept.de>
parents: 5220
diff changeset
   339
         at:#foobar ifAbsent:['no such index']
95
d22739a0c6e9 *** empty log message ***
claus
parents: 88
diff changeset
   340
    "
362
claus
parents: 360
diff changeset
   341
!
claus
parents: 360
diff changeset
   342
1366
531162d17aaa lifted #after: / #before:
Claus Gittinger <cg@exept.de>
parents: 1359
diff changeset
   343
before:anObject
531162d17aaa lifted #after: / #before:
Claus Gittinger <cg@exept.de>
parents: 1359
diff changeset
   344
    "return the element before the argument, anObject.
5231
df6dd43af1c5 comments;
Claus Gittinger <cg@exept.de>
parents: 5220
diff changeset
   345
     If anObject is not in the receiver, report an error;
df6dd43af1c5 comments;
Claus Gittinger <cg@exept.de>
parents: 5220
diff changeset
   346
     if anObject is the first in the receiver, return nil.
1366
531162d17aaa lifted #after: / #before:
Claus Gittinger <cg@exept.de>
parents: 1359
diff changeset
   347
     This depends on #before:ifAbsent: being implemented in a concrete class."
531162d17aaa lifted #after: / #before:
Claus Gittinger <cg@exept.de>
parents: 1359
diff changeset
   348
531162d17aaa lifted #after: / #before:
Claus Gittinger <cg@exept.de>
parents: 1359
diff changeset
   349
    ^ self before:anObject ifAbsent:[self errorValueNotFound:anObject]
531162d17aaa lifted #after: / #before:
Claus Gittinger <cg@exept.de>
parents: 1359
diff changeset
   350
531162d17aaa lifted #after: / #before:
Claus Gittinger <cg@exept.de>
parents: 1359
diff changeset
   351
    "
531162d17aaa lifted #after: / #before:
Claus Gittinger <cg@exept.de>
parents: 1359
diff changeset
   352
     #(4 3 2 1) asOrderedCollection before:3. 
531162d17aaa lifted #after: / #before:
Claus Gittinger <cg@exept.de>
parents: 1359
diff changeset
   353
     #(4 3 2 1) asOrderedCollection before:4 
531162d17aaa lifted #after: / #before:
Claus Gittinger <cg@exept.de>
parents: 1359
diff changeset
   354
     #(4 3 2 1) asOrderedCollection before:0 
531162d17aaa lifted #after: / #before:
Claus Gittinger <cg@exept.de>
parents: 1359
diff changeset
   355
    "
531162d17aaa lifted #after: / #before:
Claus Gittinger <cg@exept.de>
parents: 1359
diff changeset
   356
531162d17aaa lifted #after: / #before:
Claus Gittinger <cg@exept.de>
parents: 1359
diff changeset
   357
    "Created: 10.5.1996 / 14:03:27 / cg"
531162d17aaa lifted #after: / #before:
Claus Gittinger <cg@exept.de>
parents: 1359
diff changeset
   358
    "Modified: 10.5.1996 / 14:03:44 / cg"
531162d17aaa lifted #after: / #before:
Claus Gittinger <cg@exept.de>
parents: 1359
diff changeset
   359
!
531162d17aaa lifted #after: / #before:
Claus Gittinger <cg@exept.de>
parents: 1359
diff changeset
   360
531162d17aaa lifted #after: / #before:
Claus Gittinger <cg@exept.de>
parents: 1359
diff changeset
   361
before:anObject ifAbsent:exceptionBlock
5231
df6dd43af1c5 comments;
Claus Gittinger <cg@exept.de>
parents: 5220
diff changeset
   362
    "return the element, before anObject. 
df6dd43af1c5 comments;
Claus Gittinger <cg@exept.de>
parents: 5220
diff changeset
   363
     If anObject is the first in the receiver, return nil.
df6dd43af1c5 comments;
Claus Gittinger <cg@exept.de>
parents: 5220
diff changeset
   364
     If there is no such element (anObject is not found),
1366
531162d17aaa lifted #after: / #before:
Claus Gittinger <cg@exept.de>
parents: 1359
diff changeset
   365
     return the value from exceptionBlock."
531162d17aaa lifted #after: / #before:
Claus Gittinger <cg@exept.de>
parents: 1359
diff changeset
   366
531162d17aaa lifted #after: / #before:
Claus Gittinger <cg@exept.de>
parents: 1359
diff changeset
   367
    ^ self subclassResponsibility
531162d17aaa lifted #after: / #before:
Claus Gittinger <cg@exept.de>
parents: 1359
diff changeset
   368
5231
df6dd43af1c5 comments;
Claus Gittinger <cg@exept.de>
parents: 5220
diff changeset
   369
    "
df6dd43af1c5 comments;
Claus Gittinger <cg@exept.de>
parents: 5220
diff changeset
   370
     #(4 3 2 1) asOrderedCollection before:3 ifAbsent:nil. 
df6dd43af1c5 comments;
Claus Gittinger <cg@exept.de>
parents: 5220
diff changeset
   371
     #(4 3 2 1) asOrderedCollection before:5 ifAbsent:nil. 
df6dd43af1c5 comments;
Claus Gittinger <cg@exept.de>
parents: 5220
diff changeset
   372
     #(4 3 2 1) asOrderedCollection before:5. 
df6dd43af1c5 comments;
Claus Gittinger <cg@exept.de>
parents: 5220
diff changeset
   373
     #(4 3 2 1) asOrderedCollection before:4 ifAbsent:nil. 
df6dd43af1c5 comments;
Claus Gittinger <cg@exept.de>
parents: 5220
diff changeset
   374
     #(4 3 2 1) asOrderedCollection before:4.            
df6dd43af1c5 comments;
Claus Gittinger <cg@exept.de>
parents: 5220
diff changeset
   375
    "
df6dd43af1c5 comments;
Claus Gittinger <cg@exept.de>
parents: 5220
diff changeset
   376
1366
531162d17aaa lifted #after: / #before:
Claus Gittinger <cg@exept.de>
parents: 1359
diff changeset
   377
!
531162d17aaa lifted #after: / #before:
Claus Gittinger <cg@exept.de>
parents: 1359
diff changeset
   378
602
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
   379
first
5231
df6dd43af1c5 comments;
Claus Gittinger <cg@exept.de>
parents: 5220
diff changeset
   380
    "return the first element; 
df6dd43af1c5 comments;
Claus Gittinger <cg@exept.de>
parents: 5220
diff changeset
   381
     report an error, if the collection is empty."
602
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
   382
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
   383
    ^ self at:1
3468
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
   384
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
   385
    "
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
   386
     args:    
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
   387
     returns: firstElement <object>
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
   388
    "
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
   389
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
   390
    "Modified: / 20.5.1998 / 14:50:25 / cg"
362
claus
parents: 360
diff changeset
   391
!
claus
parents: 360
diff changeset
   392
4986
77673dfa1b48 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4975
diff changeset
   393
fourth
5231
df6dd43af1c5 comments;
Claus Gittinger <cg@exept.de>
parents: 5220
diff changeset
   394
    "return the fourth element;
df6dd43af1c5 comments;
Claus Gittinger <cg@exept.de>
parents: 5220
diff changeset
   395
     report an error, if the collections size is smaller than 4."
4986
77673dfa1b48 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4975
diff changeset
   396
77673dfa1b48 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4975
diff changeset
   397
    ^ self at:4
77673dfa1b48 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4975
diff changeset
   398
77673dfa1b48 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4975
diff changeset
   399
    "
77673dfa1b48 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4975
diff changeset
   400
     args:    
77673dfa1b48 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4975
diff changeset
   401
     returns: fourthElement <object>
77673dfa1b48 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4975
diff changeset
   402
    "
77673dfa1b48 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4975
diff changeset
   403
77673dfa1b48 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4975
diff changeset
   404
    "Modified: / 20.5.1998 / 14:50:25 / cg"
77673dfa1b48 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4975
diff changeset
   405
!
77673dfa1b48 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4975
diff changeset
   406
362
claus
parents: 360
diff changeset
   407
keyAtEqualValue:value
claus
parents: 360
diff changeset
   408
    "return the index of a value.
claus
parents: 360
diff changeset
   409
     This is normally not used (use indexOf:), but makes the
claus
parents: 360
diff changeset
   410
     protocol more compatible with dictionaries."
claus
parents: 360
diff changeset
   411
claus
parents: 360
diff changeset
   412
    ^ self indexOf:value
claus
parents: 360
diff changeset
   413
!
claus
parents: 360
diff changeset
   414
claus
parents: 360
diff changeset
   415
keyAtEqualValue:value ifAbsent:exceptionBlock
claus
parents: 360
diff changeset
   416
    "return the index of a value.
claus
parents: 360
diff changeset
   417
     This is normally not used (use indexOf:), but makes the
claus
parents: 360
diff changeset
   418
     protocol more compatible with dictionaries."
claus
parents: 360
diff changeset
   419
claus
parents: 360
diff changeset
   420
    ^ self indexOf:value ifAbsent:exceptionBlock
602
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
   421
!
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
   422
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
   423
keyAtValue:value
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
   424
    "return the index of a value.
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
   425
     This is normally not used (use indexOf:), but makes the
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
   426
     protocol more compatible with dictionaries."
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
   427
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
   428
    ^ self identityIndexOf:value
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
   429
!
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
   430
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
   431
keyAtValue:value ifAbsent:exceptionBlock
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
   432
    "return the index of a value.
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
   433
     This is normally not used (use indexOf:), but makes the
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
   434
     protocol more compatible with dictionaries."
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
   435
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
   436
    ^ self identityIndexOf:value ifAbsent:exceptionBlock
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
   437
!
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
last
5231
df6dd43af1c5 comments;
Claus Gittinger <cg@exept.de>
parents: 5220
diff changeset
   440
    "return the last element;
df6dd43af1c5 comments;
Claus Gittinger <cg@exept.de>
parents: 5220
diff changeset
   441
     report an error, if the collection is empty."
602
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
   442
3408
411024a56ffd check for being empty in #last
Claus Gittinger <cg@exept.de>
parents: 3234
diff changeset
   443
    |sz|
411024a56ffd check for being empty in #last
Claus Gittinger <cg@exept.de>
parents: 3234
diff changeset
   444
411024a56ffd check for being empty in #last
Claus Gittinger <cg@exept.de>
parents: 3234
diff changeset
   445
    (sz := self size) == 0 ifFalse:[
411024a56ffd check for being empty in #last
Claus Gittinger <cg@exept.de>
parents: 3234
diff changeset
   446
        ^ self at:sz
411024a56ffd check for being empty in #last
Claus Gittinger <cg@exept.de>
parents: 3234
diff changeset
   447
    ].
411024a56ffd check for being empty in #last
Claus Gittinger <cg@exept.de>
parents: 3234
diff changeset
   448
    "error if collection is empty"
411024a56ffd check for being empty in #last
Claus Gittinger <cg@exept.de>
parents: 3234
diff changeset
   449
    ^ self emptyCollectionError
411024a56ffd check for being empty in #last
Claus Gittinger <cg@exept.de>
parents: 3234
diff changeset
   450
5231
df6dd43af1c5 comments;
Claus Gittinger <cg@exept.de>
parents: 5220
diff changeset
   451
    "
df6dd43af1c5 comments;
Claus Gittinger <cg@exept.de>
parents: 5220
diff changeset
   452
     #(1 2 3 4 5) last
df6dd43af1c5 comments;
Claus Gittinger <cg@exept.de>
parents: 5220
diff changeset
   453
     #() last
df6dd43af1c5 comments;
Claus Gittinger <cg@exept.de>
parents: 5220
diff changeset
   454
    "
1370
b051117cc302 moved #upTo: down into SeqColl
Claus Gittinger <cg@exept.de>
parents: 1369
diff changeset
   455
!
b051117cc302 moved #upTo: down into SeqColl
Claus Gittinger <cg@exept.de>
parents: 1369
diff changeset
   456
4986
77673dfa1b48 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4975
diff changeset
   457
nth:n
5231
df6dd43af1c5 comments;
Claus Gittinger <cg@exept.de>
parents: 5220
diff changeset
   458
    "return the nth element;
df6dd43af1c5 comments;
Claus Gittinger <cg@exept.de>
parents: 5220
diff changeset
   459
     report an error, if the collections size is smaller than n."
4986
77673dfa1b48 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4975
diff changeset
   460
77673dfa1b48 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4975
diff changeset
   461
    ^ self at:n
77673dfa1b48 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4975
diff changeset
   462
77673dfa1b48 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4975
diff changeset
   463
    "
77673dfa1b48 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4975
diff changeset
   464
     args:    
77673dfa1b48 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4975
diff changeset
   465
     returns: nth element <object>
77673dfa1b48 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4975
diff changeset
   466
    "
77673dfa1b48 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4975
diff changeset
   467
5231
df6dd43af1c5 comments;
Claus Gittinger <cg@exept.de>
parents: 5220
diff changeset
   468
    "
df6dd43af1c5 comments;
Claus Gittinger <cg@exept.de>
parents: 5220
diff changeset
   469
     #(10 20 30 40 50) nth:4   
df6dd43af1c5 comments;
Claus Gittinger <cg@exept.de>
parents: 5220
diff changeset
   470
     #(10 20 30 40 50) nth:6
df6dd43af1c5 comments;
Claus Gittinger <cg@exept.de>
parents: 5220
diff changeset
   471
     #() nth:1
df6dd43af1c5 comments;
Claus Gittinger <cg@exept.de>
parents: 5220
diff changeset
   472
    "
df6dd43af1c5 comments;
Claus Gittinger <cg@exept.de>
parents: 5220
diff changeset
   473
4986
77673dfa1b48 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4975
diff changeset
   474
!
77673dfa1b48 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4975
diff changeset
   475
4855
d2abe6d95aa1 added #second
Claus Gittinger <cg@exept.de>
parents: 4807
diff changeset
   476
second
5231
df6dd43af1c5 comments;
Claus Gittinger <cg@exept.de>
parents: 5220
diff changeset
   477
    "return the second element;
df6dd43af1c5 comments;
Claus Gittinger <cg@exept.de>
parents: 5220
diff changeset
   478
     report an error, if the collections size is smaller than 2."
4855
d2abe6d95aa1 added #second
Claus Gittinger <cg@exept.de>
parents: 4807
diff changeset
   479
d2abe6d95aa1 added #second
Claus Gittinger <cg@exept.de>
parents: 4807
diff changeset
   480
    ^ self at:2
d2abe6d95aa1 added #second
Claus Gittinger <cg@exept.de>
parents: 4807
diff changeset
   481
d2abe6d95aa1 added #second
Claus Gittinger <cg@exept.de>
parents: 4807
diff changeset
   482
    "
d2abe6d95aa1 added #second
Claus Gittinger <cg@exept.de>
parents: 4807
diff changeset
   483
     args:    
d2abe6d95aa1 added #second
Claus Gittinger <cg@exept.de>
parents: 4807
diff changeset
   484
     returns: secondElement <object>
d2abe6d95aa1 added #second
Claus Gittinger <cg@exept.de>
parents: 4807
diff changeset
   485
    "
d2abe6d95aa1 added #second
Claus Gittinger <cg@exept.de>
parents: 4807
diff changeset
   486
d2abe6d95aa1 added #second
Claus Gittinger <cg@exept.de>
parents: 4807
diff changeset
   487
    "Modified: / 20.5.1998 / 14:50:25 / cg"
d2abe6d95aa1 added #second
Claus Gittinger <cg@exept.de>
parents: 4807
diff changeset
   488
!
d2abe6d95aa1 added #second
Claus Gittinger <cg@exept.de>
parents: 4807
diff changeset
   489
3037
1293e34a06cf added #swap:with: for compatibility
Claus Gittinger <cg@exept.de>
parents: 3003
diff changeset
   490
swap:index1 with:index2
1293e34a06cf added #swap:with: for compatibility
Claus Gittinger <cg@exept.de>
parents: 3003
diff changeset
   491
    "exchange two elements"
1293e34a06cf added #swap:with: for compatibility
Claus Gittinger <cg@exept.de>
parents: 3003
diff changeset
   492
1293e34a06cf added #swap:with: for compatibility
Claus Gittinger <cg@exept.de>
parents: 3003
diff changeset
   493
    |t|
1293e34a06cf added #swap:with: for compatibility
Claus Gittinger <cg@exept.de>
parents: 3003
diff changeset
   494
1293e34a06cf added #swap:with: for compatibility
Claus Gittinger <cg@exept.de>
parents: 3003
diff changeset
   495
    t := self at:index1.
1293e34a06cf added #swap:with: for compatibility
Claus Gittinger <cg@exept.de>
parents: 3003
diff changeset
   496
    self at:index1 put:(self at:index2).
1293e34a06cf added #swap:with: for compatibility
Claus Gittinger <cg@exept.de>
parents: 3003
diff changeset
   497
    self at:index2 put:t
1293e34a06cf added #swap:with: for compatibility
Claus Gittinger <cg@exept.de>
parents: 3003
diff changeset
   498
1293e34a06cf added #swap:with: for compatibility
Claus Gittinger <cg@exept.de>
parents: 3003
diff changeset
   499
    "Modified: 15.10.1997 / 19:27:08 / cg"
1293e34a06cf added #swap:with: for compatibility
Claus Gittinger <cg@exept.de>
parents: 3003
diff changeset
   500
!
1293e34a06cf added #swap:with: for compatibility
Claus Gittinger <cg@exept.de>
parents: 3003
diff changeset
   501
4856
2f28355b6e9f added #third
Claus Gittinger <cg@exept.de>
parents: 4855
diff changeset
   502
third
5231
df6dd43af1c5 comments;
Claus Gittinger <cg@exept.de>
parents: 5220
diff changeset
   503
    "return the third element;
df6dd43af1c5 comments;
Claus Gittinger <cg@exept.de>
parents: 5220
diff changeset
   504
     report an error, if the collections size is smaller than 3."
4856
2f28355b6e9f added #third
Claus Gittinger <cg@exept.de>
parents: 4855
diff changeset
   505
2f28355b6e9f added #third
Claus Gittinger <cg@exept.de>
parents: 4855
diff changeset
   506
    ^ self at:3
2f28355b6e9f added #third
Claus Gittinger <cg@exept.de>
parents: 4855
diff changeset
   507
2f28355b6e9f added #third
Claus Gittinger <cg@exept.de>
parents: 4855
diff changeset
   508
    "
2f28355b6e9f added #third
Claus Gittinger <cg@exept.de>
parents: 4855
diff changeset
   509
     args:    
2f28355b6e9f added #third
Claus Gittinger <cg@exept.de>
parents: 4855
diff changeset
   510
     returns: thirdElement <object>
2f28355b6e9f added #third
Claus Gittinger <cg@exept.de>
parents: 4855
diff changeset
   511
    "
2f28355b6e9f added #third
Claus Gittinger <cg@exept.de>
parents: 4855
diff changeset
   512
2f28355b6e9f added #third
Claus Gittinger <cg@exept.de>
parents: 4855
diff changeset
   513
    "Modified: / 20.5.1998 / 14:50:25 / cg"
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   514
! !
a27a279701f8 Initial revision
claus
parents:
diff changeset
   515
602
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
   516
!SequenceableCollection methodsFor:'adding & removing'!
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
   517
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
   518
add:anObject
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
   519
    "append the argument, anObject to the collection.
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
   520
     Return the argument, anObject.
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
    |newSize|
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
   528
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
   529
    newSize := self size + 1.
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
   530
    self grow:newSize.
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
   531
    self at:newSize put:anObject.
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
   532
    ^ anObject
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
   533
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
   534
    "
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
   535
     |a|
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
   536
     a := #(1 2 3 4 5 6 7 8).
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
   537
     a add:'hello'.
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
   538
     a
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
   539
    "
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
   540
    "
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
   541
     |c|
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
   542
     c := #(1 2 3 4 5 6 7 8) asOrderedCollection.
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
   543
     c add:'hello'.
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
   544
     c
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
   545
    "
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
   546
!
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
   547
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
   548
add:anElement beforeIndex:index
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
   549
    "insert the first argument, anObject into the collection before slot index.
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
   550
     Return the receiver (sigh - ST-80 compatibility).
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
   551
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
   552
     Notice, that this is modifies the receiver NOT a copy.
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
   553
     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
   554
     due to the grow:-message, which is inefficient for fixed size 
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
   555
     collections (i.e. for Strings and Arrays it is not recommened)."
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
   556
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
   557
    |newSize|
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
    newSize := self size + 1.
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
   560
    self grow:newSize.
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
   561
    self replaceFrom:index + 1 to:newSize with:self startingAt:index.
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
   562
    self at:index put:anElement
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
   563
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
   564
    "
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
   565
     #(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
   566
    "
202
40ca7cc6fb9c *** empty log message ***
claus
parents: 186
diff changeset
   567
!
40ca7cc6fb9c *** empty log message ***
claus
parents: 186
diff changeset
   568
602
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
   569
addFirst:anObject
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
   570
    "prepend the argument, anObject to the collection.
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
   571
     Return the argument, anObject.
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
   572
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
   573
     Notice, that this is modifies the receiver NOT a copy.
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
   574
     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
   575
     due to the grow:-message, which is inefficient for fixed size 
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
   576
     collections (i.e. for Strings and Arrays it is not recommened)."
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
   577
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
   578
    |newSize|
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
   579
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
   580
    newSize := self size + 1.
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
   581
    self grow:newSize.
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
   582
    self replaceFrom:2 to:newSize with:self startingAt:1.
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
   583
    self at:1 put:anObject.
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
   584
    ^ anObject
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
   585
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
   586
    "
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
   587
     |a| 
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
   588
     a:= #(1 2 3 4 5 6 7 8). 
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
   589
     a addFirst:'hello'. 
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
   590
     a 
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
   591
    "
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
   592
    "
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
   593
     |c|
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
   594
     c := #(1 2 3 4 5 6 7 8) asOrderedCollection.
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
   595
     c addFirst:'hello'.
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
   596
     c
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
   597
    "
69
4564b6328136 *** empty log message ***
claus
parents: 61
diff changeset
   598
!
4564b6328136 *** empty log message ***
claus
parents: 61
diff changeset
   599
602
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
   600
remove:anElement ifAbsent:aBlock
2346
7ebe79ad61a3 added #removeIdentical:ifAbsent:
Claus Gittinger <cg@exept.de>
parents: 2294
diff changeset
   601
    "search for an object which is equal to anElement;
7ebe79ad61a3 added #removeIdentical:ifAbsent:
Claus Gittinger <cg@exept.de>
parents: 2294
diff changeset
   602
     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
   603
     Use equality compare (=) to search for an occurrence.
602
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
     Notice, that this is modifies the receiver NOT a copy.
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
   606
     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
   607
     due to the grow:-message, which is inefficient for fixed size 
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
   608
     collections (i.e. for Strings and Arrays it is not recommened)."
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
    |any 
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
   611
     dstIndex "{ Class: SmallInteger }"
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
   612
     sz       "{ Class: SmallInteger }"|
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
   613
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
   614
    dstIndex := 1.
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
   615
    any := false.
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
   616
    sz := self size.
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
   617
    1 to:sz do:[:srcIndex |
2346
7ebe79ad61a3 added #removeIdentical:ifAbsent:
Claus Gittinger <cg@exept.de>
parents: 2294
diff changeset
   618
        (anElement = (self at:srcIndex)) ifTrue:[
7ebe79ad61a3 added #removeIdentical:ifAbsent:
Claus Gittinger <cg@exept.de>
parents: 2294
diff changeset
   619
            any := true
7ebe79ad61a3 added #removeIdentical:ifAbsent:
Claus Gittinger <cg@exept.de>
parents: 2294
diff changeset
   620
        ] ifFalse:[
7ebe79ad61a3 added #removeIdentical:ifAbsent:
Claus Gittinger <cg@exept.de>
parents: 2294
diff changeset
   621
            (dstIndex ~~ srcIndex) ifTrue:[
7ebe79ad61a3 added #removeIdentical:ifAbsent:
Claus Gittinger <cg@exept.de>
parents: 2294
diff changeset
   622
                self at:dstIndex put:(self at:srcIndex)
7ebe79ad61a3 added #removeIdentical:ifAbsent:
Claus Gittinger <cg@exept.de>
parents: 2294
diff changeset
   623
            ].
7ebe79ad61a3 added #removeIdentical:ifAbsent:
Claus Gittinger <cg@exept.de>
parents: 2294
diff changeset
   624
            dstIndex := dstIndex + 1
7ebe79ad61a3 added #removeIdentical:ifAbsent:
Claus Gittinger <cg@exept.de>
parents: 2294
diff changeset
   625
        ]
602
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
    any ifTrue:[
2346
7ebe79ad61a3 added #removeIdentical:ifAbsent:
Claus Gittinger <cg@exept.de>
parents: 2294
diff changeset
   628
        self grow:dstIndex - 1.
7ebe79ad61a3 added #removeIdentical:ifAbsent:
Claus Gittinger <cg@exept.de>
parents: 2294
diff changeset
   629
        ^ anElement
602
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
   630
    ].
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
   631
    ^ aBlock value
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
   632
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
   633
    "
1422
9a0b792f2953 showCr: -> showCR:
Claus Gittinger <cg@exept.de>
parents: 1421
diff changeset
   634
     #(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
   635
     #(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
   636
     #(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
   637
     #(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
   638
    "
2346
7ebe79ad61a3 added #removeIdentical:ifAbsent:
Claus Gittinger <cg@exept.de>
parents: 2294
diff changeset
   639
7ebe79ad61a3 added #removeIdentical:ifAbsent:
Claus Gittinger <cg@exept.de>
parents: 2294
diff changeset
   640
    "Modified: 1.2.1997 / 11:49:01 / cg"
602
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
   641
!
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
   642
1369
5e7b6fabd248 raised #atAll:put: up in the hierarchy
Claus Gittinger <cg@exept.de>
parents: 1366
diff changeset
   643
removeAllSuchThat:aBlock
5e7b6fabd248 raised #atAll:put: up in the hierarchy
Claus Gittinger <cg@exept.de>
parents: 1366
diff changeset
   644
    "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
   645
     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
   646
     for which it returns true, are removed.
5e7b6fabd248 raised #atAll:put: up in the hierarchy
Claus Gittinger <cg@exept.de>
parents: 1366
diff changeset
   647
     Return a collection containing the removed elements."
5e7b6fabd248 raised #atAll:put: up in the hierarchy
Claus Gittinger <cg@exept.de>
parents: 1366
diff changeset
   648
5e7b6fabd248 raised #atAll:put: up in the hierarchy
Claus Gittinger <cg@exept.de>
parents: 1366
diff changeset
   649
    "/ 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
   650
5e7b6fabd248 raised #atAll:put: up in the hierarchy
Claus Gittinger <cg@exept.de>
parents: 1366
diff changeset
   651
    |runIndex removed element|
5e7b6fabd248 raised #atAll:put: up in the hierarchy
Claus Gittinger <cg@exept.de>
parents: 1366
diff changeset
   652
5e7b6fabd248 raised #atAll:put: up in the hierarchy
Claus Gittinger <cg@exept.de>
parents: 1366
diff changeset
   653
    removed := self species new.
5e7b6fabd248 raised #atAll:put: up in the hierarchy
Claus Gittinger <cg@exept.de>
parents: 1366
diff changeset
   654
5e7b6fabd248 raised #atAll:put: up in the hierarchy
Claus Gittinger <cg@exept.de>
parents: 1366
diff changeset
   655
    runIndex := 1.
5e7b6fabd248 raised #atAll:put: up in the hierarchy
Claus Gittinger <cg@exept.de>
parents: 1366
diff changeset
   656
    [runIndex <= self size] whileTrue:[
5e7b6fabd248 raised #atAll:put: up in the hierarchy
Claus Gittinger <cg@exept.de>
parents: 1366
diff changeset
   657
        element := self at:runIndex.
5e7b6fabd248 raised #atAll:put: up in the hierarchy
Claus Gittinger <cg@exept.de>
parents: 1366
diff changeset
   658
        (aBlock value:element) ifTrue:[
5e7b6fabd248 raised #atAll:put: up in the hierarchy
Claus Gittinger <cg@exept.de>
parents: 1366
diff changeset
   659
            removed add:element.
5e7b6fabd248 raised #atAll:put: up in the hierarchy
Claus Gittinger <cg@exept.de>
parents: 1366
diff changeset
   660
            self removeAtIndex:runIndex
5e7b6fabd248 raised #atAll:put: up in the hierarchy
Claus Gittinger <cg@exept.de>
parents: 1366
diff changeset
   661
        ] ifFalse:[
5e7b6fabd248 raised #atAll:put: up in the hierarchy
Claus Gittinger <cg@exept.de>
parents: 1366
diff changeset
   662
            runIndex := runIndex + 1
5e7b6fabd248 raised #atAll:put: up in the hierarchy
Claus Gittinger <cg@exept.de>
parents: 1366
diff changeset
   663
        ]
5e7b6fabd248 raised #atAll:put: up in the hierarchy
Claus Gittinger <cg@exept.de>
parents: 1366
diff changeset
   664
    ].
5e7b6fabd248 raised #atAll:put: up in the hierarchy
Claus Gittinger <cg@exept.de>
parents: 1366
diff changeset
   665
    ^ removed
5e7b6fabd248 raised #atAll:put: up in the hierarchy
Claus Gittinger <cg@exept.de>
parents: 1366
diff changeset
   666
5e7b6fabd248 raised #atAll:put: up in the hierarchy
Claus Gittinger <cg@exept.de>
parents: 1366
diff changeset
   667
    "
5e7b6fabd248 raised #atAll:put: up in the hierarchy
Claus Gittinger <cg@exept.de>
parents: 1366
diff changeset
   668
     |coll|
5e7b6fabd248 raised #atAll:put: up in the hierarchy
Claus Gittinger <cg@exept.de>
parents: 1366
diff changeset
   669
5e7b6fabd248 raised #atAll:put: up in the hierarchy
Claus Gittinger <cg@exept.de>
parents: 1366
diff changeset
   670
     coll := OrderedCollection withAll:(1 to:10).
1422
9a0b792f2953 showCr: -> showCR:
Claus Gittinger <cg@exept.de>
parents: 1421
diff changeset
   671
     Transcript showCR:(coll removeAllSuchThat:[:el | el even]).
9a0b792f2953 showCr: -> showCR:
Claus Gittinger <cg@exept.de>
parents: 1421
diff changeset
   672
     Transcript showCR:coll
1369
5e7b6fabd248 raised #atAll:put: up in the hierarchy
Claus Gittinger <cg@exept.de>
parents: 1366
diff changeset
   673
    "
5e7b6fabd248 raised #atAll:put: up in the hierarchy
Claus Gittinger <cg@exept.de>
parents: 1366
diff changeset
   674
5e7b6fabd248 raised #atAll:put: up in the hierarchy
Claus Gittinger <cg@exept.de>
parents: 1366
diff changeset
   675
    "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
   676
!
5e7b6fabd248 raised #atAll:put: up in the hierarchy
Claus Gittinger <cg@exept.de>
parents: 1366
diff changeset
   677
602
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
   678
removeAtIndex:anIndex
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
   679
    "remove the element stored at anIndex. Return the removed object.
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
   680
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
   681
     Notice, that this is modifies the receiver NOT a copy.
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
   682
     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
   683
     due to the grow:-message, which is inefficient for fixed size 
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
   684
     collections (i.e. for Strings and Arrays it is not recommened)."
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
   685
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
   686
    |element|
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
    element := self at:anIndex.
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
   689
    self removeFromIndex:anIndex toIndex:anIndex.
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
   690
    ^ element
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
   691
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
   692
    "
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
   693
     #(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
   694
     #(1 2 3 4 5) asOrderedCollection removeAtIndex:6
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
   695
     #($a $b $c $d $e $f $g) removeAtIndex:3
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
   696
    "
13
62303f84ff5f *** empty log message ***
claus
parents: 5
diff changeset
   697
!
62303f84ff5f *** empty log message ***
claus
parents: 5
diff changeset
   698
602
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
   699
removeFirst
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
   700
    "remove the first element of the receiver and return it.
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
   701
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
   702
     Notice, that this is modifies the receiver NOT a copy.
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
   703
     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
   704
     due to the grow:-message, which is inefficient for fixed size 
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
   705
     collections (i.e. for Strings and Arrays it is not recommened)."
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
   706
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
   707
    ^ self removeAtIndex:1
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
   708
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
   709
    "
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
   710
     |a|
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
   711
     a := #(1 2 3 4 5 6).
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
   712
     a removeFirst.
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
   713
     a 
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
   714
    "
13
62303f84ff5f *** empty log message ***
claus
parents: 5
diff changeset
   715
!
62303f84ff5f *** empty log message ***
claus
parents: 5
diff changeset
   716
2294
ed349da6fa4e added #removeFromIndex:
Claus Gittinger <cg@exept.de>
parents: 2275
diff changeset
   717
removeFromIndex:startIndex
ed349da6fa4e added #removeFromIndex:
Claus Gittinger <cg@exept.de>
parents: 2275
diff changeset
   718
    "remove the elements stored at indexes from startIndex to the end.
ed349da6fa4e added #removeFromIndex:
Claus Gittinger <cg@exept.de>
parents: 2275
diff changeset
   719
     Return the receiver.
ed349da6fa4e added #removeFromIndex:
Claus Gittinger <cg@exept.de>
parents: 2275
diff changeset
   720
     Returning the receiver is a historic leftover - it may at one
ed349da6fa4e added #removeFromIndex:
Claus Gittinger <cg@exept.de>
parents: 2275
diff changeset
   721
     time return a collection of the removed elements.
ed349da6fa4e added #removeFromIndex:
Claus Gittinger <cg@exept.de>
parents: 2275
diff changeset
   722
ed349da6fa4e added #removeFromIndex:
Claus Gittinger <cg@exept.de>
parents: 2275
diff changeset
   723
     Notice, that this is modifies the receiver - NOT a copy; 
ed349da6fa4e added #removeFromIndex:
Claus Gittinger <cg@exept.de>
parents: 2275
diff changeset
   724
     therefore any other users of the receiver will also see this change.
ed349da6fa4e added #removeFromIndex:
Claus Gittinger <cg@exept.de>
parents: 2275
diff changeset
   725
     Also note, that it may be a slow operation for some collections,
ed349da6fa4e added #removeFromIndex:
Claus Gittinger <cg@exept.de>
parents: 2275
diff changeset
   726
     due to the grow:-message, which is inefficient for fixed size 
ed349da6fa4e added #removeFromIndex:
Claus Gittinger <cg@exept.de>
parents: 2275
diff changeset
   727
     collections (i.e. for Strings and Arrays it is not recommened)."
ed349da6fa4e added #removeFromIndex:
Claus Gittinger <cg@exept.de>
parents: 2275
diff changeset
   728
ed349da6fa4e added #removeFromIndex:
Claus Gittinger <cg@exept.de>
parents: 2275
diff changeset
   729
    ^ self removeFromIndex:startIndex toIndex:(self size)
ed349da6fa4e added #removeFromIndex:
Claus Gittinger <cg@exept.de>
parents: 2275
diff changeset
   730
ed349da6fa4e added #removeFromIndex:
Claus Gittinger <cg@exept.de>
parents: 2275
diff changeset
   731
    "
ed349da6fa4e added #removeFromIndex:
Claus Gittinger <cg@exept.de>
parents: 2275
diff changeset
   732
     #(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
   733
     #(1 2 3 4 5 6 7 8 9 0) removeFromIndex:3
ed349da6fa4e added #removeFromIndex:
Claus Gittinger <cg@exept.de>
parents: 2275
diff changeset
   734
    "
ed349da6fa4e added #removeFromIndex:
Claus Gittinger <cg@exept.de>
parents: 2275
diff changeset
   735
ed349da6fa4e added #removeFromIndex:
Claus Gittinger <cg@exept.de>
parents: 2275
diff changeset
   736
    "Modified: 28.1.1997 / 12:35:20 / cg"
ed349da6fa4e added #removeFromIndex:
Claus Gittinger <cg@exept.de>
parents: 2275
diff changeset
   737
!
ed349da6fa4e added #removeFromIndex:
Claus Gittinger <cg@exept.de>
parents: 2275
diff changeset
   738
602
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
   739
removeFromIndex:startIndex toIndex:endIndex
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
   740
    "remove the elements stored at indexes between startIndex and endIndex.
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
   741
     Return the receiver.
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
   742
     Returning the receiver is a historic leftover - it may at one
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
   743
     time return a collection of the removed elements.
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
   744
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
   745
     Notice, that this is modifies the receiver - NOT a copy; 
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
   746
     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
   747
     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
   748
     due to the grow:-message, which is inefficient for fixed size 
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
   749
     collections (i.e. for Strings and Arrays it is not recommened)."
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
   750
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
   751
    |size newSize|
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
   752
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
   753
    (endIndex >= (size := self size)) ifTrue:[
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
   754
	self grow:(startIndex - 1)
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
   755
    ] ifFalse:[
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
   756
	newSize := size - endIndex + startIndex - 1.
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
   757
	self replaceFrom:startIndex to:newSize with:self startingAt:(endIndex + 1).
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
   758
	self grow:newSize
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
   759
    ]
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
   760
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
   761
"/    |newSize|
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
"/    newSize := self size - endIndex + startIndex - 1.
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
   764
"/    newSize <= 0 ifTrue:[
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
   765
"/        self grow:0
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
   766
"/    ] ifFalse:[
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
   767
"/        self replaceFrom:startIndex to:newSize with:self startingAt:(endIndex + 1).
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
   768
"/        self grow:newSize
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
   769
"/    ]
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
     #(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
   773
     #(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
   774
     #(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
   775
     #(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
   776
    "
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
   777
!
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
   778
2346
7ebe79ad61a3 added #removeIdentical:ifAbsent:
Claus Gittinger <cg@exept.de>
parents: 2294
diff changeset
   779
removeIdentical:anElement ifAbsent:aBlock
7ebe79ad61a3 added #removeIdentical:ifAbsent:
Claus Gittinger <cg@exept.de>
parents: 2294
diff changeset
   780
    "search for an object which is identical to anElement;
7ebe79ad61a3 added #removeIdentical:ifAbsent:
Claus Gittinger <cg@exept.de>
parents: 2294
diff changeset
   781
     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
   782
     Uses identity compare (==) to search for an occurrence.
2346
7ebe79ad61a3 added #removeIdentical:ifAbsent:
Claus Gittinger <cg@exept.de>
parents: 2294
diff changeset
   783
7ebe79ad61a3 added #removeIdentical:ifAbsent:
Claus Gittinger <cg@exept.de>
parents: 2294
diff changeset
   784
     Notice, that this is modifies the receiver NOT a copy.
7ebe79ad61a3 added #removeIdentical:ifAbsent:
Claus Gittinger <cg@exept.de>
parents: 2294
diff changeset
   785
     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
   786
     due to the grow:-message, which is inefficient for fixed size 
7ebe79ad61a3 added #removeIdentical:ifAbsent:
Claus Gittinger <cg@exept.de>
parents: 2294
diff changeset
   787
     collections (i.e. for Strings and Arrays it is not recommened)."
7ebe79ad61a3 added #removeIdentical:ifAbsent:
Claus Gittinger <cg@exept.de>
parents: 2294
diff changeset
   788
2363
57cc0807827a checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2347
diff changeset
   789
    |any el
2346
7ebe79ad61a3 added #removeIdentical:ifAbsent:
Claus Gittinger <cg@exept.de>
parents: 2294
diff changeset
   790
     dstIndex "{ Class: SmallInteger }"
7ebe79ad61a3 added #removeIdentical:ifAbsent:
Claus Gittinger <cg@exept.de>
parents: 2294
diff changeset
   791
     sz       "{ Class: SmallInteger }"|
7ebe79ad61a3 added #removeIdentical:ifAbsent:
Claus Gittinger <cg@exept.de>
parents: 2294
diff changeset
   792
7ebe79ad61a3 added #removeIdentical:ifAbsent:
Claus Gittinger <cg@exept.de>
parents: 2294
diff changeset
   793
    dstIndex := 1.
7ebe79ad61a3 added #removeIdentical:ifAbsent:
Claus Gittinger <cg@exept.de>
parents: 2294
diff changeset
   794
    any := false.
7ebe79ad61a3 added #removeIdentical:ifAbsent:
Claus Gittinger <cg@exept.de>
parents: 2294
diff changeset
   795
    sz := self size.
7ebe79ad61a3 added #removeIdentical:ifAbsent:
Claus Gittinger <cg@exept.de>
parents: 2294
diff changeset
   796
    1 to:sz do:[:srcIndex |
2363
57cc0807827a checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2347
diff changeset
   797
        el := self at:srcIndex.
57cc0807827a checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2347
diff changeset
   798
        (anElement == el) ifTrue:[
2346
7ebe79ad61a3 added #removeIdentical:ifAbsent:
Claus Gittinger <cg@exept.de>
parents: 2294
diff changeset
   799
            any := true
7ebe79ad61a3 added #removeIdentical:ifAbsent:
Claus Gittinger <cg@exept.de>
parents: 2294
diff changeset
   800
        ] ifFalse:[
7ebe79ad61a3 added #removeIdentical:ifAbsent:
Claus Gittinger <cg@exept.de>
parents: 2294
diff changeset
   801
            (dstIndex ~~ srcIndex) ifTrue:[
2363
57cc0807827a checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2347
diff changeset
   802
                self at:dstIndex put:el
2346
7ebe79ad61a3 added #removeIdentical:ifAbsent:
Claus Gittinger <cg@exept.de>
parents: 2294
diff changeset
   803
            ].
7ebe79ad61a3 added #removeIdentical:ifAbsent:
Claus Gittinger <cg@exept.de>
parents: 2294
diff changeset
   804
            dstIndex := dstIndex + 1
7ebe79ad61a3 added #removeIdentical:ifAbsent:
Claus Gittinger <cg@exept.de>
parents: 2294
diff changeset
   805
        ]
7ebe79ad61a3 added #removeIdentical:ifAbsent:
Claus Gittinger <cg@exept.de>
parents: 2294
diff changeset
   806
    ].
7ebe79ad61a3 added #removeIdentical:ifAbsent:
Claus Gittinger <cg@exept.de>
parents: 2294
diff changeset
   807
    any ifTrue:[
7ebe79ad61a3 added #removeIdentical:ifAbsent:
Claus Gittinger <cg@exept.de>
parents: 2294
diff changeset
   808
        self grow:dstIndex - 1.
7ebe79ad61a3 added #removeIdentical:ifAbsent:
Claus Gittinger <cg@exept.de>
parents: 2294
diff changeset
   809
        ^ anElement
7ebe79ad61a3 added #removeIdentical:ifAbsent:
Claus Gittinger <cg@exept.de>
parents: 2294
diff changeset
   810
    ].
7ebe79ad61a3 added #removeIdentical:ifAbsent:
Claus Gittinger <cg@exept.de>
parents: 2294
diff changeset
   811
    ^ aBlock value
7ebe79ad61a3 added #removeIdentical:ifAbsent:
Claus Gittinger <cg@exept.de>
parents: 2294
diff changeset
   812
7ebe79ad61a3 added #removeIdentical:ifAbsent:
Claus Gittinger <cg@exept.de>
parents: 2294
diff changeset
   813
    "
2347
b79cdb6b553e added #removeIdentical:ifAbsent:
Claus Gittinger <cg@exept.de>
parents: 2346
diff changeset
   814
     #(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
   815
     #(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
   816
    "
7ebe79ad61a3 added #removeIdentical:ifAbsent:
Claus Gittinger <cg@exept.de>
parents: 2294
diff changeset
   817
2363
57cc0807827a checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2347
diff changeset
   818
    "Modified: 8.2.1997 / 16:26:49 / cg"
2346
7ebe79ad61a3 added #removeIdentical:ifAbsent:
Claus Gittinger <cg@exept.de>
parents: 2294
diff changeset
   819
!
7ebe79ad61a3 added #removeIdentical:ifAbsent:
Claus Gittinger <cg@exept.de>
parents: 2294
diff changeset
   820
602
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
   821
removeIndex:index
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
   822
    "remove the argument stored at index. Return the receiver.
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
   823
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
   824
     Notice, that this is modifies the receiver NOT a copy.
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
   825
     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
   826
     due to the grow:-message, which is inefficient for fixed size 
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
   827
     collections (i.e. for Strings and Arrays it is not recommened)."
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
    self removeFromIndex:index toIndex:index
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
   830
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
   831
    "
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
   832
     #(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
   833
     #(1 2 3 4 5) asOrderedCollection removeIndex:6
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
   834
     #($a $b $c $d $e $f $g) removeIndex:3
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
   835
    "
77
6c38ca59927f *** empty log message ***
claus
parents: 69
diff changeset
   836
!
6c38ca59927f *** empty log message ***
claus
parents: 69
diff changeset
   837
602
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
   838
removeLast
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
   839
    "remove the last element of the receiver and return it.
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
   840
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
   841
     Notice, that this is modifies the receiver NOT a copy.
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
   842
     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
   843
     due to the grow:-message, which is inefficient for fixed size
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
   844
     collections (i.e. for Strings and Arrays it is not recommened)."
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
   845
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
   846
    ^ self removeAtIndex:(self size) 
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
     |a|
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
   850
     a := #(1 2 3 4 5 6).
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
   851
     a removeLast.
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
   852
     a   
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
   853
    "
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
!SequenceableCollection methodsFor:'comparing'!
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
   857
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
   858
= aCollection
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
   859
    "return true if the receiver and aCollection represent collections
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
   860
     with equal contents."
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
   861
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
   862
    |index "{ Class: SmallInteger }"
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
   863
     stop  "{ Class: SmallInteger }" |
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
   864
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
   865
    (aCollection == self) ifTrue:[^true].
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
   866
    (aCollection isSequenceable) ifFalse:[^false].
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
   867
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
   868
    stop := self size.
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
   869
    stop == (aCollection size) ifFalse:[^false].
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
   870
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
   871
    index := 1.
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
   872
    [index <= stop] whileTrue:[
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
   873
	(self at:index) = (aCollection at:index) ifFalse:[^false].
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
   874
	index := index + 1
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
   875
    ].
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
   876
    ^ true
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
    "
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
   879
     #(1 2 3 4 5) = #(1 2 3 4 5)                        
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
   880
     #($1 $2 $3 $4 $5) = #(1 2 3 4 5)                   
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
   881
     #($1 $2 $3 $4 $5) = '12345'                       
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
   882
     #($1 $2 $3 $4 $5) = '54321' asSortedCollection   
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
   883
    "
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
   884
!
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
   885
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
   886
endsWith:aCollection
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
   887
    "return true, if the receivers last elements match those
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
   888
     of aCollection"
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
   889
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
   890
    |index1 "{ Class: SmallInteger }"
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
   891
     index2 "{ Class: SmallInteger }" 
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
   892
     stop   "{ Class: SmallInteger }" 
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
   893
     sz     "{ Class: SmallInteger }"|
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
   894
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
   895
    (aCollection == self) ifTrue:[^ true].
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
   896
    (aCollection isSequenceable) ifFalse:[^ false].
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
   897
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
   898
    stop := aCollection size.
77
6c38ca59927f *** empty log message ***
claus
parents: 69
diff changeset
   899
    sz := self size.
602
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
   900
    stop > sz ifTrue:[^false].
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
   901
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
   902
    index1 := sz.
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
   903
    index2 := stop.
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
   904
    [index2 > 0] whileTrue:[
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
   905
	(self at:index1) = (aCollection at:index2) ifFalse:[^ false].
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
   906
	index1 := index1 - 1.
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
   907
	index2 := index2 - 1
77
6c38ca59927f *** empty log message ***
claus
parents: 69
diff changeset
   908
    ].
602
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
   909
    ^ true
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
   910
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
   911
    "
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
   912
     'abcde' endsWith:#($d $e)
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
   913
     #[1 2 3 4] endsWith:#(3 4)    
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
   914
     #(1 2 3 4) asOrderedCollection endsWith:#(3 4)
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
   915
    "
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
   916
!
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
   917
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
   918
hash
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
   919
    "return a hash key for the receiver"
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
   920
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
   921
    "this hash is stupid - but for larger collections, the hashing
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
   922
     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
   923
     Time will show ..."
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
   924
3653
cc018fcae490 added #copyReplaceAll:with:
Claus Gittinger <cg@exept.de>
parents: 3645
diff changeset
   925
    |mySize|
cc018fcae490 added #copyReplaceAll:with:
Claus Gittinger <cg@exept.de>
parents: 3645
diff changeset
   926
cc018fcae490 added #copyReplaceAll:with:
Claus Gittinger <cg@exept.de>
parents: 3645
diff changeset
   927
    mySize := self size.
cc018fcae490 added #copyReplaceAll:with:
Claus Gittinger <cg@exept.de>
parents: 3645
diff changeset
   928
    mySize == 0 ifTrue:[^ 0].
cc018fcae490 added #copyReplaceAll:with:
Claus Gittinger <cg@exept.de>
parents: 3645
diff changeset
   929
    ^ ((self at:1) hash times:mySize) bitAnd:16r3FFFFFFF
602
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
   930
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
   931
    "
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
   932
     #(1 2 3 4 5) hash
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
   933
     #(1 2 3 4 5.0) asOrderedCollection hash
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
   934
    "
3653
cc018fcae490 added #copyReplaceAll:with:
Claus Gittinger <cg@exept.de>
parents: 3645
diff changeset
   935
cc018fcae490 added #copyReplaceAll:with:
Claus Gittinger <cg@exept.de>
parents: 3645
diff changeset
   936
    "Modified: / 27.3.1998 / 17:33:49 / cg"
602
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
   937
!
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
   938
5275
87127c0e3167 added identity-element compare: #identicalContentsAs:
Claus Gittinger <cg@exept.de>
parents: 5231
diff changeset
   939
identicalContentsAs:aCollection
87127c0e3167 added identity-element compare: #identicalContentsAs:
Claus Gittinger <cg@exept.de>
parents: 5231
diff changeset
   940
    "return true if the receiver and aCollection represent collections
87127c0e3167 added identity-element compare: #identicalContentsAs:
Claus Gittinger <cg@exept.de>
parents: 5231
diff changeset
   941
     with identical contents. This is much like #=, but compares
87127c0e3167 added identity-element compare: #identicalContentsAs:
Claus Gittinger <cg@exept.de>
parents: 5231
diff changeset
   942
     elements using #== instead of #=."
87127c0e3167 added identity-element compare: #identicalContentsAs:
Claus Gittinger <cg@exept.de>
parents: 5231
diff changeset
   943
87127c0e3167 added identity-element compare: #identicalContentsAs:
Claus Gittinger <cg@exept.de>
parents: 5231
diff changeset
   944
    |index "{ Class: SmallInteger }"
87127c0e3167 added identity-element compare: #identicalContentsAs:
Claus Gittinger <cg@exept.de>
parents: 5231
diff changeset
   945
     stop  "{ Class: SmallInteger }" |
87127c0e3167 added identity-element compare: #identicalContentsAs:
Claus Gittinger <cg@exept.de>
parents: 5231
diff changeset
   946
87127c0e3167 added identity-element compare: #identicalContentsAs:
Claus Gittinger <cg@exept.de>
parents: 5231
diff changeset
   947
    (aCollection == self) ifTrue:[^ true].
87127c0e3167 added identity-element compare: #identicalContentsAs:
Claus Gittinger <cg@exept.de>
parents: 5231
diff changeset
   948
    (aCollection isSequenceable) ifFalse:[^ false].
87127c0e3167 added identity-element compare: #identicalContentsAs:
Claus Gittinger <cg@exept.de>
parents: 5231
diff changeset
   949
87127c0e3167 added identity-element compare: #identicalContentsAs:
Claus Gittinger <cg@exept.de>
parents: 5231
diff changeset
   950
    stop := self size.
87127c0e3167 added identity-element compare: #identicalContentsAs:
Claus Gittinger <cg@exept.de>
parents: 5231
diff changeset
   951
    stop == (aCollection size) ifFalse:[^ false].
87127c0e3167 added identity-element compare: #identicalContentsAs:
Claus Gittinger <cg@exept.de>
parents: 5231
diff changeset
   952
87127c0e3167 added identity-element compare: #identicalContentsAs:
Claus Gittinger <cg@exept.de>
parents: 5231
diff changeset
   953
    index := 1.
87127c0e3167 added identity-element compare: #identicalContentsAs:
Claus Gittinger <cg@exept.de>
parents: 5231
diff changeset
   954
    [index <= stop] whileTrue:[
87127c0e3167 added identity-element compare: #identicalContentsAs:
Claus Gittinger <cg@exept.de>
parents: 5231
diff changeset
   955
        (self at:index) == (aCollection at:index) ifFalse:[^ false].
87127c0e3167 added identity-element compare: #identicalContentsAs:
Claus Gittinger <cg@exept.de>
parents: 5231
diff changeset
   956
        index := index + 1
87127c0e3167 added identity-element compare: #identicalContentsAs:
Claus Gittinger <cg@exept.de>
parents: 5231
diff changeset
   957
    ].
87127c0e3167 added identity-element compare: #identicalContentsAs:
Claus Gittinger <cg@exept.de>
parents: 5231
diff changeset
   958
    ^ true
87127c0e3167 added identity-element compare: #identicalContentsAs:
Claus Gittinger <cg@exept.de>
parents: 5231
diff changeset
   959
87127c0e3167 added identity-element compare: #identicalContentsAs:
Claus Gittinger <cg@exept.de>
parents: 5231
diff changeset
   960
    "
87127c0e3167 added identity-element compare: #identicalContentsAs:
Claus Gittinger <cg@exept.de>
parents: 5231
diff changeset
   961
     #(1 2 3 4 5) = #(1 2 3 4 5)                        
87127c0e3167 added identity-element compare: #identicalContentsAs:
Claus Gittinger <cg@exept.de>
parents: 5231
diff changeset
   962
     #(1 2 3 4 5) = #(1.0 2 3 4.0 5)                        
87127c0e3167 added identity-element compare: #identicalContentsAs:
Claus Gittinger <cg@exept.de>
parents: 5231
diff changeset
   963
     #($1 $2 $3 $4 $5) = '12345'     
87127c0e3167 added identity-element compare: #identicalContentsAs:
Claus Gittinger <cg@exept.de>
parents: 5231
diff changeset
   964
87127c0e3167 added identity-element compare: #identicalContentsAs:
Claus Gittinger <cg@exept.de>
parents: 5231
diff changeset
   965
     #(1 2 3 4 5) identicalContentsAs:#(1 2 3 4 5) 
87127c0e3167 added identity-element compare: #identicalContentsAs:
Claus Gittinger <cg@exept.de>
parents: 5231
diff changeset
   966
     #(1 2 3 4 5) identicalContentsAs: #(1.0 2 3 4.0 5)                        
87127c0e3167 added identity-element compare: #identicalContentsAs:
Claus Gittinger <cg@exept.de>
parents: 5231
diff changeset
   967
     #($1 $2 $3 $4 $5) identicalContentsAs: '12345'     
87127c0e3167 added identity-element compare: #identicalContentsAs:
Claus Gittinger <cg@exept.de>
parents: 5231
diff changeset
   968
    "
87127c0e3167 added identity-element compare: #identicalContentsAs:
Claus Gittinger <cg@exept.de>
parents: 5231
diff changeset
   969
87127c0e3167 added identity-element compare: #identicalContentsAs:
Claus Gittinger <cg@exept.de>
parents: 5231
diff changeset
   970
    "Modified: / 18.2.2000 / 19:04:27 / cg"
87127c0e3167 added identity-element compare: #identicalContentsAs:
Claus Gittinger <cg@exept.de>
parents: 5231
diff changeset
   971
!
87127c0e3167 added identity-element compare: #identicalContentsAs:
Claus Gittinger <cg@exept.de>
parents: 5231
diff changeset
   972
602
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
   973
startsWith:aCollection
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
   974
    "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
   975
     of aCollection
3655a0fea430 definite (true) return for zero-length arg in #startsWith:
Claus Gittinger <cg@exept.de>
parents: 4382
diff changeset
   976
     If the argument is empty, true is returned."
602
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
   977
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
   978
    |index "{ Class: SmallInteger }"
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
   979
     stop  "{ Class: SmallInteger }" |
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
   980
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
   981
    (aCollection == self) ifTrue:[^true].
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
   982
    (aCollection isSequenceable) ifFalse:[^false].
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
   983
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
   984
    stop := aCollection size.
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
   985
    stop > self size ifTrue:[^false].
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
   986
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
   987
    index := 1.
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
   988
    [index <= stop] whileTrue:[
4389
3655a0fea430 definite (true) return for zero-length arg in #startsWith:
Claus Gittinger <cg@exept.de>
parents: 4382
diff changeset
   989
        (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
   990
        index := index + 1
602
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
   991
    ].
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
   992
    ^ true
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
   993
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
   994
    "
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
   995
     'abcde' startsWith:#($a $b $c)
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
   996
     #[1 2 3 4] startsWith:#(1 2 3)
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
   997
     #(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
   998
     #(1 2 3 4) asOrderedCollection startsWith:#()   
602
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
   999
    "
13
62303f84ff5f *** empty log message ***
claus
parents: 5
diff changeset
  1000
! !
62303f84ff5f *** empty log message ***
claus
parents: 5
diff changeset
  1001
260
cefb485445a7 *** empty log message ***
claus
parents: 252
diff changeset
  1002
!SequenceableCollection methodsFor:'converting'!
cefb485445a7 *** empty log message ***
claus
parents: 252
diff changeset
  1003
1413
4788a0d3d6e2 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1395
diff changeset
  1004
asStringCollection
4788a0d3d6e2 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1395
diff changeset
  1005
    "return a new string collection containing the elements;
4788a0d3d6e2 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1395
diff changeset
  1006
     these ought to be strings. (i.e. String or Text instances)"
4788a0d3d6e2 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1395
diff changeset
  1007
4788a0d3d6e2 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1395
diff changeset
  1008
    |newColl sz|
4788a0d3d6e2 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1395
diff changeset
  1009
4788a0d3d6e2 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1395
diff changeset
  1010
    sz := self size.
4788a0d3d6e2 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1395
diff changeset
  1011
    newColl := (StringCollection new:sz) grow:sz.
4788a0d3d6e2 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1395
diff changeset
  1012
    newColl replaceFrom:1 to:sz with:self startingAt:1.
4788a0d3d6e2 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1395
diff changeset
  1013
    ^ newColl
4788a0d3d6e2 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1395
diff changeset
  1014
4788a0d3d6e2 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1395
diff changeset
  1015
    "Created: 18.5.1996 / 13:53:55 / cg"
4788a0d3d6e2 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1395
diff changeset
  1016
    "Modified: 18.5.1996 / 14:00:16 / cg"
4788a0d3d6e2 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1395
diff changeset
  1017
!
4788a0d3d6e2 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1395
diff changeset
  1018
1188
a9efdd724afc more asString methods
ca
parents: 1159
diff changeset
  1019
asStringWith:sepChar
a9efdd724afc more asString methods
ca
parents: 1159
diff changeset
  1020
    "return a string generated by concatenating my elements 
a9efdd724afc more asString methods
ca
parents: 1159
diff changeset
  1021
     (which must be strings or nil) and embedding sepChar characters in between.
a9efdd724afc more asString methods
ca
parents: 1159
diff changeset
  1022
     Nil entries and empty strings are counted as empty lines."
a9efdd724afc more asString methods
ca
parents: 1159
diff changeset
  1023
a9efdd724afc more asString methods
ca
parents: 1159
diff changeset
  1024
    ^ self asStringWith:sepChar from:1 to:(self size)
1413
4788a0d3d6e2 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1395
diff changeset
  1025
4788a0d3d6e2 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1395
diff changeset
  1026
    "
4788a0d3d6e2 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1395
diff changeset
  1027
     #('hello' 'world' 'foo' 'bar' 'baz') asStringWith:$;
4788a0d3d6e2 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1395
diff changeset
  1028
    "
4788a0d3d6e2 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1395
diff changeset
  1029
4788a0d3d6e2 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1395
diff changeset
  1030
    "Modified: 18.5.1996 / 15:28:14 / cg"
1188
a9efdd724afc more asString methods
ca
parents: 1159
diff changeset
  1031
!
a9efdd724afc more asString methods
ca
parents: 1159
diff changeset
  1032
a9efdd724afc more asString methods
ca
parents: 1159
diff changeset
  1033
asStringWith:sepCharacter from:firstLine to:lastLine
a9efdd724afc more asString methods
ca
parents: 1159
diff changeset
  1034
    "return part of myself as a string with embedded sepCharacters.
a9efdd724afc more asString methods
ca
parents: 1159
diff changeset
  1035
     My elements must be strings or nil; nil entries and empty strings are
a9efdd724afc more asString methods
ca
parents: 1159
diff changeset
  1036
     taken as empty lines."
a9efdd724afc more asString methods
ca
parents: 1159
diff changeset
  1037
a9efdd724afc more asString methods
ca
parents: 1159
diff changeset
  1038
    ^ self 
a9efdd724afc more asString methods
ca
parents: 1159
diff changeset
  1039
        asStringWith:sepCharacter 
a9efdd724afc more asString methods
ca
parents: 1159
diff changeset
  1040
        from:firstLine 
a9efdd724afc more asString methods
ca
parents: 1159
diff changeset
  1041
        to:lastLine
a9efdd724afc more asString methods
ca
parents: 1159
diff changeset
  1042
        compressTabs:false
a9efdd724afc more asString methods
ca
parents: 1159
diff changeset
  1043
        final:nil
a9efdd724afc more asString methods
ca
parents: 1159
diff changeset
  1044
    "
a9efdd724afc more asString methods
ca
parents: 1159
diff changeset
  1045
     creating entries for searchpath:
a9efdd724afc more asString methods
ca
parents: 1159
diff changeset
  1046
a9efdd724afc more asString methods
ca
parents: 1159
diff changeset
  1047
     #('foo' 'bar' 'baz' '/foo/bar') asStringWith:$;   
a9efdd724afc more asString methods
ca
parents: 1159
diff changeset
  1048
a9efdd724afc more asString methods
ca
parents: 1159
diff changeset
  1049
     #('foo' 'bar' 'baz' '/foo/bar') asStringWith:$: from:1 to:3   
a9efdd724afc more asString methods
ca
parents: 1159
diff changeset
  1050
    "
a9efdd724afc more asString methods
ca
parents: 1159
diff changeset
  1051
a9efdd724afc more asString methods
ca
parents: 1159
diff changeset
  1052
    "Modified: 23.2.1996 / 15:28:55 / cg"
a9efdd724afc more asString methods
ca
parents: 1159
diff changeset
  1053
!
a9efdd724afc more asString methods
ca
parents: 1159
diff changeset
  1054
260
cefb485445a7 *** empty log message ***
claus
parents: 252
diff changeset
  1055
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
  1056
    "return part of myself as a string or text with embedded sepCharacters.
263
e0195b4ad1ac *** empty log message ***
claus
parents: 260
diff changeset
  1057
     My elements must be strings or nil; nil entries and empty strings are
260
cefb485445a7 *** empty log message ***
claus
parents: 252
diff changeset
  1058
     taken as empty lines.
cefb485445a7 *** empty log message ***
claus
parents: 252
diff changeset
  1059
     If the argument compressTabs is true, leading spaces are converted
cefb485445a7 *** empty log message ***
claus
parents: 252
diff changeset
  1060
     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
  1061
     character (if non-nil)."
dd53d372c250 added #asStringWithoutEmphasis...
Claus Gittinger <cg@exept.de>
parents: 3482
diff changeset
  1062
dd53d372c250 added #asStringWithoutEmphasis...
Claus Gittinger <cg@exept.de>
parents: 3482
diff changeset
  1063
    ^ self
dd53d372c250 added #asStringWithoutEmphasis...
Claus Gittinger <cg@exept.de>
parents: 3482
diff changeset
  1064
        asStringWith:sepCharacter 
dd53d372c250 added #asStringWithoutEmphasis...
Claus Gittinger <cg@exept.de>
parents: 3482
diff changeset
  1065
        from:firstLine 
dd53d372c250 added #asStringWithoutEmphasis...
Claus Gittinger <cg@exept.de>
parents: 3482
diff changeset
  1066
        to:lastLine 
dd53d372c250 added #asStringWithoutEmphasis...
Claus Gittinger <cg@exept.de>
parents: 3482
diff changeset
  1067
        compressTabs:compressTabs 
dd53d372c250 added #asStringWithoutEmphasis...
Claus Gittinger <cg@exept.de>
parents: 3482
diff changeset
  1068
        final:endCharacter 
dd53d372c250 added #asStringWithoutEmphasis...
Claus Gittinger <cg@exept.de>
parents: 3482
diff changeset
  1069
        withEmphasis:true
dd53d372c250 added #asStringWithoutEmphasis...
Claus Gittinger <cg@exept.de>
parents: 3482
diff changeset
  1070
dd53d372c250 added #asStringWithoutEmphasis...
Claus Gittinger <cg@exept.de>
parents: 3482
diff changeset
  1071
    "Modified: / 17.6.1998 / 12:31:19 / cg"
dd53d372c250 added #asStringWithoutEmphasis...
Claus Gittinger <cg@exept.de>
parents: 3482
diff changeset
  1072
!
dd53d372c250 added #asStringWithoutEmphasis...
Claus Gittinger <cg@exept.de>
parents: 3482
diff changeset
  1073
dd53d372c250 added #asStringWithoutEmphasis...
Claus Gittinger <cg@exept.de>
parents: 3482
diff changeset
  1074
asStringWith:sepCharacter from:firstLine to:lastLine compressTabs:compressTabs final:endCharacter withEmphasis:withEmphasis
4677
90a037f88b0e allow strings as sepCharacter and endCharacter in #asStringWith:...
Claus Gittinger <cg@exept.de>
parents: 4459
diff changeset
  1075
    "return part of myself as a string or text with embedded sepCharacters
90a037f88b0e allow strings as sepCharacter and endCharacter in #asStringWith:...
Claus Gittinger <cg@exept.de>
parents: 4459
diff changeset
  1076
     and followup endCharacter.
3602
dd53d372c250 added #asStringWithoutEmphasis...
Claus Gittinger <cg@exept.de>
parents: 3482
diff changeset
  1077
     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
  1078
     taken as empty lines.
4677
90a037f88b0e allow strings as sepCharacter and endCharacter in #asStringWith:...
Claus Gittinger <cg@exept.de>
parents: 4459
diff changeset
  1079
     sepCharacter and endCharacter may be nil, a character or a string.
3602
dd53d372c250 added #asStringWithoutEmphasis...
Claus Gittinger <cg@exept.de>
parents: 3482
diff changeset
  1080
     If the argument compressTabs is true, leading spaces are converted
dd53d372c250 added #asStringWithoutEmphasis...
Claus Gittinger <cg@exept.de>
parents: 3482
diff changeset
  1081
     to tab-characters (8col tabs). The last line is followed by a final
260
cefb485445a7 *** empty log message ***
claus
parents: 252
diff changeset
  1082
     character (if non-nil).
3602
dd53d372c250 added #asStringWithoutEmphasis...
Claus Gittinger <cg@exept.de>
parents: 3482
diff changeset
  1083
     The withEmphais argument controls if the returned string should preserve
dd53d372c250 added #asStringWithoutEmphasis...
Claus Gittinger <cg@exept.de>
parents: 3482
diff changeset
  1084
     any emphasis. If false, a plain string is returned.
260
cefb485445a7 *** empty log message ***
claus
parents: 252
diff changeset
  1085
     This method is tuned for big collections, in not creating many
263
e0195b4ad1ac *** empty log message ***
claus
parents: 260
diff changeset
  1086
     intermediate strings (has linear runtime). For very small collections
e0195b4ad1ac *** empty log message ***
claus
parents: 260
diff changeset
  1087
     and small strings, it may be faster to use the comma , operation."
260
cefb485445a7 *** empty log message ***
claus
parents: 252
diff changeset
  1088
293
31df3850e98c *** empty log message ***
claus
parents: 282
diff changeset
  1089
    |idx1        "{ Class:SmallInteger }"
31df3850e98c *** empty log message ***
claus
parents: 282
diff changeset
  1090
     idx2        "{ Class:SmallInteger }"
31df3850e98c *** empty log message ***
claus
parents: 282
diff changeset
  1091
     totalLength "{ Class:SmallInteger }"
260
cefb485445a7 *** empty log message ***
claus
parents: 252
diff changeset
  1092
     pos         "{ Class:SmallInteger }"
4677
90a037f88b0e allow strings as sepCharacter and endCharacter in #asStringWith:...
Claus Gittinger <cg@exept.de>
parents: 4459
diff changeset
  1093
     sepCnt      "{ Class:SmallInteger }"
90a037f88b0e allow strings as sepCharacter and endCharacter in #asStringWith:...
Claus Gittinger <cg@exept.de>
parents: 4459
diff changeset
  1094
     newString lineString spaces idx nTabs 
1536
29d45204ceed tuned #asStringWith:... if any Text lines with emphasis are involved.
Claus Gittinger <cg@exept.de>
parents: 1495
diff changeset
  1095
     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
  1096
     thisLen anyTab|
260
cefb485445a7 *** empty log message ***
claus
parents: 252
diff changeset
  1097
cefb485445a7 *** empty log message ***
claus
parents: 252
diff changeset
  1098
    "
cefb485445a7 *** empty log message ***
claus
parents: 252
diff changeset
  1099
     first accumulate the size of the string, to avoid
cefb485445a7 *** empty log message ***
claus
parents: 252
diff changeset
  1100
     countless reallocations. If tabs are compressed,
cefb485445a7 *** empty log message ***
claus
parents: 252
diff changeset
  1101
     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
  1102
     On the fly, look if a 16bit string or emphasized text is needed.
260
cefb485445a7 *** empty log message ***
claus
parents: 252
diff changeset
  1103
    "
1395
f324be2221e3 asStringWith:... handles emphasized text
Claus Gittinger <cg@exept.de>
parents: 1385
diff changeset
  1104
    any16Bit := needEmphasis := false.
1015
a564efc63383 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1003
diff changeset
  1105
    stringClass := String.
a564efc63383 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1003
diff changeset
  1106
260
cefb485445a7 *** empty log message ***
claus
parents: 252
diff changeset
  1107
    totalLength := 0.
4677
90a037f88b0e allow strings as sepCharacter and endCharacter in #asStringWith:...
Claus Gittinger <cg@exept.de>
parents: 4459
diff changeset
  1108
    sepCharacter isNil ifTrue:[
90a037f88b0e allow strings as sepCharacter and endCharacter in #asStringWith:...
Claus Gittinger <cg@exept.de>
parents: 4459
diff changeset
  1109
        sepCnt := 0
90a037f88b0e allow strings as sepCharacter and endCharacter in #asStringWith:...
Claus Gittinger <cg@exept.de>
parents: 4459
diff changeset
  1110
    ] ifFalse:[
90a037f88b0e allow strings as sepCharacter and endCharacter in #asStringWith:...
Claus Gittinger <cg@exept.de>
parents: 4459
diff changeset
  1111
        sepCharacter isCharacter ifTrue:[
90a037f88b0e allow strings as sepCharacter and endCharacter in #asStringWith:...
Claus Gittinger <cg@exept.de>
parents: 4459
diff changeset
  1112
            sepCnt := 1
90a037f88b0e allow strings as sepCharacter and endCharacter in #asStringWith:...
Claus Gittinger <cg@exept.de>
parents: 4459
diff changeset
  1113
        ] ifFalse:[
90a037f88b0e allow strings as sepCharacter and endCharacter in #asStringWith:...
Claus Gittinger <cg@exept.de>
parents: 4459
diff changeset
  1114
            sepCnt := sepCharacter size
90a037f88b0e allow strings as sepCharacter and endCharacter in #asStringWith:...
Claus Gittinger <cg@exept.de>
parents: 4459
diff changeset
  1115
        ]
90a037f88b0e allow strings as sepCharacter and endCharacter in #asStringWith:...
Claus Gittinger <cg@exept.de>
parents: 4459
diff changeset
  1116
    ].
260
cefb485445a7 *** empty log message ***
claus
parents: 252
diff changeset
  1117
293
31df3850e98c *** empty log message ***
claus
parents: 282
diff changeset
  1118
    idx1 := firstLine.
31df3850e98c *** empty log message ***
claus
parents: 282
diff changeset
  1119
    idx2 := lastLine.
31df3850e98c *** empty log message ***
claus
parents: 282
diff changeset
  1120
    idx1 to:idx2 do:[:lineIndex |
1395
f324be2221e3 asStringWith:... handles emphasized text
Claus Gittinger <cg@exept.de>
parents: 1385
diff changeset
  1121
        lineString := self at:lineIndex.
f324be2221e3 asStringWith:... handles emphasized text
Claus Gittinger <cg@exept.de>
parents: 1385
diff changeset
  1122
4677
90a037f88b0e allow strings as sepCharacter and endCharacter in #asStringWith:...
Claus Gittinger <cg@exept.de>
parents: 4459
diff changeset
  1123
        lineString notNil ifTrue:[
3602
dd53d372c250 added #asStringWithoutEmphasis...
Claus Gittinger <cg@exept.de>
parents: 3482
diff changeset
  1124
            withEmphasis ifTrue:[
dd53d372c250 added #asStringWithoutEmphasis...
Claus Gittinger <cg@exept.de>
parents: 3482
diff changeset
  1125
                lineString hasChangeOfEmphasis ifTrue:[
dd53d372c250 added #asStringWithoutEmphasis...
Claus Gittinger <cg@exept.de>
parents: 3482
diff changeset
  1126
                    needEmphasis := true
dd53d372c250 added #asStringWithoutEmphasis...
Claus Gittinger <cg@exept.de>
parents: 3482
diff changeset
  1127
                ].
dd53d372c250 added #asStringWithoutEmphasis...
Claus Gittinger <cg@exept.de>
parents: 3482
diff changeset
  1128
                (lineString bitsPerCharacter == 16) ifTrue:[
dd53d372c250 added #asStringWithoutEmphasis...
Claus Gittinger <cg@exept.de>
parents: 3482
diff changeset
  1129
                    any16Bit := true.
dd53d372c250 added #asStringWithoutEmphasis...
Claus Gittinger <cg@exept.de>
parents: 3482
diff changeset
  1130
                    stringClass := lineString class
dd53d372c250 added #asStringWithoutEmphasis...
Claus Gittinger <cg@exept.de>
parents: 3482
diff changeset
  1131
                ].
1395
f324be2221e3 asStringWith:... handles emphasized text
Claus Gittinger <cg@exept.de>
parents: 1385
diff changeset
  1132
            ].
4677
90a037f88b0e allow strings as sepCharacter and endCharacter in #asStringWith:...
Claus Gittinger <cg@exept.de>
parents: 4459
diff changeset
  1133
            totalLength := totalLength + lineString size
90a037f88b0e allow strings as sepCharacter and endCharacter in #asStringWith:...
Claus Gittinger <cg@exept.de>
parents: 4459
diff changeset
  1134
        ].
90a037f88b0e allow strings as sepCharacter and endCharacter in #asStringWith:...
Claus Gittinger <cg@exept.de>
parents: 4459
diff changeset
  1135
        totalLength := totalLength + sepCnt
90a037f88b0e allow strings as sepCharacter and endCharacter in #asStringWith:...
Claus Gittinger <cg@exept.de>
parents: 4459
diff changeset
  1136
    ].
90a037f88b0e allow strings as sepCharacter and endCharacter in #asStringWith:...
Claus Gittinger <cg@exept.de>
parents: 4459
diff changeset
  1137
    totalLength := totalLength - sepCnt.
90a037f88b0e allow strings as sepCharacter and endCharacter in #asStringWith:...
Claus Gittinger <cg@exept.de>
parents: 4459
diff changeset
  1138
90a037f88b0e allow strings as sepCharacter and endCharacter in #asStringWith:...
Claus Gittinger <cg@exept.de>
parents: 4459
diff changeset
  1139
    endCharacter notNil ifTrue:[
90a037f88b0e allow strings as sepCharacter and endCharacter in #asStringWith:...
Claus Gittinger <cg@exept.de>
parents: 4459
diff changeset
  1140
        endCharacter isCharacter ifTrue:[
90a037f88b0e allow strings as sepCharacter and endCharacter in #asStringWith:...
Claus Gittinger <cg@exept.de>
parents: 4459
diff changeset
  1141
            totalLength := totalLength + 1
90a037f88b0e allow strings as sepCharacter and endCharacter in #asStringWith:...
Claus Gittinger <cg@exept.de>
parents: 4459
diff changeset
  1142
        ] ifFalse:[
90a037f88b0e allow strings as sepCharacter and endCharacter in #asStringWith:...
Claus Gittinger <cg@exept.de>
parents: 4459
diff changeset
  1143
            totalLength := totalLength + endCharacter size
1395
f324be2221e3 asStringWith:... handles emphasized text
Claus Gittinger <cg@exept.de>
parents: 1385
diff changeset
  1144
        ].
260
cefb485445a7 *** empty log message ***
claus
parents: 252
diff changeset
  1145
    ].
4677
90a037f88b0e allow strings as sepCharacter and endCharacter in #asStringWith:...
Claus Gittinger <cg@exept.de>
parents: 4459
diff changeset
  1146
    totalLength <= 0 ifTrue:[^ ''].
90a037f88b0e allow strings as sepCharacter and endCharacter in #asStringWith:...
Claus Gittinger <cg@exept.de>
parents: 4459
diff changeset
  1147
260
cefb485445a7 *** empty log message ***
claus
parents: 252
diff changeset
  1148
    spaces := '        '.
1016
9588a8d5a64e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1015
diff changeset
  1149
    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
  1150
1395
f324be2221e3 asStringWith:... handles emphasized text
Claus Gittinger <cg@exept.de>
parents: 1385
diff changeset
  1151
    needEmphasis ifTrue:[
1536
29d45204ceed tuned #asStringWith:... if any Text lines with emphasis are involved.
Claus Gittinger <cg@exept.de>
parents: 1495
diff changeset
  1152
        newRuns := RunArray new.
1395
f324be2221e3 asStringWith:... handles emphasized text
Claus Gittinger <cg@exept.de>
parents: 1385
diff changeset
  1153
    ].
260
cefb485445a7 *** empty log message ***
claus
parents: 252
diff changeset
  1154
cefb485445a7 *** empty log message ***
claus
parents: 252
diff changeset
  1155
    "
cefb485445a7 *** empty log message ***
claus
parents: 252
diff changeset
  1156
     now, replace ...
1536
29d45204ceed tuned #asStringWith:... if any Text lines with emphasis are involved.
Claus Gittinger <cg@exept.de>
parents: 1495
diff changeset
  1157
     Be careful with runArrays:
29d45204ceed tuned #asStringWith:... if any Text lines with emphasis are involved.
Claus Gittinger <cg@exept.de>
parents: 1495
diff changeset
  1158
        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
  1159
        Therefore, create a new runArray from scratch.
260
cefb485445a7 *** empty log message ***
claus
parents: 252
diff changeset
  1160
    "
cefb485445a7 *** empty log message ***
claus
parents: 252
diff changeset
  1161
    pos := 1.
293
31df3850e98c *** empty log message ***
claus
parents: 282
diff changeset
  1162
    idx1 to:idx2 do:[:lineIndex |
1395
f324be2221e3 asStringWith:... handles emphasized text
Claus Gittinger <cg@exept.de>
parents: 1385
diff changeset
  1163
        lineString := self at:lineIndex.
f324be2221e3 asStringWith:... handles emphasized text
Claus Gittinger <cg@exept.de>
parents: 1385
diff changeset
  1164
        thisLen := lineString size.
f324be2221e3 asStringWith:... handles emphasized text
Claus Gittinger <cg@exept.de>
parents: 1385
diff changeset
  1165
        thisLen ~~ 0 ifTrue:[
3602
dd53d372c250 added #asStringWithoutEmphasis...
Claus Gittinger <cg@exept.de>
parents: 3482
diff changeset
  1166
            withEmphasis ifFalse:[
dd53d372c250 added #asStringWithoutEmphasis...
Claus Gittinger <cg@exept.de>
parents: 3482
diff changeset
  1167
                lineString := lineString string.
dd53d372c250 added #asStringWithoutEmphasis...
Claus Gittinger <cg@exept.de>
parents: 3482
diff changeset
  1168
            ].
dd53d372c250 added #asStringWithoutEmphasis...
Claus Gittinger <cg@exept.de>
parents: 3482
diff changeset
  1169
1536
29d45204ceed tuned #asStringWith:... if any Text lines with emphasis are involved.
Claus Gittinger <cg@exept.de>
parents: 1495
diff changeset
  1170
            (anyTab := compressTabs) ifTrue:[
1395
f324be2221e3 asStringWith:... handles emphasized text
Claus Gittinger <cg@exept.de>
parents: 1385
diff changeset
  1171
                "
f324be2221e3 asStringWith:... handles emphasized text
Claus Gittinger <cg@exept.de>
parents: 1385
diff changeset
  1172
                 mhmh: could use withTabs from String-class here,
f324be2221e3 asStringWith:... handles emphasized text
Claus Gittinger <cg@exept.de>
parents: 1385
diff changeset
  1173
                 but we should avoid creating too many temporary strings
f324be2221e3 asStringWith:... handles emphasized text
Claus Gittinger <cg@exept.de>
parents: 1385
diff changeset
  1174
                 (especially, since this method is typically used when converting
f324be2221e3 asStringWith:... handles emphasized text
Claus Gittinger <cg@exept.de>
parents: 1385
diff changeset
  1175
                 big texts such as when saving in the filebrowser ...).
f324be2221e3 asStringWith:... handles emphasized text
Claus Gittinger <cg@exept.de>
parents: 1385
diff changeset
  1176
                 Therefore, we convert tabs inline here doing a direct replace
f324be2221e3 asStringWith:... handles emphasized text
Claus Gittinger <cg@exept.de>
parents: 1385
diff changeset
  1177
                 in newString."
f324be2221e3 asStringWith:... handles emphasized text
Claus Gittinger <cg@exept.de>
parents: 1385
diff changeset
  1178
f324be2221e3 asStringWith:... handles emphasized text
Claus Gittinger <cg@exept.de>
parents: 1385
diff changeset
  1179
                idx := lineString findFirst:[:c | (c ~~ Character space)].
f324be2221e3 asStringWith:... handles emphasized text
Claus Gittinger <cg@exept.de>
parents: 1385
diff changeset
  1180
                nTabs := (idx-1) // 8.
4678
Claus Gittinger <cg@exept.de>
parents: 4677
diff changeset
  1181
                anyTab := (nTabs > 0)
1536
29d45204ceed tuned #asStringWith:... if any Text lines with emphasis are involved.
Claus Gittinger <cg@exept.de>
parents: 1495
diff changeset
  1182
            ].
29d45204ceed tuned #asStringWith:... if any Text lines with emphasis are involved.
Claus Gittinger <cg@exept.de>
parents: 1495
diff changeset
  1183
            anyTab ifTrue:[
29d45204ceed tuned #asStringWith:... if any Text lines with emphasis are involved.
Claus Gittinger <cg@exept.de>
parents: 1495
diff changeset
  1184
                "any tabs"
29d45204ceed tuned #asStringWith:... if any Text lines with emphasis are involved.
Claus Gittinger <cg@exept.de>
parents: 1495
diff changeset
  1185
29d45204ceed tuned #asStringWith:... if any Text lines with emphasis are involved.
Claus Gittinger <cg@exept.de>
parents: 1495
diff changeset
  1186
                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
  1187
29d45204ceed tuned #asStringWith:... if any Text lines with emphasis are involved.
Claus Gittinger <cg@exept.de>
parents: 1495
diff changeset
  1188
                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
  1189
                newRuns notNil ifTrue:[
29d45204ceed tuned #asStringWith:... if any Text lines with emphasis are involved.
Claus Gittinger <cg@exept.de>
parents: 1495
diff changeset
  1190
                    newRuns add:nil withOccurrences:nTabs
1395
f324be2221e3 asStringWith:... handles emphasized text
Claus Gittinger <cg@exept.de>
parents: 1385
diff changeset
  1191
                ].
1536
29d45204ceed tuned #asStringWith:... if any Text lines with emphasis are involved.
Claus Gittinger <cg@exept.de>
parents: 1495
diff changeset
  1192
                pos := pos + nTabs.
29d45204ceed tuned #asStringWith:... if any Text lines with emphasis are involved.
Claus Gittinger <cg@exept.de>
parents: 1495
diff changeset
  1193
29d45204ceed tuned #asStringWith:... if any Text lines with emphasis are involved.
Claus Gittinger <cg@exept.de>
parents: 1495
diff changeset
  1194
                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
  1195
                newRuns notNil ifTrue:[
29d45204ceed tuned #asStringWith:... if any Text lines with emphasis are involved.
Claus Gittinger <cg@exept.de>
parents: 1495
diff changeset
  1196
                    lineString hasChangeOfEmphasis ifTrue:[
2860
760052935b5a oops - asStringWith: was wrong
Claus Gittinger <cg@exept.de>
parents: 2610
diff changeset
  1197
                        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
  1198
                            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
  1199
                        ]    
29d45204ceed tuned #asStringWith:... if any Text lines with emphasis are involved.
Claus Gittinger <cg@exept.de>
parents: 1495
diff changeset
  1200
                    ] ifFalse:[
29d45204ceed tuned #asStringWith:... if any Text lines with emphasis are involved.
Claus Gittinger <cg@exept.de>
parents: 1495
diff changeset
  1201
                        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
  1202
                    ]
29d45204ceed tuned #asStringWith:... if any Text lines with emphasis are involved.
Claus Gittinger <cg@exept.de>
parents: 1495
diff changeset
  1203
                ].
29d45204ceed tuned #asStringWith:... if any Text lines with emphasis are involved.
Claus Gittinger <cg@exept.de>
parents: 1495
diff changeset
  1204
                pos := pos + thisLen - (nTabs * 8).
1395
f324be2221e3 asStringWith:... handles emphasized text
Claus Gittinger <cg@exept.de>
parents: 1385
diff changeset
  1205
            ] ifFalse:[
f324be2221e3 asStringWith:... handles emphasized text
Claus Gittinger <cg@exept.de>
parents: 1385
diff changeset
  1206
                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
  1207
29d45204ceed tuned #asStringWith:... if any Text lines with emphasis are involved.
Claus Gittinger <cg@exept.de>
parents: 1495
diff changeset
  1208
                newRuns notNil ifTrue:[
29d45204ceed tuned #asStringWith:... if any Text lines with emphasis are involved.
Claus Gittinger <cg@exept.de>
parents: 1495
diff changeset
  1209
                    lineString hasChangeOfEmphasis ifTrue:[
29d45204ceed tuned #asStringWith:... if any Text lines with emphasis are involved.
Claus Gittinger <cg@exept.de>
parents: 1495
diff changeset
  1210
                        newRuns addAll:(lineString emphasis)
29d45204ceed tuned #asStringWith:... if any Text lines with emphasis are involved.
Claus Gittinger <cg@exept.de>
parents: 1495
diff changeset
  1211
                    ] ifFalse:[
29d45204ceed tuned #asStringWith:... if any Text lines with emphasis are involved.
Claus Gittinger <cg@exept.de>
parents: 1495
diff changeset
  1212
                        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
  1213
                    ]
29d45204ceed tuned #asStringWith:... if any Text lines with emphasis are involved.
Claus Gittinger <cg@exept.de>
parents: 1495
diff changeset
  1214
                ].
29d45204ceed tuned #asStringWith:... if any Text lines with emphasis are involved.
Claus Gittinger <cg@exept.de>
parents: 1495
diff changeset
  1215
                pos := pos + thisLen.
29d45204ceed tuned #asStringWith:... if any Text lines with emphasis are involved.
Claus Gittinger <cg@exept.de>
parents: 1495
diff changeset
  1216
            ].
1395
f324be2221e3 asStringWith:... handles emphasized text
Claus Gittinger <cg@exept.de>
parents: 1385
diff changeset
  1217
        ].
1536
29d45204ceed tuned #asStringWith:... if any Text lines with emphasis are involved.
Claus Gittinger <cg@exept.de>
parents: 1495
diff changeset
  1218
29d45204ceed tuned #asStringWith:... if any Text lines with emphasis are involved.
Claus Gittinger <cg@exept.de>
parents: 1495
diff changeset
  1219
        lineIndex ~~ lastLine ifTrue:[
29d45204ceed tuned #asStringWith:... if any Text lines with emphasis are involved.
Claus Gittinger <cg@exept.de>
parents: 1495
diff changeset
  1220
            c := sepCharacter
29d45204ceed tuned #asStringWith:... if any Text lines with emphasis are involved.
Claus Gittinger <cg@exept.de>
parents: 1495
diff changeset
  1221
        ] ifFalse:[
29d45204ceed tuned #asStringWith:... if any Text lines with emphasis are involved.
Claus Gittinger <cg@exept.de>
parents: 1495
diff changeset
  1222
            c := endCharacter
29d45204ceed tuned #asStringWith:... if any Text lines with emphasis are involved.
Claus Gittinger <cg@exept.de>
parents: 1495
diff changeset
  1223
        ].
29d45204ceed tuned #asStringWith:... if any Text lines with emphasis are involved.
Claus Gittinger <cg@exept.de>
parents: 1495
diff changeset
  1224
29d45204ceed tuned #asStringWith:... if any Text lines with emphasis are involved.
Claus Gittinger <cg@exept.de>
parents: 1495
diff changeset
  1225
        c notNil ifTrue:[
4677
90a037f88b0e allow strings as sepCharacter and endCharacter in #asStringWith:...
Claus Gittinger <cg@exept.de>
parents: 4459
diff changeset
  1226
            c isCharacter ifTrue:[
90a037f88b0e allow strings as sepCharacter and endCharacter in #asStringWith:...
Claus Gittinger <cg@exept.de>
parents: 4459
diff changeset
  1227
                newString at:pos put:c.
90a037f88b0e allow strings as sepCharacter and endCharacter in #asStringWith:...
Claus Gittinger <cg@exept.de>
parents: 4459
diff changeset
  1228
                newRuns notNil ifTrue:[
90a037f88b0e allow strings as sepCharacter and endCharacter in #asStringWith:...
Claus Gittinger <cg@exept.de>
parents: 4459
diff changeset
  1229
                    newRuns add:nil.
90a037f88b0e allow strings as sepCharacter and endCharacter in #asStringWith:...
Claus Gittinger <cg@exept.de>
parents: 4459
diff changeset
  1230
                ].
90a037f88b0e allow strings as sepCharacter and endCharacter in #asStringWith:...
Claus Gittinger <cg@exept.de>
parents: 4459
diff changeset
  1231
                pos := pos + 1
90a037f88b0e allow strings as sepCharacter and endCharacter in #asStringWith:...
Claus Gittinger <cg@exept.de>
parents: 4459
diff changeset
  1232
            ] ifFalse:[
90a037f88b0e allow strings as sepCharacter and endCharacter in #asStringWith:...
Claus Gittinger <cg@exept.de>
parents: 4459
diff changeset
  1233
                newString replaceFrom:pos with:c.
90a037f88b0e allow strings as sepCharacter and endCharacter in #asStringWith:...
Claus Gittinger <cg@exept.de>
parents: 4459
diff changeset
  1234
                newRuns notNil ifTrue:[
90a037f88b0e allow strings as sepCharacter and endCharacter in #asStringWith:...
Claus Gittinger <cg@exept.de>
parents: 4459
diff changeset
  1235
                    newRuns add:nil withOccurrences:c size
90a037f88b0e allow strings as sepCharacter and endCharacter in #asStringWith:...
Claus Gittinger <cg@exept.de>
parents: 4459
diff changeset
  1236
                ].
90a037f88b0e allow strings as sepCharacter and endCharacter in #asStringWith:...
Claus Gittinger <cg@exept.de>
parents: 4459
diff changeset
  1237
                pos := pos + c size
90a037f88b0e allow strings as sepCharacter and endCharacter in #asStringWith:...
Claus Gittinger <cg@exept.de>
parents: 4459
diff changeset
  1238
            ]
1536
29d45204ceed tuned #asStringWith:... if any Text lines with emphasis are involved.
Claus Gittinger <cg@exept.de>
parents: 1495
diff changeset
  1239
        ].
260
cefb485445a7 *** empty log message ***
claus
parents: 252
diff changeset
  1240
    ].
cefb485445a7 *** empty log message ***
claus
parents: 252
diff changeset
  1241
cefb485445a7 *** empty log message ***
claus
parents: 252
diff changeset
  1242
    "
cefb485445a7 *** empty log message ***
claus
parents: 252
diff changeset
  1243
     in case of tab compression, the result has to be
cefb485445a7 *** empty log message ***
claus
parents: 252
diff changeset
  1244
     cut to size ... sorry
cefb485445a7 *** empty log message ***
claus
parents: 252
diff changeset
  1245
    "
cefb485445a7 *** empty log message ***
claus
parents: 252
diff changeset
  1246
    pos ~~ totalLength ifTrue:[
1536
29d45204ceed tuned #asStringWith:... if any Text lines with emphasis are involved.
Claus Gittinger <cg@exept.de>
parents: 1495
diff changeset
  1247
        newString := newString copyTo:(pos - 1)
260
cefb485445a7 *** empty log message ***
claus
parents: 252
diff changeset
  1248
    ].
1536
29d45204ceed tuned #asStringWith:... if any Text lines with emphasis are involved.
Claus Gittinger <cg@exept.de>
parents: 1495
diff changeset
  1249
29d45204ceed tuned #asStringWith:... if any Text lines with emphasis are involved.
Claus Gittinger <cg@exept.de>
parents: 1495
diff changeset
  1250
    newRuns notNil ifTrue:[
29d45204ceed tuned #asStringWith:... if any Text lines with emphasis are involved.
Claus Gittinger <cg@exept.de>
parents: 1495
diff changeset
  1251
        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
  1252
    ].
29d45204ceed tuned #asStringWith:... if any Text lines with emphasis are involved.
Claus Gittinger <cg@exept.de>
parents: 1495
diff changeset
  1253
260
cefb485445a7 *** empty log message ***
claus
parents: 252
diff changeset
  1254
    ^ newString
cefb485445a7 *** empty log message ***
claus
parents: 252
diff changeset
  1255
cefb485445a7 *** empty log message ***
claus
parents: 252
diff changeset
  1256
    "
cefb485445a7 *** empty log message ***
claus
parents: 252
diff changeset
  1257
     creating entries for searchpath:
cefb485445a7 *** empty log message ***
claus
parents: 252
diff changeset
  1258
1395
f324be2221e3 asStringWith:... handles emphasized text
Claus Gittinger <cg@exept.de>
parents: 1385
diff changeset
  1259
       #('foo' 'bar' 'baz' '/foo/bar') 
f324be2221e3 asStringWith:... handles emphasized text
Claus Gittinger <cg@exept.de>
parents: 1385
diff changeset
  1260
          asStringWith:$: 
f324be2221e3 asStringWith:... handles emphasized text
Claus Gittinger <cg@exept.de>
parents: 1385
diff changeset
  1261
          from:1 to:4 
f324be2221e3 asStringWith:... handles emphasized text
Claus Gittinger <cg@exept.de>
parents: 1385
diff changeset
  1262
          compressTabs:false 
f324be2221e3 asStringWith:... handles emphasized text
Claus Gittinger <cg@exept.de>
parents: 1385
diff changeset
  1263
          final:nil 
260
cefb485445a7 *** empty log message ***
claus
parents: 252
diff changeset
  1264
cefb485445a7 *** empty log message ***
claus
parents: 252
diff changeset
  1265
     with trailing colon:
cefb485445a7 *** empty log message ***
claus
parents: 252
diff changeset
  1266
1395
f324be2221e3 asStringWith:... handles emphasized text
Claus Gittinger <cg@exept.de>
parents: 1385
diff changeset
  1267
       #('foo' 'bar' 'baz' '/foo/bar') 
f324be2221e3 asStringWith:... handles emphasized text
Claus Gittinger <cg@exept.de>
parents: 1385
diff changeset
  1268
          asStringWith:$: 
f324be2221e3 asStringWith:... handles emphasized text
Claus Gittinger <cg@exept.de>
parents: 1385
diff changeset
  1269
          from:1 to:4 
f324be2221e3 asStringWith:... handles emphasized text
Claus Gittinger <cg@exept.de>
parents: 1385
diff changeset
  1270
          compressTabs:false 
f324be2221e3 asStringWith:... handles emphasized text
Claus Gittinger <cg@exept.de>
parents: 1385
diff changeset
  1271
          final:$: 
260
cefb485445a7 *** empty log message ***
claus
parents: 252
diff changeset
  1272
4677
90a037f88b0e allow strings as sepCharacter and endCharacter in #asStringWith:...
Claus Gittinger <cg@exept.de>
parents: 4459
diff changeset
  1273
     concatenating elements (nil sepChars and nil endChars):
260
cefb485445a7 *** empty log message ***
claus
parents: 252
diff changeset
  1274
1395
f324be2221e3 asStringWith:... handles emphasized text
Claus Gittinger <cg@exept.de>
parents: 1385
diff changeset
  1275
       #('foo' 'bar' 'baz') 
f324be2221e3 asStringWith:... handles emphasized text
Claus Gittinger <cg@exept.de>
parents: 1385
diff changeset
  1276
          asStringWith:nil 
f324be2221e3 asStringWith:... handles emphasized text
Claus Gittinger <cg@exept.de>
parents: 1385
diff changeset
  1277
          from:1 to:3 
f324be2221e3 asStringWith:... handles emphasized text
Claus Gittinger <cg@exept.de>
parents: 1385
diff changeset
  1278
          compressTabs:false 
4677
90a037f88b0e allow strings as sepCharacter and endCharacter in #asStringWith:...
Claus Gittinger <cg@exept.de>
parents: 4459
diff changeset
  1279
          final:nil  
260
cefb485445a7 *** empty log message ***
claus
parents: 252
diff changeset
  1280
cefb485445a7 *** empty log message ***
claus
parents: 252
diff changeset
  1281
     creating a string from a collection of lines:
cefb485445a7 *** empty log message ***
claus
parents: 252
diff changeset
  1282
1395
f324be2221e3 asStringWith:... handles emphasized text
Claus Gittinger <cg@exept.de>
parents: 1385
diff changeset
  1283
       #('foo' 'bar' 'baz') 
f324be2221e3 asStringWith:... handles emphasized text
Claus Gittinger <cg@exept.de>
parents: 1385
diff changeset
  1284
          asStringWith:(Character cr) 
f324be2221e3 asStringWith:... handles emphasized text
Claus Gittinger <cg@exept.de>
parents: 1385
diff changeset
  1285
          from:1 to:3 
f324be2221e3 asStringWith:... handles emphasized text
Claus Gittinger <cg@exept.de>
parents: 1385
diff changeset
  1286
          compressTabs:false 
f324be2221e3 asStringWith:... handles emphasized text
Claus Gittinger <cg@exept.de>
parents: 1385
diff changeset
  1287
          final:(Character cr) 
f324be2221e3 asStringWith:... handles emphasized text
Claus Gittinger <cg@exept.de>
parents: 1385
diff changeset
  1288
f324be2221e3 asStringWith:... handles emphasized text
Claus Gittinger <cg@exept.de>
parents: 1385
diff changeset
  1289
     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
  1290
f324be2221e3 asStringWith:... handles emphasized text
Claus Gittinger <cg@exept.de>
parents: 1385
diff changeset
  1291
       (Array
f324be2221e3 asStringWith:... handles emphasized text
Claus Gittinger <cg@exept.de>
parents: 1385
diff changeset
  1292
            with:'foo'
f324be2221e3 asStringWith:... handles emphasized text
Claus Gittinger <cg@exept.de>
parents: 1385
diff changeset
  1293
            with:('bar' asText allBold)
f324be2221e3 asStringWith:... handles emphasized text
Claus Gittinger <cg@exept.de>
parents: 1385
diff changeset
  1294
            with:'baz'
f324be2221e3 asStringWith:... handles emphasized text
Claus Gittinger <cg@exept.de>
parents: 1385
diff changeset
  1295
            with:('baz2' asText emphasizeAllWith:#italic)
f324be2221e3 asStringWith:... handles emphasized text
Claus Gittinger <cg@exept.de>
parents: 1385
diff changeset
  1296
       ) 
f324be2221e3 asStringWith:... handles emphasized text
Claus Gittinger <cg@exept.de>
parents: 1385
diff changeset
  1297
          asStringWith:(Character cr) 
f324be2221e3 asStringWith:... handles emphasized text
Claus Gittinger <cg@exept.de>
parents: 1385
diff changeset
  1298
          from:1 to:4 
f324be2221e3 asStringWith:... handles emphasized text
Claus Gittinger <cg@exept.de>
parents: 1385
diff changeset
  1299
          compressTabs:false 
f324be2221e3 asStringWith:... handles emphasized text
Claus Gittinger <cg@exept.de>
parents: 1385
diff changeset
  1300
          final:(Character cr) 
4677
90a037f88b0e allow strings as sepCharacter and endCharacter in #asStringWith:...
Claus Gittinger <cg@exept.de>
parents: 4459
diff changeset
  1301
90a037f88b0e allow strings as sepCharacter and endCharacter in #asStringWith:...
Claus Gittinger <cg@exept.de>
parents: 4459
diff changeset
  1302
     can also use strings as separating characters:
90a037f88b0e allow strings as sepCharacter and endCharacter in #asStringWith:...
Claus Gittinger <cg@exept.de>
parents: 4459
diff changeset
  1303
90a037f88b0e allow strings as sepCharacter and endCharacter in #asStringWith:...
Claus Gittinger <cg@exept.de>
parents: 4459
diff changeset
  1304
       #('foo' 'bar' 'baz') 
90a037f88b0e allow strings as sepCharacter and endCharacter in #asStringWith:...
Claus Gittinger <cg@exept.de>
parents: 4459
diff changeset
  1305
          asStringWith:'__' 
90a037f88b0e allow strings as sepCharacter and endCharacter in #asStringWith:...
Claus Gittinger <cg@exept.de>
parents: 4459
diff changeset
  1306
          from:1 to:3 
90a037f88b0e allow strings as sepCharacter and endCharacter in #asStringWith:...
Claus Gittinger <cg@exept.de>
parents: 4459
diff changeset
  1307
          compressTabs:false 
90a037f88b0e allow strings as sepCharacter and endCharacter in #asStringWith:...
Claus Gittinger <cg@exept.de>
parents: 4459
diff changeset
  1308
          final:nil       
90a037f88b0e allow strings as sepCharacter and endCharacter in #asStringWith:...
Claus Gittinger <cg@exept.de>
parents: 4459
diff changeset
  1309
90a037f88b0e allow strings as sepCharacter and endCharacter in #asStringWith:...
Claus Gittinger <cg@exept.de>
parents: 4459
diff changeset
  1310
     and as final characters:
90a037f88b0e allow strings as sepCharacter and endCharacter in #asStringWith:...
Claus Gittinger <cg@exept.de>
parents: 4459
diff changeset
  1311
90a037f88b0e allow strings as sepCharacter and endCharacter in #asStringWith:...
Claus Gittinger <cg@exept.de>
parents: 4459
diff changeset
  1312
       #('foo' 'bar' 'baz') 
90a037f88b0e allow strings as sepCharacter and endCharacter in #asStringWith:...
Claus Gittinger <cg@exept.de>
parents: 4459
diff changeset
  1313
          asStringWith:'__' 
90a037f88b0e allow strings as sepCharacter and endCharacter in #asStringWith:...
Claus Gittinger <cg@exept.de>
parents: 4459
diff changeset
  1314
          from:1 to:3 
90a037f88b0e allow strings as sepCharacter and endCharacter in #asStringWith:...
Claus Gittinger <cg@exept.de>
parents: 4459
diff changeset
  1315
          compressTabs:false 
90a037f88b0e allow strings as sepCharacter and endCharacter in #asStringWith:...
Claus Gittinger <cg@exept.de>
parents: 4459
diff changeset
  1316
          final:'***'       
90a037f88b0e allow strings as sepCharacter and endCharacter in #asStringWith:...
Claus Gittinger <cg@exept.de>
parents: 4459
diff changeset
  1317
260
cefb485445a7 *** empty log message ***
claus
parents: 252
diff changeset
  1318
    "
1003
c82f2dcf5611 care for embedded 16bit strings when concatenating a stringCollection
Claus Gittinger <cg@exept.de>
parents: 929
diff changeset
  1319
3602
dd53d372c250 added #asStringWithoutEmphasis...
Claus Gittinger <cg@exept.de>
parents: 3482
diff changeset
  1320
    "Created: / 17.6.1998 / 12:30:32 / cg"
dd53d372c250 added #asStringWithoutEmphasis...
Claus Gittinger <cg@exept.de>
parents: 3482
diff changeset
  1321
    "Modified: / 17.6.1998 / 12:31:59 / cg"
379
5b5a130ccd09 revision added
claus
parents: 375
diff changeset
  1322
!
5b5a130ccd09 revision added
claus
parents: 375
diff changeset
  1323
602
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  1324
asStringWithCRs
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  1325
    "return a string generated by concatenating my elements 
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  1326
     (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
  1327
     Nil entries and empty strings are counted as empty lines."
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 asStringWithCRsFrom:1 to:(self size)
1413
4788a0d3d6e2 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1395
diff changeset
  1330
4788a0d3d6e2 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1395
diff changeset
  1331
    "
4788a0d3d6e2 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1395
diff changeset
  1332
     #('hello' 'world' 'foo' 'bar' 'baz') asStringWithCRs 
4788a0d3d6e2 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1395
diff changeset
  1333
4788a0d3d6e2 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1395
diff changeset
  1334
     (OrderedCollection new
4788a0d3d6e2 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1395
diff changeset
  1335
        add:'hello'; 
4788a0d3d6e2 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1395
diff changeset
  1336
        add:'world';
4788a0d3d6e2 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1395
diff changeset
  1337
        add:'foo';
4788a0d3d6e2 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1395
diff changeset
  1338
        add:('bar' asText allBold);
4788a0d3d6e2 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1395
diff changeset
  1339
        yourself) asStringWithCRs
1421
7224371d514c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1413
diff changeset
  1340
1422
9a0b792f2953 showCr: -> showCR:
Claus Gittinger <cg@exept.de>
parents: 1421
diff changeset
  1341
     Transcript showCR:
1421
7224371d514c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1413
diff changeset
  1342
         (OrderedCollection new
7224371d514c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1413
diff changeset
  1343
            add:'hello'; 
7224371d514c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1413
diff changeset
  1344
            add:'world';
7224371d514c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1413
diff changeset
  1345
            add:'foo';
7224371d514c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1413
diff changeset
  1346
            add:('bar' asText allBold);
7224371d514c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1413
diff changeset
  1347
            yourself) asStringWithCRs
1413
4788a0d3d6e2 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1395
diff changeset
  1348
    "
4788a0d3d6e2 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1395
diff changeset
  1349
1421
7224371d514c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1413
diff changeset
  1350
    "Modified: 18.5.1996 / 16:43:47 / cg"
602
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  1351
!
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  1352
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  1353
asStringWithCRsFrom:firstLine to:lastLine
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  1354
    "return a string generated by concatenating some of my elements 
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  1355
     (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
  1356
     Nil entries and empty strings are counted as empty lines."
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  1357
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  1358
    ^ self asStringWithCRsFrom:firstLine to:lastLine compressTabs:false withCR:true
1421
7224371d514c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1413
diff changeset
  1359
7224371d514c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1413
diff changeset
  1360
    "
7224371d514c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1413
diff changeset
  1361
     #('hello' 'world' 'foo' 'bar' 'baz') asStringWithCRsFrom:2 to:4 
7224371d514c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1413
diff changeset
  1362
7224371d514c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1413
diff changeset
  1363
    "
7224371d514c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1413
diff changeset
  1364
7224371d514c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1413
diff changeset
  1365
    "Modified: 18.5.1996 / 16:50:55 / cg"
602
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  1366
!
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  1367
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  1368
asStringWithCRsFrom:firstLine to:lastLine compressTabs:compressTabs
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  1369
    "return part of myself as a string with embedded cr's.
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  1370
     My elements must be strings or nil.
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  1371
     If the argument compressTabs is true, leading spaces are converted
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  1372
     to tab-characters (8col tabs).
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  1373
     Nil entries and empty strings are taken as empty lines."
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  1374
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  1375
    ^ self asStringWithCRsFrom:firstLine to:lastLine compressTabs:compressTabs withCR:true
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  1376
!
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  1377
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  1378
asStringWithCRsFrom:firstLine to:lastLine compressTabs:compressTabs withCR:withCR
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  1379
    "return part of myself as a string with embedded cr's.
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  1380
     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
  1381
     taken as empty lines.
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  1382
     If the argument compressTabs is true, leading spaces are converted
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  1383
     to tab-characters (8col tabs). WithCR controls whether the last line
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  1384
     should be followed by a cr or not."
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
    ^ self asStringWith:(Character cr)
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  1387
		   from:firstLine 
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  1388
		     to:lastLine 
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  1389
	   compressTabs:compressTabs 
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  1390
		  final:(withCR ifTrue:[Character cr] ifFalse:[nil])
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  1391
!
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  1392
379
5b5a130ccd09 revision added
claus
parents: 375
diff changeset
  1393
decodeAsLiteralArray
1245
c8afea3d5af0 commentary
Claus Gittinger <cg@exept.de>
parents: 1188
diff changeset
  1394
    "given a literalEncoding in the receiver,
c8afea3d5af0 commentary
Claus Gittinger <cg@exept.de>
parents: 1188
diff changeset
  1395
     create & return the corresponding object.
c8afea3d5af0 commentary
Claus Gittinger <cg@exept.de>
parents: 1188
diff changeset
  1396
     The inverse operation to #literalArrayEncoding."
c8afea3d5af0 commentary
Claus Gittinger <cg@exept.de>
parents: 1188
diff changeset
  1397
2165
9ef030343739 added #zeroIndex for protocol completeness (ST-80)
Claus Gittinger <cg@exept.de>
parents: 2069
diff changeset
  1398
    |clsName cls|
9ef030343739 added #zeroIndex for protocol completeness (ST-80)
Claus Gittinger <cg@exept.de>
parents: 2069
diff changeset
  1399
9ef030343739 added #zeroIndex for protocol completeness (ST-80)
Claus Gittinger <cg@exept.de>
parents: 2069
diff changeset
  1400
    clsName := self first.
9ef030343739 added #zeroIndex for protocol completeness (ST-80)
Claus Gittinger <cg@exept.de>
parents: 2069
diff changeset
  1401
    cls := Smalltalk at:clsName ifAbsent:nil.
379
5b5a130ccd09 revision added
claus
parents: 375
diff changeset
  1402
    cls isNil ifTrue:[
4197
8ae90a572914 raise a special signal, when a literalencodings class
Claus Gittinger <cg@exept.de>
parents: 4154
diff changeset
  1403
        ^ MissingClassInLiteralArrayErrorSignal 
5446
e5ecc71d3054 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5443
diff changeset
  1404
                raiseRequestWith:clsName 
e5ecc71d3054 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5443
diff changeset
  1405
                errorString:('unknown class in literalArray-spec: ' , clsName)
379
5b5a130ccd09 revision added
claus
parents: 375
diff changeset
  1406
    ].
2371
280aa91ff41e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2363
diff changeset
  1407
    ^ cls decodeFromLiteralArray:self.
379
5b5a130ccd09 revision added
claus
parents: 375
diff changeset
  1408
5b5a130ccd09 revision added
claus
parents: 375
diff changeset
  1409
    "
5b5a130ccd09 revision added
claus
parents: 375
diff changeset
  1410
     #(Point 10 20) decodeAsLiteralArray  
5b5a130ccd09 revision added
claus
parents: 375
diff changeset
  1411
     #(Rectangle 100 200 400 500) decodeAsLiteralArray 
2417
64115b76cd15 commentary
Claus Gittinger <cg@exept.de>
parents: 2413
diff changeset
  1412
     #(#MenuItem #rawLabel: 'right' #value: #right) decodeAsLiteralArray 
379
5b5a130ccd09 revision added
claus
parents: 375
diff changeset
  1413
    "
1245
c8afea3d5af0 commentary
Claus Gittinger <cg@exept.de>
parents: 1188
diff changeset
  1414
4197
8ae90a572914 raise a special signal, when a literalencodings class
Claus Gittinger <cg@exept.de>
parents: 4154
diff changeset
  1415
    "Modified: / 18.5.1999 / 14:51:58 / cg"
422
claus
parents: 384
diff changeset
  1416
!
claus
parents: 384
diff changeset
  1417
claus
parents: 384
diff changeset
  1418
literalArrayEncoding
1245
c8afea3d5af0 commentary
Claus Gittinger <cg@exept.de>
parents: 1188
diff changeset
  1419
    "encode myself as an array literal, from which a copy of the receiver
c8afea3d5af0 commentary
Claus Gittinger <cg@exept.de>
parents: 1188
diff changeset
  1420
     can be reconstructed with #decodeAsLiteralArray."
c8afea3d5af0 commentary
Claus Gittinger <cg@exept.de>
parents: 1188
diff changeset
  1421
4807
Claus Gittinger <cg@exept.de>
parents: 4788
diff changeset
  1422
    |encoding|
Claus Gittinger <cg@exept.de>
parents: 4788
diff changeset
  1423
Claus Gittinger <cg@exept.de>
parents: 4788
diff changeset
  1424
    encoding := OrderedCollection with:(self class name).
Claus Gittinger <cg@exept.de>
parents: 4788
diff changeset
  1425
    self do:[:el| encoding add:(el literalArrayEncoding) ].
Claus Gittinger <cg@exept.de>
parents: 4788
diff changeset
  1426
  ^ encoding asArray
Claus Gittinger <cg@exept.de>
parents: 4788
diff changeset
  1427
422
claus
parents: 384
diff changeset
  1428
claus
parents: 384
diff changeset
  1429
    "
claus
parents: 384
diff changeset
  1430
     (Array with:(Color red:50 green:50 blue:50)
1245
c8afea3d5af0 commentary
Claus Gittinger <cg@exept.de>
parents: 1188
diff changeset
  1431
            with:(1 @ 2)
4807
Claus Gittinger <cg@exept.de>
parents: 4788
diff changeset
  1432
     ) literalArrayEncoding decodeAsLiteralArray  
422
claus
parents: 384
diff changeset
  1433
    "
1245
c8afea3d5af0 commentary
Claus Gittinger <cg@exept.de>
parents: 1188
diff changeset
  1434
c8afea3d5af0 commentary
Claus Gittinger <cg@exept.de>
parents: 1188
diff changeset
  1435
    "Modified: 22.4.1996 / 13:00:56 / cg"
260
cefb485445a7 *** empty log message ***
claus
parents: 252
diff changeset
  1436
! !
cefb485445a7 *** empty log message ***
claus
parents: 252
diff changeset
  1437
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1438
!SequenceableCollection methodsFor:'copying'!
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1439
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1440
, aCollection
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1441
    "return a new collection formed from concatenating the receiver with
44
b262907c93ea *** empty log message ***
claus
parents: 42
diff changeset
  1442
     the argument. The class of the new collection is determined by the
b262907c93ea *** empty log message ***
claus
parents: 42
diff changeset
  1443
     receivers class, so mixing classes is possible, if the second collections
b262907c93ea *** empty log message ***
claus
parents: 42
diff changeset
  1444
     elements can be stored into instances of the receivers class."
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1445
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1446
    |newCollection 
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1447
     mySize    "{ Class: SmallInteger }"
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1448
     newSize   "{ Class: SmallInteger }"
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1449
     otherSize "{ Class: SmallInteger }"
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1450
     dstIndex  "{ Class: SmallInteger }"|
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1451
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1452
    mySize := self size.
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1453
    otherSize := aCollection size.
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1454
    newSize := mySize + otherSize.
202
40ca7cc6fb9c *** empty log message ***
claus
parents: 186
diff changeset
  1455
252
  1456
    newCollection := self copyEmptyAndGrow:newSize.   "must grow, otherwise replace fails"
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1457
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1458
    newCollection replaceFrom:1 to:mySize with:self startingAt:1.
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1459
    dstIndex := mySize + 1.
202
40ca7cc6fb9c *** empty log message ***
claus
parents: 186
diff changeset
  1460
    aCollection isSequenceable ifTrue:[
40ca7cc6fb9c *** empty log message ***
claus
parents: 186
diff changeset
  1461
	"
40ca7cc6fb9c *** empty log message ***
claus
parents: 186
diff changeset
  1462
	 yes, aCollection has indexed elements
40ca7cc6fb9c *** empty log message ***
claus
parents: 186
diff changeset
  1463
	"
159
514c749165c3 *** empty log message ***
claus
parents: 118
diff changeset
  1464
	newCollection replaceFrom:dstIndex to:newSize
514c749165c3 *** empty log message ***
claus
parents: 118
diff changeset
  1465
			     with:aCollection startingAt:1.
514c749165c3 *** empty log message ***
claus
parents: 118
diff changeset
  1466
	^ newCollection
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1467
    ] ifFalse:[
202
40ca7cc6fb9c *** empty log message ***
claus
parents: 186
diff changeset
  1468
	"
40ca7cc6fb9c *** empty log message ***
claus
parents: 186
diff changeset
  1469
	 no, enumerate aCollection
40ca7cc6fb9c *** empty log message ***
claus
parents: 186
diff changeset
  1470
	"
159
514c749165c3 *** empty log message ***
claus
parents: 118
diff changeset
  1471
	aCollection do:[:element |
514c749165c3 *** empty log message ***
claus
parents: 118
diff changeset
  1472
	    newCollection at:dstIndex put:element.
514c749165c3 *** empty log message ***
claus
parents: 118
diff changeset
  1473
	    dstIndex := dstIndex + 1
514c749165c3 *** empty log message ***
claus
parents: 118
diff changeset
  1474
	]
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1475
    ].
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1476
    ^ newCollection
44
b262907c93ea *** empty log message ***
claus
parents: 42
diff changeset
  1477
95
d22739a0c6e9 *** empty log message ***
claus
parents: 88
diff changeset
  1478
    "
d22739a0c6e9 *** empty log message ***
claus
parents: 88
diff changeset
  1479
     #($a $b $c) , #(1 2 3)
d22739a0c6e9 *** empty log message ***
claus
parents: 88
diff changeset
  1480
     #($a $b $c) , '123'
d22739a0c6e9 *** empty log message ***
claus
parents: 88
diff changeset
  1481
     'abc' , '123'
d22739a0c6e9 *** empty log message ***
claus
parents: 88
diff changeset
  1482
     'abc' , #($q $w $e $r $t $y) asSortedCollection
d22739a0c6e9 *** empty log message ***
claus
parents: 88
diff changeset
  1483
     'abc' , #(1 2 3 4 5)"  "-- will fail, since strings cannot store integers
d22739a0c6e9 *** empty log message ***
claus
parents: 88
diff changeset
  1484
     'abc' asArray , #(1 2 3 4 5)
d22739a0c6e9 *** empty log message ***
claus
parents: 88
diff changeset
  1485
    "
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1486
!
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1487
5206
c0ebfca02f7c added #copyButFirst: and #copyButLast:
Claus Gittinger <cg@exept.de>
parents: 5188
diff changeset
  1488
copyButFirst:count
c0ebfca02f7c added #copyButFirst: and #copyButLast:
Claus Gittinger <cg@exept.de>
parents: 5188
diff changeset
  1489
    "return a new collection consisting of the receivers elements
c0ebfca02f7c added #copyButFirst: and #copyButLast:
Claus Gittinger <cg@exept.de>
parents: 5188
diff changeset
  1490
     except for the first count elements - for convenience."
c0ebfca02f7c added #copyButFirst: and #copyButLast:
Claus Gittinger <cg@exept.de>
parents: 5188
diff changeset
  1491
c0ebfca02f7c added #copyButFirst: and #copyButLast:
Claus Gittinger <cg@exept.de>
parents: 5188
diff changeset
  1492
    ^ self copyFrom:(count + 1)
c0ebfca02f7c added #copyButFirst: and #copyButLast:
Claus Gittinger <cg@exept.de>
parents: 5188
diff changeset
  1493
c0ebfca02f7c added #copyButFirst: and #copyButLast:
Claus Gittinger <cg@exept.de>
parents: 5188
diff changeset
  1494
    "
c0ebfca02f7c added #copyButFirst: and #copyButLast:
Claus Gittinger <cg@exept.de>
parents: 5188
diff changeset
  1495
     #($a $b $c $d $e $f $g) copyButFirst:2 
c0ebfca02f7c added #copyButFirst: and #copyButLast:
Claus Gittinger <cg@exept.de>
parents: 5188
diff changeset
  1496
     '1234567890' copyButFirst:2
c0ebfca02f7c added #copyButFirst: and #copyButLast:
Claus Gittinger <cg@exept.de>
parents: 5188
diff changeset
  1497
    "
c0ebfca02f7c added #copyButFirst: and #copyButLast:
Claus Gittinger <cg@exept.de>
parents: 5188
diff changeset
  1498
!
c0ebfca02f7c added #copyButFirst: and #copyButLast:
Claus Gittinger <cg@exept.de>
parents: 5188
diff changeset
  1499
c0ebfca02f7c added #copyButFirst: and #copyButLast:
Claus Gittinger <cg@exept.de>
parents: 5188
diff changeset
  1500
copyButLast:count
c0ebfca02f7c added #copyButFirst: and #copyButLast:
Claus Gittinger <cg@exept.de>
parents: 5188
diff changeset
  1501
    "return a new collection consisting of the receivers elements
c0ebfca02f7c added #copyButFirst: and #copyButLast:
Claus Gittinger <cg@exept.de>
parents: 5188
diff changeset
  1502
     except for the last count elements - for convenience."
c0ebfca02f7c added #copyButFirst: and #copyButLast:
Claus Gittinger <cg@exept.de>
parents: 5188
diff changeset
  1503
c0ebfca02f7c added #copyButFirst: and #copyButLast:
Claus Gittinger <cg@exept.de>
parents: 5188
diff changeset
  1504
    ^ self copyTo:(self size - count)
c0ebfca02f7c added #copyButFirst: and #copyButLast:
Claus Gittinger <cg@exept.de>
parents: 5188
diff changeset
  1505
c0ebfca02f7c added #copyButFirst: and #copyButLast:
Claus Gittinger <cg@exept.de>
parents: 5188
diff changeset
  1506
    "
c0ebfca02f7c added #copyButFirst: and #copyButLast:
Claus Gittinger <cg@exept.de>
parents: 5188
diff changeset
  1507
     #($a $b $c $d $e $f $g) copyButLast:2 
c0ebfca02f7c added #copyButFirst: and #copyButLast:
Claus Gittinger <cg@exept.de>
parents: 5188
diff changeset
  1508
     '1234567890' copyButLast:2 
c0ebfca02f7c added #copyButFirst: and #copyButLast:
Claus Gittinger <cg@exept.de>
parents: 5188
diff changeset
  1509
    "
c0ebfca02f7c added #copyButFirst: and #copyButLast:
Claus Gittinger <cg@exept.de>
parents: 5188
diff changeset
  1510
!
c0ebfca02f7c added #copyButFirst: and #copyButLast:
Claus Gittinger <cg@exept.de>
parents: 5188
diff changeset
  1511
602
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  1512
copyFirst:count
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  1513
    "return a new collection consisting of the receivers first count
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  1514
     elements - this is just a rename of copyTo: - for compatibility."
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  1515
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  1516
    ^ self copyFrom:1 to:count
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
    "
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  1519
     #($a $b $c $d $e $f $g) copyFirst:5
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  1520
     '1234567890' copyFirst:4
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  1521
    "
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  1522
!
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  1523
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  1524
copyFrom:start
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  1525
    "return a new collection consisting of receivers elements
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  1526
     from start to the end of the collection"
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  1527
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  1528
    ^ self copyFrom:start to:(self size)
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  1529
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  1530
    "
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  1531
     #($a $b $c $d $e $f $g) copyFrom:2
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  1532
     '1234567890' copyFrom:2
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  1533
    "
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  1534
!
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  1535
2413
a3f91741d7ba added #replaceFrom:count:* methods
Claus Gittinger <cg@exept.de>
parents: 2411
diff changeset
  1536
copyFrom:start count:numberOfElements
a3f91741d7ba added #replaceFrom:count:* methods
Claus Gittinger <cg@exept.de>
parents: 2411
diff changeset
  1537
    "return a new collection consisting of numberOfElements elements
a3f91741d7ba added #replaceFrom:count:* methods
Claus Gittinger <cg@exept.de>
parents: 2411
diff changeset
  1538
     extracted from the receiver starting at index start
a3f91741d7ba added #replaceFrom:count:* methods
Claus Gittinger <cg@exept.de>
parents: 2411
diff changeset
  1539
     (i.e. extract a slice)"
a3f91741d7ba added #replaceFrom:count:* methods
Claus Gittinger <cg@exept.de>
parents: 2411
diff changeset
  1540
a3f91741d7ba added #replaceFrom:count:* methods
Claus Gittinger <cg@exept.de>
parents: 2411
diff changeset
  1541
    ^ self
a3f91741d7ba added #replaceFrom:count:* methods
Claus Gittinger <cg@exept.de>
parents: 2411
diff changeset
  1542
        copyFrom:start
a3f91741d7ba added #replaceFrom:count:* methods
Claus Gittinger <cg@exept.de>
parents: 2411
diff changeset
  1543
        to:(start + numberOfElements - 1)
a3f91741d7ba added #replaceFrom:count:* methods
Claus Gittinger <cg@exept.de>
parents: 2411
diff changeset
  1544
a3f91741d7ba added #replaceFrom:count:* methods
Claus Gittinger <cg@exept.de>
parents: 2411
diff changeset
  1545
    "
a3f91741d7ba added #replaceFrom:count:* methods
Claus Gittinger <cg@exept.de>
parents: 2411
diff changeset
  1546
     #($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
  1547
     '1234567890' copyFrom:2 count:5    
a3f91741d7ba added #replaceFrom:count:* methods
Claus Gittinger <cg@exept.de>
parents: 2411
diff changeset
  1548
    "
a3f91741d7ba added #replaceFrom:count:* methods
Claus Gittinger <cg@exept.de>
parents: 2411
diff changeset
  1549
a3f91741d7ba added #replaceFrom:count:* methods
Claus Gittinger <cg@exept.de>
parents: 2411
diff changeset
  1550
    "Modified: 20.2.1997 / 14:23:01 / cg"
a3f91741d7ba added #replaceFrom:count:* methods
Claus Gittinger <cg@exept.de>
parents: 2411
diff changeset
  1551
!
a3f91741d7ba added #replaceFrom:count:* methods
Claus Gittinger <cg@exept.de>
parents: 2411
diff changeset
  1552
602
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  1553
copyFrom:start to:stop
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  1554
    "return a new collection consisting of receivers elements
4403
eb4379909671 comment
Claus Gittinger <cg@exept.de>
parents: 4402
diff changeset
  1555
     between start and stop.
eb4379909671 comment
Claus Gittinger <cg@exept.de>
parents: 4402
diff changeset
  1556
     Returns an empty collection in some situations"
602
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  1557
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  1558
    |newCollection newSize|
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  1559
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  1560
    newSize := stop - start + 1.
4402
7c19502120b7 care for bad startIndex in #copyFrom:to:
Claus Gittinger <cg@exept.de>
parents: 4389
diff changeset
  1561
    newSize < 0 ifTrue:[
7c19502120b7 care for bad startIndex in #copyFrom:to:
Claus Gittinger <cg@exept.de>
parents: 4389
diff changeset
  1562
        newSize := 0
7c19502120b7 care for bad startIndex in #copyFrom:to:
Claus Gittinger <cg@exept.de>
parents: 4389
diff changeset
  1563
    ].
602
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  1564
    newCollection := self copyEmptyAndGrow:newSize.
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  1565
    newCollection replaceFrom:1 to:newSize with:self startingAt:start.
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  1566
    ^ newCollection
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  1567
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  1568
    "
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  1569
     #($a $b $c $d $e $f $g) copyFrom:2 to:5
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  1570
     '1234567890' copyFrom:2 to:5
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  1571
    "
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  1572
!
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  1573
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  1574
copyLast:count
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  1575
    "return a new collection consisting of the receivers last count
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  1576
     elements."
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  1577
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  1578
    |sz|
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  1579
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  1580
    sz := self size.
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  1581
    ^ self copyFrom:(sz - count + 1) to:sz
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  1582
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  1583
    "
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  1584
     #($a $b $c $d $e $f $g) copyLast:5
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  1585
     '1234567890' copyLast:4
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  1586
    "
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  1587
!
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  1588
3653
cc018fcae490 added #copyReplaceAll:with:
Claus Gittinger <cg@exept.de>
parents: 3645
diff changeset
  1589
copyReplaceAll:oldElement with:newElement
cc018fcae490 added #copyReplaceAll:with:
Claus Gittinger <cg@exept.de>
parents: 3645
diff changeset
  1590
    "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
  1591
     have been replaced by newElement."
cc018fcae490 added #copyReplaceAll:with:
Claus Gittinger <cg@exept.de>
parents: 3645
diff changeset
  1592
cc018fcae490 added #copyReplaceAll:with:
Claus Gittinger <cg@exept.de>
parents: 3645
diff changeset
  1593
    ^ self copy replaceAll:oldElement with:newElement
cc018fcae490 added #copyReplaceAll:with:
Claus Gittinger <cg@exept.de>
parents: 3645
diff changeset
  1594
cc018fcae490 added #copyReplaceAll:with:
Claus Gittinger <cg@exept.de>
parents: 3645
diff changeset
  1595
    "
cc018fcae490 added #copyReplaceAll:with:
Claus Gittinger <cg@exept.de>
parents: 3645
diff changeset
  1596
     #(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
  1597
     'hello world' copyReplaceAll:$l with:$*         
cc018fcae490 added #copyReplaceAll:with:
Claus Gittinger <cg@exept.de>
parents: 3645
diff changeset
  1598
    "
cc018fcae490 added #copyReplaceAll:with:
Claus Gittinger <cg@exept.de>
parents: 3645
diff changeset
  1599
cc018fcae490 added #copyReplaceAll:with:
Claus Gittinger <cg@exept.de>
parents: 3645
diff changeset
  1600
    "Modified: / 18.7.1998 / 22:52:17 / cg"
cc018fcae490 added #copyReplaceAll:with:
Claus Gittinger <cg@exept.de>
parents: 3645
diff changeset
  1601
!
cc018fcae490 added #copyReplaceAll:with:
Claus Gittinger <cg@exept.de>
parents: 3645
diff changeset
  1602
3992
549eefe16a28 added #copyReplaceAll:withAll:
Claus Gittinger <cg@exept.de>
parents: 3887
diff changeset
  1603
copyReplaceAll:oldObject withAll:aCollection
549eefe16a28 added #copyReplaceAll:withAll:
Claus Gittinger <cg@exept.de>
parents: 3887
diff changeset
  1604
    "return a copy, where all oldObjects are replaced by all
549eefe16a28 added #copyReplaceAll:withAll:
Claus Gittinger <cg@exept.de>
parents: 3887
diff changeset
  1605
     elements from aCollection (i.e. sliced in).
549eefe16a28 added #copyReplaceAll:withAll:
Claus Gittinger <cg@exept.de>
parents: 3887
diff changeset
  1606
     Non-destructive; returns a new collection.
549eefe16a28 added #copyReplaceAll:withAll:
Claus Gittinger <cg@exept.de>
parents: 3887
diff changeset
  1607
     The implementation here is a general-purpose one;
549eefe16a28 added #copyReplaceAll:withAll:
Claus Gittinger <cg@exept.de>
parents: 3887
diff changeset
  1608
     and should be redefined in String, if heavily used."
549eefe16a28 added #copyReplaceAll:withAll:
Claus Gittinger <cg@exept.de>
parents: 3887
diff changeset
  1609
549eefe16a28 added #copyReplaceAll:withAll:
Claus Gittinger <cg@exept.de>
parents: 3887
diff changeset
  1610
    |s i|
549eefe16a28 added #copyReplaceAll:withAll:
Claus Gittinger <cg@exept.de>
parents: 3887
diff changeset
  1611
549eefe16a28 added #copyReplaceAll:withAll:
Claus Gittinger <cg@exept.de>
parents: 3887
diff changeset
  1612
    s := WriteStream on:self species new.
549eefe16a28 added #copyReplaceAll:withAll:
Claus Gittinger <cg@exept.de>
parents: 3887
diff changeset
  1613
    self do:[:el |
549eefe16a28 added #copyReplaceAll:withAll:
Claus Gittinger <cg@exept.de>
parents: 3887
diff changeset
  1614
        el = oldObject ifTrue:[
549eefe16a28 added #copyReplaceAll:withAll:
Claus Gittinger <cg@exept.de>
parents: 3887
diff changeset
  1615
            aCollection do:[:el2 |
549eefe16a28 added #copyReplaceAll:withAll:
Claus Gittinger <cg@exept.de>
parents: 3887
diff changeset
  1616
                s nextPut:el2
549eefe16a28 added #copyReplaceAll:withAll:
Claus Gittinger <cg@exept.de>
parents: 3887
diff changeset
  1617
            ]
549eefe16a28 added #copyReplaceAll:withAll:
Claus Gittinger <cg@exept.de>
parents: 3887
diff changeset
  1618
        ] ifFalse:[
549eefe16a28 added #copyReplaceAll:withAll:
Claus Gittinger <cg@exept.de>
parents: 3887
diff changeset
  1619
            s nextPut:el
549eefe16a28 added #copyReplaceAll:withAll:
Claus Gittinger <cg@exept.de>
parents: 3887
diff changeset
  1620
        ]
549eefe16a28 added #copyReplaceAll:withAll:
Claus Gittinger <cg@exept.de>
parents: 3887
diff changeset
  1621
    ].
549eefe16a28 added #copyReplaceAll:withAll:
Claus Gittinger <cg@exept.de>
parents: 3887
diff changeset
  1622
    ^ s contents
549eefe16a28 added #copyReplaceAll:withAll:
Claus Gittinger <cg@exept.de>
parents: 3887
diff changeset
  1623
549eefe16a28 added #copyReplaceAll:withAll:
Claus Gittinger <cg@exept.de>
parents: 3887
diff changeset
  1624
    "
549eefe16a28 added #copyReplaceAll:withAll:
Claus Gittinger <cg@exept.de>
parents: 3887
diff changeset
  1625
     args:    oldObject  : <object>
549eefe16a28 added #copyReplaceAll:withAll:
Claus Gittinger <cg@exept.de>
parents: 3887
diff changeset
  1626
              newObject  : <collection>
549eefe16a28 added #copyReplaceAll:withAll:
Claus Gittinger <cg@exept.de>
parents: 3887
diff changeset
  1627
549eefe16a28 added #copyReplaceAll:withAll:
Claus Gittinger <cg@exept.de>
parents: 3887
diff changeset
  1628
     returns: newCollection
549eefe16a28 added #copyReplaceAll:withAll:
Claus Gittinger <cg@exept.de>
parents: 3887
diff changeset
  1629
    "
549eefe16a28 added #copyReplaceAll:withAll:
Claus Gittinger <cg@exept.de>
parents: 3887
diff changeset
  1630
549eefe16a28 added #copyReplaceAll:withAll:
Claus Gittinger <cg@exept.de>
parents: 3887
diff changeset
  1631
    "
549eefe16a28 added #copyReplaceAll:withAll:
Claus Gittinger <cg@exept.de>
parents: 3887
diff changeset
  1632
     '123123abc123' copyReplaceAll:$1 withAll:'one'    
549eefe16a28 added #copyReplaceAll:withAll:
Claus Gittinger <cg@exept.de>
parents: 3887
diff changeset
  1633
     #(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
  1634
    "
549eefe16a28 added #copyReplaceAll:withAll:
Claus Gittinger <cg@exept.de>
parents: 3887
diff changeset
  1635
549eefe16a28 added #copyReplaceAll:withAll:
Claus Gittinger <cg@exept.de>
parents: 3887
diff changeset
  1636
!
549eefe16a28 added #copyReplaceAll:withAll:
Claus Gittinger <cg@exept.de>
parents: 3887
diff changeset
  1637
602
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  1638
copyReplaceFrom:startIndex to:endIndex with:aCollection
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  1639
    "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
  1640
     endIndex have been replaced by the elements of aCollection"
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  1641
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  1642
    |newColl sz replSize|
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  1643
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  1644
    replSize := aCollection size.
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  1645
    sz := self size - (endIndex - startIndex + 1) + replSize.
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  1646
    newColl := self copyEmptyAndGrow:sz.
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  1647
    newColl replaceFrom:1 to:(startIndex - 1) with:self.
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  1648
    newColl replaceFrom:startIndex with:aCollection.
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  1649
    newColl replaceFrom:(startIndex + replSize) with:self startingAt:(endIndex + 1).
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  1650
    ^ newColl
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  1651
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  1652
    "
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  1653
     #(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
  1654
     'hello world' copyReplaceFrom:6 to:6 with:' there, '  
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  1655
    "
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  1656
!
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  1657
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  1658
copyReplaceFrom:startIndex with:aCollection
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  1659
    "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
  1660
     the end have been replaced by the elements of aCollection"
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  1661
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  1662
    ^ self copyReplaceFrom:startIndex to:(self size) with:aCollection
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  1663
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  1664
    "
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  1665
     #(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
  1666
     'hello world' copyReplaceFrom:7 with:'smalltalk fan'  
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  1667
    "
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  1668
!
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  1669
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  1670
copyThrough:element
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  1671
    "return a new collection consisting of the receiver elements
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  1672
     up-to (AND including) the first occurence of element."
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  1673
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  1674
    |idx|
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
    idx := self indexOf:element.
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  1677
    idx == 0 ifTrue:[^ nil].    "question: is this ok?"
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  1678
    ^ self copyFrom:1 to:idx
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  1679
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
     #($a $b $c $d $e $f $g) copyThrough:$d
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  1682
     '1234567890' copyThrough:$5
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  1683
     '1234567890' copyThrough:$a
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  1684
     '1234567890' copyThrough:$1
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  1685
    "
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  1686
!
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  1687
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  1688
copyTo:stop
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  1689
    "return a new collection consisting of receivers elements
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  1690
     from 1 up to (including) index stop"
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  1691
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  1692
    ^ self copyFrom:1 to:stop
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  1693
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
     #($a $b $c $d $e $f $g) copyTo:5
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  1696
     '1234567890' copyTo:4
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  1697
    "
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  1698
!
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  1699
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  1700
copyUpTo:element
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  1701
    "return a new collection consisting of the receiver elements
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  1702
     up-to (but excluding) the first occurence of element;
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  1703
     or to the end, if element is not included"
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  1704
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  1705
    |idx|
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  1706
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  1707
    idx := self indexOf:element.
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  1708
    idx == 0 ifTrue:[^ self copy].    "question: is this ok?"
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  1709
    idx == 1 ifTrue:[^ self copyEmpty].
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  1710
    ^ self copyFrom:1 to:(idx-1)
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  1711
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  1712
    "
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  1713
     #($a $b $c $d $e $f $g) copyUpTo:$d
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  1714
     '1234567890' copyUpTo:$5
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  1715
     '1234567890' copyUpTo:$a
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  1716
     '1234567890' copyUpTo:$1
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  1717
     '123456789' copyUpTo:$0
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  1718
    "
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  1719
!
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  1720
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1721
copyWith:newElement
233
98f588af201a comments
claus
parents: 202
diff changeset
  1722
    "return a new collection containing the receivers elements
98f588af201a comments
claus
parents: 202
diff changeset
  1723
     and the single new element, newElement. 
98f588af201a comments
claus
parents: 202
diff changeset
  1724
     This is different from concatentation, which expects another collection
98f588af201a comments
claus
parents: 202
diff changeset
  1725
     as argument, but equivalent to copy-and-addLast."
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1726
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1727
    |newCollection mySize newSize|
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1728
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1729
    mySize := self size.
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1730
    newSize := mySize + 1.
252
  1731
    newCollection := self copyEmptyAndGrow:newSize.
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1732
    newCollection replaceFrom:1 to:mySize with:self startingAt:1.
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1733
    newCollection at:newSize put:newElement.
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1734
    ^newCollection
44
b262907c93ea *** empty log message ***
claus
parents: 42
diff changeset
  1735
95
d22739a0c6e9 *** empty log message ***
claus
parents: 88
diff changeset
  1736
    "
d22739a0c6e9 *** empty log message ***
claus
parents: 88
diff changeset
  1737
     #(1 2 3 4 5) copyWith:$a
d22739a0c6e9 *** empty log message ***
claus
parents: 88
diff changeset
  1738
     'abcdefg' copyWith:$h
d22739a0c6e9 *** empty log message ***
claus
parents: 88
diff changeset
  1739
     'abcdefg' copyWith:'123'   -- will fail: string cannot be stored into string
d22739a0c6e9 *** empty log message ***
claus
parents: 88
diff changeset
  1740
     'abcdefg' copyWith:1       -- will fail: integer cannot be stored into string
d22739a0c6e9 *** empty log message ***
claus
parents: 88
diff changeset
  1741
    "
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1742
!
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1743
61
claus
parents: 44
diff changeset
  1744
copyWithout:elementToSkip
claus
parents: 44
diff changeset
  1745
    "return a new collection consisting of a copy of the receiver, with
claus
parents: 44
diff changeset
  1746
     ALL elements equal to elementToSkip are left out.
claus
parents: 44
diff changeset
  1747
     No error is reported, if elementToSkip is not in the collection."
claus
parents: 44
diff changeset
  1748
293
31df3850e98c *** empty log message ***
claus
parents: 282
diff changeset
  1749
    |n         "{ Class: SmallInteger }"
31df3850e98c *** empty log message ***
claus
parents: 282
diff changeset
  1750
     sz        "{ Class: SmallInteger }"
31df3850e98c *** empty log message ***
claus
parents: 282
diff changeset
  1751
     srcIndex  "{ Class: SmallInteger }"
31df3850e98c *** empty log message ***
claus
parents: 282
diff changeset
  1752
     dstIndex  "{ Class: SmallInteger }"
31df3850e98c *** empty log message ***
claus
parents: 282
diff changeset
  1753
     skipIndex "{ Class: SmallInteger }"
31df3850e98c *** empty log message ***
claus
parents: 282
diff changeset
  1754
     copy l|
61
claus
parents: 44
diff changeset
  1755
claus
parents: 44
diff changeset
  1756
    "the code below may look like overkill, 
claus
parents: 44
diff changeset
  1757
     however, for big collections its better to move data
claus
parents: 44
diff changeset
  1758
     around in big chunks"
claus
parents: 44
diff changeset
  1759
claus
parents: 44
diff changeset
  1760
    n := self occurrencesOf:elementToSkip.
claus
parents: 44
diff changeset
  1761
    n == 0 ifTrue:[^ self copy].
claus
parents: 44
diff changeset
  1762
claus
parents: 44
diff changeset
  1763
    sz := self size.
252
  1764
    copy := self copyEmptyAndGrow:(sz - n).
61
claus
parents: 44
diff changeset
  1765
claus
parents: 44
diff changeset
  1766
    srcIndex := 1.
claus
parents: 44
diff changeset
  1767
    dstIndex := 1.
claus
parents: 44
diff changeset
  1768
claus
parents: 44
diff changeset
  1769
    n timesRepeat:[
159
514c749165c3 *** empty log message ***
claus
parents: 118
diff changeset
  1770
	skipIndex := self indexOf:elementToSkip startingAt:srcIndex.
514c749165c3 *** empty log message ***
claus
parents: 118
diff changeset
  1771
	l := skipIndex - srcIndex.
514c749165c3 *** empty log message ***
claus
parents: 118
diff changeset
  1772
	l ~~ 0 ifTrue:[
514c749165c3 *** empty log message ***
claus
parents: 118
diff changeset
  1773
	    copy replaceFrom:dstIndex to:(dstIndex + l - 1) 
514c749165c3 *** empty log message ***
claus
parents: 118
diff changeset
  1774
			with:self startingAt:srcIndex.
514c749165c3 *** empty log message ***
claus
parents: 118
diff changeset
  1775
	    dstIndex := dstIndex + l
514c749165c3 *** empty log message ***
claus
parents: 118
diff changeset
  1776
	].
514c749165c3 *** empty log message ***
claus
parents: 118
diff changeset
  1777
	srcIndex := skipIndex + 1
61
claus
parents: 44
diff changeset
  1778
    ].
claus
parents: 44
diff changeset
  1779
    l := sz - srcIndex.
claus
parents: 44
diff changeset
  1780
    copy replaceFrom:dstIndex to:(dstIndex + l)
159
514c749165c3 *** empty log message ***
claus
parents: 118
diff changeset
  1781
		with:self startingAt:srcIndex.
61
claus
parents: 44
diff changeset
  1782
    ^ copy
claus
parents: 44
diff changeset
  1783
95
d22739a0c6e9 *** empty log message ***
claus
parents: 88
diff changeset
  1784
    "
d22739a0c6e9 *** empty log message ***
claus
parents: 88
diff changeset
  1785
     #($a $b $c $d $e $f $g) copyWithout:$d
d22739a0c6e9 *** empty log message ***
claus
parents: 88
diff changeset
  1786
     #($a $b $c $d $e $f $g) copyWithout:$a
d22739a0c6e9 *** empty log message ***
claus
parents: 88
diff changeset
  1787
     #($a $b $c $d $e $f $g) copyWithout:$g
202
40ca7cc6fb9c *** empty log message ***
claus
parents: 186
diff changeset
  1788
     'abcdefghi' copyWithout:$h    
40ca7cc6fb9c *** empty log message ***
claus
parents: 186
diff changeset
  1789
     'abcdefg' copyWithout:$h       
95
d22739a0c6e9 *** empty log message ***
claus
parents: 88
diff changeset
  1790
     #($a $b $c $a $a $d $e $a $f $g) copyWithout:$a
d22739a0c6e9 *** empty log message ***
claus
parents: 88
diff changeset
  1791
     #($a $b $c $d $e $f $g) copyWithout:$x
d22739a0c6e9 *** empty log message ***
claus
parents: 88
diff changeset
  1792
     #(90 80 70 60 50) copyWithout:70
d22739a0c6e9 *** empty log message ***
claus
parents: 88
diff changeset
  1793
     #(90 80 70 80 60 45 80 50) copyWithout:80
d22739a0c6e9 *** empty log message ***
claus
parents: 88
diff changeset
  1794
    "
61
claus
parents: 44
diff changeset
  1795
!
claus
parents: 44
diff changeset
  1796
602
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  1797
copyWithoutFirst:elementToSkip
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  1798
    "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
  1799
     without the first elementToSkip, if it was present. 
5206
c0ebfca02f7c added #copyButFirst: and #copyButLast:
Claus Gittinger <cg@exept.de>
parents: 5188
diff changeset
  1800
     No error is reported, if elementToSkip is not in the collection.
c0ebfca02f7c added #copyButFirst: and #copyButLast:
Claus Gittinger <cg@exept.de>
parents: 5188
diff changeset
  1801
     Do not confuse this with copyButFirst:"
602
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  1802
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  1803
    |copy skipIndex sz|
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
    skipIndex := self indexOf:elementToSkip startingAt:1.
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  1806
    (skipIndex == 0) ifTrue:[^ self copy].
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  1807
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  1808
    sz := self size - 1.
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  1809
    copy := self copyEmptyAndGrow:sz.
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  1810
    copy replaceFrom:1 to:(skipIndex - 1) with:self startingAt:1.
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  1811
    copy replaceFrom:skipIndex to:sz with:self startingAt:(skipIndex + 1).
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  1812
    ^ copy
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  1813
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  1814
    "
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  1815
     #($a $b $c $d $e $f $g) copyWithoutFirst:$d
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  1816
     #($a $b $c $d $e $f $g) copyWithoutFirst:$x
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  1817
     #(90 80 70 60 50) copyWithoutFirst:70
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  1818
     #(90 80 70 80 60 45 80 50) copyWithoutFirst:80
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  1819
    "
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  1820
!
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  1821
61
claus
parents: 44
diff changeset
  1822
copyWithoutIndex:omitIndex
claus
parents: 44
diff changeset
  1823
    "return a new collection consisting of receivers elements
claus
parents: 44
diff changeset
  1824
     without the argument stored at omitIndex"
claus
parents: 44
diff changeset
  1825
claus
parents: 44
diff changeset
  1826
    |copy sz|
claus
parents: 44
diff changeset
  1827
202
40ca7cc6fb9c *** empty log message ***
claus
parents: 186
diff changeset
  1828
    sz := self size - 1.
252
  1829
    copy := self copyEmptyAndGrow:sz.
293
31df3850e98c *** empty log message ***
claus
parents: 282
diff changeset
  1830
    copy replaceFrom:1 to:(omitIndex - 1) with:self startingAt:1.
31df3850e98c *** empty log message ***
claus
parents: 282
diff changeset
  1831
    copy replaceFrom:omitIndex to:sz with:self startingAt:(omitIndex + 1).
61
claus
parents: 44
diff changeset
  1832
    ^ copy
claus
parents: 44
diff changeset
  1833
95
d22739a0c6e9 *** empty log message ***
claus
parents: 88
diff changeset
  1834
    "
d22739a0c6e9 *** empty log message ***
claus
parents: 88
diff changeset
  1835
     #(1 2 3 4 5 6 7 8 9 0) copyWithoutIndex:3
d22739a0c6e9 *** empty log message ***
claus
parents: 88
diff changeset
  1836
     'abcdefghijkl' copyWithoutIndex:5
d22739a0c6e9 *** empty log message ***
claus
parents: 88
diff changeset
  1837
    "
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1838
!
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1839
202
40ca7cc6fb9c *** empty log message ***
claus
parents: 186
diff changeset
  1840
copyWithoutLast:count
40ca7cc6fb9c *** empty log message ***
claus
parents: 186
diff changeset
  1841
    "return a new collection consisting of the receivers elements
5206
c0ebfca02f7c added #copyButFirst: and #copyButLast:
Claus Gittinger <cg@exept.de>
parents: 5188
diff changeset
  1842
     except the last count elements.
c0ebfca02f7c added #copyButFirst: and #copyButLast:
Claus Gittinger <cg@exept.de>
parents: 5188
diff changeset
  1843
     That is the same as copyButLast: and badly named (for compatibility),
c0ebfca02f7c added #copyButFirst: and #copyButLast:
Claus Gittinger <cg@exept.de>
parents: 5188
diff changeset
  1844
     because the name may confuse users with the copyWithoutFirst: functionality.
c0ebfca02f7c added #copyButFirst: and #copyButLast:
Claus Gittinger <cg@exept.de>
parents: 5188
diff changeset
  1845
     Please use copyButLast:."
c0ebfca02f7c added #copyButFirst: and #copyButLast:
Claus Gittinger <cg@exept.de>
parents: 5188
diff changeset
  1846
c0ebfca02f7c added #copyButFirst: and #copyButLast:
Claus Gittinger <cg@exept.de>
parents: 5188
diff changeset
  1847
    ^ self copyTo:(self size - count)
202
40ca7cc6fb9c *** empty log message ***
claus
parents: 186
diff changeset
  1848
40ca7cc6fb9c *** empty log message ***
claus
parents: 186
diff changeset
  1849
    "
40ca7cc6fb9c *** empty log message ***
claus
parents: 186
diff changeset
  1850
     #($a $b $c $d $e $f $g) copyWithoutLast:5 
40ca7cc6fb9c *** empty log message ***
claus
parents: 186
diff changeset
  1851
     '1234567890' copyWithoutLast:4 
40ca7cc6fb9c *** empty log message ***
claus
parents: 186
diff changeset
  1852
    "
5231
df6dd43af1c5 comments;
Claus Gittinger <cg@exept.de>
parents: 5220
diff changeset
  1853
!
df6dd43af1c5 comments;
Claus Gittinger <cg@exept.de>
parents: 5220
diff changeset
  1854
df6dd43af1c5 comments;
Claus Gittinger <cg@exept.de>
parents: 5220
diff changeset
  1855
restAfter:anElement
df6dd43af1c5 comments;
Claus Gittinger <cg@exept.de>
parents: 5220
diff changeset
  1856
    "return a new collection consisting of the receivers elements from
df6dd43af1c5 comments;
Claus Gittinger <cg@exept.de>
parents: 5220
diff changeset
  1857
     (but excluding) anElement.
df6dd43af1c5 comments;
Claus Gittinger <cg@exept.de>
parents: 5220
diff changeset
  1858
     If anElement is not in the receiver, an empty collection is returned.
df6dd43af1c5 comments;
Claus Gittinger <cg@exept.de>
parents: 5220
diff changeset
  1859
     See also #upTo: and #copyFrom:index."
df6dd43af1c5 comments;
Claus Gittinger <cg@exept.de>
parents: 5220
diff changeset
  1860
df6dd43af1c5 comments;
Claus Gittinger <cg@exept.de>
parents: 5220
diff changeset
  1861
    |pos|
df6dd43af1c5 comments;
Claus Gittinger <cg@exept.de>
parents: 5220
diff changeset
  1862
df6dd43af1c5 comments;
Claus Gittinger <cg@exept.de>
parents: 5220
diff changeset
  1863
    pos := self indexOf:anElement.
df6dd43af1c5 comments;
Claus Gittinger <cg@exept.de>
parents: 5220
diff changeset
  1864
    pos == 0 ifTrue:[^ self species new].
df6dd43af1c5 comments;
Claus Gittinger <cg@exept.de>
parents: 5220
diff changeset
  1865
    ^ self copyFrom:(pos + 1)
df6dd43af1c5 comments;
Claus Gittinger <cg@exept.de>
parents: 5220
diff changeset
  1866
df6dd43af1c5 comments;
Claus Gittinger <cg@exept.de>
parents: 5220
diff changeset
  1867
    "
df6dd43af1c5 comments;
Claus Gittinger <cg@exept.de>
parents: 5220
diff changeset
  1868
     #(1 2 3 4 5 6 7 8 9) restAfter:5  
df6dd43af1c5 comments;
Claus Gittinger <cg@exept.de>
parents: 5220
diff changeset
  1869
     #(1 2 3 4 5 6 7 8 9) restAfter:10  
df6dd43af1c5 comments;
Claus Gittinger <cg@exept.de>
parents: 5220
diff changeset
  1870
     'hello world' restAfter:Character space  
df6dd43af1c5 comments;
Claus Gittinger <cg@exept.de>
parents: 5220
diff changeset
  1871
     #(9 8 7 6 5 4 3 2 1) asSortedCollection restAfter:5 
df6dd43af1c5 comments;
Claus Gittinger <cg@exept.de>
parents: 5220
diff changeset
  1872
df6dd43af1c5 comments;
Claus Gittinger <cg@exept.de>
parents: 5220
diff changeset
  1873
     ('hello world' upTo:Character space) 
df6dd43af1c5 comments;
Claus Gittinger <cg@exept.de>
parents: 5220
diff changeset
  1874
     , 
df6dd43af1c5 comments;
Claus Gittinger <cg@exept.de>
parents: 5220
diff changeset
  1875
     ('hello world' restAfter:Character space)     
df6dd43af1c5 comments;
Claus Gittinger <cg@exept.de>
parents: 5220
diff changeset
  1876
df6dd43af1c5 comments;
Claus Gittinger <cg@exept.de>
parents: 5220
diff changeset
  1877
     raises an error:
df6dd43af1c5 comments;
Claus Gittinger <cg@exept.de>
parents: 5220
diff changeset
  1878
df6dd43af1c5 comments;
Claus Gittinger <cg@exept.de>
parents: 5220
diff changeset
  1879
     (Dictionary new 
df6dd43af1c5 comments;
Claus Gittinger <cg@exept.de>
parents: 5220
diff changeset
  1880
        at:#foo put:'foo';
df6dd43af1c5 comments;
Claus Gittinger <cg@exept.de>
parents: 5220
diff changeset
  1881
        at:#bar put:'bar';
df6dd43af1c5 comments;
Claus Gittinger <cg@exept.de>
parents: 5220
diff changeset
  1882
        at:#baz put:'baz';
df6dd43af1c5 comments;
Claus Gittinger <cg@exept.de>
parents: 5220
diff changeset
  1883
        yourself) restAfter:#bar
df6dd43af1c5 comments;
Claus Gittinger <cg@exept.de>
parents: 5220
diff changeset
  1884
                
df6dd43af1c5 comments;
Claus Gittinger <cg@exept.de>
parents: 5220
diff changeset
  1885
    "
df6dd43af1c5 comments;
Claus Gittinger <cg@exept.de>
parents: 5220
diff changeset
  1886
df6dd43af1c5 comments;
Claus Gittinger <cg@exept.de>
parents: 5220
diff changeset
  1887
    "Modified: 11.5.1996 / 11:14:05 / cg"
df6dd43af1c5 comments;
Claus Gittinger <cg@exept.de>
parents: 5220
diff changeset
  1888
!
df6dd43af1c5 comments;
Claus Gittinger <cg@exept.de>
parents: 5220
diff changeset
  1889
df6dd43af1c5 comments;
Claus Gittinger <cg@exept.de>
parents: 5220
diff changeset
  1890
upTo:anElement
df6dd43af1c5 comments;
Claus Gittinger <cg@exept.de>
parents: 5220
diff changeset
  1891
    "return a new collection consisting of the receivers elements upTo
df6dd43af1c5 comments;
Claus Gittinger <cg@exept.de>
parents: 5220
diff changeset
  1892
     (but excluding) anElement.
df6dd43af1c5 comments;
Claus Gittinger <cg@exept.de>
parents: 5220
diff changeset
  1893
     If anElement is not in the receiver, the returned collection
df6dd43af1c5 comments;
Claus Gittinger <cg@exept.de>
parents: 5220
diff changeset
  1894
     will consist of all elements of the receiver.
df6dd43af1c5 comments;
Claus Gittinger <cg@exept.de>
parents: 5220
diff changeset
  1895
     See also #copyFrom:index."
df6dd43af1c5 comments;
Claus Gittinger <cg@exept.de>
parents: 5220
diff changeset
  1896
df6dd43af1c5 comments;
Claus Gittinger <cg@exept.de>
parents: 5220
diff changeset
  1897
    |pos|
df6dd43af1c5 comments;
Claus Gittinger <cg@exept.de>
parents: 5220
diff changeset
  1898
df6dd43af1c5 comments;
Claus Gittinger <cg@exept.de>
parents: 5220
diff changeset
  1899
    pos := self indexOf:anElement.
df6dd43af1c5 comments;
Claus Gittinger <cg@exept.de>
parents: 5220
diff changeset
  1900
    pos == 0 ifTrue:[^ self copy].
df6dd43af1c5 comments;
Claus Gittinger <cg@exept.de>
parents: 5220
diff changeset
  1901
df6dd43af1c5 comments;
Claus Gittinger <cg@exept.de>
parents: 5220
diff changeset
  1902
    ^ self copyFrom:1 to:(pos - 1)
df6dd43af1c5 comments;
Claus Gittinger <cg@exept.de>
parents: 5220
diff changeset
  1903
df6dd43af1c5 comments;
Claus Gittinger <cg@exept.de>
parents: 5220
diff changeset
  1904
    "
df6dd43af1c5 comments;
Claus Gittinger <cg@exept.de>
parents: 5220
diff changeset
  1905
     #(1 2 3 4 5 6 7 8 9) upTo:5  
df6dd43af1c5 comments;
Claus Gittinger <cg@exept.de>
parents: 5220
diff changeset
  1906
     'hello world' upTo:Character space  
df6dd43af1c5 comments;
Claus Gittinger <cg@exept.de>
parents: 5220
diff changeset
  1907
     #(9 8 7 6 5 4 3 2 1) asSortedCollection upTo:5 
df6dd43af1c5 comments;
Claus Gittinger <cg@exept.de>
parents: 5220
diff changeset
  1908
df6dd43af1c5 comments;
Claus Gittinger <cg@exept.de>
parents: 5220
diff changeset
  1909
     raises an error:
df6dd43af1c5 comments;
Claus Gittinger <cg@exept.de>
parents: 5220
diff changeset
  1910
df6dd43af1c5 comments;
Claus Gittinger <cg@exept.de>
parents: 5220
diff changeset
  1911
     (Dictionary new 
df6dd43af1c5 comments;
Claus Gittinger <cg@exept.de>
parents: 5220
diff changeset
  1912
        at:#foo put:'foo';
df6dd43af1c5 comments;
Claus Gittinger <cg@exept.de>
parents: 5220
diff changeset
  1913
        at:#bar put:'bar';
df6dd43af1c5 comments;
Claus Gittinger <cg@exept.de>
parents: 5220
diff changeset
  1914
        at:#baz put:'baz';
df6dd43af1c5 comments;
Claus Gittinger <cg@exept.de>
parents: 5220
diff changeset
  1915
        yourself) upTo:#bar
df6dd43af1c5 comments;
Claus Gittinger <cg@exept.de>
parents: 5220
diff changeset
  1916
                
df6dd43af1c5 comments;
Claus Gittinger <cg@exept.de>
parents: 5220
diff changeset
  1917
    "
df6dd43af1c5 comments;
Claus Gittinger <cg@exept.de>
parents: 5220
diff changeset
  1918
df6dd43af1c5 comments;
Claus Gittinger <cg@exept.de>
parents: 5220
diff changeset
  1919
    "Modified: 11.5.1996 / 11:14:05 / cg"
df6dd43af1c5 comments;
Claus Gittinger <cg@exept.de>
parents: 5220
diff changeset
  1920
!
df6dd43af1c5 comments;
Claus Gittinger <cg@exept.de>
parents: 5220
diff changeset
  1921
df6dd43af1c5 comments;
Claus Gittinger <cg@exept.de>
parents: 5220
diff changeset
  1922
upTo:anElement count:count
df6dd43af1c5 comments;
Claus Gittinger <cg@exept.de>
parents: 5220
diff changeset
  1923
    "return a new collection consisting of the receivers elements upTo
df6dd43af1c5 comments;
Claus Gittinger <cg@exept.de>
parents: 5220
diff changeset
  1924
     (but excluding) count found anElements, i.e. the first found count-1 
df6dd43af1c5 comments;
Claus Gittinger <cg@exept.de>
parents: 5220
diff changeset
  1925
     elements are included in the returned collection; if count < 0 the 
df6dd43af1c5 comments;
Claus Gittinger <cg@exept.de>
parents: 5220
diff changeset
  1926
     procedure is done from the end of the collection backwards.
df6dd43af1c5 comments;
Claus Gittinger <cg@exept.de>
parents: 5220
diff changeset
  1927
     If anElement is not in the receiver, the returned collection
df6dd43af1c5 comments;
Claus Gittinger <cg@exept.de>
parents: 5220
diff changeset
  1928
     will consist of all elements of the receiver"
df6dd43af1c5 comments;
Claus Gittinger <cg@exept.de>
parents: 5220
diff changeset
  1929
df6dd43af1c5 comments;
Claus Gittinger <cg@exept.de>
parents: 5220
diff changeset
  1930
    |startPos endPos pos found|
df6dd43af1c5 comments;
Claus Gittinger <cg@exept.de>
parents: 5220
diff changeset
  1931
df6dd43af1c5 comments;
Claus Gittinger <cg@exept.de>
parents: 5220
diff changeset
  1932
    (count == 0 or: [count == 1]) ifTrue:[
df6dd43af1c5 comments;
Claus Gittinger <cg@exept.de>
parents: 5220
diff changeset
  1933
        ^ self upTo:anElement
df6dd43af1c5 comments;
Claus Gittinger <cg@exept.de>
parents: 5220
diff changeset
  1934
    ].
df6dd43af1c5 comments;
Claus Gittinger <cg@exept.de>
parents: 5220
diff changeset
  1935
df6dd43af1c5 comments;
Claus Gittinger <cg@exept.de>
parents: 5220
diff changeset
  1936
    startPos := 1.
df6dd43af1c5 comments;
Claus Gittinger <cg@exept.de>
parents: 5220
diff changeset
  1937
    endPos   := self size.
df6dd43af1c5 comments;
Claus Gittinger <cg@exept.de>
parents: 5220
diff changeset
  1938
    found    := 0.
df6dd43af1c5 comments;
Claus Gittinger <cg@exept.de>
parents: 5220
diff changeset
  1939
df6dd43af1c5 comments;
Claus Gittinger <cg@exept.de>
parents: 5220
diff changeset
  1940
    count > 1 ifTrue:[
df6dd43af1c5 comments;
Claus Gittinger <cg@exept.de>
parents: 5220
diff changeset
  1941
        pos := 0.
df6dd43af1c5 comments;
Claus Gittinger <cg@exept.de>
parents: 5220
diff changeset
  1942
        [pos < self size and: [found < count]]
df6dd43af1c5 comments;
Claus Gittinger <cg@exept.de>
parents: 5220
diff changeset
  1943
            whileTrue: [pos := pos + 1. (self at: pos) == anElement ifTrue: [found := found + 1]].
df6dd43af1c5 comments;
Claus Gittinger <cg@exept.de>
parents: 5220
diff changeset
  1944
        found == count ifTrue:[
df6dd43af1c5 comments;
Claus Gittinger <cg@exept.de>
parents: 5220
diff changeset
  1945
            endPos   := pos - 1
df6dd43af1c5 comments;
Claus Gittinger <cg@exept.de>
parents: 5220
diff changeset
  1946
        ]
df6dd43af1c5 comments;
Claus Gittinger <cg@exept.de>
parents: 5220
diff changeset
  1947
    ].     
df6dd43af1c5 comments;
Claus Gittinger <cg@exept.de>
parents: 5220
diff changeset
  1948
df6dd43af1c5 comments;
Claus Gittinger <cg@exept.de>
parents: 5220
diff changeset
  1949
    count < 0 ifTrue:[
df6dd43af1c5 comments;
Claus Gittinger <cg@exept.de>
parents: 5220
diff changeset
  1950
        pos := self size + 1.
df6dd43af1c5 comments;
Claus Gittinger <cg@exept.de>
parents: 5220
diff changeset
  1951
        [pos > 1 and: [found < count abs]]
df6dd43af1c5 comments;
Claus Gittinger <cg@exept.de>
parents: 5220
diff changeset
  1952
            whileTrue: [pos := pos - 1. (self at: pos) == anElement ifTrue: [found := found + 1]].
df6dd43af1c5 comments;
Claus Gittinger <cg@exept.de>
parents: 5220
diff changeset
  1953
        found == count abs ifTrue:[
df6dd43af1c5 comments;
Claus Gittinger <cg@exept.de>
parents: 5220
diff changeset
  1954
            startPos := pos + 1
df6dd43af1c5 comments;
Claus Gittinger <cg@exept.de>
parents: 5220
diff changeset
  1955
        ]
df6dd43af1c5 comments;
Claus Gittinger <cg@exept.de>
parents: 5220
diff changeset
  1956
    ].    
df6dd43af1c5 comments;
Claus Gittinger <cg@exept.de>
parents: 5220
diff changeset
  1957
df6dd43af1c5 comments;
Claus Gittinger <cg@exept.de>
parents: 5220
diff changeset
  1958
    ^ self copyFrom: startPos to: endPos
df6dd43af1c5 comments;
Claus Gittinger <cg@exept.de>
parents: 5220
diff changeset
  1959
df6dd43af1c5 comments;
Claus Gittinger <cg@exept.de>
parents: 5220
diff changeset
  1960
    "
df6dd43af1c5 comments;
Claus Gittinger <cg@exept.de>
parents: 5220
diff changeset
  1961
     'hello1_hello2_hello3' upTo:$_ count:  2     returns first two 'hellos' 
df6dd43af1c5 comments;
Claus Gittinger <cg@exept.de>
parents: 5220
diff changeset
  1962
     'hello1_hello2_hello3' upTo:$_ count: -1     returns last 'hello'
df6dd43af1c5 comments;
Claus Gittinger <cg@exept.de>
parents: 5220
diff changeset
  1963
     'hello1_hello2_hello3' upTo:$_ count: 0      returns first 'hello1'
df6dd43af1c5 comments;
Claus Gittinger <cg@exept.de>
parents: 5220
diff changeset
  1964
     'hello1_hello2_hello3' upTo:$_ count: 1      returns first 'hello1'
df6dd43af1c5 comments;
Claus Gittinger <cg@exept.de>
parents: 5220
diff changeset
  1965
     'hello1_hello2_hello3' upTo:$_               same; returns first 'hello1'
df6dd43af1c5 comments;
Claus Gittinger <cg@exept.de>
parents: 5220
diff changeset
  1966
    "
602
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  1967
! !
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  1968
5471
a57eeb01c5ab General encoding method (#encodeOn:with:)
Stefan Vogel <sv@exept.de>
parents: 5446
diff changeset
  1969
!SequenceableCollection methodsFor:'encoding'!
a57eeb01c5ab General encoding method (#encodeOn:with:)
Stefan Vogel <sv@exept.de>
parents: 5446
diff changeset
  1970
a57eeb01c5ab General encoding method (#encodeOn:with:)
Stefan Vogel <sv@exept.de>
parents: 5446
diff changeset
  1971
encodeOn:anEncoder with:aParameter
a57eeb01c5ab General encoding method (#encodeOn:with:)
Stefan Vogel <sv@exept.de>
parents: 5446
diff changeset
  1972
a57eeb01c5ab General encoding method (#encodeOn:with:)
Stefan Vogel <sv@exept.de>
parents: 5446
diff changeset
  1973
    anEncoder encodeSequencableCollection:self with:aParameter
a57eeb01c5ab General encoding method (#encodeOn:with:)
Stefan Vogel <sv@exept.de>
parents: 5446
diff changeset
  1974
a57eeb01c5ab General encoding method (#encodeOn:with:)
Stefan Vogel <sv@exept.de>
parents: 5446
diff changeset
  1975
a57eeb01c5ab General encoding method (#encodeOn:with:)
Stefan Vogel <sv@exept.de>
parents: 5446
diff changeset
  1976
! !
a57eeb01c5ab General encoding method (#encodeOn:with:)
Stefan Vogel <sv@exept.de>
parents: 5446
diff changeset
  1977
602
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  1978
!SequenceableCollection methodsFor:'enumerating'!
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  1979
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  1980
collect:aBlock
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  1981
    "evaluate the argument, aBlock for every element in the collection
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  1982
     and return a collection of the results"
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
    |newCollection
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  1985
     sz  "{ Class:SmallInteger }"|
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  1986
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  1987
    sz := self size.
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  1988
    newCollection := self copyEmptyAndGrow:sz.
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  1989
    1 to:sz do:[:index |
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  1990
	newCollection at:index put:(aBlock value:(self at:index)).
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  1991
    ].
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  1992
    ^ newCollection
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  1993
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  1994
    "
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  1995
     #(one two three four five six) collect:[:element | element asUppercase]  
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  1996
     #(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
  1997
     (1 to:9) collect:[:element | element * element]   
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  1998
    "
202
40ca7cc6fb9c *** empty log message ***
claus
parents: 186
diff changeset
  1999
!
40ca7cc6fb9c *** empty log message ***
claus
parents: 186
diff changeset
  2000
602
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  2001
do:aBlock
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  2002
    "evaluate the argument, aBlock for every element in the collection."
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
    |stop "{ Class:SmallInteger }"|
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  2005
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  2006
    stop := self size.
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  2007
    1 to:stop do:[:index |
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  2008
	aBlock value:(self at:index).
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  2009
    ]
2927
1434c3d7f78a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2881
diff changeset
  2010
602
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  2011
    "
1422
9a0b792f2953 showCr: -> showCR:
Claus Gittinger <cg@exept.de>
parents: 1421
diff changeset
  2012
     #(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
  2013
    "
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  2014
!
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  2015
2927
1434c3d7f78a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2881
diff changeset
  2016
do:aBlock separatedBy:sepBlock
1434c3d7f78a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2881
diff changeset
  2017
    "evaluate the argument, aBlock for every element in the collection.
1434c3d7f78a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2881
diff changeset
  2018
     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
  2019
     last element), evaluate sepBlock.
1434c3d7f78a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2881
diff changeset
  2020
     This supports printing of collections with elements separated by some
1434c3d7f78a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2881
diff changeset
  2021
     string."
1434c3d7f78a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2881
diff changeset
  2022
1434c3d7f78a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2881
diff changeset
  2023
    |stop "{ Class:SmallInteger }"|
1434c3d7f78a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2881
diff changeset
  2024
1434c3d7f78a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2881
diff changeset
  2025
    stop := self size.
1434c3d7f78a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2881
diff changeset
  2026
    stop < 1 ifTrue:[^ self].
1434c3d7f78a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2881
diff changeset
  2027
    aBlock value:(self at:1).
1434c3d7f78a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2881
diff changeset
  2028
    2 to:stop do:[:index |
1434c3d7f78a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2881
diff changeset
  2029
	sepBlock value.
1434c3d7f78a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2881
diff changeset
  2030
	aBlock value:(self at:index)
1434c3d7f78a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2881
diff changeset
  2031
    ].
1434c3d7f78a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2881
diff changeset
  2032
1434c3d7f78a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2881
diff changeset
  2033
    "
1434c3d7f78a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2881
diff changeset
  2034
     #(one two three four five six)
1434c3d7f78a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2881
diff changeset
  2035
	do:[:each | Transcript show:each]
1434c3d7f78a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2881
diff changeset
  2036
	separatedBy:[Transcript show:' , ']
1434c3d7f78a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2881
diff changeset
  2037
    "
1434c3d7f78a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2881
diff changeset
  2038
!
3003
0f66385bbbd2 replaceAny / replaceAll
Claus Gittinger <cg@exept.de>
parents: 2980
diff changeset
  2039
3044
a0bbac91639b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3037
diff changeset
  2040
doWithIndex:aBlock
a0bbac91639b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3037
diff changeset
  2041
    "Squeak compatibility; like keysAndValuesDo:, but passes
a0bbac91639b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3037
diff changeset
  2042
     the index as second argument."
a0bbac91639b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3037
diff changeset
  2043
a0bbac91639b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3037
diff changeset
  2044
    self keysAndValuesDo:[:index :value |
a0bbac91639b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3037
diff changeset
  2045
        aBlock value:value value:index
a0bbac91639b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3037
diff changeset
  2046
    ].
a0bbac91639b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3037
diff changeset
  2047
a0bbac91639b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3037
diff changeset
  2048
    "Created: 17.10.1997 / 12:33:10 / cg"
a0bbac91639b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3037
diff changeset
  2049
!
a0bbac91639b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3037
diff changeset
  2050
5220
66ac0778fe08 added #from:collect: - for convenience
Claus Gittinger <cg@exept.de>
parents: 5206
diff changeset
  2051
from:start collect:aBlock
66ac0778fe08 added #from:collect: - for convenience
Claus Gittinger <cg@exept.de>
parents: 5206
diff changeset
  2052
    "evaluate the argument, aBlock for the elements starting at start
66ac0778fe08 added #from:collect: - for convenience
Claus Gittinger <cg@exept.de>
parents: 5206
diff changeset
  2053
     to the end and return a collection of the results"
66ac0778fe08 added #from:collect: - for convenience
Claus Gittinger <cg@exept.de>
parents: 5206
diff changeset
  2054
66ac0778fe08 added #from:collect: - for convenience
Claus Gittinger <cg@exept.de>
parents: 5206
diff changeset
  2055
    ^ self from:start to:self size collect:aBlock
66ac0778fe08 added #from:collect: - for convenience
Claus Gittinger <cg@exept.de>
parents: 5206
diff changeset
  2056
66ac0778fe08 added #from:collect: - for convenience
Claus Gittinger <cg@exept.de>
parents: 5206
diff changeset
  2057
    "
66ac0778fe08 added #from:collect: - for convenience
Claus Gittinger <cg@exept.de>
parents: 5206
diff changeset
  2058
     #(one two three four five six) 
66ac0778fe08 added #from:collect: - for convenience
Claus Gittinger <cg@exept.de>
parents: 5206
diff changeset
  2059
        from:2 
66ac0778fe08 added #from:collect: - for convenience
Claus Gittinger <cg@exept.de>
parents: 5206
diff changeset
  2060
        collect:[:element | element asUppercase]  
66ac0778fe08 added #from:collect: - for convenience
Claus Gittinger <cg@exept.de>
parents: 5206
diff changeset
  2061
    "
66ac0778fe08 added #from:collect: - for convenience
Claus Gittinger <cg@exept.de>
parents: 5206
diff changeset
  2062
66ac0778fe08 added #from:collect: - for convenience
Claus Gittinger <cg@exept.de>
parents: 5206
diff changeset
  2063
    "Created: / 30.1.2000 / 01:02:28 / cg"
66ac0778fe08 added #from:collect: - for convenience
Claus Gittinger <cg@exept.de>
parents: 5206
diff changeset
  2064
!
66ac0778fe08 added #from:collect: - for convenience
Claus Gittinger <cg@exept.de>
parents: 5206
diff changeset
  2065
602
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  2066
from:startIndex do:aBlock
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  2067
    "evaluate the argument, aBlock for the elements starting with the
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  2068
     element at startIndex to the end."
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  2069
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  2070
    ^ self from:startIndex to:self size do:aBlock
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  2071
95
d22739a0c6e9 *** empty log message ***
claus
parents: 88
diff changeset
  2072
    "
2927
1434c3d7f78a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2881
diff changeset
  2073
     #(one two three four five six) 
1434c3d7f78a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2881
diff changeset
  2074
	from:3 
1434c3d7f78a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2881
diff changeset
  2075
	do:[:element | Transcript showCR:element]
602
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  2076
    "
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  2077
!
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  2078
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  2079
from:start to:stop collect:aBlock
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  2080
    "evaluate the argument, aBlock for the elements indexed by start
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  2081
     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
  2082
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  2083
    |newCollection sz
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  2084
     idx  "{ Class:SmallInteger }"|
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  2085
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  2086
    sz := stop - start + 1.
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  2087
    newCollection := self copyEmptyAndGrow:sz.
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  2088
    idx := 1.
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  2089
    start to:stop do:[:index |
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  2090
	newCollection at:idx put:(aBlock value:(self at:index)).
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  2091
	idx := idx + 1
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  2092
    ].
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  2093
    ^ newCollection
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  2094
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  2095
    "
2927
1434c3d7f78a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2881
diff changeset
  2096
     #(one two three four five six) 
1434c3d7f78a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2881
diff changeset
  2097
	from:2 
1434c3d7f78a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2881
diff changeset
  2098
	to:4 
1434c3d7f78a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2881
diff changeset
  2099
	collect:[:element | element asUppercase]  
602
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  2100
    "
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  2101
!
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  2102
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  2103
from:index1 to:index2 do:aBlock
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  2104
    "evaluate the argument, aBlock for the elements with index index1 to
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  2105
     index2 in the collection"
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  2106
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  2107
    |start "{ Class:SmallInteger }"
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  2108
     stop  "{ Class:SmallInteger }" |
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  2109
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  2110
    start := index1.
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  2111
    stop := index2.
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  2112
    start to:stop do:[:index |
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  2113
	aBlock value:(self at:index).
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  2114
    ]
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  2115
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  2116
    "
2927
1434c3d7f78a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2881
diff changeset
  2117
     #(one two three four five six) 
1434c3d7f78a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2881
diff changeset
  2118
	from:3 
1434c3d7f78a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2881
diff changeset
  2119
	to:5 
1434c3d7f78a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2881
diff changeset
  2120
	do:[:element | Transcript showCR:element]
602
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  2121
    "
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  2122
!
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  2123
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  2124
from:index1 to:index2 reverseDo:aBlock
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  2125
    "evaluate the argument, aBlock for the elements with index index1 to
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  2126
     index2 in the collection. Step in reverse order"
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  2127
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  2128
    |start "{ Class:SmallInteger }"
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  2129
     stop  "{ Class:SmallInteger }" |
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  2130
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  2131
    start := index1.
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  2132
    stop := index2.
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  2133
    stop to:start by:-1 do:[:index |
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  2134
	aBlock value:(self at:index).
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  2135
    ]
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  2136
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  2137
    "
2927
1434c3d7f78a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2881
diff changeset
  2138
     #(one two three four five six) 
1434c3d7f78a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2881
diff changeset
  2139
	from:3 
1434c3d7f78a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2881
diff changeset
  2140
	to:5 
1434c3d7f78a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2881
diff changeset
  2141
	reverseDo:[:element | Transcript showCR:element]
95
d22739a0c6e9 *** empty log message ***
claus
parents: 88
diff changeset
  2142
    "
61
claus
parents: 44
diff changeset
  2143
!
claus
parents: 44
diff changeset
  2144
602
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  2145
keysAndValuesDo:aTwoArgBlock
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  2146
    "evaluate the argument, aBlock for every element in the collection,
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  2147
     passing both index and element as arguments."
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  2148
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  2149
    |stop  "{ Class:SmallInteger }"|
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  2150
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  2151
    stop := self size.
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  2152
    1 to:stop do:[:index |
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  2153
	aTwoArgBlock value:index value:(self at:index).
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  2154
    ]
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  2155
    "
2927
1434c3d7f78a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2881
diff changeset
  2156
     #(one two three four five six) 
1434c3d7f78a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2881
diff changeset
  2157
	keysAndValuesDo:[:key :element | 
1434c3d7f78a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2881
diff changeset
  2158
			    Transcript show:key; space; showCR:element
1434c3d7f78a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2881
diff changeset
  2159
			]
602
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  2160
    "
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  2161
!
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  2162
1359
5ff95f3f0baf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1289
diff changeset
  2163
keysAndValuesReverseDo:aTwoArgBlock
5ff95f3f0baf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1289
diff changeset
  2164
    "evaluate the argument, aBlock in reverse order, for every element 
5ff95f3f0baf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1289
diff changeset
  2165
     in the collection, passing both index and element as arguments."
5ff95f3f0baf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1289
diff changeset
  2166
5ff95f3f0baf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1289
diff changeset
  2167
    |stop  "{ Class:SmallInteger }"|
5ff95f3f0baf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1289
diff changeset
  2168
5ff95f3f0baf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1289
diff changeset
  2169
    stop := self size.
5ff95f3f0baf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1289
diff changeset
  2170
    stop to:1 by:-1 do:[:index |
5ff95f3f0baf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1289
diff changeset
  2171
        aTwoArgBlock value:index value:(self at:index).
5ff95f3f0baf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1289
diff changeset
  2172
    ]
5ff95f3f0baf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1289
diff changeset
  2173
5ff95f3f0baf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1289
diff changeset
  2174
    "
5ff95f3f0baf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1289
diff changeset
  2175
     #(one two three four five six) 
2927
1434c3d7f78a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2881
diff changeset
  2176
        keysAndValuesReverseDo:[:key :element | 
1434c3d7f78a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2881
diff changeset
  2177
				    Transcript show:key; space; showCR:element
1434c3d7f78a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2881
diff changeset
  2178
			       ]
1359
5ff95f3f0baf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1289
diff changeset
  2179
    "
5ff95f3f0baf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1289
diff changeset
  2180
5ff95f3f0baf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1289
diff changeset
  2181
    "Modified: 9.5.1996 / 00:57:23 / cg"
5ff95f3f0baf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1289
diff changeset
  2182
!
5ff95f3f0baf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1289
diff changeset
  2183
602
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  2184
nonNilElementsDo:aBlock
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  2185
    "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
  2186
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  2187
    |stop "{ Class:SmallInteger }"
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  2188
     element|
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  2189
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  2190
    stop := self size.
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  2191
    1 to:stop do:[:index |
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  2192
	(element := self at:index) notNil ifTrue:[
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  2193
	    aBlock value:element.
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  2194
	]
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  2195
    ]
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  2196
    "
1422
9a0b792f2953 showCr: -> showCR:
Claus Gittinger <cg@exept.de>
parents: 1421
diff changeset
  2197
     #(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
  2198
    "
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  2199
!
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  2200
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  2201
pairWiseCollect:aBlock
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  2202
    "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
  2203
     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
  2204
     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
  2205
     is not a multiple of 2.
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  2206
     Collect the results and return a new collection containing those."
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  2207
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  2208
    |stop newCollection dstIdx "{ Class:SmallInteger }"|
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  2209
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  2210
    stop := self size.
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  2211
    newCollection := self copyEmptyAndGrow:stop // 2.
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  2212
    dstIdx := 1.
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  2213
    1 to:stop by:2 do:[:index |
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  2214
	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
  2215
	dstIdx := dstIdx + 1
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  2216
    ].
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  2217
    ^ newCollection
44
b262907c93ea *** empty log message ***
claus
parents: 42
diff changeset
  2218
95
d22739a0c6e9 *** empty log message ***
claus
parents: 88
diff changeset
  2219
    "
602
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  2220
     #(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
  2221
     pairWiseCollect:[:num :sym | sym->num] 
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  2222
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  2223
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  2224
     #(1 1  1 2  1 3  1 4  1 5) 
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  2225
     pairWiseCollect:[:x :y | x@y] 
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  2226
    "
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  2227
!
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  2228
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  2229
pairWiseDo:aBlock
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  2230
    "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
  2231
     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
  2232
     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
  2233
     is not a multiple of 2."
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  2234
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  2235
    |stop "{ Class:SmallInteger }"|
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  2236
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  2237
    stop := self size.
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  2238
    1 to:stop by:2 do:[:index |
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  2239
	aBlock value:(self at:index) value:(self at:index+1).
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  2240
    ]
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  2241
    "
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  2242
     #(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
  2243
     pairWiseDo:[:num :sym | Transcript show:num; show:' is: '; showCR:sym]
602
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  2244
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  2245
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  2246
     #(1 1  1 2  1 3  1 4  1 5) 
1422
9a0b792f2953 showCr: -> showCR:
Claus Gittinger <cg@exept.de>
parents: 1421
diff changeset
  2247
     pairWiseDo:[:x :y | Transcript showCR:x@y]
95
d22739a0c6e9 *** empty log message ***
claus
parents: 88
diff changeset
  2248
    "
61
claus
parents: 44
diff changeset
  2249
!
claus
parents: 44
diff changeset
  2250
602
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  2251
reverseDo:aBlock
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  2252
    "evaluate the argument, aBlock for every element in the collection
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  2253
     in reverse order"
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  2254
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  2255
    |sz  "{ Class:SmallInteger }"|
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  2256
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  2257
    sz := self size.
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  2258
    sz to:1 by:-1 do:[:index |
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  2259
	aBlock value:(self at:index).
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  2260
    ]
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  2261
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  2262
    "
1422
9a0b792f2953 showCr: -> showCR:
Claus Gittinger <cg@exept.de>
parents: 1421
diff changeset
  2263
     #(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
  2264
    "
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  2265
!
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  2266
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  2267
select:aBlock
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  2268
    "evaluate the argument, aBlock for every element in the collection
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  2269
     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
  2270
     true"
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  2271
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  2272
    |element newColl species needCopy
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  2273
     sz  "{ Class:SmallInteger }"|
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  2274
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  2275
    sz := self size.
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  2276
    species := self species.
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  2277
    species growIsCheap ifFalse:[
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  2278
	newColl := OrderedCollection new:sz.
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  2279
	needCopy := true
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  2280
    ] ifTrue:[
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  2281
	newColl := self copyEmpty:sz.
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  2282
	needCopy := false
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  2283
    ].
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  2284
    1 to:sz do:[:index |
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  2285
	element := self at:index.
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  2286
	(aBlock value:element) ifTrue:[
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  2287
	    newColl add:element
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  2288
	].
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  2289
    ].
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  2290
    needCopy ifTrue:[
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  2291
	newColl := (species withAll:newColl) postCopyFrom:self
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  2292
    ].
61
claus
parents: 44
diff changeset
  2293
    ^ newColl
claus
parents: 44
diff changeset
  2294
95
d22739a0c6e9 *** empty log message ***
claus
parents: 88
diff changeset
  2295
    "
602
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  2296
     #(one two three four five six) select:[:element | element startsWith:'f']   
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  2297
     #(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
  2298
     (#(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
  2299
     (1 to:9) select:[:element | element odd]   
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  2300
     (Smalltalk allClasses) select:[:class | class name startsWith:'S']   
95
d22739a0c6e9 *** empty log message ***
claus
parents: 88
diff changeset
  2301
    "
186
a4c3032fc825 *** empty log message ***
claus
parents: 159
diff changeset
  2302
!
a4c3032fc825 *** empty log message ***
claus
parents: 159
diff changeset
  2303
602
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  2304
with:aSequenceableCollection do:aTwoArgBlock
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  2305
    "evaluate the argument, aBlock for successive elements from
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  2306
     each the receiver and the argument, aSequenceableCollection.
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  2307
     The second argument, aBlock must be a two-argument block.
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  2308
     The collection argument must implement access via a numeric key."
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  2309
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  2310
    |stop  "{ Class: SmallInteger }" |
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  2311
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  2312
    stop := self size.
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  2313
    1 to:stop do:[:index |
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  2314
	aTwoArgBlock value:(self at:index) value:(aSequenceableCollection at:index).
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  2315
    ]
186
a4c3032fc825 *** empty log message ***
claus
parents: 159
diff changeset
  2316
    "
1422
9a0b792f2953 showCr: -> showCR:
Claus Gittinger <cg@exept.de>
parents: 1421
diff changeset
  2317
     #(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
  2318
    "
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  2319
! !
a27a279701f8 Initial revision
claus
parents:
diff changeset
  2320
4154
6938d9274ee4 category rename
Claus Gittinger <cg@exept.de>
parents: 3992
diff changeset
  2321
!SequenceableCollection methodsFor:'filling & replacing'!
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  2322
602
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  2323
atAllPut:anObject
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  2324
    "replace all elements of the collection by the argument, anObject.
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  2325
     Notice: This operation modifies the receiver, NOT a copy;
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  2326
     therefore the change may affect all others referencing the receiver."
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  2327
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  2328
    self from:1 to:(self size) put:anObject
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  2329
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  2330
    "
3468
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  2331
     args:    anObject : <object>
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  2332
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  2333
     returns: self
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  2334
    "
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  2335
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  2336
    "
602
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  2337
     (Array new:10) atAllPut:1
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  2338
     (String new:10) atAllPut:$a
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  2339
    "
3468
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  2340
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  2341
    "Modified: / 20.5.1998 / 15:14:11 / cg"
602
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  2342
!
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  2343
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  2344
from:index1 to:index2 put:anObject
a27a279701f8 Initial revision
claus
parents:
diff changeset
  2345
    "replace the elements from index1 to index2 of the collection
44
b262907c93ea *** empty log message ***
claus
parents: 42
diff changeset
  2346
     by the argument, anObject.
b262907c93ea *** empty log message ***
claus
parents: 42
diff changeset
  2347
     Notice: This operation modifies the receiver, NOT a copy;
b262907c93ea *** empty log message ***
claus
parents: 42
diff changeset
  2348
     therefore the change may affect all others referencing the receiver."
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  2349
a27a279701f8 Initial revision
claus
parents:
diff changeset
  2350
    |index "{ Class: SmallInteger }"
a27a279701f8 Initial revision
claus
parents:
diff changeset
  2351
     end   "{ Class: SmallInteger }"|
a27a279701f8 Initial revision
claus
parents:
diff changeset
  2352
a27a279701f8 Initial revision
claus
parents:
diff changeset
  2353
    index := index1.
a27a279701f8 Initial revision
claus
parents:
diff changeset
  2354
    end := index2.
a27a279701f8 Initial revision
claus
parents:
diff changeset
  2355
    [index <= end] whileTrue:[
3468
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  2356
        self at:index put:anObject.
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  2357
        index := index + 1
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  2358
    ]
44
b262907c93ea *** empty log message ***
claus
parents: 42
diff changeset
  2359
95
d22739a0c6e9 *** empty log message ***
claus
parents: 88
diff changeset
  2360
    "
3468
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  2361
     args:    index1    : <integer>
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  2362
              index2    : <integer>
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  2363
              anObject  : <object>
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  2364
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  2365
     returns: self
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  2366
    "
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
    "
95
d22739a0c6e9 *** empty log message ***
claus
parents: 88
diff changeset
  2369
     #(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
  2370
     'abcdefghijkl' from:3 to:6 put:$X
d22739a0c6e9 *** empty log message ***
claus
parents: 88
diff changeset
  2371
    "
3468
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  2372
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  2373
    "Modified: / 20.5.1998 / 15:16:52 / cg"
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  2374
!
a27a279701f8 Initial revision
claus
parents:
diff changeset
  2375
3003
0f66385bbbd2 replaceAny / replaceAll
Claus Gittinger <cg@exept.de>
parents: 2980
diff changeset
  2376
replaceAll:oldObject by:newObject
0f66385bbbd2 replaceAny / replaceAll
Claus Gittinger <cg@exept.de>
parents: 2980
diff changeset
  2377
    "backward ST/X compatibility: an alias for #replaceAll:with:.
0f66385bbbd2 replaceAny / replaceAll
Claus Gittinger <cg@exept.de>
parents: 2980
diff changeset
  2378
     Pleace do no longer use this one;
0f66385bbbd2 replaceAny / replaceAll
Claus Gittinger <cg@exept.de>
parents: 2980
diff changeset
  2379
     instead use #replaceAll:with: for ST-80 compatibility."
0f66385bbbd2 replaceAny / replaceAll
Claus Gittinger <cg@exept.de>
parents: 2980
diff changeset
  2380
3468
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  2381
    self obsoleteMethodWarning:'use #replaceAll:with:'.
3003
0f66385bbbd2 replaceAny / replaceAll
Claus Gittinger <cg@exept.de>
parents: 2980
diff changeset
  2382
    ^ self replaceAll:oldObject with:newObject
0f66385bbbd2 replaceAny / replaceAll
Claus Gittinger <cg@exept.de>
parents: 2980
diff changeset
  2383
3468
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  2384
    "
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  2385
     args:    oldObject  : <object>
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  2386
              newObject  : <object>
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  2387
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  2388
     returns: self
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  2389
    "
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  2390
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  2391
    "Modified: / 20.5.1998 / 15:16:28 / cg"
3003
0f66385bbbd2 replaceAny / replaceAll
Claus Gittinger <cg@exept.de>
parents: 2980
diff changeset
  2392
!
0f66385bbbd2 replaceAny / replaceAll
Claus Gittinger <cg@exept.de>
parents: 2980
diff changeset
  2393
0f66385bbbd2 replaceAny / replaceAll
Claus Gittinger <cg@exept.de>
parents: 2980
diff changeset
  2394
replaceAll:oldObject by:newObject from:startIndex to:stopIndex
0f66385bbbd2 replaceAny / replaceAll
Claus Gittinger <cg@exept.de>
parents: 2980
diff changeset
  2395
    "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
  2396
     Please do no longer use this one;
3003
0f66385bbbd2 replaceAny / replaceAll
Claus Gittinger <cg@exept.de>
parents: 2980
diff changeset
  2397
     instead use #replaceAll:with:from:to: for ST-80 compatibility."
0f66385bbbd2 replaceAny / replaceAll
Claus Gittinger <cg@exept.de>
parents: 2980
diff changeset
  2398
3468
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  2399
    self obsoleteMethodWarning:'use #replaceAll:with:from:to:'.
3003
0f66385bbbd2 replaceAny / replaceAll
Claus Gittinger <cg@exept.de>
parents: 2980
diff changeset
  2400
    ^ 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
  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:    oldObject  : <object>
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  2404
              newObject  : <object>
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  2405
              startIndex : <integer>
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  2406
              stopIndex  : <integer>
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  2407
        
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  2408
     returns: self
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  2409
    "
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  2410
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  2411
    "Modified: / 20.5.1998 / 15:16:02 / cg"
3003
0f66385bbbd2 replaceAny / replaceAll
Claus Gittinger <cg@exept.de>
parents: 2980
diff changeset
  2412
!
0f66385bbbd2 replaceAny / replaceAll
Claus Gittinger <cg@exept.de>
parents: 2980
diff changeset
  2413
2927
1434c3d7f78a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2881
diff changeset
  2414
replaceAll:oldObject with:newObject
44
b262907c93ea *** empty log message ***
claus
parents: 42
diff changeset
  2415
    "replace all oldObjects by newObject in the receiver.
3468
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  2416
44
b262907c93ea *** empty log message ***
claus
parents: 42
diff changeset
  2417
     Notice: This operation modifies the receiver, NOT a copy;
b262907c93ea *** empty log message ***
claus
parents: 42
diff changeset
  2418
     therefore the change may affect all others referencing the receiver."
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  2419
3468
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  2420
    ^ self 
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  2421
        replaceAll:oldObject 
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  2422
        with:newObject 
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  2423
        from:1 
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  2424
        to:self size
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  2425
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  2426
    "
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  2427
     args:    oldObject  : <object>
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  2428
              newObject  : <object>
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  2429
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  2430
     returns: self
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  2431
    "
362
claus
parents: 360
diff changeset
  2432
claus
parents: 360
diff changeset
  2433
    "
2980
a662ffcfad1d *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2927
diff changeset
  2434
     '123123abc123' replaceAll:$1 with:$*  
a662ffcfad1d *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2927
diff changeset
  2435
     #(1 2 3 4 1 2 3 4) copy replaceAll:1 with:'one' 
362
claus
parents: 360
diff changeset
  2436
    "
3468
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
    "Modified: / 20.5.1998 / 15:26:10 / cg"
362
claus
parents: 360
diff changeset
  2439
!
293
31df3850e98c *** empty log message ***
claus
parents: 282
diff changeset
  2440
2927
1434c3d7f78a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2881
diff changeset
  2441
replaceAll:oldObject with:newObject from:startIndex to:stopIndex
362
claus
parents: 360
diff changeset
  2442
    "replace all oldObjects found between startIndex and endIndex,
claus
parents: 360
diff changeset
  2443
     by newObject in the receiver.
3468
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  2444
362
claus
parents: 360
diff changeset
  2445
     Notice: This operation modifies the receiver, NOT a copy;
claus
parents: 360
diff changeset
  2446
     therefore the change may affect all others referencing the receiver."
claus
parents: 360
diff changeset
  2447
claus
parents: 360
diff changeset
  2448
    |start "{ Class: SmallInteger }"
claus
parents: 360
diff changeset
  2449
     stop  "{ Class: SmallInteger }"|
claus
parents: 360
diff changeset
  2450
claus
parents: 360
diff changeset
  2451
    start := startIndex.
claus
parents: 360
diff changeset
  2452
    stop := stopIndex.
claus
parents: 360
diff changeset
  2453
    startIndex to:stopIndex do:[:index |
3468
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  2454
        (self at:index) = oldObject ifTrue:[
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  2455
            self at:index put:newObject
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  2456
        ]
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  2457
    ]
44
b262907c93ea *** empty log message ***
claus
parents: 42
diff changeset
  2458
95
d22739a0c6e9 *** empty log message ***
claus
parents: 88
diff changeset
  2459
    "
3468
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  2460
     args:    oldObject  : <object>
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  2461
              newObject  : <object>
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  2462
              startIndex : <integer>
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  2463
              stopIndex  : <integer> 
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  2464
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  2465
     returns: self
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  2466
    "
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  2467
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  2468
    "
2980
a662ffcfad1d *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2927
diff changeset
  2469
     '123123abc123' replaceAll:$1 with:$*
a662ffcfad1d *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2927
diff changeset
  2470
     '123123abc123' replaceAll:$1 with:$* from:1 to:6
a662ffcfad1d *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2927
diff changeset
  2471
     #(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
  2472
    "
3468
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  2473
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  2474
    "Modified: / 20.5.1998 / 15:23:10 / cg"
95
d22739a0c6e9 *** empty log message ***
claus
parents: 88
diff changeset
  2475
!
d22739a0c6e9 *** empty log message ***
claus
parents: 88
diff changeset
  2476
5320
bad0dcfeb534 added #replaceAllIdentical:with:
Claus Gittinger <cg@exept.de>
parents: 5275
diff changeset
  2477
replaceAllIdentical:oldObject with:newObject
bad0dcfeb534 added #replaceAllIdentical:with:
Claus Gittinger <cg@exept.de>
parents: 5275
diff changeset
  2478
    "replace all oldObjects by newObject in the receiver.
bad0dcfeb534 added #replaceAllIdentical:with:
Claus Gittinger <cg@exept.de>
parents: 5275
diff changeset
  2479
     This is like #replaceAll:with:from:to:, but uses an identity compare.
bad0dcfeb534 added #replaceAllIdentical:with:
Claus Gittinger <cg@exept.de>
parents: 5275
diff changeset
  2480
bad0dcfeb534 added #replaceAllIdentical:with:
Claus Gittinger <cg@exept.de>
parents: 5275
diff changeset
  2481
     Notice: This operation modifies the receiver, NOT a copy;
bad0dcfeb534 added #replaceAllIdentical:with:
Claus Gittinger <cg@exept.de>
parents: 5275
diff changeset
  2482
     therefore the change may affect all others referencing the receiver."
bad0dcfeb534 added #replaceAllIdentical:with:
Claus Gittinger <cg@exept.de>
parents: 5275
diff changeset
  2483
bad0dcfeb534 added #replaceAllIdentical:with:
Claus Gittinger <cg@exept.de>
parents: 5275
diff changeset
  2484
    ^ self 
bad0dcfeb534 added #replaceAllIdentical:with:
Claus Gittinger <cg@exept.de>
parents: 5275
diff changeset
  2485
        replaceAllIdentical:oldObject 
bad0dcfeb534 added #replaceAllIdentical:with:
Claus Gittinger <cg@exept.de>
parents: 5275
diff changeset
  2486
        with:newObject 
bad0dcfeb534 added #replaceAllIdentical:with:
Claus Gittinger <cg@exept.de>
parents: 5275
diff changeset
  2487
        from:1 
bad0dcfeb534 added #replaceAllIdentical:with:
Claus Gittinger <cg@exept.de>
parents: 5275
diff changeset
  2488
        to:self size
bad0dcfeb534 added #replaceAllIdentical:with:
Claus Gittinger <cg@exept.de>
parents: 5275
diff changeset
  2489
bad0dcfeb534 added #replaceAllIdentical:with:
Claus Gittinger <cg@exept.de>
parents: 5275
diff changeset
  2490
    "
bad0dcfeb534 added #replaceAllIdentical:with:
Claus Gittinger <cg@exept.de>
parents: 5275
diff changeset
  2491
     args:    oldObject  : <object>
bad0dcfeb534 added #replaceAllIdentical:with:
Claus Gittinger <cg@exept.de>
parents: 5275
diff changeset
  2492
              newObject  : <object>
bad0dcfeb534 added #replaceAllIdentical:with:
Claus Gittinger <cg@exept.de>
parents: 5275
diff changeset
  2493
bad0dcfeb534 added #replaceAllIdentical:with:
Claus Gittinger <cg@exept.de>
parents: 5275
diff changeset
  2494
     returns: self
bad0dcfeb534 added #replaceAllIdentical:with:
Claus Gittinger <cg@exept.de>
parents: 5275
diff changeset
  2495
    "
bad0dcfeb534 added #replaceAllIdentical:with:
Claus Gittinger <cg@exept.de>
parents: 5275
diff changeset
  2496
bad0dcfeb534 added #replaceAllIdentical:with:
Claus Gittinger <cg@exept.de>
parents: 5275
diff changeset
  2497
    "
bad0dcfeb534 added #replaceAllIdentical:with:
Claus Gittinger <cg@exept.de>
parents: 5275
diff changeset
  2498
     #(1 2 3 4 1.0 2.0 3.0 4.0) copy replaceAll:1 with:'one'     
bad0dcfeb534 added #replaceAllIdentical:with:
Claus Gittinger <cg@exept.de>
parents: 5275
diff changeset
  2499
     #(1 2 3 4 1.0 2.0 3.0 4.0) copy replaceAllIdentical:1 with:'one' 
bad0dcfeb534 added #replaceAllIdentical:with:
Claus Gittinger <cg@exept.de>
parents: 5275
diff changeset
  2500
    "
bad0dcfeb534 added #replaceAllIdentical:with:
Claus Gittinger <cg@exept.de>
parents: 5275
diff changeset
  2501
bad0dcfeb534 added #replaceAllIdentical:with:
Claus Gittinger <cg@exept.de>
parents: 5275
diff changeset
  2502
!
bad0dcfeb534 added #replaceAllIdentical:with:
Claus Gittinger <cg@exept.de>
parents: 5275
diff changeset
  2503
bad0dcfeb534 added #replaceAllIdentical:with:
Claus Gittinger <cg@exept.de>
parents: 5275
diff changeset
  2504
replaceAllIdentical:oldObject with:newObject from:startIndex to:stopIndex
bad0dcfeb534 added #replaceAllIdentical:with:
Claus Gittinger <cg@exept.de>
parents: 5275
diff changeset
  2505
    "replace all oldObjects found between startIndex and endIndex,
bad0dcfeb534 added #replaceAllIdentical:with:
Claus Gittinger <cg@exept.de>
parents: 5275
diff changeset
  2506
     by newObject in the receiver.
bad0dcfeb534 added #replaceAllIdentical:with:
Claus Gittinger <cg@exept.de>
parents: 5275
diff changeset
  2507
     This is like #replaceAll:with:from:to:, but uses an identity compare.
bad0dcfeb534 added #replaceAllIdentical:with:
Claus Gittinger <cg@exept.de>
parents: 5275
diff changeset
  2508
bad0dcfeb534 added #replaceAllIdentical:with:
Claus Gittinger <cg@exept.de>
parents: 5275
diff changeset
  2509
     Notice: This operation modifies the receiver, NOT a copy;
bad0dcfeb534 added #replaceAllIdentical:with:
Claus Gittinger <cg@exept.de>
parents: 5275
diff changeset
  2510
     therefore the change may affect all others referencing the receiver."
bad0dcfeb534 added #replaceAllIdentical:with:
Claus Gittinger <cg@exept.de>
parents: 5275
diff changeset
  2511
bad0dcfeb534 added #replaceAllIdentical:with:
Claus Gittinger <cg@exept.de>
parents: 5275
diff changeset
  2512
    |start "{ Class: SmallInteger }"
bad0dcfeb534 added #replaceAllIdentical:with:
Claus Gittinger <cg@exept.de>
parents: 5275
diff changeset
  2513
     stop  "{ Class: SmallInteger }"|
bad0dcfeb534 added #replaceAllIdentical:with:
Claus Gittinger <cg@exept.de>
parents: 5275
diff changeset
  2514
bad0dcfeb534 added #replaceAllIdentical:with:
Claus Gittinger <cg@exept.de>
parents: 5275
diff changeset
  2515
    start := startIndex.
bad0dcfeb534 added #replaceAllIdentical:with:
Claus Gittinger <cg@exept.de>
parents: 5275
diff changeset
  2516
    stop := stopIndex.
bad0dcfeb534 added #replaceAllIdentical:with:
Claus Gittinger <cg@exept.de>
parents: 5275
diff changeset
  2517
    startIndex to:stopIndex do:[:index |
bad0dcfeb534 added #replaceAllIdentical:with:
Claus Gittinger <cg@exept.de>
parents: 5275
diff changeset
  2518
        (self at:index) == oldObject ifTrue:[
bad0dcfeb534 added #replaceAllIdentical:with:
Claus Gittinger <cg@exept.de>
parents: 5275
diff changeset
  2519
            self at:index put:newObject
bad0dcfeb534 added #replaceAllIdentical:with:
Claus Gittinger <cg@exept.de>
parents: 5275
diff changeset
  2520
        ]
bad0dcfeb534 added #replaceAllIdentical:with:
Claus Gittinger <cg@exept.de>
parents: 5275
diff changeset
  2521
    ]
bad0dcfeb534 added #replaceAllIdentical:with:
Claus Gittinger <cg@exept.de>
parents: 5275
diff changeset
  2522
bad0dcfeb534 added #replaceAllIdentical:with:
Claus Gittinger <cg@exept.de>
parents: 5275
diff changeset
  2523
    "
bad0dcfeb534 added #replaceAllIdentical:with:
Claus Gittinger <cg@exept.de>
parents: 5275
diff changeset
  2524
     args:    oldObject  : <object>
bad0dcfeb534 added #replaceAllIdentical:with:
Claus Gittinger <cg@exept.de>
parents: 5275
diff changeset
  2525
              newObject  : <object>
bad0dcfeb534 added #replaceAllIdentical:with:
Claus Gittinger <cg@exept.de>
parents: 5275
diff changeset
  2526
              startIndex : <integer>
bad0dcfeb534 added #replaceAllIdentical:with:
Claus Gittinger <cg@exept.de>
parents: 5275
diff changeset
  2527
              stopIndex  : <integer> 
bad0dcfeb534 added #replaceAllIdentical:with:
Claus Gittinger <cg@exept.de>
parents: 5275
diff changeset
  2528
bad0dcfeb534 added #replaceAllIdentical:with:
Claus Gittinger <cg@exept.de>
parents: 5275
diff changeset
  2529
     returns: self
bad0dcfeb534 added #replaceAllIdentical:with:
Claus Gittinger <cg@exept.de>
parents: 5275
diff changeset
  2530
    "
bad0dcfeb534 added #replaceAllIdentical:with:
Claus Gittinger <cg@exept.de>
parents: 5275
diff changeset
  2531
bad0dcfeb534 added #replaceAllIdentical:with:
Claus Gittinger <cg@exept.de>
parents: 5275
diff changeset
  2532
    "
bad0dcfeb534 added #replaceAllIdentical:with:
Claus Gittinger <cg@exept.de>
parents: 5275
diff changeset
  2533
     #(1 2 3 4 1 2 3 4) replaceAll:1 with:'one' from:1 to:8 
bad0dcfeb534 added #replaceAllIdentical:with:
Claus Gittinger <cg@exept.de>
parents: 5275
diff changeset
  2534
     #(1 2 3 4 1.0 2.0 3.0 4.0) replaceAllIdentical:1 with:'one' from:1 to:8
bad0dcfeb534 added #replaceAllIdentical:with:
Claus Gittinger <cg@exept.de>
parents: 5275
diff changeset
  2535
    "
bad0dcfeb534 added #replaceAllIdentical:with:
Claus Gittinger <cg@exept.de>
parents: 5275
diff changeset
  2536
bad0dcfeb534 added #replaceAllIdentical:with:
Claus Gittinger <cg@exept.de>
parents: 5275
diff changeset
  2537
!
bad0dcfeb534 added #replaceAllIdentical:with:
Claus Gittinger <cg@exept.de>
parents: 5275
diff changeset
  2538
3003
0f66385bbbd2 replaceAny / replaceAll
Claus Gittinger <cg@exept.de>
parents: 2980
diff changeset
  2539
replaceAny:aCollection by:newObject
0f66385bbbd2 replaceAny / replaceAll
Claus Gittinger <cg@exept.de>
parents: 2980
diff changeset
  2540
    "backward ST/X compatibility; alias for #replaceAny:with:.
2927
1434c3d7f78a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2881
diff changeset
  2541
     Pleace do no longer use this one;
3003
0f66385bbbd2 replaceAny / replaceAll
Claus Gittinger <cg@exept.de>
parents: 2980
diff changeset
  2542
     instead use #replaceAny:with: for naming consistence."
0f66385bbbd2 replaceAny / replaceAll
Claus Gittinger <cg@exept.de>
parents: 2980
diff changeset
  2543
3468
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  2544
    self obsoleteMethodWarning:'use #replaceAny:with:'.
3003
0f66385bbbd2 replaceAny / replaceAll
Claus Gittinger <cg@exept.de>
parents: 2980
diff changeset
  2545
    ^ self replaceAny:aCollection with:newObject from:1 to:self size 
0f66385bbbd2 replaceAny / replaceAll
Claus Gittinger <cg@exept.de>
parents: 2980
diff changeset
  2546
0f66385bbbd2 replaceAny / replaceAll
Claus Gittinger <cg@exept.de>
parents: 2980
diff changeset
  2547
    "
3468
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  2548
     args:    aCollection    : <colleciton of <object> >
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  2549
              newObject      : <object>
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  2550
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  2551
     returns: self
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  2552
    "
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  2553
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  2554
    "
3003
0f66385bbbd2 replaceAny / replaceAll
Claus Gittinger <cg@exept.de>
parents: 2980
diff changeset
  2555
     '123123abc123' replaceAny:#($1 $2) with:$*
0f66385bbbd2 replaceAny / replaceAll
Claus Gittinger <cg@exept.de>
parents: 2980
diff changeset
  2556
     #('foo' 'bar' 'foo' 'baz' foo 1 2 3) replaceAny:#(foo 1) with:'*'
0f66385bbbd2 replaceAny / replaceAll
Claus Gittinger <cg@exept.de>
parents: 2980
diff changeset
  2557
    "
0f66385bbbd2 replaceAny / replaceAll
Claus Gittinger <cg@exept.de>
parents: 2980
diff changeset
  2558
3468
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  2559
    "Modified: / 20.5.1998 / 15:17:51 / cg"
602
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  2560
!
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  2561
3003
0f66385bbbd2 replaceAny / replaceAll
Claus Gittinger <cg@exept.de>
parents: 2980
diff changeset
  2562
replaceAny:aCollection by:newObject from:startIndex to:stopIndex
0f66385bbbd2 replaceAny / replaceAll
Claus Gittinger <cg@exept.de>
parents: 2980
diff changeset
  2563
    "backward ST/X compatibility; alias for #replaceAny:with:from:to:.
2927
1434c3d7f78a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2881
diff changeset
  2564
     Pleace do no longer use this one;
3003
0f66385bbbd2 replaceAny / replaceAll
Claus Gittinger <cg@exept.de>
parents: 2980
diff changeset
  2565
     instead use #replaceAny:with:from:to: for naming consistence."
0f66385bbbd2 replaceAny / replaceAll
Claus Gittinger <cg@exept.de>
parents: 2980
diff changeset
  2566
    
3468
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  2567
    self obsoleteMethodWarning:'use #replaceAny:with:from:to:'.
3003
0f66385bbbd2 replaceAny / replaceAll
Claus Gittinger <cg@exept.de>
parents: 2980
diff changeset
  2568
    ^ self replaceAny:aCollection with:newObject from:startIndex to:stopIndex 
0f66385bbbd2 replaceAny / replaceAll
Claus Gittinger <cg@exept.de>
parents: 2980
diff changeset
  2569
0f66385bbbd2 replaceAny / replaceAll
Claus Gittinger <cg@exept.de>
parents: 2980
diff changeset
  2570
    "
3468
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  2571
     args:    aCollection    : <colleciton of <object> >
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  2572
              newObject      : <object>
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  2573
              startIndex     : <integer>
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  2574
              stopIndex     : <integer>
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  2575
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  2576
     returns: self
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  2577
    "
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  2578
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  2579
    "
3003
0f66385bbbd2 replaceAny / replaceAll
Claus Gittinger <cg@exept.de>
parents: 2980
diff changeset
  2580
     '123123abc123' replaceAny:#($1 $2) with:$* from:1 to:6      
0f66385bbbd2 replaceAny / replaceAll
Claus Gittinger <cg@exept.de>
parents: 2980
diff changeset
  2581
     #('foo' 'bar' 'foo' 'baz' foo 1 2 3) replaceAny:#(foo 1) with:'*'  
0f66385bbbd2 replaceAny / replaceAll
Claus Gittinger <cg@exept.de>
parents: 2980
diff changeset
  2582
    "
0f66385bbbd2 replaceAny / replaceAll
Claus Gittinger <cg@exept.de>
parents: 2980
diff changeset
  2583
3468
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  2584
    "Modified: / 20.5.1998 / 15:18:16 / cg"
2927
1434c3d7f78a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2881
diff changeset
  2585
!
1434c3d7f78a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2881
diff changeset
  2586
1434c3d7f78a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2881
diff changeset
  2587
replaceAny:aCollection with:newObject
1434c3d7f78a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2881
diff changeset
  2588
    "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
  2589
2927
1434c3d7f78a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2881
diff changeset
  2590
     Notice: This operation modifies the receiver, NOT a copy;
1434c3d7f78a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2881
diff changeset
  2591
     therefore the change may affect all others referencing the receiver."
1434c3d7f78a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2881
diff changeset
  2592
3468
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  2593
    ^ self 
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  2594
        replaceAny:aCollection 
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  2595
        with:newObject 
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  2596
        from:1 
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  2597
        to:self size
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  2598
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  2599
    "
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  2600
     args:    aCollection    : <colleciton of <object> >
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  2601
              newObject      : <object>
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  2602
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  2603
     returns: self
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  2604
    "
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  2605
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  2606
    "Modified: / 20.5.1998 / 15:25:58 / cg"
602
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  2607
!
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  2608
2927
1434c3d7f78a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2881
diff changeset
  2609
replaceAny:aCollection with:newObject from:startIndex to:stopIndex
362
claus
parents: 360
diff changeset
  2610
    "replace all elements within a range,
claus
parents: 360
diff changeset
  2611
     which are in contained in aCollection by newObject.
3468
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  2612
362
claus
parents: 360
diff changeset
  2613
     Notice: This operation modifies the receiver, NOT a copy;
claus
parents: 360
diff changeset
  2614
     therefore the change may affect all others referencing the receiver."
claus
parents: 360
diff changeset
  2615
claus
parents: 360
diff changeset
  2616
    |start "{ Class: SmallInteger }"
claus
parents: 360
diff changeset
  2617
     stop "{ Class: SmallInteger }"|
claus
parents: 360
diff changeset
  2618
claus
parents: 360
diff changeset
  2619
    start := startIndex.
claus
parents: 360
diff changeset
  2620
    stop := stopIndex.
claus
parents: 360
diff changeset
  2621
    startIndex to:stopIndex do:[:index |
3468
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  2622
        (aCollection includes:(self at:index)) ifTrue:[
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  2623
            self at:index put:newObject
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  2624
        ]
95
d22739a0c6e9 *** empty log message ***
claus
parents: 88
diff changeset
  2625
    ]
d22739a0c6e9 *** empty log message ***
claus
parents: 88
diff changeset
  2626
d22739a0c6e9 *** empty log message ***
claus
parents: 88
diff changeset
  2627
    "
3468
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  2628
     args:    aCollection    : <colleciton of <object> >
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  2629
              newObject      : <object>
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  2630
              startIndex     : <integer>
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  2631
              stopIndex      : <integer>
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  2632
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  2633
     returns: self
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  2634
    "
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  2635
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  2636
    "
2927
1434c3d7f78a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2881
diff changeset
  2637
     '123123abc123' replaceAny:#($1 $2) with:$* from:1 to:6      
1434c3d7f78a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2881
diff changeset
  2638
     #('foo' 'bar' 'foo' 'baz' foo 1 2 3) replaceAny:#(foo 1) with:'*'  
95
d22739a0c6e9 *** empty log message ***
claus
parents: 88
diff changeset
  2639
    "
3468
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  2640
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  2641
    "Modified: / 20.5.1998 / 15:22:43 / cg"
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  2642
!
a27a279701f8 Initial revision
claus
parents:
diff changeset
  2643
3468
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  2644
replaceFrom:startIndex count:numberOfElements with:replacementCollection
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  2645
    "replace numberOfElements elements in the receiver from startIndex,
2413
a3f91741d7ba added #replaceFrom:count:* methods
Claus Gittinger <cg@exept.de>
parents: 2411
diff changeset
  2646
     with elements taken from replacementCollection starting at 1.
3468
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  2647
2413
a3f91741d7ba added #replaceFrom:count:* methods
Claus Gittinger <cg@exept.de>
parents: 2411
diff changeset
  2648
     Notice: This operation modifies the receiver, NOT a copy;
a3f91741d7ba added #replaceFrom:count:* methods
Claus Gittinger <cg@exept.de>
parents: 2411
diff changeset
  2649
     therefore the change may affect all others referencing the receiver."
a3f91741d7ba added #replaceFrom:count:* methods
Claus Gittinger <cg@exept.de>
parents: 2411
diff changeset
  2650
3468
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  2651
    ^ self 
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  2652
        replaceFrom:startIndex
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  2653
        to:(startIndex + numberOfElements - 1)
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  2654
        with:replacementCollection
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  2655
        startingAt:1
2413
a3f91741d7ba added #replaceFrom:count:* methods
Claus Gittinger <cg@exept.de>
parents: 2411
diff changeset
  2656
a3f91741d7ba added #replaceFrom:count:* methods
Claus Gittinger <cg@exept.de>
parents: 2411
diff changeset
  2657
    "
a3f91741d7ba added #replaceFrom:count:* methods
Claus Gittinger <cg@exept.de>
parents: 2411
diff changeset
  2658
     '1234567890' replaceFrom:5 count:3 with:'abcdef'  
a3f91741d7ba added #replaceFrom:count:* methods
Claus Gittinger <cg@exept.de>
parents: 2411
diff changeset
  2659
     #($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
  2660
    "
a3f91741d7ba added #replaceFrom:count:* methods
Claus Gittinger <cg@exept.de>
parents: 2411
diff changeset
  2661
3468
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  2662
    "Modified: / 20.5.1998 / 15:25:46 / cg"
2413
a3f91741d7ba added #replaceFrom:count:* methods
Claus Gittinger <cg@exept.de>
parents: 2411
diff changeset
  2663
!
a3f91741d7ba added #replaceFrom:count:* methods
Claus Gittinger <cg@exept.de>
parents: 2411
diff changeset
  2664
3468
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  2665
replaceFrom:startIndex count:numberOfElementsToReplace with:replacementCollection startingAt:repStartIndex
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  2666
    "replace numberOfElementsToReplace elements in the receiver from startIndex,
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  2667
     with elements taken from replacementCollection starting at repStartIndex.
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  2668
2413
a3f91741d7ba added #replaceFrom:count:* methods
Claus Gittinger <cg@exept.de>
parents: 2411
diff changeset
  2669
     Notice: This operation modifies the receiver, NOT a copy;
a3f91741d7ba added #replaceFrom:count:* methods
Claus Gittinger <cg@exept.de>
parents: 2411
diff changeset
  2670
     therefore the change may affect all others referencing the receiver."
a3f91741d7ba added #replaceFrom:count:* methods
Claus Gittinger <cg@exept.de>
parents: 2411
diff changeset
  2671
a3f91741d7ba added #replaceFrom:count:* methods
Claus Gittinger <cg@exept.de>
parents: 2411
diff changeset
  2672
    ^ self
3468
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  2673
        replaceFrom:startIndex
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  2674
        to:(startIndex + numberOfElementsToReplace - 1)
2413
a3f91741d7ba added #replaceFrom:count:* methods
Claus Gittinger <cg@exept.de>
parents: 2411
diff changeset
  2675
        with:replacementCollection
3468
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  2676
        startingAt:repStartIndex
2413
a3f91741d7ba added #replaceFrom:count:* methods
Claus Gittinger <cg@exept.de>
parents: 2411
diff changeset
  2677
a3f91741d7ba added #replaceFrom:count:* methods
Claus Gittinger <cg@exept.de>
parents: 2411
diff changeset
  2678
    "
a3f91741d7ba added #replaceFrom:count:* methods
Claus Gittinger <cg@exept.de>
parents: 2411
diff changeset
  2679
     '1234567890' replaceFrom:5 count:3 with:'abcdef' startingAt:3  
a3f91741d7ba added #replaceFrom:count:* methods
Claus Gittinger <cg@exept.de>
parents: 2411
diff changeset
  2680
     #($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
  2681
     #($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
  2682
    "
a3f91741d7ba added #replaceFrom:count:* methods
Claus Gittinger <cg@exept.de>
parents: 2411
diff changeset
  2683
3468
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  2684
    "Modified: / 20.5.1998 / 15:22:22 / cg"
2413
a3f91741d7ba added #replaceFrom:count:* methods
Claus Gittinger <cg@exept.de>
parents: 2411
diff changeset
  2685
!
a3f91741d7ba added #replaceFrom:count:* methods
Claus Gittinger <cg@exept.de>
parents: 2411
diff changeset
  2686
3468
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  2687
replaceFrom:startIndex to:stopIndex with:replacementCollection
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  2688
    "replace elements in the receiver between index startIndex and stopIndex,
44
b262907c93ea *** empty log message ***
claus
parents: 42
diff changeset
  2689
     with elements taken from replacementCollection starting at 1.
3468
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  2690
44
b262907c93ea *** empty log message ***
claus
parents: 42
diff changeset
  2691
     Notice: This operation modifies the receiver, NOT a copy;
b262907c93ea *** empty log message ***
claus
parents: 42
diff changeset
  2692
     therefore the change may affect all others referencing the receiver."
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  2693
3468
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  2694
    ^ self 
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  2695
        replaceFrom:startIndex
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  2696
        to:stopIndex
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  2697
        with:replacementCollection
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  2698
        startingAt:1
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  2699
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  2700
    "
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  2701
     args:    startIndex            : <integer>
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  2702
              stopIndex             : <integer>
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  2703
              replacementCollection : <colleciton of <object> >
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  2704
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  2705
     returns: self
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  2706
    "
61
claus
parents: 44
diff changeset
  2707
95
d22739a0c6e9 *** empty log message ***
claus
parents: 88
diff changeset
  2708
    "
d22739a0c6e9 *** empty log message ***
claus
parents: 88
diff changeset
  2709
     '1234567890' replaceFrom:5 to:7 with:'abcdef'
d22739a0c6e9 *** empty log message ***
claus
parents: 88
diff changeset
  2710
     #($a $b $c $d $e) replaceFrom:2 to:3 with:'12345'
d22739a0c6e9 *** empty log message ***
claus
parents: 88
diff changeset
  2711
    "
3468
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  2712
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  2713
    "Modified: / 20.5.1998 / 15:25:37 / cg"
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  2714
!
a27a279701f8 Initial revision
claus
parents:
diff changeset
  2715
3468
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  2716
replaceFrom:startIndex to:stopIndex with:replacementCollection startingAt:repStartIndex
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  2717
    "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
  2718
     with elements  taken from replacementCollection starting at repStartIndex.
3234
4cc58bc6a8ed comment
Claus Gittinger <cg@exept.de>
parents: 3055
diff changeset
  2719
     Return the receiver.
3468
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  2720
44
b262907c93ea *** empty log message ***
claus
parents: 42
diff changeset
  2721
     Notice: This operation modifies the receiver, NOT a copy;
b262907c93ea *** empty log message ***
claus
parents: 42
diff changeset
  2722
     therefore the change may affect all others referencing the receiver."
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  2723
a27a279701f8 Initial revision
claus
parents:
diff changeset
  2724
    |srcIndex "{ Class: SmallInteger }"
a27a279701f8 Initial revision
claus
parents:
diff changeset
  2725
     dstIndex "{ Class: SmallInteger }"
a27a279701f8 Initial revision
claus
parents:
diff changeset
  2726
     end      "{ Class: SmallInteger }" |
a27a279701f8 Initial revision
claus
parents:
diff changeset
  2727
3468
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  2728
    (repStartIndex < startIndex) ifTrue:[
3234
4cc58bc6a8ed comment
Claus Gittinger <cg@exept.de>
parents: 3055
diff changeset
  2729
        " must do reverse copy "
3468
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  2730
        srcIndex := repStartIndex + (stopIndex - startIndex).
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  2731
        dstIndex := stopIndex.
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  2732
        end := startIndex.
3234
4cc58bc6a8ed comment
Claus Gittinger <cg@exept.de>
parents: 3055
diff changeset
  2733
        [dstIndex >= end] whileTrue:[
4cc58bc6a8ed comment
Claus Gittinger <cg@exept.de>
parents: 3055
diff changeset
  2734
            self at:dstIndex put:(replacementCollection at:srcIndex).
4cc58bc6a8ed comment
Claus Gittinger <cg@exept.de>
parents: 3055
diff changeset
  2735
            srcIndex := srcIndex - 1.
4cc58bc6a8ed comment
Claus Gittinger <cg@exept.de>
parents: 3055
diff changeset
  2736
            dstIndex := dstIndex - 1
4cc58bc6a8ed comment
Claus Gittinger <cg@exept.de>
parents: 3055
diff changeset
  2737
        ].
4cc58bc6a8ed comment
Claus Gittinger <cg@exept.de>
parents: 3055
diff changeset
  2738
        ^ self
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  2739
    ].
a27a279701f8 Initial revision
claus
parents:
diff changeset
  2740
3468
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  2741
    srcIndex := repStartIndex.
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  2742
    dstIndex := startIndex.
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  2743
    end := stopIndex.
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  2744
    [dstIndex <= end] whileTrue:[
3234
4cc58bc6a8ed comment
Claus Gittinger <cg@exept.de>
parents: 3055
diff changeset
  2745
        self at:dstIndex put:(replacementCollection at:srcIndex).
4cc58bc6a8ed comment
Claus Gittinger <cg@exept.de>
parents: 3055
diff changeset
  2746
        srcIndex := srcIndex + 1.
4cc58bc6a8ed comment
Claus Gittinger <cg@exept.de>
parents: 3055
diff changeset
  2747
        dstIndex := dstIndex + 1
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  2748
    ]
61
claus
parents: 44
diff changeset
  2749
95
d22739a0c6e9 *** empty log message ***
claus
parents: 88
diff changeset
  2750
    "
3468
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  2751
     args:    startIndex            : <integer>
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  2752
              stopIndex             : <integer>
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  2753
              replacementCollection : <colleciton of <object> >
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  2754
              repStartIndex         : <integer>
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  2755
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  2756
     returns: self
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  2757
    "
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  2758
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  2759
    "
282
94f5c3a6230d *** empty log message ***
claus
parents: 266
diff changeset
  2760
     '1234567890' replaceFrom:5 to:7 with:'abcdef' startingAt:3  
94f5c3a6230d *** empty log message ***
claus
parents: 266
diff changeset
  2761
     #($a $b $c $d $e) replaceFrom:2 to:3 with:'12345' startingAt:4 
94f5c3a6230d *** empty log message ***
claus
parents: 266
diff changeset
  2762
     #($a $b $c $d $e) asOrderedCollection replaceFrom:2 to:3 with:'12345' startingAt:4 
94f5c3a6230d *** empty log message ***
claus
parents: 266
diff changeset
  2763
94f5c3a6230d *** empty log message ***
claus
parents: 266
diff changeset
  2764
     |c|
94f5c3a6230d *** empty log message ***
claus
parents: 266
diff changeset
  2765
     c := #($a $b $c $d $e) asOrderedCollection.
94f5c3a6230d *** empty log message ***
claus
parents: 266
diff changeset
  2766
     c replaceFrom:2 to:3 with:c startingAt:4  
94f5c3a6230d *** empty log message ***
claus
parents: 266
diff changeset
  2767
94f5c3a6230d *** empty log message ***
claus
parents: 266
diff changeset
  2768
     |c|
94f5c3a6230d *** empty log message ***
claus
parents: 266
diff changeset
  2769
     c := #($a $b $c $d $e) asOrderedCollection.
94f5c3a6230d *** empty log message ***
claus
parents: 266
diff changeset
  2770
     c replaceFrom:4 to:5 with:c startingAt:2  
95
d22739a0c6e9 *** empty log message ***
claus
parents: 88
diff changeset
  2771
    "
3234
4cc58bc6a8ed comment
Claus Gittinger <cg@exept.de>
parents: 3055
diff changeset
  2772
3468
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  2773
    "Modified: / 20.5.1998 / 15:23:21 / cg"
61
claus
parents: 44
diff changeset
  2774
!
claus
parents: 44
diff changeset
  2775
3468
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  2776
replaceFrom:startIndex with:replacementCollection
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  2777
    "replace elements in the receiver starting at startIndex,
602
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  2778
     with elements taken from replacementCollection starting at 1
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  2779
     to the end of replacementCollection.
3468
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  2780
602
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  2781
     Notice: This operation modifies the receiver, NOT a copy;
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  2782
     therefore the change may affect all others referencing the receiver."
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  2783
3468
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  2784
    ^ self 
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  2785
        replaceFrom:startIndex 
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  2786
        to:(startIndex + replacementCollection size - 1)
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  2787
        with:replacementCollection
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  2788
        startingAt:1
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  2789
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  2790
    "
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  2791
     args:    startIndex            : <integer>
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  2792
              replacementCollection : <colleciton of <object> >
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  2793
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  2794
     returns: self
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  2795
    "
602
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  2796
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  2797
    "
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  2798
     '1234567890' replaceFrom:5 with:'abc'
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  2799
     #($a $b $c $d $e) replaceFrom:2 with:'123'
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  2800
    "
3468
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  2801
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  2802
    "Modified: / 20.5.1998 / 15:25:27 / cg"
602
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  2803
!
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  2804
3468
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  2805
replaceFrom:startIndex with:replacementCollection startingAt:repStartIndex
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  2806
    "replace elements in the receiver starting at startIndex,
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  2807
     with elements taken from replacementCollection starting at repStartIndex
602
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  2808
     to the end of replacementCollection.
3468
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  2809
602
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  2810
     Notice: This operation modifies the receiver, NOT a copy;
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  2811
     therefore the change may affect all others referencing the receiver."
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  2812
3468
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  2813
    ^ self 
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  2814
        replaceFrom:startIndex 
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  2815
        to:(startIndex + replacementCollection size - repStartIndex)
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  2816
        with:replacementCollection
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  2817
        startingAt:repStartIndex
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  2818
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  2819
    "
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  2820
     args:    startIndex            : <integer>
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  2821
              replacementCollection : <colleciton of <object> >
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  2822
              offset                : <integer>
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  2823
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  2824
     returns: self
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  2825
    "
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  2826
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  2827
    "
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  2828
     '1234567890' replaceFrom:5 with:'abcdef' startingAt:3  
602
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  2829
     #($a $b $c $d $e) replaceFrom:2 with:'12345' startingAt:4
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  2830
    "
3468
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  2831
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  2832
    "Modified: / 20.5.1998 / 15:25:18 / cg"
602
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  2833
!
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  2834
61
claus
parents: 44
diff changeset
  2835
startingAt:sourceStart replaceElementsIn:destColl from:destStartIndex to:destEndIndex
claus
parents: 44
diff changeset
  2836
    "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
  2837
61
claus
parents: 44
diff changeset
  2838
     Notice: This operation modifies the destination collection, NOT a copy;
claus
parents: 44
diff changeset
  2839
     therefore the change may affect all others referencing this object."
claus
parents: 44
diff changeset
  2840
3468
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  2841
    destColl 
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  2842
        replaceFrom:destStartIndex 
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  2843
        to:destEndIndex 
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  2844
        with:self 
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  2845
        startingAt:sourceStart
61
claus
parents: 44
diff changeset
  2846
claus
parents: 44
diff changeset
  2847
    "
claus
parents: 44
diff changeset
  2848
     |s|
claus
parents: 44
diff changeset
  2849
     s := 'abcdefghijklmnop'.
claus
parents: 44
diff changeset
  2850
     '1234567890' startingAt:1 replaceElementsIn:s from:1 to:3.
claus
parents: 44
diff changeset
  2851
     s'123defghijklmnop'
claus
parents: 44
diff changeset
  2852
    "
3468
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  2853
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  2854
    "Modified: / 20.5.1998 / 15:25:08 / cg"
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  2855
! !
a27a279701f8 Initial revision
claus
parents:
diff changeset
  2856
5153
dc159974af2b paddedCopy methods moved from CharacterArray
Claus Gittinger <cg@exept.de>
parents: 5004
diff changeset
  2857
!SequenceableCollection methodsFor:'padded copying'!
dc159974af2b paddedCopy methods moved from CharacterArray
Claus Gittinger <cg@exept.de>
parents: 5004
diff changeset
  2858
dc159974af2b paddedCopy methods moved from CharacterArray
Claus Gittinger <cg@exept.de>
parents: 5004
diff changeset
  2859
leftPaddedTo:size with:padElement
dc159974af2b paddedCopy methods moved from CharacterArray
Claus Gittinger <cg@exept.de>
parents: 5004
diff changeset
  2860
    "return a new collection of length size, which contains the receiver
dc159974af2b paddedCopy methods moved from CharacterArray
Claus Gittinger <cg@exept.de>
parents: 5004
diff changeset
  2861
     right-adjusted (i.e. padded on the left).
dc159974af2b paddedCopy methods moved from CharacterArray
Claus Gittinger <cg@exept.de>
parents: 5004
diff changeset
  2862
     Elements on the left are filled with padElement.
dc159974af2b paddedCopy methods moved from CharacterArray
Claus Gittinger <cg@exept.de>
parents: 5004
diff changeset
  2863
     If the receivers size is equal or greater than the length argument, 
dc159974af2b paddedCopy methods moved from CharacterArray
Claus Gittinger <cg@exept.de>
parents: 5004
diff changeset
  2864
     the original receiver is returned unchanged."
dc159974af2b paddedCopy methods moved from CharacterArray
Claus Gittinger <cg@exept.de>
parents: 5004
diff changeset
  2865
dc159974af2b paddedCopy methods moved from CharacterArray
Claus Gittinger <cg@exept.de>
parents: 5004
diff changeset
  2866
    |len s|
dc159974af2b paddedCopy methods moved from CharacterArray
Claus Gittinger <cg@exept.de>
parents: 5004
diff changeset
  2867
dc159974af2b paddedCopy methods moved from CharacterArray
Claus Gittinger <cg@exept.de>
parents: 5004
diff changeset
  2868
    len := self size.
dc159974af2b paddedCopy methods moved from CharacterArray
Claus Gittinger <cg@exept.de>
parents: 5004
diff changeset
  2869
    (len < size) ifTrue:[
dc159974af2b paddedCopy methods moved from CharacterArray
Claus Gittinger <cg@exept.de>
parents: 5004
diff changeset
  2870
        s := self species new:size withAll:padElement.
dc159974af2b paddedCopy methods moved from CharacterArray
Claus Gittinger <cg@exept.de>
parents: 5004
diff changeset
  2871
        s replaceFrom:(size - len + 1) with:self.
dc159974af2b paddedCopy methods moved from CharacterArray
Claus Gittinger <cg@exept.de>
parents: 5004
diff changeset
  2872
        ^ s
dc159974af2b paddedCopy methods moved from CharacterArray
Claus Gittinger <cg@exept.de>
parents: 5004
diff changeset
  2873
    ]
dc159974af2b paddedCopy methods moved from CharacterArray
Claus Gittinger <cg@exept.de>
parents: 5004
diff changeset
  2874
dc159974af2b paddedCopy methods moved from CharacterArray
Claus Gittinger <cg@exept.de>
parents: 5004
diff changeset
  2875
    "
dc159974af2b paddedCopy methods moved from CharacterArray
Claus Gittinger <cg@exept.de>
parents: 5004
diff changeset
  2876
     'foo' leftPaddedTo:10 with:$.      
dc159974af2b paddedCopy methods moved from CharacterArray
Claus Gittinger <cg@exept.de>
parents: 5004
diff changeset
  2877
     'fooBar' leftPaddedTo:5 with:$.      
dc159974af2b paddedCopy methods moved from CharacterArray
Claus Gittinger <cg@exept.de>
parents: 5004
diff changeset
  2878
     123 printString leftPaddedTo:10 with:$.        
dc159974af2b paddedCopy methods moved from CharacterArray
Claus Gittinger <cg@exept.de>
parents: 5004
diff changeset
  2879
     (' ' , 123 printString) leftPaddedTo:10 with:$.        
dc159974af2b paddedCopy methods moved from CharacterArray
Claus Gittinger <cg@exept.de>
parents: 5004
diff changeset
  2880
     (Float pi printString) leftPaddedTo:15 with:(Character space)  
dc159974af2b paddedCopy methods moved from CharacterArray
Claus Gittinger <cg@exept.de>
parents: 5004
diff changeset
  2881
     (Float pi printString) leftPaddedTo:15 with:$-           
dc159974af2b paddedCopy methods moved from CharacterArray
Claus Gittinger <cg@exept.de>
parents: 5004
diff changeset
  2882
     (' ' , Float pi class name) leftPaddedTo:15 with:$.     
dc159974af2b paddedCopy methods moved from CharacterArray
Claus Gittinger <cg@exept.de>
parents: 5004
diff changeset
  2883
     #[1 2 3 4] leftPaddedTo:6 with:0     
dc159974af2b paddedCopy methods moved from CharacterArray
Claus Gittinger <cg@exept.de>
parents: 5004
diff changeset
  2884
     #[1 2 3 4] leftPaddedTo:10 with:99     
dc159974af2b paddedCopy methods moved from CharacterArray
Claus Gittinger <cg@exept.de>
parents: 5004
diff changeset
  2885
     #(1 2 3 4) leftPaddedTo:8 with:nil     
dc159974af2b paddedCopy methods moved from CharacterArray
Claus Gittinger <cg@exept.de>
parents: 5004
diff changeset
  2886
    "
dc159974af2b paddedCopy methods moved from CharacterArray
Claus Gittinger <cg@exept.de>
parents: 5004
diff changeset
  2887
!
dc159974af2b paddedCopy methods moved from CharacterArray
Claus Gittinger <cg@exept.de>
parents: 5004
diff changeset
  2888
dc159974af2b paddedCopy methods moved from CharacterArray
Claus Gittinger <cg@exept.de>
parents: 5004
diff changeset
  2889
paddedTo:newSize with:padElement
dc159974af2b paddedCopy methods moved from CharacterArray
Claus Gittinger <cg@exept.de>
parents: 5004
diff changeset
  2890
    "return a new collection consisting of the receivers elements,
dc159974af2b paddedCopy methods moved from CharacterArray
Claus Gittinger <cg@exept.de>
parents: 5004
diff changeset
  2891
     plus pad elements up to length.
dc159974af2b paddedCopy methods moved from CharacterArray
Claus Gittinger <cg@exept.de>
parents: 5004
diff changeset
  2892
     If the receivers size is equal or greater than the length argument, 
dc159974af2b paddedCopy methods moved from CharacterArray
Claus Gittinger <cg@exept.de>
parents: 5004
diff changeset
  2893
     the original receiver is returned unchanged."
dc159974af2b paddedCopy methods moved from CharacterArray
Claus Gittinger <cg@exept.de>
parents: 5004
diff changeset
  2894
dc159974af2b paddedCopy methods moved from CharacterArray
Claus Gittinger <cg@exept.de>
parents: 5004
diff changeset
  2895
    |s len|
dc159974af2b paddedCopy methods moved from CharacterArray
Claus Gittinger <cg@exept.de>
parents: 5004
diff changeset
  2896
dc159974af2b paddedCopy methods moved from CharacterArray
Claus Gittinger <cg@exept.de>
parents: 5004
diff changeset
  2897
    len := self size.
dc159974af2b paddedCopy methods moved from CharacterArray
Claus Gittinger <cg@exept.de>
parents: 5004
diff changeset
  2898
    len < newSize ifTrue:[
dc159974af2b paddedCopy methods moved from CharacterArray
Claus Gittinger <cg@exept.de>
parents: 5004
diff changeset
  2899
        s := self species new:newSize withAll:padElement.
dc159974af2b paddedCopy methods moved from CharacterArray
Claus Gittinger <cg@exept.de>
parents: 5004
diff changeset
  2900
        s replaceFrom:1 to:len with:self.
dc159974af2b paddedCopy methods moved from CharacterArray
Claus Gittinger <cg@exept.de>
parents: 5004
diff changeset
  2901
        ^ s
dc159974af2b paddedCopy methods moved from CharacterArray
Claus Gittinger <cg@exept.de>
parents: 5004
diff changeset
  2902
    ]
dc159974af2b paddedCopy methods moved from CharacterArray
Claus Gittinger <cg@exept.de>
parents: 5004
diff changeset
  2903
dc159974af2b paddedCopy methods moved from CharacterArray
Claus Gittinger <cg@exept.de>
parents: 5004
diff changeset
  2904
    "
dc159974af2b paddedCopy methods moved from CharacterArray
Claus Gittinger <cg@exept.de>
parents: 5004
diff changeset
  2905
     'foo' paddedTo:10 with:$.             
dc159974af2b paddedCopy methods moved from CharacterArray
Claus Gittinger <cg@exept.de>
parents: 5004
diff changeset
  2906
     123 printString paddedTo:10 with:$*   
dc159974af2b paddedCopy methods moved from CharacterArray
Claus Gittinger <cg@exept.de>
parents: 5004
diff changeset
  2907
     (Float pi printString) paddedTo:15 with:(Character space)  
dc159974af2b paddedCopy methods moved from CharacterArray
Claus Gittinger <cg@exept.de>
parents: 5004
diff changeset
  2908
     (Float pi printString) paddedTo:15 with:$-  
dc159974af2b paddedCopy methods moved from CharacterArray
Claus Gittinger <cg@exept.de>
parents: 5004
diff changeset
  2909
     (Float pi class name , ' ') paddedTo:15 with:$.  
dc159974af2b paddedCopy methods moved from CharacterArray
Claus Gittinger <cg@exept.de>
parents: 5004
diff changeset
  2910
     #[1 2 3 4] paddedTo:6 with:0     
dc159974af2b paddedCopy methods moved from CharacterArray
Claus Gittinger <cg@exept.de>
parents: 5004
diff changeset
  2911
     #[1 2 3 4] paddedTo:10 with:99     
dc159974af2b paddedCopy methods moved from CharacterArray
Claus Gittinger <cg@exept.de>
parents: 5004
diff changeset
  2912
     #(1 2 3 4) paddedTo:8 with:nil     
dc159974af2b paddedCopy methods moved from CharacterArray
Claus Gittinger <cg@exept.de>
parents: 5004
diff changeset
  2913
    "
dc159974af2b paddedCopy methods moved from CharacterArray
Claus Gittinger <cg@exept.de>
parents: 5004
diff changeset
  2914
! !
dc159974af2b paddedCopy methods moved from CharacterArray
Claus Gittinger <cg@exept.de>
parents: 5004
diff changeset
  2915
2069
f6183117f922 comments
Claus Gittinger <cg@exept.de>
parents: 1673
diff changeset
  2916
!SequenceableCollection methodsFor:'private sorting helpers'!
f6183117f922 comments
Claus Gittinger <cg@exept.de>
parents: 1673
diff changeset
  2917
5358
79b21b5a4783 added #isSorted;
Claus Gittinger <cg@exept.de>
parents: 5320
diff changeset
  2918
mergeFirst: first middle: middle last: last into: dst by: aBlock
79b21b5a4783 added #isSorted;
Claus Gittinger <cg@exept.de>
parents: 5320
diff changeset
  2919
    "Private!! 
79b21b5a4783 added #isSorted;
Claus Gittinger <cg@exept.de>
parents: 5320
diff changeset
  2920
     Merge the sorted ranges [first..middle] and [middle+1..last] of the receiver into the range [first..last] of dst."
79b21b5a4783 added #isSorted;
Claus Gittinger <cg@exept.de>
parents: 5320
diff changeset
  2921
79b21b5a4783 added #isSorted;
Claus Gittinger <cg@exept.de>
parents: 5320
diff changeset
  2922
    | i1 i2 val1 val2 out |
79b21b5a4783 added #isSorted;
Claus Gittinger <cg@exept.de>
parents: 5320
diff changeset
  2923
79b21b5a4783 added #isSorted;
Claus Gittinger <cg@exept.de>
parents: 5320
diff changeset
  2924
    i1 := first.
79b21b5a4783 added #isSorted;
Claus Gittinger <cg@exept.de>
parents: 5320
diff changeset
  2925
    i2 := middle + 1.
79b21b5a4783 added #isSorted;
Claus Gittinger <cg@exept.de>
parents: 5320
diff changeset
  2926
    val1 := self at: i1.
79b21b5a4783 added #isSorted;
Claus Gittinger <cg@exept.de>
parents: 5320
diff changeset
  2927
    val2 := self at: i2.
79b21b5a4783 added #isSorted;
Claus Gittinger <cg@exept.de>
parents: 5320
diff changeset
  2928
    out := first - 1.  "will be pre-incremented"
79b21b5a4783 added #isSorted;
Claus Gittinger <cg@exept.de>
parents: 5320
diff changeset
  2929
79b21b5a4783 added #isSorted;
Claus Gittinger <cg@exept.de>
parents: 5320
diff changeset
  2930
    "select 'lower' half of the elements based on comparator"
79b21b5a4783 added #isSorted;
Claus Gittinger <cg@exept.de>
parents: 5320
diff changeset
  2931
    [(i1 <= middle) and: [i2 <= last]] whileTrue: [
79b21b5a4783 added #isSorted;
Claus Gittinger <cg@exept.de>
parents: 5320
diff changeset
  2932
            (aBlock value: val1 value: val2)
79b21b5a4783 added #isSorted;
Claus Gittinger <cg@exept.de>
parents: 5320
diff changeset
  2933
                    ifTrue: [
79b21b5a4783 added #isSorted;
Claus Gittinger <cg@exept.de>
parents: 5320
diff changeset
  2934
                            dst at: (out := out + 1) put: val1.
79b21b5a4783 added #isSorted;
Claus Gittinger <cg@exept.de>
parents: 5320
diff changeset
  2935
                            val1 := self at: (i1 := i1 + 1)]
79b21b5a4783 added #isSorted;
Claus Gittinger <cg@exept.de>
parents: 5320
diff changeset
  2936
                    ifFalse: [
79b21b5a4783 added #isSorted;
Claus Gittinger <cg@exept.de>
parents: 5320
diff changeset
  2937
                            dst at: (out := out + 1) put: val2.
79b21b5a4783 added #isSorted;
Claus Gittinger <cg@exept.de>
parents: 5320
diff changeset
  2938
                            i2 := i2 + 1.
79b21b5a4783 added #isSorted;
Claus Gittinger <cg@exept.de>
parents: 5320
diff changeset
  2939
                            i2 <= last ifTrue: [val2 := self at: i2]]].
79b21b5a4783 added #isSorted;
Claus Gittinger <cg@exept.de>
parents: 5320
diff changeset
  2940
79b21b5a4783 added #isSorted;
Claus Gittinger <cg@exept.de>
parents: 5320
diff changeset
  2941
    "copy the remaining elements"
79b21b5a4783 added #isSorted;
Claus Gittinger <cg@exept.de>
parents: 5320
diff changeset
  2942
    i1 <= middle
79b21b5a4783 added #isSorted;
Claus Gittinger <cg@exept.de>
parents: 5320
diff changeset
  2943
            ifTrue: [
79b21b5a4783 added #isSorted;
Claus Gittinger <cg@exept.de>
parents: 5320
diff changeset
  2944
                    dst replaceFrom: out + 1 to: last with: self startingAt: i1]
79b21b5a4783 added #isSorted;
Claus Gittinger <cg@exept.de>
parents: 5320
diff changeset
  2945
            ifFalse: [
79b21b5a4783 added #isSorted;
Claus Gittinger <cg@exept.de>
parents: 5320
diff changeset
  2946
                    dst replaceFrom: out + 1 to: last with: self startingAt: i2].
79b21b5a4783 added #isSorted;
Claus Gittinger <cg@exept.de>
parents: 5320
diff changeset
  2947
79b21b5a4783 added #isSorted;
Claus Gittinger <cg@exept.de>
parents: 5320
diff changeset
  2948
!
79b21b5a4783 added #isSorted;
Claus Gittinger <cg@exept.de>
parents: 5320
diff changeset
  2949
79b21b5a4783 added #isSorted;
Claus Gittinger <cg@exept.de>
parents: 5320
diff changeset
  2950
mergeSortFrom: first to: last src: src dst: dst by: aBlock
79b21b5a4783 added #isSorted;
Claus Gittinger <cg@exept.de>
parents: 5320
diff changeset
  2951
    "Private!! Split the range to be sorted in half, sort each half, and merge the two half-ranges into dst."
79b21b5a4783 added #isSorted;
Claus Gittinger <cg@exept.de>
parents: 5320
diff changeset
  2952
79b21b5a4783 added #isSorted;
Claus Gittinger <cg@exept.de>
parents: 5320
diff changeset
  2953
    | middle |
79b21b5a4783 added #isSorted;
Claus Gittinger <cg@exept.de>
parents: 5320
diff changeset
  2954
79b21b5a4783 added #isSorted;
Claus Gittinger <cg@exept.de>
parents: 5320
diff changeset
  2955
    first = last ifTrue: [^ self].
79b21b5a4783 added #isSorted;
Claus Gittinger <cg@exept.de>
parents: 5320
diff changeset
  2956
    middle := (first + last) // 2.
79b21b5a4783 added #isSorted;
Claus Gittinger <cg@exept.de>
parents: 5320
diff changeset
  2957
    self mergeSortFrom: first to: middle src: dst dst: src by: aBlock.
79b21b5a4783 added #isSorted;
Claus Gittinger <cg@exept.de>
parents: 5320
diff changeset
  2958
    self mergeSortFrom: middle + 1 to: last src: dst dst: src by: aBlock.
79b21b5a4783 added #isSorted;
Claus Gittinger <cg@exept.de>
parents: 5320
diff changeset
  2959
    src mergeFirst: first middle: middle last: last into: dst by: aBlock.
79b21b5a4783 added #isSorted;
Claus Gittinger <cg@exept.de>
parents: 5320
diff changeset
  2960
79b21b5a4783 added #isSorted;
Claus Gittinger <cg@exept.de>
parents: 5320
diff changeset
  2961
79b21b5a4783 added #isSorted;
Claus Gittinger <cg@exept.de>
parents: 5320
diff changeset
  2962
!
79b21b5a4783 added #isSorted;
Claus Gittinger <cg@exept.de>
parents: 5320
diff changeset
  2963
2069
f6183117f922 comments
Claus Gittinger <cg@exept.de>
parents: 1673
diff changeset
  2964
quickSortFrom:inBegin to:inEnd
f6183117f922 comments
Claus Gittinger <cg@exept.de>
parents: 1673
diff changeset
  2965
    "actual quicksort worker for sort-message"
f6183117f922 comments
Claus Gittinger <cg@exept.de>
parents: 1673
diff changeset
  2966
f6183117f922 comments
Claus Gittinger <cg@exept.de>
parents: 1673
diff changeset
  2967
    |begin   "{ Class: SmallInteger }"
f6183117f922 comments
Claus Gittinger <cg@exept.de>
parents: 1673
diff changeset
  2968
     end     "{ Class: SmallInteger }"
f6183117f922 comments
Claus Gittinger <cg@exept.de>
parents: 1673
diff changeset
  2969
     b       "{ Class: SmallInteger }"
f6183117f922 comments
Claus Gittinger <cg@exept.de>
parents: 1673
diff changeset
  2970
     e       "{ Class: SmallInteger }"
f6183117f922 comments
Claus Gittinger <cg@exept.de>
parents: 1673
diff changeset
  2971
     middleElement temp1 temp2 |
f6183117f922 comments
Claus Gittinger <cg@exept.de>
parents: 1673
diff changeset
  2972
f6183117f922 comments
Claus Gittinger <cg@exept.de>
parents: 1673
diff changeset
  2973
    begin := inBegin.   "/ this also does a type-check
f6183117f922 comments
Claus Gittinger <cg@exept.de>
parents: 1673
diff changeset
  2974
    end := inEnd.
f6183117f922 comments
Claus Gittinger <cg@exept.de>
parents: 1673
diff changeset
  2975
f6183117f922 comments
Claus Gittinger <cg@exept.de>
parents: 1673
diff changeset
  2976
    b := begin.
f6183117f922 comments
Claus Gittinger <cg@exept.de>
parents: 1673
diff changeset
  2977
    e := end.
f6183117f922 comments
Claus Gittinger <cg@exept.de>
parents: 1673
diff changeset
  2978
    middleElement := self at:((b + e) // 2).
f6183117f922 comments
Claus Gittinger <cg@exept.de>
parents: 1673
diff changeset
  2979
f6183117f922 comments
Claus Gittinger <cg@exept.de>
parents: 1673
diff changeset
  2980
    [b < e] whileTrue:[
f6183117f922 comments
Claus Gittinger <cg@exept.de>
parents: 1673
diff changeset
  2981
	[b < end and:[(self at:b) < middleElement]] whileTrue:[b := b + 1].
f6183117f922 comments
Claus Gittinger <cg@exept.de>
parents: 1673
diff changeset
  2982
	[e > begin and:[middleElement < (self at:e)]] whileTrue:[e := e - 1].
f6183117f922 comments
Claus Gittinger <cg@exept.de>
parents: 1673
diff changeset
  2983
f6183117f922 comments
Claus Gittinger <cg@exept.de>
parents: 1673
diff changeset
  2984
	(b <= e) ifTrue:[
f6183117f922 comments
Claus Gittinger <cg@exept.de>
parents: 1673
diff changeset
  2985
	    (b == e) ifFalse:[
f6183117f922 comments
Claus Gittinger <cg@exept.de>
parents: 1673
diff changeset
  2986
		temp1 := self at:b. temp2 := self at:e. 
f6183117f922 comments
Claus Gittinger <cg@exept.de>
parents: 1673
diff changeset
  2987
		self at:b put:temp2. self at:e put:temp1
f6183117f922 comments
Claus Gittinger <cg@exept.de>
parents: 1673
diff changeset
  2988
	    ].
f6183117f922 comments
Claus Gittinger <cg@exept.de>
parents: 1673
diff changeset
  2989
	    b := b + 1.
f6183117f922 comments
Claus Gittinger <cg@exept.de>
parents: 1673
diff changeset
  2990
	    e := e - 1
f6183117f922 comments
Claus Gittinger <cg@exept.de>
parents: 1673
diff changeset
  2991
	]
f6183117f922 comments
Claus Gittinger <cg@exept.de>
parents: 1673
diff changeset
  2992
    ].
f6183117f922 comments
Claus Gittinger <cg@exept.de>
parents: 1673
diff changeset
  2993
    (begin < e) ifTrue:[self quickSortFrom:begin to:e].
f6183117f922 comments
Claus Gittinger <cg@exept.de>
parents: 1673
diff changeset
  2994
    (b < end) ifTrue:[self quickSortFrom:b to:end]
f6183117f922 comments
Claus Gittinger <cg@exept.de>
parents: 1673
diff changeset
  2995
!
f6183117f922 comments
Claus Gittinger <cg@exept.de>
parents: 1673
diff changeset
  2996
f6183117f922 comments
Claus Gittinger <cg@exept.de>
parents: 1673
diff changeset
  2997
quickSortFrom:inBegin to:inEnd sortBlock:sortBlock
f6183117f922 comments
Claus Gittinger <cg@exept.de>
parents: 1673
diff changeset
  2998
    "actual quicksort worker for sort:-message"
f6183117f922 comments
Claus Gittinger <cg@exept.de>
parents: 1673
diff changeset
  2999
f6183117f922 comments
Claus Gittinger <cg@exept.de>
parents: 1673
diff changeset
  3000
    |begin   "{ Class: SmallInteger }"
f6183117f922 comments
Claus Gittinger <cg@exept.de>
parents: 1673
diff changeset
  3001
     end     "{ Class: SmallInteger }"
f6183117f922 comments
Claus Gittinger <cg@exept.de>
parents: 1673
diff changeset
  3002
     b       "{ Class: SmallInteger }"
f6183117f922 comments
Claus Gittinger <cg@exept.de>
parents: 1673
diff changeset
  3003
     e       "{ Class: SmallInteger }"
f6183117f922 comments
Claus Gittinger <cg@exept.de>
parents: 1673
diff changeset
  3004
     middleElement temp1 temp2 |
f6183117f922 comments
Claus Gittinger <cg@exept.de>
parents: 1673
diff changeset
  3005
f6183117f922 comments
Claus Gittinger <cg@exept.de>
parents: 1673
diff changeset
  3006
    begin := inBegin.   "/ this also does a type-check
f6183117f922 comments
Claus Gittinger <cg@exept.de>
parents: 1673
diff changeset
  3007
    end := inEnd.
f6183117f922 comments
Claus Gittinger <cg@exept.de>
parents: 1673
diff changeset
  3008
f6183117f922 comments
Claus Gittinger <cg@exept.de>
parents: 1673
diff changeset
  3009
    b := begin.
f6183117f922 comments
Claus Gittinger <cg@exept.de>
parents: 1673
diff changeset
  3010
    e := end.
f6183117f922 comments
Claus Gittinger <cg@exept.de>
parents: 1673
diff changeset
  3011
    middleElement := self at:((b + e) // 2).
f6183117f922 comments
Claus Gittinger <cg@exept.de>
parents: 1673
diff changeset
  3012
f6183117f922 comments
Claus Gittinger <cg@exept.de>
parents: 1673
diff changeset
  3013
    [b < e] whileTrue:[
f6183117f922 comments
Claus Gittinger <cg@exept.de>
parents: 1673
diff changeset
  3014
	[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
  3015
	[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
  3016
f6183117f922 comments
Claus Gittinger <cg@exept.de>
parents: 1673
diff changeset
  3017
	(b <= e) ifTrue:[
f6183117f922 comments
Claus Gittinger <cg@exept.de>
parents: 1673
diff changeset
  3018
	    (b == e) ifFalse:[
f6183117f922 comments
Claus Gittinger <cg@exept.de>
parents: 1673
diff changeset
  3019
		temp1 := self at:b. temp2 := self at:e. 
f6183117f922 comments
Claus Gittinger <cg@exept.de>
parents: 1673
diff changeset
  3020
		self at:b put:temp2. self at:e put:temp1
f6183117f922 comments
Claus Gittinger <cg@exept.de>
parents: 1673
diff changeset
  3021
	    ].
f6183117f922 comments
Claus Gittinger <cg@exept.de>
parents: 1673
diff changeset
  3022
	    b := b + 1.
f6183117f922 comments
Claus Gittinger <cg@exept.de>
parents: 1673
diff changeset
  3023
	    e := e - 1
f6183117f922 comments
Claus Gittinger <cg@exept.de>
parents: 1673
diff changeset
  3024
	]
f6183117f922 comments
Claus Gittinger <cg@exept.de>
parents: 1673
diff changeset
  3025
    ].
f6183117f922 comments
Claus Gittinger <cg@exept.de>
parents: 1673
diff changeset
  3026
    (begin < e) ifTrue:[self quickSortFrom:begin to:e sortBlock:sortBlock].
f6183117f922 comments
Claus Gittinger <cg@exept.de>
parents: 1673
diff changeset
  3027
    (b < end) ifTrue:[self quickSortFrom:b to:end sortBlock:sortBlock]
f6183117f922 comments
Claus Gittinger <cg@exept.de>
parents: 1673
diff changeset
  3028
!
f6183117f922 comments
Claus Gittinger <cg@exept.de>
parents: 1673
diff changeset
  3029
3055
0832fba4c740 support 3-arg sort, passing a collationPolicy
Claus Gittinger <cg@exept.de>
parents: 3044
diff changeset
  3030
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
  3031
    "actual quicksort worker for sort:-message"
0832fba4c740 support 3-arg sort, passing a collationPolicy
Claus Gittinger <cg@exept.de>
parents: 3044
diff changeset
  3032
0832fba4c740 support 3-arg sort, passing a collationPolicy
Claus Gittinger <cg@exept.de>
parents: 3044
diff changeset
  3033
    |begin   "{ Class: SmallInteger }"
0832fba4c740 support 3-arg sort, passing a collationPolicy
Claus Gittinger <cg@exept.de>
parents: 3044
diff changeset
  3034
     end     "{ Class: SmallInteger }"
0832fba4c740 support 3-arg sort, passing a collationPolicy
Claus Gittinger <cg@exept.de>
parents: 3044
diff changeset
  3035
     b       "{ Class: SmallInteger }"
0832fba4c740 support 3-arg sort, passing a collationPolicy
Claus Gittinger <cg@exept.de>
parents: 3044
diff changeset
  3036
     e       "{ Class: SmallInteger }"
0832fba4c740 support 3-arg sort, passing a collationPolicy
Claus Gittinger <cg@exept.de>
parents: 3044
diff changeset
  3037
     middleElement temp1 temp2 |
0832fba4c740 support 3-arg sort, passing a collationPolicy
Claus Gittinger <cg@exept.de>
parents: 3044
diff changeset
  3038
0832fba4c740 support 3-arg sort, passing a collationPolicy
Claus Gittinger <cg@exept.de>
parents: 3044
diff changeset
  3039
    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
  3040
    end := inEnd.
0832fba4c740 support 3-arg sort, passing a collationPolicy
Claus Gittinger <cg@exept.de>
parents: 3044
diff changeset
  3041
0832fba4c740 support 3-arg sort, passing a collationPolicy
Claus Gittinger <cg@exept.de>
parents: 3044
diff changeset
  3042
    b := begin.
0832fba4c740 support 3-arg sort, passing a collationPolicy
Claus Gittinger <cg@exept.de>
parents: 3044
diff changeset
  3043
    e := end.
0832fba4c740 support 3-arg sort, passing a collationPolicy
Claus Gittinger <cg@exept.de>
parents: 3044
diff changeset
  3044
    middleElement := self at:((b + e) // 2).
0832fba4c740 support 3-arg sort, passing a collationPolicy
Claus Gittinger <cg@exept.de>
parents: 3044
diff changeset
  3045
0832fba4c740 support 3-arg sort, passing a collationPolicy
Claus Gittinger <cg@exept.de>
parents: 3044
diff changeset
  3046
    [b < e] whileTrue:[
0832fba4c740 support 3-arg sort, passing a collationPolicy
Claus Gittinger <cg@exept.de>
parents: 3044
diff changeset
  3047
        [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
  3048
        [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
  3049
0832fba4c740 support 3-arg sort, passing a collationPolicy
Claus Gittinger <cg@exept.de>
parents: 3044
diff changeset
  3050
        (b <= e) ifTrue:[
0832fba4c740 support 3-arg sort, passing a collationPolicy
Claus Gittinger <cg@exept.de>
parents: 3044
diff changeset
  3051
            (b == e) ifFalse:[
0832fba4c740 support 3-arg sort, passing a collationPolicy
Claus Gittinger <cg@exept.de>
parents: 3044
diff changeset
  3052
                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
  3053
                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
  3054
            ].
0832fba4c740 support 3-arg sort, passing a collationPolicy
Claus Gittinger <cg@exept.de>
parents: 3044
diff changeset
  3055
            b := b + 1.
0832fba4c740 support 3-arg sort, passing a collationPolicy
Claus Gittinger <cg@exept.de>
parents: 3044
diff changeset
  3056
            e := e - 1
0832fba4c740 support 3-arg sort, passing a collationPolicy
Claus Gittinger <cg@exept.de>
parents: 3044
diff changeset
  3057
        ]
0832fba4c740 support 3-arg sort, passing a collationPolicy
Claus Gittinger <cg@exept.de>
parents: 3044
diff changeset
  3058
    ].
0832fba4c740 support 3-arg sort, passing a collationPolicy
Claus Gittinger <cg@exept.de>
parents: 3044
diff changeset
  3059
    (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
  3060
    (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
  3061
0832fba4c740 support 3-arg sort, passing a collationPolicy
Claus Gittinger <cg@exept.de>
parents: 3044
diff changeset
  3062
    "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
  3063
!
0832fba4c740 support 3-arg sort, passing a collationPolicy
Claus Gittinger <cg@exept.de>
parents: 3044
diff changeset
  3064
2069
f6183117f922 comments
Claus Gittinger <cg@exept.de>
parents: 1673
diff changeset
  3065
quickSortFrom:inBegin to:inEnd sortBlock:sortBlock with:aCollection
f6183117f922 comments
Claus Gittinger <cg@exept.de>
parents: 1673
diff changeset
  3066
    "actual quicksort worker for sort:with:-message"
f6183117f922 comments
Claus Gittinger <cg@exept.de>
parents: 1673
diff changeset
  3067
f6183117f922 comments
Claus Gittinger <cg@exept.de>
parents: 1673
diff changeset
  3068
    |begin   "{ Class: SmallInteger }"
f6183117f922 comments
Claus Gittinger <cg@exept.de>
parents: 1673
diff changeset
  3069
     end     "{ Class: SmallInteger }"
f6183117f922 comments
Claus Gittinger <cg@exept.de>
parents: 1673
diff changeset
  3070
     b       "{ Class: SmallInteger }"
f6183117f922 comments
Claus Gittinger <cg@exept.de>
parents: 1673
diff changeset
  3071
     e       "{ Class: SmallInteger }"
f6183117f922 comments
Claus Gittinger <cg@exept.de>
parents: 1673
diff changeset
  3072
     middleElement temp1 temp2 |
f6183117f922 comments
Claus Gittinger <cg@exept.de>
parents: 1673
diff changeset
  3073
f6183117f922 comments
Claus Gittinger <cg@exept.de>
parents: 1673
diff changeset
  3074
    begin := inBegin.   "/ this also does a type-check
f6183117f922 comments
Claus Gittinger <cg@exept.de>
parents: 1673
diff changeset
  3075
    end := inEnd.
f6183117f922 comments
Claus Gittinger <cg@exept.de>
parents: 1673
diff changeset
  3076
f6183117f922 comments
Claus Gittinger <cg@exept.de>
parents: 1673
diff changeset
  3077
    b := begin.
f6183117f922 comments
Claus Gittinger <cg@exept.de>
parents: 1673
diff changeset
  3078
    e := end.
f6183117f922 comments
Claus Gittinger <cg@exept.de>
parents: 1673
diff changeset
  3079
    middleElement := self at:((b + e) // 2).
f6183117f922 comments
Claus Gittinger <cg@exept.de>
parents: 1673
diff changeset
  3080
f6183117f922 comments
Claus Gittinger <cg@exept.de>
parents: 1673
diff changeset
  3081
    [b < e] whileTrue:[
f6183117f922 comments
Claus Gittinger <cg@exept.de>
parents: 1673
diff changeset
  3082
        [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
  3083
        [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
  3084
f6183117f922 comments
Claus Gittinger <cg@exept.de>
parents: 1673
diff changeset
  3085
        (b <= e) ifTrue:[
f6183117f922 comments
Claus Gittinger <cg@exept.de>
parents: 1673
diff changeset
  3086
            (b == e) ifFalse:[
f6183117f922 comments
Claus Gittinger <cg@exept.de>
parents: 1673
diff changeset
  3087
                temp1 := self at:b. temp2 := self at:e. 
f6183117f922 comments
Claus Gittinger <cg@exept.de>
parents: 1673
diff changeset
  3088
                self at:b put:temp2. self at:e put:temp1.
f6183117f922 comments
Claus Gittinger <cg@exept.de>
parents: 1673
diff changeset
  3089
                temp1 := aCollection at:b. temp2 := aCollection at:e. 
f6183117f922 comments
Claus Gittinger <cg@exept.de>
parents: 1673
diff changeset
  3090
                aCollection at:b put:temp2. aCollection at:e put:temp1
f6183117f922 comments
Claus Gittinger <cg@exept.de>
parents: 1673
diff changeset
  3091
            ].
f6183117f922 comments
Claus Gittinger <cg@exept.de>
parents: 1673
diff changeset
  3092
            b := b + 1.
f6183117f922 comments
Claus Gittinger <cg@exept.de>
parents: 1673
diff changeset
  3093
            e := e - 1
f6183117f922 comments
Claus Gittinger <cg@exept.de>
parents: 1673
diff changeset
  3094
        ]
f6183117f922 comments
Claus Gittinger <cg@exept.de>
parents: 1673
diff changeset
  3095
    ].
f6183117f922 comments
Claus Gittinger <cg@exept.de>
parents: 1673
diff changeset
  3096
    (begin < e) ifTrue:[self quickSortFrom:begin to:e sortBlock:sortBlock with:aCollection].
f6183117f922 comments
Claus Gittinger <cg@exept.de>
parents: 1673
diff changeset
  3097
    (b < end) ifTrue:[self quickSortFrom:b to:end sortBlock:sortBlock with:aCollection]
f6183117f922 comments
Claus Gittinger <cg@exept.de>
parents: 1673
diff changeset
  3098
f6183117f922 comments
Claus Gittinger <cg@exept.de>
parents: 1673
diff changeset
  3099
    "Modified: 5.1.1997 / 18:12:36 / cg"
f6183117f922 comments
Claus Gittinger <cg@exept.de>
parents: 1673
diff changeset
  3100
!
f6183117f922 comments
Claus Gittinger <cg@exept.de>
parents: 1673
diff changeset
  3101
f6183117f922 comments
Claus Gittinger <cg@exept.de>
parents: 1673
diff changeset
  3102
quickSortFrom:inBegin to:inEnd with:aCollection
f6183117f922 comments
Claus Gittinger <cg@exept.de>
parents: 1673
diff changeset
  3103
    "actual quicksort worker for sortWith-message"
f6183117f922 comments
Claus Gittinger <cg@exept.de>
parents: 1673
diff changeset
  3104
f6183117f922 comments
Claus Gittinger <cg@exept.de>
parents: 1673
diff changeset
  3105
    |begin   "{ Class: SmallInteger }"
f6183117f922 comments
Claus Gittinger <cg@exept.de>
parents: 1673
diff changeset
  3106
     end     "{ Class: SmallInteger }"
f6183117f922 comments
Claus Gittinger <cg@exept.de>
parents: 1673
diff changeset
  3107
     b       "{ Class: SmallInteger }"
f6183117f922 comments
Claus Gittinger <cg@exept.de>
parents: 1673
diff changeset
  3108
     e       "{ Class: SmallInteger }"
f6183117f922 comments
Claus Gittinger <cg@exept.de>
parents: 1673
diff changeset
  3109
     middleElement temp1 temp2 |
f6183117f922 comments
Claus Gittinger <cg@exept.de>
parents: 1673
diff changeset
  3110
f6183117f922 comments
Claus Gittinger <cg@exept.de>
parents: 1673
diff changeset
  3111
    begin := inBegin.   "/ this also does a type-check
f6183117f922 comments
Claus Gittinger <cg@exept.de>
parents: 1673
diff changeset
  3112
    end := inEnd.
f6183117f922 comments
Claus Gittinger <cg@exept.de>
parents: 1673
diff changeset
  3113
f6183117f922 comments
Claus Gittinger <cg@exept.de>
parents: 1673
diff changeset
  3114
    b := begin.
f6183117f922 comments
Claus Gittinger <cg@exept.de>
parents: 1673
diff changeset
  3115
    e := end.
f6183117f922 comments
Claus Gittinger <cg@exept.de>
parents: 1673
diff changeset
  3116
    middleElement := self at:((b + e) // 2).
f6183117f922 comments
Claus Gittinger <cg@exept.de>
parents: 1673
diff changeset
  3117
f6183117f922 comments
Claus Gittinger <cg@exept.de>
parents: 1673
diff changeset
  3118
    [b < e] whileTrue:[
f6183117f922 comments
Claus Gittinger <cg@exept.de>
parents: 1673
diff changeset
  3119
	[b < end and:[(self at:b) < middleElement]] whileTrue:[b := b + 1].
f6183117f922 comments
Claus Gittinger <cg@exept.de>
parents: 1673
diff changeset
  3120
	[e > begin and:[middleElement < (self at:e)]] whileTrue:[e := e - 1].
f6183117f922 comments
Claus Gittinger <cg@exept.de>
parents: 1673
diff changeset
  3121
f6183117f922 comments
Claus Gittinger <cg@exept.de>
parents: 1673
diff changeset
  3122
	(b <= e) ifTrue:[
f6183117f922 comments
Claus Gittinger <cg@exept.de>
parents: 1673
diff changeset
  3123
	    (b == e) ifFalse:[
f6183117f922 comments
Claus Gittinger <cg@exept.de>
parents: 1673
diff changeset
  3124
		temp1 := self at:b. temp2 := self at:e. 
f6183117f922 comments
Claus Gittinger <cg@exept.de>
parents: 1673
diff changeset
  3125
		self at:b put:temp2. self at:e put:temp1.
f6183117f922 comments
Claus Gittinger <cg@exept.de>
parents: 1673
diff changeset
  3126
		temp1 := aCollection at:b. temp2 := aCollection at:e. 
f6183117f922 comments
Claus Gittinger <cg@exept.de>
parents: 1673
diff changeset
  3127
		aCollection at:b put:temp2. aCollection at:e put:temp1
f6183117f922 comments
Claus Gittinger <cg@exept.de>
parents: 1673
diff changeset
  3128
	    ].
f6183117f922 comments
Claus Gittinger <cg@exept.de>
parents: 1673
diff changeset
  3129
	    b := b + 1.
f6183117f922 comments
Claus Gittinger <cg@exept.de>
parents: 1673
diff changeset
  3130
	    e := e - 1
f6183117f922 comments
Claus Gittinger <cg@exept.de>
parents: 1673
diff changeset
  3131
	]
f6183117f922 comments
Claus Gittinger <cg@exept.de>
parents: 1673
diff changeset
  3132
    ].
f6183117f922 comments
Claus Gittinger <cg@exept.de>
parents: 1673
diff changeset
  3133
    (begin < e) ifTrue:[self quickSortFrom:begin to:e with:aCollection].
f6183117f922 comments
Claus Gittinger <cg@exept.de>
parents: 1673
diff changeset
  3134
    (b < end) ifTrue:[self quickSortFrom:b to:end with:aCollection]
2881
452f9154d0dc comments; added #randomizedQuickSort.
Claus Gittinger <cg@exept.de>
parents: 2860
diff changeset
  3135
!
452f9154d0dc comments; added #randomizedQuickSort.
Claus Gittinger <cg@exept.de>
parents: 2860
diff changeset
  3136
452f9154d0dc comments; added #randomizedQuickSort.
Claus Gittinger <cg@exept.de>
parents: 2860
diff changeset
  3137
randomizedQuickSortFrom:inBegin to:inEnd sortBlock:sortBlock with:aCollection
452f9154d0dc comments; added #randomizedQuickSort.
Claus Gittinger <cg@exept.de>
parents: 2860
diff changeset
  3138
    "actual randomizedQuicksort worker for sort:with:-message.
452f9154d0dc comments; added #randomizedQuickSort.
Claus Gittinger <cg@exept.de>
parents: 2860
diff changeset
  3139
     This exchanges a random element within the partition, to avoid
452f9154d0dc comments; added #randomizedQuickSort.
Claus Gittinger <cg@exept.de>
parents: 2860
diff changeset
  3140
     the worst case O-square situation of quickSort.
452f9154d0dc comments; added #randomizedQuickSort.
Claus Gittinger <cg@exept.de>
parents: 2860
diff changeset
  3141
452f9154d0dc comments; added #randomizedQuickSort.
Claus Gittinger <cg@exept.de>
parents: 2860
diff changeset
  3142
     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
  3143
     runTime, due to the random number generation.
452f9154d0dc comments; added #randomizedQuickSort.
Claus Gittinger <cg@exept.de>
parents: 2860
diff changeset
  3144
     The worst case of quickSort is encountered, if the choosen pivot
452f9154d0dc comments; added #randomizedQuickSort.
Claus Gittinger <cg@exept.de>
parents: 2860
diff changeset
  3145
     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
  3146
     creates partitions of size 1 and (n-1).
452f9154d0dc comments; added #randomizedQuickSort.
Claus Gittinger <cg@exept.de>
parents: 2860
diff changeset
  3147
     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
  3148
     to be encountered."
452f9154d0dc comments; added #randomizedQuickSort.
Claus Gittinger <cg@exept.de>
parents: 2860
diff changeset
  3149
452f9154d0dc comments; added #randomizedQuickSort.
Claus Gittinger <cg@exept.de>
parents: 2860
diff changeset
  3150
    |begin   "{ Class: SmallInteger }"
452f9154d0dc comments; added #randomizedQuickSort.
Claus Gittinger <cg@exept.de>
parents: 2860
diff changeset
  3151
     end     "{ Class: SmallInteger }"
452f9154d0dc comments; added #randomizedQuickSort.
Claus Gittinger <cg@exept.de>
parents: 2860
diff changeset
  3152
     b       "{ Class: SmallInteger }"
452f9154d0dc comments; added #randomizedQuickSort.
Claus Gittinger <cg@exept.de>
parents: 2860
diff changeset
  3153
     e       "{ Class: SmallInteger }"
452f9154d0dc comments; added #randomizedQuickSort.
Claus Gittinger <cg@exept.de>
parents: 2860
diff changeset
  3154
     rnd     "{ Class: SmallInteger }"
452f9154d0dc comments; added #randomizedQuickSort.
Claus Gittinger <cg@exept.de>
parents: 2860
diff changeset
  3155
     middleElement temp1 temp2 |
452f9154d0dc comments; added #randomizedQuickSort.
Claus Gittinger <cg@exept.de>
parents: 2860
diff changeset
  3156
452f9154d0dc comments; added #randomizedQuickSort.
Claus Gittinger <cg@exept.de>
parents: 2860
diff changeset
  3157
    begin := inBegin.   "/ this also does a type-check
452f9154d0dc comments; added #randomizedQuickSort.
Claus Gittinger <cg@exept.de>
parents: 2860
diff changeset
  3158
    end := inEnd.
452f9154d0dc comments; added #randomizedQuickSort.
Claus Gittinger <cg@exept.de>
parents: 2860
diff changeset
  3159
452f9154d0dc comments; added #randomizedQuickSort.
Claus Gittinger <cg@exept.de>
parents: 2860
diff changeset
  3160
    b := begin.
452f9154d0dc comments; added #randomizedQuickSort.
Claus Gittinger <cg@exept.de>
parents: 2860
diff changeset
  3161
    e := end.
452f9154d0dc comments; added #randomizedQuickSort.
Claus Gittinger <cg@exept.de>
parents: 2860
diff changeset
  3162
452f9154d0dc comments; added #randomizedQuickSort.
Claus Gittinger <cg@exept.de>
parents: 2860
diff changeset
  3163
    "/ randomize that partition
452f9154d0dc comments; added #randomizedQuickSort.
Claus Gittinger <cg@exept.de>
parents: 2860
diff changeset
  3164
    "/ by exchanging the first element with any random
452f9154d0dc comments; added #randomizedQuickSort.
Claus Gittinger <cg@exept.de>
parents: 2860
diff changeset
  3165
    "/ element.
452f9154d0dc comments; added #randomizedQuickSort.
Claus Gittinger <cg@exept.de>
parents: 2860
diff changeset
  3166
    rnd := Random nextIntegerBetween:b and:e.
452f9154d0dc comments; added #randomizedQuickSort.
Claus Gittinger <cg@exept.de>
parents: 2860
diff changeset
  3167
    temp1 := self at:b. temp2 := self at:rnd.
452f9154d0dc comments; added #randomizedQuickSort.
Claus Gittinger <cg@exept.de>
parents: 2860
diff changeset
  3168
    self at:b put:temp2. self at:rnd put:temp1.
452f9154d0dc comments; added #randomizedQuickSort.
Claus Gittinger <cg@exept.de>
parents: 2860
diff changeset
  3169
    aCollection notNil ifTrue:[
452f9154d0dc comments; added #randomizedQuickSort.
Claus Gittinger <cg@exept.de>
parents: 2860
diff changeset
  3170
        temp1 := aCollection at:b. temp2 := aCollection at:rnd. 
452f9154d0dc comments; added #randomizedQuickSort.
Claus Gittinger <cg@exept.de>
parents: 2860
diff changeset
  3171
        aCollection at:b put:temp2. aCollection at:rnd put:temp1
452f9154d0dc comments; added #randomizedQuickSort.
Claus Gittinger <cg@exept.de>
parents: 2860
diff changeset
  3172
    ].
452f9154d0dc comments; added #randomizedQuickSort.
Claus Gittinger <cg@exept.de>
parents: 2860
diff changeset
  3173
452f9154d0dc comments; added #randomizedQuickSort.
Claus Gittinger <cg@exept.de>
parents: 2860
diff changeset
  3174
    "/
452f9154d0dc comments; added #randomizedQuickSort.
Claus Gittinger <cg@exept.de>
parents: 2860
diff changeset
  3175
    "/ now proceed as usual
452f9154d0dc comments; added #randomizedQuickSort.
Claus Gittinger <cg@exept.de>
parents: 2860
diff changeset
  3176
    "/
452f9154d0dc comments; added #randomizedQuickSort.
Claus Gittinger <cg@exept.de>
parents: 2860
diff changeset
  3177
    middleElement := self at:((b + e) // 2).
452f9154d0dc comments; added #randomizedQuickSort.
Claus Gittinger <cg@exept.de>
parents: 2860
diff changeset
  3178
452f9154d0dc comments; added #randomizedQuickSort.
Claus Gittinger <cg@exept.de>
parents: 2860
diff changeset
  3179
    [b < e] whileTrue:[
452f9154d0dc comments; added #randomizedQuickSort.
Claus Gittinger <cg@exept.de>
parents: 2860
diff changeset
  3180
        [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
  3181
        [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
  3182
452f9154d0dc comments; added #randomizedQuickSort.
Claus Gittinger <cg@exept.de>
parents: 2860
diff changeset
  3183
        (b <= e) ifTrue:[
452f9154d0dc comments; added #randomizedQuickSort.
Claus Gittinger <cg@exept.de>
parents: 2860
diff changeset
  3184
            (b == e) ifFalse:[
452f9154d0dc comments; added #randomizedQuickSort.
Claus Gittinger <cg@exept.de>
parents: 2860
diff changeset
  3185
                temp1 := self at:b. temp2 := self at:e. 
452f9154d0dc comments; added #randomizedQuickSort.
Claus Gittinger <cg@exept.de>
parents: 2860
diff changeset
  3186
                self at:b put:temp2. self at:e put:temp1.
452f9154d0dc comments; added #randomizedQuickSort.
Claus Gittinger <cg@exept.de>
parents: 2860
diff changeset
  3187
                aCollection notNil ifTrue:[
452f9154d0dc comments; added #randomizedQuickSort.
Claus Gittinger <cg@exept.de>
parents: 2860
diff changeset
  3188
                    temp1 := aCollection at:b. temp2 := aCollection at:e. 
452f9154d0dc comments; added #randomizedQuickSort.
Claus Gittinger <cg@exept.de>
parents: 2860
diff changeset
  3189
                    aCollection at:b put:temp2. aCollection at:e put:temp1
452f9154d0dc comments; added #randomizedQuickSort.
Claus Gittinger <cg@exept.de>
parents: 2860
diff changeset
  3190
                ].
452f9154d0dc comments; added #randomizedQuickSort.
Claus Gittinger <cg@exept.de>
parents: 2860
diff changeset
  3191
            ].
452f9154d0dc comments; added #randomizedQuickSort.
Claus Gittinger <cg@exept.de>
parents: 2860
diff changeset
  3192
            b := b + 1.
452f9154d0dc comments; added #randomizedQuickSort.
Claus Gittinger <cg@exept.de>
parents: 2860
diff changeset
  3193
            e := e - 1
452f9154d0dc comments; added #randomizedQuickSort.
Claus Gittinger <cg@exept.de>
parents: 2860
diff changeset
  3194
        ]
452f9154d0dc comments; added #randomizedQuickSort.
Claus Gittinger <cg@exept.de>
parents: 2860
diff changeset
  3195
    ].
452f9154d0dc comments; added #randomizedQuickSort.
Claus Gittinger <cg@exept.de>
parents: 2860
diff changeset
  3196
    (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
  3197
    (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
  3198
452f9154d0dc comments; added #randomizedQuickSort.
Claus Gittinger <cg@exept.de>
parents: 2860
diff changeset
  3199
    "Created: 21.8.1997 / 18:13:35 / cg"
452f9154d0dc comments; added #randomizedQuickSort.
Claus Gittinger <cg@exept.de>
parents: 2860
diff changeset
  3200
    "Modified: 21.8.1997 / 18:34:31 / cg"
452f9154d0dc comments; added #randomizedQuickSort.
Claus Gittinger <cg@exept.de>
parents: 2860
diff changeset
  3201
!
452f9154d0dc comments; added #randomizedQuickSort.
Claus Gittinger <cg@exept.de>
parents: 2860
diff changeset
  3202
452f9154d0dc comments; added #randomizedQuickSort.
Claus Gittinger <cg@exept.de>
parents: 2860
diff changeset
  3203
randomizedQuickSortFrom:inBegin to:inEnd with:aCollection
452f9154d0dc comments; added #randomizedQuickSort.
Claus Gittinger <cg@exept.de>
parents: 2860
diff changeset
  3204
    "actual randomizedQuicksort worker for randomizedSort:-message.
452f9154d0dc comments; added #randomizedQuickSort.
Claus Gittinger <cg@exept.de>
parents: 2860
diff changeset
  3205
     This exchanges a random element within the partition, to avoid
452f9154d0dc comments; added #randomizedQuickSort.
Claus Gittinger <cg@exept.de>
parents: 2860
diff changeset
  3206
     the worst case O-square situation of quickSort.
452f9154d0dc comments; added #randomizedQuickSort.
Claus Gittinger <cg@exept.de>
parents: 2860
diff changeset
  3207
452f9154d0dc comments; added #randomizedQuickSort.
Claus Gittinger <cg@exept.de>
parents: 2860
diff changeset
  3208
     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
  3209
     runTime, due to the random number generation.
452f9154d0dc comments; added #randomizedQuickSort.
Claus Gittinger <cg@exept.de>
parents: 2860
diff changeset
  3210
     The worst case of quickSort is encountered, if the choosen pivot
452f9154d0dc comments; added #randomizedQuickSort.
Claus Gittinger <cg@exept.de>
parents: 2860
diff changeset
  3211
     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
  3212
     creates partitions of size 1 and (n-1).
452f9154d0dc comments; added #randomizedQuickSort.
Claus Gittinger <cg@exept.de>
parents: 2860
diff changeset
  3213
     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
  3214
     to be encountered."
452f9154d0dc comments; added #randomizedQuickSort.
Claus Gittinger <cg@exept.de>
parents: 2860
diff changeset
  3215
452f9154d0dc comments; added #randomizedQuickSort.
Claus Gittinger <cg@exept.de>
parents: 2860
diff changeset
  3216
    |begin   "{ Class: SmallInteger }"
452f9154d0dc comments; added #randomizedQuickSort.
Claus Gittinger <cg@exept.de>
parents: 2860
diff changeset
  3217
     end     "{ Class: SmallInteger }"
452f9154d0dc comments; added #randomizedQuickSort.
Claus Gittinger <cg@exept.de>
parents: 2860
diff changeset
  3218
     b       "{ Class: SmallInteger }"
452f9154d0dc comments; added #randomizedQuickSort.
Claus Gittinger <cg@exept.de>
parents: 2860
diff changeset
  3219
     e       "{ Class: SmallInteger }"
452f9154d0dc comments; added #randomizedQuickSort.
Claus Gittinger <cg@exept.de>
parents: 2860
diff changeset
  3220
     rnd     "{ Class: SmallInteger }"
452f9154d0dc comments; added #randomizedQuickSort.
Claus Gittinger <cg@exept.de>
parents: 2860
diff changeset
  3221
     middleElement temp1 temp2 |
452f9154d0dc comments; added #randomizedQuickSort.
Claus Gittinger <cg@exept.de>
parents: 2860
diff changeset
  3222
452f9154d0dc comments; added #randomizedQuickSort.
Claus Gittinger <cg@exept.de>
parents: 2860
diff changeset
  3223
    begin := inBegin.   "/ this also does a type-check
452f9154d0dc comments; added #randomizedQuickSort.
Claus Gittinger <cg@exept.de>
parents: 2860
diff changeset
  3224
    end := inEnd.
452f9154d0dc comments; added #randomizedQuickSort.
Claus Gittinger <cg@exept.de>
parents: 2860
diff changeset
  3225
452f9154d0dc comments; added #randomizedQuickSort.
Claus Gittinger <cg@exept.de>
parents: 2860
diff changeset
  3226
    b := begin.
452f9154d0dc comments; added #randomizedQuickSort.
Claus Gittinger <cg@exept.de>
parents: 2860
diff changeset
  3227
    e := end.
452f9154d0dc comments; added #randomizedQuickSort.
Claus Gittinger <cg@exept.de>
parents: 2860
diff changeset
  3228
452f9154d0dc comments; added #randomizedQuickSort.
Claus Gittinger <cg@exept.de>
parents: 2860
diff changeset
  3229
    "/ randomize that partition
452f9154d0dc comments; added #randomizedQuickSort.
Claus Gittinger <cg@exept.de>
parents: 2860
diff changeset
  3230
    "/ by exchanging the first element with any random
452f9154d0dc comments; added #randomizedQuickSort.
Claus Gittinger <cg@exept.de>
parents: 2860
diff changeset
  3231
    "/ element.
452f9154d0dc comments; added #randomizedQuickSort.
Claus Gittinger <cg@exept.de>
parents: 2860
diff changeset
  3232
    rnd := Random nextIntegerBetween:b and:e.
452f9154d0dc comments; added #randomizedQuickSort.
Claus Gittinger <cg@exept.de>
parents: 2860
diff changeset
  3233
    temp1 := self at:b. temp2 := self at:rnd.
452f9154d0dc comments; added #randomizedQuickSort.
Claus Gittinger <cg@exept.de>
parents: 2860
diff changeset
  3234
    self at:b put:temp2. self at:rnd put:temp1.
452f9154d0dc comments; added #randomizedQuickSort.
Claus Gittinger <cg@exept.de>
parents: 2860
diff changeset
  3235
    aCollection notNil ifTrue:[
452f9154d0dc comments; added #randomizedQuickSort.
Claus Gittinger <cg@exept.de>
parents: 2860
diff changeset
  3236
        temp1 := aCollection at:b. temp2 := aCollection at:rnd. 
452f9154d0dc comments; added #randomizedQuickSort.
Claus Gittinger <cg@exept.de>
parents: 2860
diff changeset
  3237
        aCollection at:b put:temp2. aCollection at:rnd put:temp1
452f9154d0dc comments; added #randomizedQuickSort.
Claus Gittinger <cg@exept.de>
parents: 2860
diff changeset
  3238
    ].
452f9154d0dc comments; added #randomizedQuickSort.
Claus Gittinger <cg@exept.de>
parents: 2860
diff changeset
  3239
452f9154d0dc comments; added #randomizedQuickSort.
Claus Gittinger <cg@exept.de>
parents: 2860
diff changeset
  3240
    "/
452f9154d0dc comments; added #randomizedQuickSort.
Claus Gittinger <cg@exept.de>
parents: 2860
diff changeset
  3241
    "/ now proceed as usual
452f9154d0dc comments; added #randomizedQuickSort.
Claus Gittinger <cg@exept.de>
parents: 2860
diff changeset
  3242
    "/
452f9154d0dc comments; added #randomizedQuickSort.
Claus Gittinger <cg@exept.de>
parents: 2860
diff changeset
  3243
    middleElement := self at:((b + e) // 2).
452f9154d0dc comments; added #randomizedQuickSort.
Claus Gittinger <cg@exept.de>
parents: 2860
diff changeset
  3244
452f9154d0dc comments; added #randomizedQuickSort.
Claus Gittinger <cg@exept.de>
parents: 2860
diff changeset
  3245
    [b < e] whileTrue:[
452f9154d0dc comments; added #randomizedQuickSort.
Claus Gittinger <cg@exept.de>
parents: 2860
diff changeset
  3246
        [b < end and:[(self at:b) < middleElement]] whileTrue:[b := b + 1].
452f9154d0dc comments; added #randomizedQuickSort.
Claus Gittinger <cg@exept.de>
parents: 2860
diff changeset
  3247
        [e > begin and:[middleElement < (self at:e)]] whileTrue:[e := e - 1].
452f9154d0dc comments; added #randomizedQuickSort.
Claus Gittinger <cg@exept.de>
parents: 2860
diff changeset
  3248
452f9154d0dc comments; added #randomizedQuickSort.
Claus Gittinger <cg@exept.de>
parents: 2860
diff changeset
  3249
        (b <= e) ifTrue:[
452f9154d0dc comments; added #randomizedQuickSort.
Claus Gittinger <cg@exept.de>
parents: 2860
diff changeset
  3250
            (b == e) ifFalse:[
452f9154d0dc comments; added #randomizedQuickSort.
Claus Gittinger <cg@exept.de>
parents: 2860
diff changeset
  3251
                temp1 := self at:b. temp2 := self at:e. 
452f9154d0dc comments; added #randomizedQuickSort.
Claus Gittinger <cg@exept.de>
parents: 2860
diff changeset
  3252
                self at:b put:temp2. self at:e put:temp1.
452f9154d0dc comments; added #randomizedQuickSort.
Claus Gittinger <cg@exept.de>
parents: 2860
diff changeset
  3253
                aCollection notNil ifTrue:[
452f9154d0dc comments; added #randomizedQuickSort.
Claus Gittinger <cg@exept.de>
parents: 2860
diff changeset
  3254
                    temp1 := aCollection at:b. temp2 := aCollection at:e. 
452f9154d0dc comments; added #randomizedQuickSort.
Claus Gittinger <cg@exept.de>
parents: 2860
diff changeset
  3255
                    aCollection at:b put:temp2. aCollection at:e put:temp1
452f9154d0dc comments; added #randomizedQuickSort.
Claus Gittinger <cg@exept.de>
parents: 2860
diff changeset
  3256
                ].
452f9154d0dc comments; added #randomizedQuickSort.
Claus Gittinger <cg@exept.de>
parents: 2860
diff changeset
  3257
            ].
452f9154d0dc comments; added #randomizedQuickSort.
Claus Gittinger <cg@exept.de>
parents: 2860
diff changeset
  3258
            b := b + 1.
452f9154d0dc comments; added #randomizedQuickSort.
Claus Gittinger <cg@exept.de>
parents: 2860
diff changeset
  3259
            e := e - 1
452f9154d0dc comments; added #randomizedQuickSort.
Claus Gittinger <cg@exept.de>
parents: 2860
diff changeset
  3260
        ]
452f9154d0dc comments; added #randomizedQuickSort.
Claus Gittinger <cg@exept.de>
parents: 2860
diff changeset
  3261
    ].
452f9154d0dc comments; added #randomizedQuickSort.
Claus Gittinger <cg@exept.de>
parents: 2860
diff changeset
  3262
    (begin < e) ifTrue:[self randomizedQuickSortFrom:begin to:e with:aCollection].
452f9154d0dc comments; added #randomizedQuickSort.
Claus Gittinger <cg@exept.de>
parents: 2860
diff changeset
  3263
    (b < end) ifTrue:[self randomizedQuickSortFrom:b to:end with:aCollection]
452f9154d0dc comments; added #randomizedQuickSort.
Claus Gittinger <cg@exept.de>
parents: 2860
diff changeset
  3264
452f9154d0dc comments; added #randomizedQuickSort.
Claus Gittinger <cg@exept.de>
parents: 2860
diff changeset
  3265
    "Modified: 21.8.1997 / 18:30:19 / cg"
452f9154d0dc comments; added #randomizedQuickSort.
Claus Gittinger <cg@exept.de>
parents: 2860
diff changeset
  3266
    "Created: 21.8.1997 / 18:34:23 / cg"
2069
f6183117f922 comments
Claus Gittinger <cg@exept.de>
parents: 1673
diff changeset
  3267
! !
f6183117f922 comments
Claus Gittinger <cg@exept.de>
parents: 1673
diff changeset
  3268
602
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  3269
!SequenceableCollection methodsFor:'queries'!
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  3270
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  3271
firstIndex
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  3272
    "return the first elements index"
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  3273
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  3274
    ^ 1
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  3275
!
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  3276
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  3277
isSequenceable
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  3278
    "return true, if the receiver is some kind of sequenceableCollection"
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  3279
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  3280
    ^ true
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  3281
!
a27a279701f8 Initial revision
claus
parents:
diff changeset
  3282
602
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  3283
isSequenceableCollection
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  3284
    "OBSOLETE: use isSequenceable for ST-80 compatibility.
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  3285
     This method is a historic leftover and will be removed."
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  3286
3435
04c06b559fa6 isSequenceableCollection is now obsolete;
Claus Gittinger <cg@exept.de>
parents: 3408
diff changeset
  3287
    self obsoleteMethodWarning:'use #isSequenceable'.
602
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  3288
    ^ true
3435
04c06b559fa6 isSequenceableCollection is now obsolete;
Claus Gittinger <cg@exept.de>
parents: 3408
diff changeset
  3289
04c06b559fa6 isSequenceableCollection is now obsolete;
Claus Gittinger <cg@exept.de>
parents: 3408
diff changeset
  3290
    "Modified: / 8.5.1998 / 21:27:18 / cg"
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  3291
!
a27a279701f8 Initial revision
claus
parents:
diff changeset
  3292
5358
79b21b5a4783 added #isSorted;
Claus Gittinger <cg@exept.de>
parents: 5320
diff changeset
  3293
isSorted
79b21b5a4783 added #isSorted;
Claus Gittinger <cg@exept.de>
parents: 5320
diff changeset
  3294
    "return true. if my elements are sorted (already)"
79b21b5a4783 added #isSorted;
Claus Gittinger <cg@exept.de>
parents: 5320
diff changeset
  3295
79b21b5a4783 added #isSorted;
Claus Gittinger <cg@exept.de>
parents: 5320
diff changeset
  3296
    |lastEl el|
79b21b5a4783 added #isSorted;
Claus Gittinger <cg@exept.de>
parents: 5320
diff changeset
  3297
79b21b5a4783 added #isSorted;
Claus Gittinger <cg@exept.de>
parents: 5320
diff changeset
  3298
    lastEl := self first.
79b21b5a4783 added #isSorted;
Claus Gittinger <cg@exept.de>
parents: 5320
diff changeset
  3299
    2 to:self size do:[:i |
79b21b5a4783 added #isSorted;
Claus Gittinger <cg@exept.de>
parents: 5320
diff changeset
  3300
        el := self at:i.
79b21b5a4783 added #isSorted;
Claus Gittinger <cg@exept.de>
parents: 5320
diff changeset
  3301
        el >= lastEl ifFalse: [^ false].
79b21b5a4783 added #isSorted;
Claus Gittinger <cg@exept.de>
parents: 5320
diff changeset
  3302
        lastEl := el
79b21b5a4783 added #isSorted;
Claus Gittinger <cg@exept.de>
parents: 5320
diff changeset
  3303
    ].
79b21b5a4783 added #isSorted;
Claus Gittinger <cg@exept.de>
parents: 5320
diff changeset
  3304
    ^ true
79b21b5a4783 added #isSorted;
Claus Gittinger <cg@exept.de>
parents: 5320
diff changeset
  3305
79b21b5a4783 added #isSorted;
Claus Gittinger <cg@exept.de>
parents: 5320
diff changeset
  3306
    "
79b21b5a4783 added #isSorted;
Claus Gittinger <cg@exept.de>
parents: 5320
diff changeset
  3307
     #(1 2 3 5 10 100) isSorted    
79b21b5a4783 added #isSorted;
Claus Gittinger <cg@exept.de>
parents: 5320
diff changeset
  3308
     #(1 2 3 5 100 10) isSorted    
79b21b5a4783 added #isSorted;
Claus Gittinger <cg@exept.de>
parents: 5320
diff changeset
  3309
    "
79b21b5a4783 added #isSorted;
Claus Gittinger <cg@exept.de>
parents: 5320
diff changeset
  3310
!
79b21b5a4783 added #isSorted;
Claus Gittinger <cg@exept.de>
parents: 5320
diff changeset
  3311
79b21b5a4783 added #isSorted;
Claus Gittinger <cg@exept.de>
parents: 5320
diff changeset
  3312
isSortedBy:aBlock
79b21b5a4783 added #isSorted;
Claus Gittinger <cg@exept.de>
parents: 5320
diff changeset
  3313
    "return true, if my elements are sorted (already) by the given criterion (sortBlock)"
79b21b5a4783 added #isSorted;
Claus Gittinger <cg@exept.de>
parents: 5320
diff changeset
  3314
79b21b5a4783 added #isSorted;
Claus Gittinger <cg@exept.de>
parents: 5320
diff changeset
  3315
    |lastEl el|
79b21b5a4783 added #isSorted;
Claus Gittinger <cg@exept.de>
parents: 5320
diff changeset
  3316
79b21b5a4783 added #isSorted;
Claus Gittinger <cg@exept.de>
parents: 5320
diff changeset
  3317
    lastEl := self first.
79b21b5a4783 added #isSorted;
Claus Gittinger <cg@exept.de>
parents: 5320
diff changeset
  3318
    2 to:self size do:[:i |
79b21b5a4783 added #isSorted;
Claus Gittinger <cg@exept.de>
parents: 5320
diff changeset
  3319
        el := self at:i.
79b21b5a4783 added #isSorted;
Claus Gittinger <cg@exept.de>
parents: 5320
diff changeset
  3320
        (aBlock value:lastEl value:el) ifFalse: [^ false].
79b21b5a4783 added #isSorted;
Claus Gittinger <cg@exept.de>
parents: 5320
diff changeset
  3321
        lastEl := el
79b21b5a4783 added #isSorted;
Claus Gittinger <cg@exept.de>
parents: 5320
diff changeset
  3322
    ].
79b21b5a4783 added #isSorted;
Claus Gittinger <cg@exept.de>
parents: 5320
diff changeset
  3323
    ^ true
79b21b5a4783 added #isSorted;
Claus Gittinger <cg@exept.de>
parents: 5320
diff changeset
  3324
79b21b5a4783 added #isSorted;
Claus Gittinger <cg@exept.de>
parents: 5320
diff changeset
  3325
    "
79b21b5a4783 added #isSorted;
Claus Gittinger <cg@exept.de>
parents: 5320
diff changeset
  3326
     #(1 2 3 5 10 100) isSortedBy:[:a :b | a <= b]    
79b21b5a4783 added #isSorted;
Claus Gittinger <cg@exept.de>
parents: 5320
diff changeset
  3327
     #(1 2 3 5 100 10) isSortedBy:[:a :b | a <= b]       
79b21b5a4783 added #isSorted;
Claus Gittinger <cg@exept.de>
parents: 5320
diff changeset
  3328
     #(100 10 5 3 2 1) isSortedBy:[:a :b | a <= b]       
79b21b5a4783 added #isSorted;
Claus Gittinger <cg@exept.de>
parents: 5320
diff changeset
  3329
     #(100 10 5 3 2 1) isSortedBy:[:a :b | a > b]       
79b21b5a4783 added #isSorted;
Claus Gittinger <cg@exept.de>
parents: 5320
diff changeset
  3330
    "
79b21b5a4783 added #isSorted;
Claus Gittinger <cg@exept.de>
parents: 5320
diff changeset
  3331
79b21b5a4783 added #isSorted;
Claus Gittinger <cg@exept.de>
parents: 5320
diff changeset
  3332
!
79b21b5a4783 added #isSorted;
Claus Gittinger <cg@exept.de>
parents: 5320
diff changeset
  3333
602
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  3334
keys
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  3335
    "return a collection with all keys in the Smalltalk dictionary"
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  3336
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  3337
    |sz|
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  3338
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  3339
    sz := self size.
602
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  3340
    sz == 0 ifTrue:[
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  3341
	^ #()
61
claus
parents: 44
diff changeset
  3342
    ].
602
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  3343
    ^ 1 to:sz
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  3344
!
a27a279701f8 Initial revision
claus
parents:
diff changeset
  3345
602
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  3346
lastIndex
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  3347
    "return the last elements index"
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  3348
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  3349
    ^ self size
61
claus
parents: 44
diff changeset
  3350
!
claus
parents: 44
diff changeset
  3351
602
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  3352
size
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  3353
    "return the number of elements in the collection.
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  3354
     concrete implementations must define this"
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  3355
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  3356
    ^ self subclassResponsibility
2165
9ef030343739 added #zeroIndex for protocol completeness (ST-80)
Claus Gittinger <cg@exept.de>
parents: 2069
diff changeset
  3357
!
9ef030343739 added #zeroIndex for protocol completeness (ST-80)
Claus Gittinger <cg@exept.de>
parents: 2069
diff changeset
  3358
9ef030343739 added #zeroIndex for protocol completeness (ST-80)
Claus Gittinger <cg@exept.de>
parents: 2069
diff changeset
  3359
zeroIndex
9ef030343739 added #zeroIndex for protocol completeness (ST-80)
Claus Gittinger <cg@exept.de>
parents: 2069
diff changeset
  3360
    "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
  3361
     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
  3362
     ST-compatibility"
9ef030343739 added #zeroIndex for protocol completeness (ST-80)
Claus Gittinger <cg@exept.de>
parents: 2069
diff changeset
  3363
9ef030343739 added #zeroIndex for protocol completeness (ST-80)
Claus Gittinger <cg@exept.de>
parents: 2069
diff changeset
  3364
    ^ 0
9ef030343739 added #zeroIndex for protocol completeness (ST-80)
Claus Gittinger <cg@exept.de>
parents: 2069
diff changeset
  3365
9ef030343739 added #zeroIndex for protocol completeness (ST-80)
Claus Gittinger <cg@exept.de>
parents: 2069
diff changeset
  3366
    "Created: 14.2.1997 / 16:13:03 / cg"
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  3367
! !
a27a279701f8 Initial revision
claus
parents:
diff changeset
  3368
5471
a57eeb01c5ab General encoding method (#encodeOn:with:)
Stefan Vogel <sv@exept.de>
parents: 5446
diff changeset
  3369
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  3370
!SequenceableCollection methodsFor:'searching'!
a27a279701f8 Initial revision
claus
parents:
diff changeset
  3371
a27a279701f8 Initial revision
claus
parents:
diff changeset
  3372
detect:aBlock ifNone:exceptionBlock
a27a279701f8 Initial revision
claus
parents:
diff changeset
  3373
    "find the first element, for which evaluation of the argument, aBlock
a27a279701f8 Initial revision
claus
parents:
diff changeset
  3374
     return true; if none does so, return the evaluation of exceptionBlock
a27a279701f8 Initial revision
claus
parents:
diff changeset
  3375
a27a279701f8 Initial revision
claus
parents:
diff changeset
  3376
    reimplemented here for speed"
a27a279701f8 Initial revision
claus
parents:
diff changeset
  3377
32
ee1a621c696c *** empty log message ***
claus
parents: 13
diff changeset
  3378
    |stop  "{ Class: SmallInteger }"
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  3379
     element|
a27a279701f8 Initial revision
claus
parents:
diff changeset
  3380
32
ee1a621c696c *** empty log message ***
claus
parents: 13
diff changeset
  3381
    stop := self size.
ee1a621c696c *** empty log message ***
claus
parents: 13
diff changeset
  3382
    1 to:stop do:[:index |
159
514c749165c3 *** empty log message ***
claus
parents: 118
diff changeset
  3383
	element := self at:index.
514c749165c3 *** empty log message ***
claus
parents: 118
diff changeset
  3384
	(aBlock value:element) ifTrue:[
514c749165c3 *** empty log message ***
claus
parents: 118
diff changeset
  3385
	    ^ element
514c749165c3 *** empty log message ***
claus
parents: 118
diff changeset
  3386
	].
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  3387
    ].
a27a279701f8 Initial revision
claus
parents:
diff changeset
  3388
    ^ exceptionBlock value
159
514c749165c3 *** empty log message ***
claus
parents: 118
diff changeset
  3389
514c749165c3 *** empty log message ***
claus
parents: 118
diff changeset
  3390
    "
514c749165c3 *** empty log message ***
claus
parents: 118
diff changeset
  3391
     #(11 12 13 14) detect:[:n | n odd] ifNone:['sorry']    
514c749165c3 *** empty log message ***
claus
parents: 118
diff changeset
  3392
     #(12 14 16 18) detect:[:n | n odd] ifNone:['sorry']     
514c749165c3 *** empty log message ***
claus
parents: 118
diff changeset
  3393
    "
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  3394
!
a27a279701f8 Initial revision
claus
parents:
diff changeset
  3395
3887
c3c86dcca908 added #detect:startingAt:
Claus Gittinger <cg@exept.de>
parents: 3764
diff changeset
  3396
detect:aBlock startingAt:startIndex
c3c86dcca908 added #detect:startingAt:
Claus Gittinger <cg@exept.de>
parents: 3764
diff changeset
  3397
    "find the first element, for which evaluation of the argument, aBlock
c3c86dcca908 added #detect:startingAt:
Claus Gittinger <cg@exept.de>
parents: 3764
diff changeset
  3398
     return true, starting the search with startIndex.
c3c86dcca908 added #detect:startingAt:
Claus Gittinger <cg@exept.de>
parents: 3764
diff changeset
  3399
     If none does so, report an error"
c3c86dcca908 added #detect:startingAt:
Claus Gittinger <cg@exept.de>
parents: 3764
diff changeset
  3400
c3c86dcca908 added #detect:startingAt:
Claus Gittinger <cg@exept.de>
parents: 3764
diff changeset
  3401
    ^ self detect:aBlock startingAt:startIndex ifNone:[self errorNotFound]
c3c86dcca908 added #detect:startingAt:
Claus Gittinger <cg@exept.de>
parents: 3764
diff changeset
  3402
c3c86dcca908 added #detect:startingAt:
Claus Gittinger <cg@exept.de>
parents: 3764
diff changeset
  3403
    "
c3c86dcca908 added #detect:startingAt:
Claus Gittinger <cg@exept.de>
parents: 3764
diff changeset
  3404
     #(11 12 13 14) detect:[:n | n odd] startingAt:3    
c3c86dcca908 added #detect:startingAt:
Claus Gittinger <cg@exept.de>
parents: 3764
diff changeset
  3405
     #(12 14 16 18) detect:[:n | n odd] startingAt:3     
c3c86dcca908 added #detect:startingAt:
Claus Gittinger <cg@exept.de>
parents: 3764
diff changeset
  3406
    "
c3c86dcca908 added #detect:startingAt:
Claus Gittinger <cg@exept.de>
parents: 3764
diff changeset
  3407
c3c86dcca908 added #detect:startingAt:
Claus Gittinger <cg@exept.de>
parents: 3764
diff changeset
  3408
    "Created: / 21.10.1998 / 18:47:28 / cg"
c3c86dcca908 added #detect:startingAt:
Claus Gittinger <cg@exept.de>
parents: 3764
diff changeset
  3409
!
c3c86dcca908 added #detect:startingAt:
Claus Gittinger <cg@exept.de>
parents: 3764
diff changeset
  3410
c3c86dcca908 added #detect:startingAt:
Claus Gittinger <cg@exept.de>
parents: 3764
diff changeset
  3411
detect:aBlock startingAt:startIndex ifNone:exceptionBlock
c3c86dcca908 added #detect:startingAt:
Claus Gittinger <cg@exept.de>
parents: 3764
diff changeset
  3412
    "find the first element, for which evaluation of the argument, aBlock
c3c86dcca908 added #detect:startingAt:
Claus Gittinger <cg@exept.de>
parents: 3764
diff changeset
  3413
     return true, starting the search with startIndex.
c3c86dcca908 added #detect:startingAt:
Claus Gittinger <cg@exept.de>
parents: 3764
diff changeset
  3414
     If none does so, return the evaluation of exceptionBlock
c3c86dcca908 added #detect:startingAt:
Claus Gittinger <cg@exept.de>
parents: 3764
diff changeset
  3415
c3c86dcca908 added #detect:startingAt:
Claus Gittinger <cg@exept.de>
parents: 3764
diff changeset
  3416
    reimplemented here for speed"
c3c86dcca908 added #detect:startingAt:
Claus Gittinger <cg@exept.de>
parents: 3764
diff changeset
  3417
c3c86dcca908 added #detect:startingAt:
Claus Gittinger <cg@exept.de>
parents: 3764
diff changeset
  3418
    |stop  "{ Class: SmallInteger }"
c3c86dcca908 added #detect:startingAt:
Claus Gittinger <cg@exept.de>
parents: 3764
diff changeset
  3419
     element|
c3c86dcca908 added #detect:startingAt:
Claus Gittinger <cg@exept.de>
parents: 3764
diff changeset
  3420
c3c86dcca908 added #detect:startingAt:
Claus Gittinger <cg@exept.de>
parents: 3764
diff changeset
  3421
    stop := self size.
c3c86dcca908 added #detect:startingAt:
Claus Gittinger <cg@exept.de>
parents: 3764
diff changeset
  3422
    startIndex to:stop do:[:index |
c3c86dcca908 added #detect:startingAt:
Claus Gittinger <cg@exept.de>
parents: 3764
diff changeset
  3423
        element := self at:index.
c3c86dcca908 added #detect:startingAt:
Claus Gittinger <cg@exept.de>
parents: 3764
diff changeset
  3424
        (aBlock value:element) ifTrue:[
c3c86dcca908 added #detect:startingAt:
Claus Gittinger <cg@exept.de>
parents: 3764
diff changeset
  3425
            ^ element
c3c86dcca908 added #detect:startingAt:
Claus Gittinger <cg@exept.de>
parents: 3764
diff changeset
  3426
        ].
c3c86dcca908 added #detect:startingAt:
Claus Gittinger <cg@exept.de>
parents: 3764
diff changeset
  3427
    ].
c3c86dcca908 added #detect:startingAt:
Claus Gittinger <cg@exept.de>
parents: 3764
diff changeset
  3428
    ^ exceptionBlock value
c3c86dcca908 added #detect:startingAt:
Claus Gittinger <cg@exept.de>
parents: 3764
diff changeset
  3429
c3c86dcca908 added #detect:startingAt:
Claus Gittinger <cg@exept.de>
parents: 3764
diff changeset
  3430
    "
c3c86dcca908 added #detect:startingAt:
Claus Gittinger <cg@exept.de>
parents: 3764
diff changeset
  3431
     #(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
  3432
     #(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
  3433
    "
c3c86dcca908 added #detect:startingAt:
Claus Gittinger <cg@exept.de>
parents: 3764
diff changeset
  3434
c3c86dcca908 added #detect:startingAt:
Claus Gittinger <cg@exept.de>
parents: 3764
diff changeset
  3435
    "Created: / 21.10.1998 / 18:46:01 / cg"
c3c86dcca908 added #detect:startingAt:
Claus Gittinger <cg@exept.de>
parents: 3764
diff changeset
  3436
!
c3c86dcca908 added #detect:startingAt:
Claus Gittinger <cg@exept.de>
parents: 3764
diff changeset
  3437
602
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  3438
findFirst:aBlock
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  3439
    "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
  3440
     returns true; return its index or 0 if none detected.
c3c86dcca908 added #detect:startingAt:
Claus Gittinger <cg@exept.de>
parents: 3764
diff changeset
  3441
     This is much like #detect, however, here an INDEX is returned,
c3c86dcca908 added #detect:startingAt:
Claus Gittinger <cg@exept.de>
parents: 3764
diff changeset
  3442
     while #detect returns the element."
602
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  3443
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  3444
    |stop  "{ Class: SmallInteger }" |
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  3445
32
ee1a621c696c *** empty log message ***
claus
parents: 13
diff changeset
  3446
    stop := self size.
602
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  3447
    1 to:stop do:[:index |
3887
c3c86dcca908 added #detect:startingAt:
Claus Gittinger <cg@exept.de>
parents: 3764
diff changeset
  3448
        (aBlock value:(self at:index)) ifTrue:[^ index].
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  3449
    ].
a27a279701f8 Initial revision
claus
parents:
diff changeset
  3450
    ^ 0
159
514c749165c3 *** empty log message ***
claus
parents: 118
diff changeset
  3451
95
d22739a0c6e9 *** empty log message ***
claus
parents: 88
diff changeset
  3452
    "
602
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  3453
     #(1 2 3 4 5 6) findFirst:[:x | (x >= 3)]
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  3454
     #(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
  3455
     #(1 2 3 4 5 6) findFirst:[:x | (x >= 8)]           
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  3456
     'one.two.three' findFirst:[:c | (c == $.)]
5443
a16da4e95ddd comment
Claus Gittinger <cg@exept.de>
parents: 5391
diff changeset
  3457
     '__one.two.three' findFirst:[:c | (c ~= $_)] 
a16da4e95ddd comment
Claus Gittinger <cg@exept.de>
parents: 5391
diff changeset
  3458
     'one.two.three' findFirst:[:c | (c ~= $_)] 
95
d22739a0c6e9 *** empty log message ***
claus
parents: 88
diff changeset
  3459
    "
3887
c3c86dcca908 added #detect:startingAt:
Claus Gittinger <cg@exept.de>
parents: 3764
diff changeset
  3460
c3c86dcca908 added #detect:startingAt:
Claus Gittinger <cg@exept.de>
parents: 3764
diff changeset
  3461
    "Modified: / 21.10.1998 / 18:48:10 / cg"
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  3462
!
a27a279701f8 Initial revision
claus
parents:
diff changeset
  3463
929
674de4c05dcb added findFirst:startingAt: and findLast:startingAt:
Claus Gittinger <cg@exept.de>
parents: 911
diff changeset
  3464
findFirst:aBlock startingAt:startIndex
674de4c05dcb added findFirst:startingAt: and findLast:startingAt:
Claus Gittinger <cg@exept.de>
parents: 911
diff changeset
  3465
    "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
  3466
     returns true; return its index or 0 if none detected.
c3c86dcca908 added #detect:startingAt:
Claus Gittinger <cg@exept.de>
parents: 3764
diff changeset
  3467
     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
  3468
     while #detect returns the element."
929
674de4c05dcb added findFirst:startingAt: and findLast:startingAt:
Claus Gittinger <cg@exept.de>
parents: 911
diff changeset
  3469
674de4c05dcb added findFirst:startingAt: and findLast:startingAt:
Claus Gittinger <cg@exept.de>
parents: 911
diff changeset
  3470
    |start "{ Class: SmallInteger }"
674de4c05dcb added findFirst:startingAt: and findLast:startingAt:
Claus Gittinger <cg@exept.de>
parents: 911
diff changeset
  3471
     stop  "{ Class: SmallInteger }" |
674de4c05dcb added findFirst:startingAt: and findLast:startingAt:
Claus Gittinger <cg@exept.de>
parents: 911
diff changeset
  3472
674de4c05dcb added findFirst:startingAt: and findLast:startingAt:
Claus Gittinger <cg@exept.de>
parents: 911
diff changeset
  3473
    start := startIndex. "/ as a compiler hint
674de4c05dcb added findFirst:startingAt: and findLast:startingAt:
Claus Gittinger <cg@exept.de>
parents: 911
diff changeset
  3474
    stop := self size.
674de4c05dcb added findFirst:startingAt: and findLast:startingAt:
Claus Gittinger <cg@exept.de>
parents: 911
diff changeset
  3475
    start to:stop do:[:index |
3887
c3c86dcca908 added #detect:startingAt:
Claus Gittinger <cg@exept.de>
parents: 3764
diff changeset
  3476
        (aBlock value:(self at:index)) ifTrue:[^ index].
929
674de4c05dcb added findFirst:startingAt: and findLast:startingAt:
Claus Gittinger <cg@exept.de>
parents: 911
diff changeset
  3477
    ].
674de4c05dcb added findFirst:startingAt: and findLast:startingAt:
Claus Gittinger <cg@exept.de>
parents: 911
diff changeset
  3478
    ^ 0
674de4c05dcb added findFirst:startingAt: and findLast:startingAt:
Claus Gittinger <cg@exept.de>
parents: 911
diff changeset
  3479
674de4c05dcb added findFirst:startingAt: and findLast:startingAt:
Claus Gittinger <cg@exept.de>
parents: 911
diff changeset
  3480
    "
674de4c05dcb added findFirst:startingAt: and findLast:startingAt:
Claus Gittinger <cg@exept.de>
parents: 911
diff changeset
  3481
     #(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
  3482
     'one.two.three' findFirst:[:c | (c == $.)] startingAt:5
674de4c05dcb added findFirst:startingAt: and findLast:startingAt:
Claus Gittinger <cg@exept.de>
parents: 911
diff changeset
  3483
    "
3887
c3c86dcca908 added #detect:startingAt:
Claus Gittinger <cg@exept.de>
parents: 3764
diff changeset
  3484
c3c86dcca908 added #detect:startingAt:
Claus Gittinger <cg@exept.de>
parents: 3764
diff changeset
  3485
    "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
  3486
!
674de4c05dcb added findFirst:startingAt: and findLast:startingAt:
Claus Gittinger <cg@exept.de>
parents: 911
diff changeset
  3487
602
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  3488
findLast:aBlock
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  3489
    "find the last element, for which evaluation of the argument, aBlock
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  3490
     returns true; return its index or 0 if none detected."
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  3491
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  3492
    |start "{ Class: SmallInteger }"|
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  3493
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  3494
    start := self size.
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  3495
    start to:1 by:-1 do:[:index |
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  3496
	(aBlock value:(self at:index)) ifTrue:[^ index].
252
  3497
    ].
  3498
    ^ 0
  3499
  3500
    "
602
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  3501
     #(1 99 3 99 5 6) findLast:[:x | (x == 99)]
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  3502
     'one.two.three' findLast:[:c | (c == $.)]
252
  3503
    "
  3504
!
  3505
929
674de4c05dcb added findFirst:startingAt: and findLast:startingAt:
Claus Gittinger <cg@exept.de>
parents: 911
diff changeset
  3506
findLast:aBlock startingAt:startIndex
674de4c05dcb added findFirst:startingAt: and findLast:startingAt:
Claus Gittinger <cg@exept.de>
parents: 911
diff changeset
  3507
    "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
  3508
     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
  3509
674de4c05dcb added findFirst:startingAt: and findLast:startingAt:
Claus Gittinger <cg@exept.de>
parents: 911
diff changeset
  3510
    |start "{ Class: SmallInteger }"|
674de4c05dcb added findFirst:startingAt: and findLast:startingAt:
Claus Gittinger <cg@exept.de>
parents: 911
diff changeset
  3511
674de4c05dcb added findFirst:startingAt: and findLast:startingAt:
Claus Gittinger <cg@exept.de>
parents: 911
diff changeset
  3512
    start := startIndex.
674de4c05dcb added findFirst:startingAt: and findLast:startingAt:
Claus Gittinger <cg@exept.de>
parents: 911
diff changeset
  3513
    start to:1 by:-1 do:[:index |
674de4c05dcb added findFirst:startingAt: and findLast:startingAt:
Claus Gittinger <cg@exept.de>
parents: 911
diff changeset
  3514
	(aBlock value:(self at:index)) ifTrue:[^ index].
674de4c05dcb added findFirst:startingAt: and findLast:startingAt:
Claus Gittinger <cg@exept.de>
parents: 911
diff changeset
  3515
    ].
674de4c05dcb added findFirst:startingAt: and findLast:startingAt:
Claus Gittinger <cg@exept.de>
parents: 911
diff changeset
  3516
    ^ 0
674de4c05dcb added findFirst:startingAt: and findLast:startingAt:
Claus Gittinger <cg@exept.de>
parents: 911
diff changeset
  3517
674de4c05dcb added findFirst:startingAt: and findLast:startingAt:
Claus Gittinger <cg@exept.de>
parents: 911
diff changeset
  3518
    "
674de4c05dcb added findFirst:startingAt: and findLast:startingAt:
Claus Gittinger <cg@exept.de>
parents: 911
diff changeset
  3519
     #(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
  3520
     'one.two.three' findLast:[:c | (c == $.)] startingAt:7
674de4c05dcb added findFirst:startingAt: and findLast:startingAt:
Claus Gittinger <cg@exept.de>
parents: 911
diff changeset
  3521
    "
674de4c05dcb added findFirst:startingAt: and findLast:startingAt:
Claus Gittinger <cg@exept.de>
parents: 911
diff changeset
  3522
!
674de4c05dcb added findFirst:startingAt: and findLast:startingAt:
Claus Gittinger <cg@exept.de>
parents: 911
diff changeset
  3523
159
514c749165c3 *** empty log message ***
claus
parents: 118
diff changeset
  3524
indexOfAny:aCollection
514c749165c3 *** empty log message ***
claus
parents: 118
diff changeset
  3525
    "search the collection for an element in aCollection.
514c749165c3 *** empty log message ***
claus
parents: 118
diff changeset
  3526
     if found, return the index otherwise return 0.
514c749165c3 *** empty log message ***
claus
parents: 118
diff changeset
  3527
     The comparison is done using = 
514c749165c3 *** empty log message ***
claus
parents: 118
diff changeset
  3528
     (i.e. equality test - not identity test).
514c749165c3 *** empty log message ***
claus
parents: 118
diff changeset
  3529
514c749165c3 *** empty log message ***
claus
parents: 118
diff changeset
  3530
     Notice, that for big collections, the runtime of this search
514c749165c3 *** empty log message ***
claus
parents: 118
diff changeset
  3531
     grows proportional to size(receiver) * size(aCollection).
514c749165c3 *** empty log message ***
claus
parents: 118
diff changeset
  3532
     You may think about using other mechanisms (Sets, Dictionaries etc)."
514c749165c3 *** empty log message ***
claus
parents: 118
diff changeset
  3533
514c749165c3 *** empty log message ***
claus
parents: 118
diff changeset
  3534
    ^ self indexOfAny:aCollection startingAt:1
514c749165c3 *** empty log message ***
claus
parents: 118
diff changeset
  3535
514c749165c3 *** empty log message ***
claus
parents: 118
diff changeset
  3536
    "
514c749165c3 *** empty log message ***
claus
parents: 118
diff changeset
  3537
     #(10 20 30 40 50 60 70) indexOfAny:#(40 30 50)
514c749165c3 *** empty log message ***
claus
parents: 118
diff changeset
  3538
     #(10 20 30 40 50 60 70) indexOfAny:#(40.0 30.0 50)
514c749165c3 *** empty log message ***
claus
parents: 118
diff changeset
  3539
    "
514c749165c3 *** empty log message ***
claus
parents: 118
diff changeset
  3540
!
514c749165c3 *** empty log message ***
claus
parents: 118
diff changeset
  3541
514c749165c3 *** empty log message ***
claus
parents: 118
diff changeset
  3542
indexOfAny:aCollection startingAt:start
514c749165c3 *** empty log message ***
claus
parents: 118
diff changeset
  3543
    "search the collection for an element in aCollection,
514c749165c3 *** empty log message ***
claus
parents: 118
diff changeset
  3544
     starting the search at index start;
514c749165c3 *** empty log message ***
claus
parents: 118
diff changeset
  3545
     if found, return the index otherwise return 0.
514c749165c3 *** empty log message ***
claus
parents: 118
diff changeset
  3546
     The comparison is done using = 
514c749165c3 *** empty log message ***
claus
parents: 118
diff changeset
  3547
     (i.e. equality test - not identity test).
514c749165c3 *** empty log message ***
claus
parents: 118
diff changeset
  3548
514c749165c3 *** empty log message ***
claus
parents: 118
diff changeset
  3549
     Notice, that for big collections, the runtime of this search
514c749165c3 *** empty log message ***
claus
parents: 118
diff changeset
  3550
     grows proportional to size(receiver) * size(aCollection).
514c749165c3 *** empty log message ***
claus
parents: 118
diff changeset
  3551
     You may think about using other mechanisms (Sets, Dictionaries etc)."
514c749165c3 *** empty log message ***
claus
parents: 118
diff changeset
  3552
514c749165c3 *** empty log message ***
claus
parents: 118
diff changeset
  3553
514c749165c3 *** empty log message ***
claus
parents: 118
diff changeset
  3554
    |startIndex "{ Class: SmallInteger }"
514c749165c3 *** empty log message ***
claus
parents: 118
diff changeset
  3555
     stop       "{ Class: SmallInteger }" |
514c749165c3 *** empty log message ***
claus
parents: 118
diff changeset
  3556
514c749165c3 *** empty log message ***
claus
parents: 118
diff changeset
  3557
    startIndex := start.
514c749165c3 *** empty log message ***
claus
parents: 118
diff changeset
  3558
    stop := self size.
514c749165c3 *** empty log message ***
claus
parents: 118
diff changeset
  3559
    startIndex to:stop do:[:index |
514c749165c3 *** empty log message ***
claus
parents: 118
diff changeset
  3560
	(aCollection includes:(self at:index)) ifTrue:[^ index].
514c749165c3 *** empty log message ***
claus
parents: 118
diff changeset
  3561
    ].
514c749165c3 *** empty log message ***
claus
parents: 118
diff changeset
  3562
    ^ 0
514c749165c3 *** empty log message ***
claus
parents: 118
diff changeset
  3563
    "
514c749165c3 *** empty log message ***
claus
parents: 118
diff changeset
  3564
     #(10 20 30 40 10 20 30 40) indexOfAny:#(40 50 30) startingAt:5  
514c749165c3 *** empty log message ***
claus
parents: 118
diff changeset
  3565
     #(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
  3566
    "
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  3567
!
a27a279701f8 Initial revision
claus
parents:
diff changeset
  3568
518
5372a8875432 added indexOfAny:startingAt:ifAbsent:
Claus Gittinger <cg@exept.de>
parents: 424
diff changeset
  3569
indexOfAny:aCollection startingAt:start ifAbsent:exceptionBlock
5372a8875432 added indexOfAny:startingAt:ifAbsent:
Claus Gittinger <cg@exept.de>
parents: 424
diff changeset
  3570
    "search the collection for an element in aCollection,
5372a8875432 added indexOfAny:startingAt:ifAbsent:
Claus Gittinger <cg@exept.de>
parents: 424
diff changeset
  3571
     starting the search at index start;
5372a8875432 added indexOfAny:startingAt:ifAbsent:
Claus Gittinger <cg@exept.de>
parents: 424
diff changeset
  3572
     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
  3573
     The comparison is done using = 
5372a8875432 added indexOfAny:startingAt:ifAbsent:
Claus Gittinger <cg@exept.de>
parents: 424
diff changeset
  3574
     (i.e. equality test - not identity test).
5372a8875432 added indexOfAny:startingAt:ifAbsent:
Claus Gittinger <cg@exept.de>
parents: 424
diff changeset
  3575
5372a8875432 added indexOfAny:startingAt:ifAbsent:
Claus Gittinger <cg@exept.de>
parents: 424
diff changeset
  3576
     Notice, that for big collections, the runtime of this search
5372a8875432 added indexOfAny:startingAt:ifAbsent:
Claus Gittinger <cg@exept.de>
parents: 424
diff changeset
  3577
     grows proportional to size(receiver) * size(aCollection).
5372a8875432 added indexOfAny:startingAt:ifAbsent:
Claus Gittinger <cg@exept.de>
parents: 424
diff changeset
  3578
     You may think about using other mechanisms (Sets, Dictionaries etc)."
5372a8875432 added indexOfAny:startingAt:ifAbsent:
Claus Gittinger <cg@exept.de>
parents: 424
diff changeset
  3579
5372a8875432 added indexOfAny:startingAt:ifAbsent:
Claus Gittinger <cg@exept.de>
parents: 424
diff changeset
  3580
5372a8875432 added indexOfAny:startingAt:ifAbsent:
Claus Gittinger <cg@exept.de>
parents: 424
diff changeset
  3581
    |val|
5372a8875432 added indexOfAny:startingAt:ifAbsent:
Claus Gittinger <cg@exept.de>
parents: 424
diff changeset
  3582
5372a8875432 added indexOfAny:startingAt:ifAbsent:
Claus Gittinger <cg@exept.de>
parents: 424
diff changeset
  3583
    val := self indexOfAny:aCollection startingAt:start .
5372a8875432 added indexOfAny:startingAt:ifAbsent:
Claus Gittinger <cg@exept.de>
parents: 424
diff changeset
  3584
    val == 0 ifTrue:[^ exceptionBlock value].
5372a8875432 added indexOfAny:startingAt:ifAbsent:
Claus Gittinger <cg@exept.de>
parents: 424
diff changeset
  3585
    ^ val.
5372a8875432 added indexOfAny:startingAt:ifAbsent:
Claus Gittinger <cg@exept.de>
parents: 424
diff changeset
  3586
5372a8875432 added indexOfAny:startingAt:ifAbsent:
Claus Gittinger <cg@exept.de>
parents: 424
diff changeset
  3587
    "
5372a8875432 added indexOfAny:startingAt:ifAbsent:
Claus Gittinger <cg@exept.de>
parents: 424
diff changeset
  3588
     #(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
  3589
     #(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
  3590
     #(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
  3591
    "
5372a8875432 added indexOfAny:startingAt:ifAbsent:
Claus Gittinger <cg@exept.de>
parents: 424
diff changeset
  3592
!
5372a8875432 added indexOfAny:startingAt:ifAbsent:
Claus Gittinger <cg@exept.de>
parents: 424
diff changeset
  3593
4338
326f43992dcd added #indexOfAnyOf:* for squeak compatibility.
Claus Gittinger <cg@exept.de>
parents: 4303
diff changeset
  3594
indexOfAnyOf:aCollection
326f43992dcd added #indexOfAnyOf:* for squeak compatibility.
Claus Gittinger <cg@exept.de>
parents: 4303
diff changeset
  3595
    "squeak compatibility: same as #indexOfAny:"
326f43992dcd added #indexOfAnyOf:* for squeak compatibility.
Claus Gittinger <cg@exept.de>
parents: 4303
diff changeset
  3596
326f43992dcd added #indexOfAnyOf:* for squeak compatibility.
Claus Gittinger <cg@exept.de>
parents: 4303
diff changeset
  3597
    ^ self indexOfAny:aCollection
326f43992dcd added #indexOfAnyOf:* for squeak compatibility.
Claus Gittinger <cg@exept.de>
parents: 4303
diff changeset
  3598
326f43992dcd added #indexOfAnyOf:* for squeak compatibility.
Claus Gittinger <cg@exept.de>
parents: 4303
diff changeset
  3599
    "
326f43992dcd added #indexOfAnyOf:* for squeak compatibility.
Claus Gittinger <cg@exept.de>
parents: 4303
diff changeset
  3600
     #(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
  3601
     #(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
  3602
    "
326f43992dcd added #indexOfAnyOf:* for squeak compatibility.
Claus Gittinger <cg@exept.de>
parents: 4303
diff changeset
  3603
!
326f43992dcd added #indexOfAnyOf:* for squeak compatibility.
Claus Gittinger <cg@exept.de>
parents: 4303
diff changeset
  3604
326f43992dcd added #indexOfAnyOf:* for squeak compatibility.
Claus Gittinger <cg@exept.de>
parents: 4303
diff changeset
  3605
indexOfAnyOf:aCollection startingAt:start 
326f43992dcd added #indexOfAnyOf:* for squeak compatibility.
Claus Gittinger <cg@exept.de>
parents: 4303
diff changeset
  3606
    "squeak compatibility: same as #indexOfAny:startingAt:"
326f43992dcd added #indexOfAnyOf:* for squeak compatibility.
Claus Gittinger <cg@exept.de>
parents: 4303
diff changeset
  3607
326f43992dcd added #indexOfAnyOf:* for squeak compatibility.
Claus Gittinger <cg@exept.de>
parents: 4303
diff changeset
  3608
    ^ self indexOfAny:aCollection startingAt:start
326f43992dcd added #indexOfAnyOf:* for squeak compatibility.
Claus Gittinger <cg@exept.de>
parents: 4303
diff changeset
  3609
326f43992dcd added #indexOfAnyOf:* for squeak compatibility.
Claus Gittinger <cg@exept.de>
parents: 4303
diff changeset
  3610
    "
326f43992dcd added #indexOfAnyOf:* for squeak compatibility.
Claus Gittinger <cg@exept.de>
parents: 4303
diff changeset
  3611
     #(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
  3612
     #(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
  3613
    "
326f43992dcd added #indexOfAnyOf:* for squeak compatibility.
Claus Gittinger <cg@exept.de>
parents: 4303
diff changeset
  3614
!
326f43992dcd added #indexOfAnyOf:* for squeak compatibility.
Claus Gittinger <cg@exept.de>
parents: 4303
diff changeset
  3615
326f43992dcd added #indexOfAnyOf:* for squeak compatibility.
Claus Gittinger <cg@exept.de>
parents: 4303
diff changeset
  3616
indexOfAnyOf:aCollection startingAt:start ifAbsent:exceptionBlock
326f43992dcd added #indexOfAnyOf:* for squeak compatibility.
Claus Gittinger <cg@exept.de>
parents: 4303
diff changeset
  3617
    "squeak compatibility: same as #indexOfAny:startingAt:ifAbsent:"
326f43992dcd added #indexOfAnyOf:* for squeak compatibility.
Claus Gittinger <cg@exept.de>
parents: 4303
diff changeset
  3618
326f43992dcd added #indexOfAnyOf:* for squeak compatibility.
Claus Gittinger <cg@exept.de>
parents: 4303
diff changeset
  3619
    ^ self indexOfAny:aCollection startingAt:start ifAbsent:exceptionBlock
326f43992dcd added #indexOfAnyOf:* for squeak compatibility.
Claus Gittinger <cg@exept.de>
parents: 4303
diff changeset
  3620
326f43992dcd added #indexOfAnyOf:* for squeak compatibility.
Claus Gittinger <cg@exept.de>
parents: 4303
diff changeset
  3621
!
326f43992dcd added #indexOfAnyOf:* for squeak compatibility.
Claus Gittinger <cg@exept.de>
parents: 4303
diff changeset
  3622
368
a3c21a89ec37 *** empty log message ***
claus
parents: 362
diff changeset
  3623
indexOfSubCollection:aCollection
a3c21a89ec37 *** empty log message ***
claus
parents: 362
diff changeset
  3624
    "find a subcollection. 
a3c21a89ec37 *** empty log message ***
claus
parents: 362
diff changeset
  3625
     If found, return the index; if not found, return 0."
a3c21a89ec37 *** empty log message ***
claus
parents: 362
diff changeset
  3626
1145
a094d90e11bf dont use [0] blocks - use 0 constant instead
Claus Gittinger <cg@exept.de>
parents: 1016
diff changeset
  3627
    ^ self indexOfSubCollection:aCollection startingAt:1 ifAbsent:0
368
a3c21a89ec37 *** empty log message ***
claus
parents: 362
diff changeset
  3628
a3c21a89ec37 *** empty log message ***
claus
parents: 362
diff changeset
  3629
    "
a3c21a89ec37 *** empty log message ***
claus
parents: 362
diff changeset
  3630
     #(1 2 3 4 5 6 7) indexOfSubCollection:#()  
a3c21a89ec37 *** empty log message ***
claus
parents: 362
diff changeset
  3631
     #(1 2 3 4 5 6 7) indexOfSubCollection:#(1)      
a3c21a89ec37 *** empty log message ***
claus
parents: 362
diff changeset
  3632
     #(1 2 3 4 5 6 7) indexOfSubCollection:#(1 2 3 4) 
a3c21a89ec37 *** empty log message ***
claus
parents: 362
diff changeset
  3633
     #(1 2 3 4 5 6 7) indexOfSubCollection:#(2 3 5)   
a3c21a89ec37 *** empty log message ***
claus
parents: 362
diff changeset
  3634
     #(1 2 3 2 3 4 5) indexOfSubCollection:#(2 3 4)  
a3c21a89ec37 *** empty log message ***
claus
parents: 362
diff changeset
  3635
     #(1 2 3 4 5 6 7) indexOfSubCollection:#(5 6 7)  
a3c21a89ec37 *** empty log message ***
claus
parents: 362
diff changeset
  3636
     #(1 2 3 4 5 6 7) indexOfSubCollection:#(5 6 8)  
a3c21a89ec37 *** empty log message ***
claus
parents: 362
diff changeset
  3637
     #(1 2 3 4 5 6 7) indexOfSubCollection:#(5 6 7 8)  
a3c21a89ec37 *** empty log message ***
claus
parents: 362
diff changeset
  3638
    "
a3c21a89ec37 *** empty log message ***
claus
parents: 362
diff changeset
  3639
!
a3c21a89ec37 *** empty log message ***
claus
parents: 362
diff changeset
  3640
602
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  3641
indexOfSubCollection:aCollection ifAbsent:exceptionBlock
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  3642
    "find a subcollection. If found, return the index;
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  3643
     if not found, return the result of evaluating exceptionBlock."
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  3644
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  3645
    ^ self indexOfSubCollection:aCollection startingAt:1 ifAbsent:exceptionBlock
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  3646
!
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  3647
368
a3c21a89ec37 *** empty log message ***
claus
parents: 362
diff changeset
  3648
indexOfSubCollection:aCollection startingAt:startIndex
a3c21a89ec37 *** empty log message ***
claus
parents: 362
diff changeset
  3649
    "find a subcollection starting at index. 
a3c21a89ec37 *** empty log message ***
claus
parents: 362
diff changeset
  3650
     If found, return the index; if not found, return 0."
a3c21a89ec37 *** empty log message ***
claus
parents: 362
diff changeset
  3651
1145
a094d90e11bf dont use [0] blocks - use 0 constant instead
Claus Gittinger <cg@exept.de>
parents: 1016
diff changeset
  3652
    ^ self indexOfSubCollection:aCollection startingAt:startIndex ifAbsent:0
368
a3c21a89ec37 *** empty log message ***
claus
parents: 362
diff changeset
  3653
!
a3c21a89ec37 *** empty log message ***
claus
parents: 362
diff changeset
  3654
a3c21a89ec37 *** empty log message ***
claus
parents: 362
diff changeset
  3655
indexOfSubCollection:aCollection startingAt:startIndex ifAbsent:exceptionBlock
a3c21a89ec37 *** empty log message ***
claus
parents: 362
diff changeset
  3656
    "find a subcollection, starting at index. If found, return the index;
a3c21a89ec37 *** empty log message ***
claus
parents: 362
diff changeset
  3657
     if not found, return the result of evaluating exceptionBlock.
a3c21a89ec37 *** empty log message ***
claus
parents: 362
diff changeset
  3658
     This is a q&d hack - not very efficient"
a3c21a89ec37 *** empty log message ***
claus
parents: 362
diff changeset
  3659
a3c21a89ec37 *** empty log message ***
claus
parents: 362
diff changeset
  3660
    |same first 
a3c21a89ec37 *** empty log message ***
claus
parents: 362
diff changeset
  3661
     mySize     "{Class: SmallInteger }"
a3c21a89ec37 *** empty log message ***
claus
parents: 362
diff changeset
  3662
     checkIndex "{Class: SmallInteger }"
a3c21a89ec37 *** empty log message ***
claus
parents: 362
diff changeset
  3663
     cmpIndex   "{Class: SmallInteger }"
a3c21a89ec37 *** empty log message ***
claus
parents: 362
diff changeset
  3664
     sz         "{Class: SmallInteger }"|
a3c21a89ec37 *** empty log message ***
claus
parents: 362
diff changeset
  3665
a3c21a89ec37 *** empty log message ***
claus
parents: 362
diff changeset
  3666
    mySize := self size.
a3c21a89ec37 *** empty log message ***
claus
parents: 362
diff changeset
  3667
    sz := aCollection size.
a3c21a89ec37 *** empty log message ***
claus
parents: 362
diff changeset
  3668
    sz == 0 ifTrue:[^ exceptionBlock value].
a3c21a89ec37 *** empty log message ***
claus
parents: 362
diff changeset
  3669
    first := aCollection at:1.
a3c21a89ec37 *** empty log message ***
claus
parents: 362
diff changeset
  3670
a3c21a89ec37 *** empty log message ***
claus
parents: 362
diff changeset
  3671
    checkIndex := startIndex - 1.    
a3c21a89ec37 *** empty log message ***
claus
parents: 362
diff changeset
  3672
    [true] whileTrue:[
a3c21a89ec37 *** empty log message ***
claus
parents: 362
diff changeset
  3673
	checkIndex := self indexOf:first startingAt:checkIndex+1.
a3c21a89ec37 *** empty log message ***
claus
parents: 362
diff changeset
  3674
	checkIndex == 0 ifTrue:[^ exceptionBlock value].
a3c21a89ec37 *** empty log message ***
claus
parents: 362
diff changeset
  3675
a3c21a89ec37 *** empty log message ***
claus
parents: 362
diff changeset
  3676
	(checkIndex + sz - 1) > mySize ifTrue:[
a3c21a89ec37 *** empty log message ***
claus
parents: 362
diff changeset
  3677
	    ^ 0
a3c21a89ec37 *** empty log message ***
claus
parents: 362
diff changeset
  3678
	].
a3c21a89ec37 *** empty log message ***
claus
parents: 362
diff changeset
  3679
	same := true.
a3c21a89ec37 *** empty log message ***
claus
parents: 362
diff changeset
  3680
	cmpIndex := 1.
a3c21a89ec37 *** empty log message ***
claus
parents: 362
diff changeset
  3681
	[same and:[cmpIndex <= sz]] whileTrue:[
a3c21a89ec37 *** empty log message ***
claus
parents: 362
diff changeset
  3682
	    (self at:checkIndex + cmpIndex - 1) = (aCollection at:cmpIndex) ifFalse:[
a3c21a89ec37 *** empty log message ***
claus
parents: 362
diff changeset
  3683
		same := false
a3c21a89ec37 *** empty log message ***
claus
parents: 362
diff changeset
  3684
	    ] ifTrue:[
a3c21a89ec37 *** empty log message ***
claus
parents: 362
diff changeset
  3685
		cmpIndex := cmpIndex + 1
a3c21a89ec37 *** empty log message ***
claus
parents: 362
diff changeset
  3686
	    ]
a3c21a89ec37 *** empty log message ***
claus
parents: 362
diff changeset
  3687
	].
a3c21a89ec37 *** empty log message ***
claus
parents: 362
diff changeset
  3688
	same ifTrue:[^ checkIndex].
a3c21a89ec37 *** empty log message ***
claus
parents: 362
diff changeset
  3689
    ]    
a3c21a89ec37 *** empty log message ***
claus
parents: 362
diff changeset
  3690
a3c21a89ec37 *** empty log message ***
claus
parents: 362
diff changeset
  3691
    "
a3c21a89ec37 *** empty log message ***
claus
parents: 362
diff changeset
  3692
     #(1 2 3 4 5 6 7) indexOfSubCollection:#()  startingAt:2 
a3c21a89ec37 *** empty log message ***
claus
parents: 362
diff changeset
  3693
     #(1 2 3 4 5 6 7) indexOfSubCollection:#(1) startingAt:2     
a3c21a89ec37 *** empty log message ***
claus
parents: 362
diff changeset
  3694
     #(1 2 1 2 1 2 3) indexOfSubCollection:#(1 2 3) startingAt:2 
a3c21a89ec37 *** empty log message ***
claus
parents: 362
diff changeset
  3695
     #(1 2 1 2 1 2 3) indexOfSubCollection:#(1 2)   startingAt:2  
a3c21a89ec37 *** empty log message ***
claus
parents: 362
diff changeset
  3696
     #(1 2 1 2 1 2 3) indexOfSubCollection:#(1 2)   startingAt:3  
a3c21a89ec37 *** empty log message ***
claus
parents: 362
diff changeset
  3697
     #(1 2 1 2 1 2 3) indexOfSubCollection:#(1 2)   startingAt:4 
a3c21a89ec37 *** empty log message ***
claus
parents: 362
diff changeset
  3698
    "
602
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  3699
!
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  3700
3452
95d66fc71059 added #lastIndexOfSubCollection family of methods.
Claus Gittinger <cg@exept.de>
parents: 3435
diff changeset
  3701
lastIndexOfSubCollection:aCollection
95d66fc71059 added #lastIndexOfSubCollection family of methods.
Claus Gittinger <cg@exept.de>
parents: 3435
diff changeset
  3702
    "find a subcollection from the end. 
95d66fc71059 added #lastIndexOfSubCollection family of methods.
Claus Gittinger <cg@exept.de>
parents: 3435
diff changeset
  3703
     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
  3704
95d66fc71059 added #lastIndexOfSubCollection family of methods.
Claus Gittinger <cg@exept.de>
parents: 3435
diff changeset
  3705
    ^ self lastIndexOfSubCollection:aCollection startingAt:self size ifAbsent:0
95d66fc71059 added #lastIndexOfSubCollection family of methods.
Claus Gittinger <cg@exept.de>
parents: 3435
diff changeset
  3706
95d66fc71059 added #lastIndexOfSubCollection family of methods.
Claus Gittinger <cg@exept.de>
parents: 3435
diff changeset
  3707
    "Created: / 16.5.1998 / 20:08:55 / cg"
95d66fc71059 added #lastIndexOfSubCollection family of methods.
Claus Gittinger <cg@exept.de>
parents: 3435
diff changeset
  3708
    "Modified: / 16.5.1998 / 20:12:37 / cg"
95d66fc71059 added #lastIndexOfSubCollection family of methods.
Claus Gittinger <cg@exept.de>
parents: 3435
diff changeset
  3709
!
95d66fc71059 added #lastIndexOfSubCollection family of methods.
Claus Gittinger <cg@exept.de>
parents: 3435
diff changeset
  3710
95d66fc71059 added #lastIndexOfSubCollection family of methods.
Claus Gittinger <cg@exept.de>
parents: 3435
diff changeset
  3711
lastIndexOfSubCollection:aCollection ifAbsent:exceptionBlock
95d66fc71059 added #lastIndexOfSubCollection family of methods.
Claus Gittinger <cg@exept.de>
parents: 3435
diff changeset
  3712
    "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
  3713
     if not found, return the result of evaluating exceptionBlock."
95d66fc71059 added #lastIndexOfSubCollection family of methods.
Claus Gittinger <cg@exept.de>
parents: 3435
diff changeset
  3714
95d66fc71059 added #lastIndexOfSubCollection family of methods.
Claus Gittinger <cg@exept.de>
parents: 3435
diff changeset
  3715
    ^ self lastIndexOfSubCollection:aCollection startingAt:self size ifAbsent:exceptionBlock
95d66fc71059 added #lastIndexOfSubCollection family of methods.
Claus Gittinger <cg@exept.de>
parents: 3435
diff changeset
  3716
95d66fc71059 added #lastIndexOfSubCollection family of methods.
Claus Gittinger <cg@exept.de>
parents: 3435
diff changeset
  3717
    "Created: / 16.5.1998 / 20:09:08 / cg"
95d66fc71059 added #lastIndexOfSubCollection family of methods.
Claus Gittinger <cg@exept.de>
parents: 3435
diff changeset
  3718
    "Modified: / 16.5.1998 / 20:12:39 / cg"
95d66fc71059 added #lastIndexOfSubCollection family of methods.
Claus Gittinger <cg@exept.de>
parents: 3435
diff changeset
  3719
!
95d66fc71059 added #lastIndexOfSubCollection family of methods.
Claus Gittinger <cg@exept.de>
parents: 3435
diff changeset
  3720
95d66fc71059 added #lastIndexOfSubCollection family of methods.
Claus Gittinger <cg@exept.de>
parents: 3435
diff changeset
  3721
lastIndexOfSubCollection:aCollection startingAt:startIndex
95d66fc71059 added #lastIndexOfSubCollection family of methods.
Claus Gittinger <cg@exept.de>
parents: 3435
diff changeset
  3722
    "find a subcollection from the end starting at index. 
95d66fc71059 added #lastIndexOfSubCollection family of methods.
Claus Gittinger <cg@exept.de>
parents: 3435
diff changeset
  3723
     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
  3724
95d66fc71059 added #lastIndexOfSubCollection family of methods.
Claus Gittinger <cg@exept.de>
parents: 3435
diff changeset
  3725
    ^ self lastIndexOfSubCollection:aCollection startingAt:startIndex ifAbsent:0
95d66fc71059 added #lastIndexOfSubCollection family of methods.
Claus Gittinger <cg@exept.de>
parents: 3435
diff changeset
  3726
95d66fc71059 added #lastIndexOfSubCollection family of methods.
Claus Gittinger <cg@exept.de>
parents: 3435
diff changeset
  3727
    "Created: / 16.5.1998 / 20:09:23 / cg"
95d66fc71059 added #lastIndexOfSubCollection family of methods.
Claus Gittinger <cg@exept.de>
parents: 3435
diff changeset
  3728
!
95d66fc71059 added #lastIndexOfSubCollection family of methods.
Claus Gittinger <cg@exept.de>
parents: 3435
diff changeset
  3729
95d66fc71059 added #lastIndexOfSubCollection family of methods.
Claus Gittinger <cg@exept.de>
parents: 3435
diff changeset
  3730
lastIndexOfSubCollection:aCollection startingAt:startIndex ifAbsent:exceptionBlock
95d66fc71059 added #lastIndexOfSubCollection family of methods.
Claus Gittinger <cg@exept.de>
parents: 3435
diff changeset
  3731
    "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
  3732
     if not found, return the result of evaluating exceptionBlock.
95d66fc71059 added #lastIndexOfSubCollection family of methods.
Claus Gittinger <cg@exept.de>
parents: 3435
diff changeset
  3733
     This is a q&d hack - not very efficient"
95d66fc71059 added #lastIndexOfSubCollection family of methods.
Claus Gittinger <cg@exept.de>
parents: 3435
diff changeset
  3734
95d66fc71059 added #lastIndexOfSubCollection family of methods.
Claus Gittinger <cg@exept.de>
parents: 3435
diff changeset
  3735
    |same last 
95d66fc71059 added #lastIndexOfSubCollection family of methods.
Claus Gittinger <cg@exept.de>
parents: 3435
diff changeset
  3736
     mySize     "{Class: SmallInteger }"
95d66fc71059 added #lastIndexOfSubCollection family of methods.
Claus Gittinger <cg@exept.de>
parents: 3435
diff changeset
  3737
     checkIndex "{Class: SmallInteger }"
95d66fc71059 added #lastIndexOfSubCollection family of methods.
Claus Gittinger <cg@exept.de>
parents: 3435
diff changeset
  3738
     cmpIndex   "{Class: SmallInteger }"
95d66fc71059 added #lastIndexOfSubCollection family of methods.
Claus Gittinger <cg@exept.de>
parents: 3435
diff changeset
  3739
     sz         "{Class: SmallInteger }"|
95d66fc71059 added #lastIndexOfSubCollection family of methods.
Claus Gittinger <cg@exept.de>
parents: 3435
diff changeset
  3740
95d66fc71059 added #lastIndexOfSubCollection family of methods.
Claus Gittinger <cg@exept.de>
parents: 3435
diff changeset
  3741
    mySize := self size.
95d66fc71059 added #lastIndexOfSubCollection family of methods.
Claus Gittinger <cg@exept.de>
parents: 3435
diff changeset
  3742
    sz := aCollection size.
95d66fc71059 added #lastIndexOfSubCollection family of methods.
Claus Gittinger <cg@exept.de>
parents: 3435
diff changeset
  3743
    sz == 0 ifTrue:[^ exceptionBlock value].
95d66fc71059 added #lastIndexOfSubCollection family of methods.
Claus Gittinger <cg@exept.de>
parents: 3435
diff changeset
  3744
    last := aCollection at:sz.
95d66fc71059 added #lastIndexOfSubCollection family of methods.
Claus Gittinger <cg@exept.de>
parents: 3435
diff changeset
  3745
95d66fc71059 added #lastIndexOfSubCollection family of methods.
Claus Gittinger <cg@exept.de>
parents: 3435
diff changeset
  3746
    checkIndex := startIndex + sz.    
95d66fc71059 added #lastIndexOfSubCollection family of methods.
Claus Gittinger <cg@exept.de>
parents: 3435
diff changeset
  3747
    checkIndex >  mySize ifTrue:[
95d66fc71059 added #lastIndexOfSubCollection family of methods.
Claus Gittinger <cg@exept.de>
parents: 3435
diff changeset
  3748
        checkIndex := mySize + 1
95d66fc71059 added #lastIndexOfSubCollection family of methods.
Claus Gittinger <cg@exept.de>
parents: 3435
diff changeset
  3749
    ].
95d66fc71059 added #lastIndexOfSubCollection family of methods.
Claus Gittinger <cg@exept.de>
parents: 3435
diff changeset
  3750
    [true] whileTrue:[
95d66fc71059 added #lastIndexOfSubCollection family of methods.
Claus Gittinger <cg@exept.de>
parents: 3435
diff changeset
  3751
        checkIndex := self lastIndexOf:last startingAt:checkIndex-1.
95d66fc71059 added #lastIndexOfSubCollection family of methods.
Claus Gittinger <cg@exept.de>
parents: 3435
diff changeset
  3752
        checkIndex == 0 ifTrue:[^ exceptionBlock value].
95d66fc71059 added #lastIndexOfSubCollection family of methods.
Claus Gittinger <cg@exept.de>
parents: 3435
diff changeset
  3753
95d66fc71059 added #lastIndexOfSubCollection family of methods.
Claus Gittinger <cg@exept.de>
parents: 3435
diff changeset
  3754
        (checkIndex - sz + 1) < 1 ifTrue:[
95d66fc71059 added #lastIndexOfSubCollection family of methods.
Claus Gittinger <cg@exept.de>
parents: 3435
diff changeset
  3755
            ^ 0
95d66fc71059 added #lastIndexOfSubCollection family of methods.
Claus Gittinger <cg@exept.de>
parents: 3435
diff changeset
  3756
        ].
95d66fc71059 added #lastIndexOfSubCollection family of methods.
Claus Gittinger <cg@exept.de>
parents: 3435
diff changeset
  3757
        same := true.
95d66fc71059 added #lastIndexOfSubCollection family of methods.
Claus Gittinger <cg@exept.de>
parents: 3435
diff changeset
  3758
        cmpIndex := 1.
95d66fc71059 added #lastIndexOfSubCollection family of methods.
Claus Gittinger <cg@exept.de>
parents: 3435
diff changeset
  3759
        [same and:[cmpIndex <= sz]] whileTrue:[
95d66fc71059 added #lastIndexOfSubCollection family of methods.
Claus Gittinger <cg@exept.de>
parents: 3435
diff changeset
  3760
            (self at:checkIndex - sz + cmpIndex) = (aCollection at:cmpIndex) ifFalse:[
95d66fc71059 added #lastIndexOfSubCollection family of methods.
Claus Gittinger <cg@exept.de>
parents: 3435
diff changeset
  3761
                same := false
95d66fc71059 added #lastIndexOfSubCollection family of methods.
Claus Gittinger <cg@exept.de>
parents: 3435
diff changeset
  3762
            ] ifTrue:[
95d66fc71059 added #lastIndexOfSubCollection family of methods.
Claus Gittinger <cg@exept.de>
parents: 3435
diff changeset
  3763
                cmpIndex := cmpIndex + 1
95d66fc71059 added #lastIndexOfSubCollection family of methods.
Claus Gittinger <cg@exept.de>
parents: 3435
diff changeset
  3764
            ]
95d66fc71059 added #lastIndexOfSubCollection family of methods.
Claus Gittinger <cg@exept.de>
parents: 3435
diff changeset
  3765
        ].
95d66fc71059 added #lastIndexOfSubCollection family of methods.
Claus Gittinger <cg@exept.de>
parents: 3435
diff changeset
  3766
        same ifTrue:[^ checkIndex - sz + 1].
95d66fc71059 added #lastIndexOfSubCollection family of methods.
Claus Gittinger <cg@exept.de>
parents: 3435
diff changeset
  3767
    ]    
95d66fc71059 added #lastIndexOfSubCollection family of methods.
Claus Gittinger <cg@exept.de>
parents: 3435
diff changeset
  3768
95d66fc71059 added #lastIndexOfSubCollection family of methods.
Claus Gittinger <cg@exept.de>
parents: 3435
diff changeset
  3769
    "
95d66fc71059 added #lastIndexOfSubCollection family of methods.
Claus Gittinger <cg@exept.de>
parents: 3435
diff changeset
  3770
     #(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
  3771
     #(1 2 3 4 5 6 7) lastIndexOfSubCollection:#(1)  
95d66fc71059 added #lastIndexOfSubCollection family of methods.
Claus Gittinger <cg@exept.de>
parents: 3435
diff changeset
  3772
     #(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
  3773
     #(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
  3774
     #(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
  3775
     #(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
  3776
     #(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
  3777
     #(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
  3778
     #(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
  3779
    "
95d66fc71059 added #lastIndexOfSubCollection family of methods.
Claus Gittinger <cg@exept.de>
parents: 3435
diff changeset
  3780
95d66fc71059 added #lastIndexOfSubCollection family of methods.
Claus Gittinger <cg@exept.de>
parents: 3435
diff changeset
  3781
    "Modified: / 16.5.1998 / 20:21:46 / cg"
3468
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
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  3784
!SequenceableCollection methodsFor:'searching - equality'!
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
includes:anElement
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  3787
    "return true if the collection contains anElement; false otherwise.
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  3788
     Comparison is done using equality compare (i.e. =).
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  3789
     See #includesIdentical: if identity is asked for."
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  3790
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  3791
    ((self indexOf:anElement startingAt:1) == 0) ifTrue:[^ false].
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  3792
    ^ true
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  3793
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
     args:    anElement : <object> 
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  3796
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  3797
     returns: true  - if found
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  3798
              false - if not found
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  3799
    "
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  3800
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  3801
    "
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  3802
     #(10 20 30 40 50 60 70) includes:99      
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  3803
     #(10 20 30 40 50 60 70) includes:40     
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  3804
     #(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
  3805
    "
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  3806
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  3807
    "Modified: / 20.5.1998 / 15:00:23 / cg"
3452
95d66fc71059 added #lastIndexOfSubCollection family of methods.
Claus Gittinger <cg@exept.de>
parents: 3435
diff changeset
  3808
!
95d66fc71059 added #lastIndexOfSubCollection family of methods.
Claus Gittinger <cg@exept.de>
parents: 3435
diff changeset
  3809
3468
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  3810
indexOf:anElement
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  3811
    "search the collection for anElement;
602
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  3812
     if found, return the index otherwise return 0.
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  3813
     The comparison is done using = 
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  3814
     (i.e. equality test - not identity test)."
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  3815
3468
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  3816
    ^ self indexOf:anElement startingAt:1
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
    "
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  3819
     args:    anElement : <object>
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
     returns: elementIndex - if found
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  3822
              0            - if not found
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  3823
    "
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
     #(10 20 30 40 50 60 70) indexOf:40
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  3827
     #(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
  3828
    "
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  3829
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  3830
    "Modified: / 20.5.1998 / 14:59:55 / cg"
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
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  3833
indexOf:anElement ifAbsent:exceptionBlock
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  3834
    "search the collection for anElement;
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  3835
     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
  3836
     exceptionBlock.
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  3837
     The comparison is done using = 
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  3838
     (i.e. equality test - not identity test)."
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  3839
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  3840
    |index|
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  3841
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  3842
    index := self indexOf:anElement startingAt:1.
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  3843
    (index == 0) ifTrue:[^ exceptionBlock value].
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  3844
    ^ index
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
     args:    anElement      : <object>
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  3848
              exceptionBlock : <valueImplementor>
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  3849
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  3850
     returns: elementIndex         - if found
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  3851
              exceptionBlock value - if not found
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  3852
    "
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
     #(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
  3856
     #(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
  3857
     #(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
  3858
    "
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
    "Modified: / 20.5.1998 / 14:57:35 / cg"
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  3861
!
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
indexOf:elementToFind replaceWith:replacement startingAt:start stoppingAt:stop
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  3864
    "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
  3865
     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
  3866
     and return the index.
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  3867
     If not found, return 0."
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
    |idx|
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
    idx := self indexOf:elementToFind startingAt:start.
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  3872
    ((idx > 0) and:[idx <= stop]) ifTrue:[
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  3873
        self at:idx put:replacement.
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  3874
        ^ idx
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
    ^ 0
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
    "
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  3879
     args:    elementToFind : <object> 
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  3880
              replacement   : <integer>
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  3881
              start         : <integer>
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  3882
              stop          : <integer>
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
     returns: elementIndex - if found (and replaced)
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  3885
              0            - if not found
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  3886
    "
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  3887
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  3888
    "
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  3889
     |a|
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
     a := #(10 20 30 40 50 60 70).
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  3892
     (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
  3893
     a printNL.
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  3894
    "
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
    "Modified: / 20.5.1998 / 14:59:30 / cg"
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  3897
!
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
indexOf:anElement startingAt:start
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  3900
    "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
  3901
     if found, return the index otherwise return 0.
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  3902
     The comparison is done using = 
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  3903
     (i.e. equality test - not identity test)."
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  3904
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  3905
    |startIndex "{ Class: SmallInteger }"
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  3906
     stop       "{ Class: SmallInteger }" |
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  3907
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  3908
    startIndex := start.
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  3909
    stop := self size.
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  3910
    startIndex to:stop do:[:index |
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  3911
        anElement = (self at:index) ifTrue:[^ index].
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  3912
    ].
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  3913
    ^ 0
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  3914
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  3915
    "
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  3916
     args:    anElement : <object> 
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  3917
              start     : <integer>
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
     returns: elementIndex - if found
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  3920
              0            - if not found
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  3921
    "
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
     #(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
  3925
     #(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
  3926
    "
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  3927
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  3928
    "Modified: / 20.5.1998 / 14:58:49 / cg"
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
indexOf:anElement startingAt:start endingAt:stop
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  3932
    "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
  3933
     ending at stop.
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  3934
     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
  3935
     The comparison is done using = 
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  3936
     (i.e. equality test - not identity test)."
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  3937
602
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  3938
    |startIndex "{ Class: SmallInteger }"
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  3939
     stopIndex  "{ Class: SmallInteger }" |
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  3940
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  3941
    startIndex := start.
3468
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  3942
    stopIndex := self size min:stop.
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  3943
    startIndex to:stopIndex do:[:index |
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  3944
        anElement = (self at:index) ifTrue:[^ index].
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  3945
    ].
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  3946
    ^ 0
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
    "
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  3949
     args:    anElement      : <object> 
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  3950
              start          : <integer> 
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  3951
              stop           : <integer> 
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  3952
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  3953
     returns: elementIndex         - if found
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  3954
              exceptionBlock value - if not found
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
    "
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  3958
     #(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
  3959
     #(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
  3960
     #(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
  3961
     #(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
  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
    "Created: / 12.4.1996 / 17:37:13 / cg"
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  3965
    "Modified: / 20.5.1998 / 14:58:28 / cg"
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  3966
!
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  3967
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  3968
indexOf:anElement startingAt:start ifAbsent:exceptionBlock
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  3969
    "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
  3970
     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
  3971
     exceptionBlock.
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  3972
     The comparison is done using = 
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  3973
     (i.e. equality test - not identity test)."
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
    |index|
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  3976
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  3977
    index := self indexOf:anElement startingAt:start.
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  3978
    (index == 0) ifTrue:[^ exceptionBlock value].
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  3979
    ^ index
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  3980
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
     args:    anElement      : <object> 
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  3983
              start          : <integer> 
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  3984
              exceptionBlock : <valueImplementor>
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  3985
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  3986
     returns: elementIndex         - if found
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  3987
              exceptionBlock value - if not found
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
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  3990
    "
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  3991
     #(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
  3992
     #(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
  3993
     #(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
  3994
    "
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
    "Modified: / 20.5.1998 / 14:58:05 / cg"
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
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  3999
lastIndexOf:anElement
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  4000
    "search the collection backwards for anElement;
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  4001
     if found, return the index otherwise return 0.
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  4002
     The comparison is done using = 
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  4003
     (i.e. equality test - not identity test)."
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  4004
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  4005
    ^ self lastIndexOf:anElement startingAt:self size 
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  4006
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  4007
    "
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  4008
     args:    anElement      : <object>
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  4009
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  4010
     returns: elementIndex - if found
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  4011
              0            - if not found
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  4012
    "
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  4013
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  4014
    "
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  4015
     #(10 20 30 40 50 60 70) lastIndexOf:40    
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  4016
     #(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
  4017
     #(10 20 30 40 50 60 70) lastIndexOf:35    
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  4018
     #(10 20 30 40 50 60 70) lastIndexOf:10    
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  4019
    "
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  4020
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  4021
    "Modified: / 20.5.1998 / 15:02:10 / cg"
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  4022
!
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  4023
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  4024
lastIndexOf:anElement ifAbsent:exceptionBlock
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  4025
    "search the collection backwards for anElement;
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  4026
     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
  4027
     exceptionBlock.
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  4028
     The comparison is done using = 
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  4029
     (i.e. equality test - not identity test)."
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  4030
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  4031
    |index|
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  4032
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  4033
    index := self lastIndexOf:anElement startingAt:self size.
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  4034
    (index == 0) ifTrue:[^ exceptionBlock value].
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  4035
    ^ index
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  4036
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  4037
    "
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  4038
     #(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
  4039
     #(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
  4040
     #(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
  4041
     #(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
  4042
    "
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  4043
!
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  4044
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  4045
lastIndexOf:anElement startingAt:start
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  4046
    "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
  4047
     if found, return the index otherwise return 0.
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  4048
     The comparison is done using = 
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  4049
     (i.e. equality test - not identity test)."
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  4050
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  4051
    |startIndex "{ Class: SmallInteger }"|
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  4052
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  4053
    startIndex := start.
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  4054
    startIndex to:1 by:-1 do:[:index |
602
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  4055
	anElement = (self at:index) ifTrue:[^ index].
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  4056
    ].
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  4057
    ^ 0
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  4058
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  4059
    "
3468
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  4060
     #(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
  4061
     #(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
  4062
     #(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
  4063
     #(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
  4064
     #(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
  4065
    "
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  4066
!
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  4067
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  4068
lastIndexOf:anElement startingAt:start ifAbsent:exceptionBlock
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  4069
    "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
  4070
     index start; if found, return the index 
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  4071
     otherwise return the value of the exceptionBlock.
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  4072
     The comparison is done using = 
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  4073
     (i.e. equality test - not identity test)."
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  4074
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  4075
    |index|
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  4076
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  4077
    index := self lastIndexOf:anElement startingAt:start.
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  4078
    (index == 0) ifTrue:[^ exceptionBlock value].
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  4079
    ^ index
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  4080
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  4081
    "
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  4082
     #(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
  4083
     #(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
  4084
     #(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
  4085
     #(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
  4086
    "
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  4087
!
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  4088
4788
3dc29c8e6ca8 added #lastIndexOfAny:
Claus Gittinger <cg@exept.de>
parents: 4678
diff changeset
  4089
lastIndexOfAny:aCollection
3dc29c8e6ca8 added #lastIndexOfAny:
Claus Gittinger <cg@exept.de>
parents: 4678
diff changeset
  4090
    "search the collection backwards for any in aCollection;
3dc29c8e6ca8 added #lastIndexOfAny:
Claus Gittinger <cg@exept.de>
parents: 4678
diff changeset
  4091
     if found, return the index, otherwise return 0.
3dc29c8e6ca8 added #lastIndexOfAny:
Claus Gittinger <cg@exept.de>
parents: 4678
diff changeset
  4092
     The comparison is done using = 
3dc29c8e6ca8 added #lastIndexOfAny:
Claus Gittinger <cg@exept.de>
parents: 4678
diff changeset
  4093
     (i.e. equality test - not identity test)."
3dc29c8e6ca8 added #lastIndexOfAny:
Claus Gittinger <cg@exept.de>
parents: 4678
diff changeset
  4094
3dc29c8e6ca8 added #lastIndexOfAny:
Claus Gittinger <cg@exept.de>
parents: 4678
diff changeset
  4095
    ^ self lastIndexOfAny:aCollection startingAt:self size 
3dc29c8e6ca8 added #lastIndexOfAny:
Claus Gittinger <cg@exept.de>
parents: 4678
diff changeset
  4096
3dc29c8e6ca8 added #lastIndexOfAny:
Claus Gittinger <cg@exept.de>
parents: 4678
diff changeset
  4097
    "
3dc29c8e6ca8 added #lastIndexOfAny:
Claus Gittinger <cg@exept.de>
parents: 4678
diff changeset
  4098
     args:    aCollection    : <collection>
3dc29c8e6ca8 added #lastIndexOfAny:
Claus Gittinger <cg@exept.de>
parents: 4678
diff changeset
  4099
3dc29c8e6ca8 added #lastIndexOfAny:
Claus Gittinger <cg@exept.de>
parents: 4678
diff changeset
  4100
     returns: elementIndex - if found
3dc29c8e6ca8 added #lastIndexOfAny:
Claus Gittinger <cg@exept.de>
parents: 4678
diff changeset
  4101
              0            - if not found
3dc29c8e6ca8 added #lastIndexOfAny:
Claus Gittinger <cg@exept.de>
parents: 4678
diff changeset
  4102
    "
3dc29c8e6ca8 added #lastIndexOfAny:
Claus Gittinger <cg@exept.de>
parents: 4678
diff changeset
  4103
3dc29c8e6ca8 added #lastIndexOfAny:
Claus Gittinger <cg@exept.de>
parents: 4678
diff changeset
  4104
    "
3dc29c8e6ca8 added #lastIndexOfAny:
Claus Gittinger <cg@exept.de>
parents: 4678
diff changeset
  4105
     #(10 20 30 40 50 60 70) lastIndexOfAny:#(40 60)   
3dc29c8e6ca8 added #lastIndexOfAny:
Claus Gittinger <cg@exept.de>
parents: 4678
diff changeset
  4106
     #(10 20 30 40 50 60 70) lastIndexOfAny:#(40.0 60)
3dc29c8e6ca8 added #lastIndexOfAny:
Claus Gittinger <cg@exept.de>
parents: 4678
diff changeset
  4107
     #(10 20 30 40 50 60 70) lastIndexOfAny:#(35 40)    
3dc29c8e6ca8 added #lastIndexOfAny:
Claus Gittinger <cg@exept.de>
parents: 4678
diff changeset
  4108
     #(10 20 30 40 50 60 70) lastIndexOfAny:#(15 35)    
3dc29c8e6ca8 added #lastIndexOfAny:
Claus Gittinger <cg@exept.de>
parents: 4678
diff changeset
  4109
    "
3dc29c8e6ca8 added #lastIndexOfAny:
Claus Gittinger <cg@exept.de>
parents: 4678
diff changeset
  4110
3dc29c8e6ca8 added #lastIndexOfAny:
Claus Gittinger <cg@exept.de>
parents: 4678
diff changeset
  4111
    "Modified: / 20.5.1998 / 15:02:10 / cg"
3dc29c8e6ca8 added #lastIndexOfAny:
Claus Gittinger <cg@exept.de>
parents: 4678
diff changeset
  4112
!
3dc29c8e6ca8 added #lastIndexOfAny:
Claus Gittinger <cg@exept.de>
parents: 4678
diff changeset
  4113
3dc29c8e6ca8 added #lastIndexOfAny:
Claus Gittinger <cg@exept.de>
parents: 4678
diff changeset
  4114
lastIndexOfAny:aCollection startingAt:start
3dc29c8e6ca8 added #lastIndexOfAny:
Claus Gittinger <cg@exept.de>
parents: 4678
diff changeset
  4115
    "search the collection backwards for any in aCollection, starting the search at index start;
3dc29c8e6ca8 added #lastIndexOfAny:
Claus Gittinger <cg@exept.de>
parents: 4678
diff changeset
  4116
     if found, return the index, otherwise return 0.
3dc29c8e6ca8 added #lastIndexOfAny:
Claus Gittinger <cg@exept.de>
parents: 4678
diff changeset
  4117
     The comparison is done using = 
3dc29c8e6ca8 added #lastIndexOfAny:
Claus Gittinger <cg@exept.de>
parents: 4678
diff changeset
  4118
     (i.e. equality test - not identity test)."
3dc29c8e6ca8 added #lastIndexOfAny:
Claus Gittinger <cg@exept.de>
parents: 4678
diff changeset
  4119
3dc29c8e6ca8 added #lastIndexOfAny:
Claus Gittinger <cg@exept.de>
parents: 4678
diff changeset
  4120
    |startIndex "{ Class: SmallInteger }"|
3dc29c8e6ca8 added #lastIndexOfAny:
Claus Gittinger <cg@exept.de>
parents: 4678
diff changeset
  4121
3dc29c8e6ca8 added #lastIndexOfAny:
Claus Gittinger <cg@exept.de>
parents: 4678
diff changeset
  4122
    startIndex := start.
3dc29c8e6ca8 added #lastIndexOfAny:
Claus Gittinger <cg@exept.de>
parents: 4678
diff changeset
  4123
    startIndex to:1 by:-1 do:[:index |
3dc29c8e6ca8 added #lastIndexOfAny:
Claus Gittinger <cg@exept.de>
parents: 4678
diff changeset
  4124
        (aCollection includes:(self at:index)) ifTrue:[^ index].
3dc29c8e6ca8 added #lastIndexOfAny:
Claus Gittinger <cg@exept.de>
parents: 4678
diff changeset
  4125
    ].
3dc29c8e6ca8 added #lastIndexOfAny:
Claus Gittinger <cg@exept.de>
parents: 4678
diff changeset
  4126
    ^ 0
3dc29c8e6ca8 added #lastIndexOfAny:
Claus Gittinger <cg@exept.de>
parents: 4678
diff changeset
  4127
3dc29c8e6ca8 added #lastIndexOfAny:
Claus Gittinger <cg@exept.de>
parents: 4678
diff changeset
  4128
    "
3dc29c8e6ca8 added #lastIndexOfAny:
Claus Gittinger <cg@exept.de>
parents: 4678
diff changeset
  4129
     #(10 20 30 40 10 20 30 40) lastIndexOfAny:#(40 60)   startingAt:8  
3dc29c8e6ca8 added #lastIndexOfAny:
Claus Gittinger <cg@exept.de>
parents: 4678
diff changeset
  4130
     #(10 20 30 40 10 20 30 40) lastIndexOfAny:#(40 60)   startingAt:7  
3dc29c8e6ca8 added #lastIndexOfAny:
Claus Gittinger <cg@exept.de>
parents: 4678
diff changeset
  4131
    "
3dc29c8e6ca8 added #lastIndexOfAny:
Claus Gittinger <cg@exept.de>
parents: 4678
diff changeset
  4132
!
3dc29c8e6ca8 added #lastIndexOfAny:
Claus Gittinger <cg@exept.de>
parents: 4678
diff changeset
  4133
3468
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  4134
nextIndexOf:anElement from:start to:stop
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  4135
    "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
  4136
     stopping at:stop;
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  4137
     if found, return the index otherwise return nil.
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  4138
     The comparison is done using = 
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  4139
     (i.e. equality test - not identity test).
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  4140
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  4141
     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
  4142
             although this is somewhat strange (the indexOf-search
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  4143
             methods return 0), this is done for VW compatibility."
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  4144
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  4145
    |startIndex "{ Class: SmallInteger }"
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  4146
     stopIndex  "{ Class: SmallInteger }" |
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  4147
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  4148
    startIndex := start.
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  4149
    stopIndex :=  stop.
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  4150
    startIndex to:stop do:[:index |
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  4151
        anElement = (self at:index) ifTrue:[^ index].
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  4152
    ].
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  4153
    ^ nil
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  4154
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  4155
    "
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  4156
     args:    anElement : <object>
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  4157
              start     : <integer>
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  4158
              stop      : <integer>
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  4159
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  4160
     returns: elementIndex - if found
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  4161
              nil          - if not found
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  4162
    "
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  4163
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  4164
    "
602
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  4165
     #(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
  4166
     #(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
  4167
     #(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
  4168
    "
3468
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  4169
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  4170
    "Modified: / 20.5.1998 / 15:11:32 / cg"
602
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  4171
!
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  4172
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  4173
nextIndexOf:anElement from:start to:stop ifAbsent:exceptionBlock
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  4174
    "search the collection for anElement, starting the search at index start
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  4175
     and stopping at stop;
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  4176
     if found, return the index otherwise return the value of the
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  4177
     exceptionBlock.
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  4178
     The comparison is done using = 
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  4179
     (i.e. equality test - not identity test)."
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  4180
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  4181
    |index|
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  4182
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  4183
    index := self nextIndexOf:anElement from:start to:stop.
3468
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  4184
    index isNil ifTrue:[^ exceptionBlock value].
602
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  4185
    ^ index
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  4186
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  4187
    "
3468
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  4188
     args:    anElement      : <object>
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  4189
              start          : <integer>
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  4190
              stop           : <integer>
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  4191
              exceptionBlock : <valueImplementor>
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  4192
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  4193
     returns: elementIndex           - if found
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  4194
              valueImplementor value - if not found
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  4195
    "
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  4196
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  4197
    "
602
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  4198
     #(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
  4199
     #(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
  4200
     #(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
  4201
    "
3468
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  4202
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  4203
    "Modified: / 20.5.1998 / 15:12:36 / cg"
2275
882e11d07295 added prevIndexOf:from:to:
Claus Gittinger <cg@exept.de>
parents: 2165
diff changeset
  4204
!
882e11d07295 added prevIndexOf:from:to:
Claus Gittinger <cg@exept.de>
parents: 2165
diff changeset
  4205
882e11d07295 added prevIndexOf:from:to:
Claus Gittinger <cg@exept.de>
parents: 2165
diff changeset
  4206
prevIndexOf:anElement from:startSearchIndex to:endSearchIndex
882e11d07295 added prevIndexOf:from:to:
Claus Gittinger <cg@exept.de>
parents: 2165
diff changeset
  4207
    "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
  4208
     ending at stop, going in reverse direction.
3468
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  4209
     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
  4210
     The comparison is done using = 
3468
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  4211
     (i.e. equality test - not identity test).
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  4212
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  4213
     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
  4214
             although this is somewhat strange (the indexOf-search
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  4215
             methods return 0), this is done for VW compatibility."
2275
882e11d07295 added prevIndexOf:from:to:
Claus Gittinger <cg@exept.de>
parents: 2165
diff changeset
  4216
882e11d07295 added prevIndexOf:from:to:
Claus Gittinger <cg@exept.de>
parents: 2165
diff changeset
  4217
    |startIndex "{ Class: SmallInteger }"
882e11d07295 added prevIndexOf:from:to:
Claus Gittinger <cg@exept.de>
parents: 2165
diff changeset
  4218
     stopIndex  "{ Class: SmallInteger }" |
882e11d07295 added prevIndexOf:from:to:
Claus Gittinger <cg@exept.de>
parents: 2165
diff changeset
  4219
882e11d07295 added prevIndexOf:from:to:
Claus Gittinger <cg@exept.de>
parents: 2165
diff changeset
  4220
    startIndex := startSearchIndex.
882e11d07295 added prevIndexOf:from:to:
Claus Gittinger <cg@exept.de>
parents: 2165
diff changeset
  4221
    stopIndex := endSearchIndex max:1.
882e11d07295 added prevIndexOf:from:to:
Claus Gittinger <cg@exept.de>
parents: 2165
diff changeset
  4222
    startIndex to:stopIndex by:-1 do:[:index |
882e11d07295 added prevIndexOf:from:to:
Claus Gittinger <cg@exept.de>
parents: 2165
diff changeset
  4223
        anElement = (self at:index) ifTrue:[^ index].
882e11d07295 added prevIndexOf:from:to:
Claus Gittinger <cg@exept.de>
parents: 2165
diff changeset
  4224
    ].
3468
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  4225
    ^ nil
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  4226
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  4227
    "
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  4228
     args:    anElement : <object>
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  4229
              start     : <integer>
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  4230
              stop      : <integer>
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  4231
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  4232
     returns: elementIndex - if found
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  4233
              nil          - if not found
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  4234
    "
2275
882e11d07295 added prevIndexOf:from:to:
Claus Gittinger <cg@exept.de>
parents: 2165
diff changeset
  4235
882e11d07295 added prevIndexOf:from:to:
Claus Gittinger <cg@exept.de>
parents: 2165
diff changeset
  4236
    "
882e11d07295 added prevIndexOf:from:to:
Claus Gittinger <cg@exept.de>
parents: 2165
diff changeset
  4237
     #(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
  4238
     #(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
  4239
     #(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
  4240
    "
882e11d07295 added prevIndexOf:from:to:
Claus Gittinger <cg@exept.de>
parents: 2165
diff changeset
  4241
3468
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  4242
    "Modified: / 20.5.1998 / 15:13:27 / cg"
2275
882e11d07295 added prevIndexOf:from:to:
Claus Gittinger <cg@exept.de>
parents: 2165
diff changeset
  4243
!
882e11d07295 added prevIndexOf:from:to:
Claus Gittinger <cg@exept.de>
parents: 2165
diff changeset
  4244
882e11d07295 added prevIndexOf:from:to:
Claus Gittinger <cg@exept.de>
parents: 2165
diff changeset
  4245
prevIndexOf:anElement from:start to:stop ifAbsent:exceptionBlock
882e11d07295 added prevIndexOf:from:to:
Claus Gittinger <cg@exept.de>
parents: 2165
diff changeset
  4246
    "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
  4247
     and stopping at stop, doing a reverse search;
882e11d07295 added prevIndexOf:from:to:
Claus Gittinger <cg@exept.de>
parents: 2165
diff changeset
  4248
     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
  4249
     exceptionBlock.
882e11d07295 added prevIndexOf:from:to:
Claus Gittinger <cg@exept.de>
parents: 2165
diff changeset
  4250
     The comparison is done using = 
882e11d07295 added prevIndexOf:from:to:
Claus Gittinger <cg@exept.de>
parents: 2165
diff changeset
  4251
     (i.e. equality test - not identity test)."
882e11d07295 added prevIndexOf:from:to:
Claus Gittinger <cg@exept.de>
parents: 2165
diff changeset
  4252
882e11d07295 added prevIndexOf:from:to:
Claus Gittinger <cg@exept.de>
parents: 2165
diff changeset
  4253
    |index|
882e11d07295 added prevIndexOf:from:to:
Claus Gittinger <cg@exept.de>
parents: 2165
diff changeset
  4254
882e11d07295 added prevIndexOf:from:to:
Claus Gittinger <cg@exept.de>
parents: 2165
diff changeset
  4255
    index := self prevIndexOf:anElement from:start to:stop.
882e11d07295 added prevIndexOf:from:to:
Claus Gittinger <cg@exept.de>
parents: 2165
diff changeset
  4256
    (index == 0) ifTrue:[^ exceptionBlock value].
882e11d07295 added prevIndexOf:from:to:
Claus Gittinger <cg@exept.de>
parents: 2165
diff changeset
  4257
    ^ index
882e11d07295 added prevIndexOf:from:to:
Claus Gittinger <cg@exept.de>
parents: 2165
diff changeset
  4258
882e11d07295 added prevIndexOf:from:to:
Claus Gittinger <cg@exept.de>
parents: 2165
diff changeset
  4259
    "
3468
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  4260
     args:    anElement      : <object>
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  4261
              start          : <integer>
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  4262
              stop           : <integer>
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  4263
              exceptionBlock : <valueImplementor>
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  4264
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  4265
     returns: elementIndex           - if found
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  4266
              valueImplementor value - if not found
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  4267
    "
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  4268
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  4269
    "
2275
882e11d07295 added prevIndexOf:from:to:
Claus Gittinger <cg@exept.de>
parents: 2165
diff changeset
  4270
     #(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
  4271
     #(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
  4272
     #(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
  4273
    "
882e11d07295 added prevIndexOf:from:to:
Claus Gittinger <cg@exept.de>
parents: 2165
diff changeset
  4274
3468
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  4275
    "Modified: / 20.5.1998 / 15:13:05 / cg"
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  4276
! !
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  4277
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  4278
!SequenceableCollection methodsFor:'searching - identity'!
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  4279
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  4280
identityIndexOf:anElement
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  4281
    "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
  4282
     if found, return the index otherwise return 0."
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  4283
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  4284
    ^ self identityIndexOf:anElement startingAt:1
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  4285
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  4286
    "
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  4287
     args:    anElement : <object>
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  4288
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  4289
     returns: elementIndex - if found
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  4290
              0            - if not found
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  4291
    "
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  4292
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  4293
    "
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  4294
     #(10 20 30 40 50 60 70) identityIndexOf:40
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  4295
     #(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
  4296
     #(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
  4297
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  4298
    be careful:
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  4299
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  4300
     #(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
  4301
     #(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
  4302
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  4303
    "
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  4304
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  4305
    "Modified: / 20.5.1998 / 14:57:14 / cg"
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  4306
!
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  4307
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  4308
identityIndexOf:anElement ifAbsent:exceptionBlock
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  4309
    "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
  4310
     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
  4311
     exceptionBlock."
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  4312
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  4313
    |index|
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  4314
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  4315
    index := self identityIndexOf:anElement startingAt:1.
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  4316
    (index == 0) ifTrue:[^ exceptionBlock value].
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  4317
    ^ index
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  4318
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  4319
    "
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  4320
     args:    anElement      : <object>
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  4321
              exceptionBlock : <valueImplementor>
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  4322
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  4323
     returns: elementIndex         - if found
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  4324
              exceptionBlock value - if not found
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  4325
    "
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  4326
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  4327
    "
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  4328
     #(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
  4329
     #(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
  4330
     #(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
  4331
     #(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
  4332
    "
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  4333
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  4334
    "Modified: / 20.5.1998 / 14:57:31 / cg"
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  4335
!
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  4336
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  4337
identityIndexOf:anElement startingAt:start
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  4338
    "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
  4339
     using identity compare  (i.e. ==);
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  4340
     if found, return the index otherwise return 0."
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  4341
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  4342
    |startIndex "{ Class: SmallInteger }"
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  4343
     stop       "{ Class: SmallInteger }" |
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  4344
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  4345
    startIndex := start.
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  4346
    stop := self size.
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  4347
    startIndex to:stop do:[:index |
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  4348
        anElement == (self at:index) ifTrue:[^ index].
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  4349
    ].
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  4350
    ^ 0
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  4351
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  4352
    "
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  4353
     args:    anElement : <object>
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  4354
              start     : <integer>
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  4355
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  4356
     returns: elementIndex - if found
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  4357
              0            - if not found
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  4358
    "
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  4359
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  4360
    "
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  4361
     #(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
  4362
     #(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
  4363
     #(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
  4364
    "
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  4365
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  4366
    "Modified: / 20.5.1998 / 14:57:09 / cg"
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  4367
!
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  4368
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  4369
identityIndexOf:anElement startingAt:start endingAt:stop
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  4370
    "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
  4371
     ending at stop.
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  4372
     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
  4373
     The comparison is done using = 
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  4374
     (i.e. equality test - not identity test)."
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  4375
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  4376
    |startIndex "{ Class: SmallInteger }"
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  4377
     stopIndex  "{ Class: SmallInteger }" |
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  4378
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  4379
    startIndex := start.
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  4380
    stopIndex := self size min:stop.
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  4381
    startIndex to:stopIndex do:[:index |
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  4382
        anElement == (self at:index) ifTrue:[^ index].
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  4383
    ].
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  4384
    ^ 0
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  4385
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  4386
    "
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  4387
     args:    anElement : <object>
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  4388
              start     : <integer>
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  4389
              stop      : <integer>
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  4390
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  4391
     returns: elementIndex - if found
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  4392
              0            - if not found
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  4393
    "
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  4394
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  4395
    "Created: / 12.4.1996 / 18:23:07 / cg"
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  4396
    "Modified: / 20.5.1998 / 15:00:50 / cg"
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  4397
!
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  4398
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  4399
identityIndexOf:anElement startingAt:start ifAbsent:exceptionBlock
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  4400
    "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
  4401
     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
  4402
     exceptionBlock.
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  4403
     This one searches for identical objects (i.e. ==)."
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  4404
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  4405
    |index|
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  4406
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  4407
    index := self identityIndexOf:anElement startingAt:start.
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  4408
    (index == 0) ifTrue:[^ exceptionBlock value].
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  4409
    ^ index
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  4410
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  4411
    "
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  4412
     args:    anElement      : <object>
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  4413
              start          : <integer>
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  4414
              exceptionBlock : <valueImplementor>
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  4415
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  4416
     returns: elementIndex         - if found
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  4417
              exceptionBlock value - if not found
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  4418
    "
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  4419
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  4420
    "
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  4421
     #(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
  4422
     #(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
  4423
    "
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  4424
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  4425
    "Modified: / 20.5.1998 / 15:01:23 / cg"
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  4426
!
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  4427
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  4428
includesIdentical:anElement
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  4429
    "return true if the collection contains anElement; false otherwise.
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  4430
     Comparison is done using identity compare (i.e. ==).
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  4431
     See #includes: if equality is asked for."
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  4432
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  4433
    ((self identityIndexOf:anElement startingAt:1) == 0) ifTrue:[^ false].
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  4434
    ^ true
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  4435
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  4436
    "
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  4437
     args:    anElement : <object> 
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  4438
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  4439
     returns: true  - if found
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  4440
              false - if not found
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  4441
    "
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  4442
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  4443
    "
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  4444
     #(10 20 30 40 50 60 70) includesIdentical:40     
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  4445
     #(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
  4446
     #(10 20 30 40 50 60 70) includes:40     
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  4447
     #(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
  4448
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  4449
     be careful:
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  4450
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  4451
     #(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
  4452
     #(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
  4453
    "
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  4454
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  4455
    "Modified: / 20.5.1998 / 15:00:16 / cg"
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  4456
!
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  4457
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  4458
lastIdentityIndexOf:anElement
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  4459
    "search the collection backwards for anElement;
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  4460
     if found, return the index otherwise return 0.
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  4461
     The comparison is done using == 
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  4462
     (i.e. identity test - not equality test)."
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  4463
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  4464
    ^ self lastIdentityIndexOf:anElement startingAt:self size 
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  4465
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  4466
    "
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  4467
     args:    anElement      : <object>
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  4468
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  4469
     returns: elementIndex - if found
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  4470
              0            - if not found
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  4471
    "
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  4472
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  4473
    "
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  4474
     #(10 20 30 40 50 60 70) lastIdentityIndexOf:40    
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  4475
     #(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
  4476
     #(10 20 30 40 50 60 70) lastIdentityIndexOf:35    
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  4477
     #(10 20 30 40 50 60 70) lastIdentityIndexOf:10    
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  4478
    "
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  4479
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  4480
    "Created: / 20.5.1998 / 15:03:06 / cg"
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  4481
!
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  4482
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  4483
lastIdentityIndexOf:anElement ifAbsent:exceptionBlock
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  4484
    "search the collection backwards for anElement;
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  4485
     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
  4486
     exceptionBlock.
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  4487
     The comparison is done using == 
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  4488
     (i.e. identity test - not equality test)."
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  4489
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  4490
    |index|
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  4491
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  4492
    index := self lastIdentityIndexOf:anElement startingAt:self size.
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  4493
    (index == 0) ifTrue:[^ exceptionBlock value].
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  4494
    ^ index
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  4495
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  4496
    "
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  4497
     args:    anElement      : <object>
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  4498
              exceptionBlock : <valueImplementor>
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  4499
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  4500
     returns: elementIndex         - if found
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  4501
              exceptionBlock value - if not found
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  4502
    "
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  4503
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  4504
    "
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  4505
     #(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
  4506
     #(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
  4507
     #(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
  4508
     #(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
  4509
    "
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  4510
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  4511
    "Created: / 20.5.1998 / 15:04:46 / cg"
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  4512
    "Modified: / 20.5.1998 / 15:05:53 / cg"
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  4513
!
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  4514
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  4515
lastIdentityIndexOf:anElement startingAt:start
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  4516
    "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
  4517
     if found, return the index otherwise return 0.
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  4518
     The comparison is done using == 
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  4519
     (i.e. identity test - not equality test)."
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  4520
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  4521
    |startIndex "{ Class: SmallInteger }"|
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  4522
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  4523
    startIndex := start.
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  4524
    startIndex to:1 by:-1 do:[:index |
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  4525
        anElement == (self at:index) ifTrue:[^ index].
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  4526
    ].
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  4527
    ^ 0
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  4528
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  4529
    "
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  4530
     args:    anElement      : <object>
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  4531
              start          : <integer>
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  4532
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  4533
     returns: elementIndex - if found
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  4534
              0            - if not found
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  4535
    "
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  4536
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  4537
    "
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  4538
     #(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
  4539
     #(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
  4540
     #(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
  4541
     #(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
  4542
     #(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
  4543
    "
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  4544
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  4545
    "Modified: / 20.5.1998 / 15:06:04 / cg"
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  4546
!
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  4547
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  4548
lastIdentityIndexOf:anElement startingAt:start ifAbsent:exceptionBlock
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  4549
    "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
  4550
     index start; if found, return the index 
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  4551
     otherwise return the value of the exceptionBlock.
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  4552
     The comparison is done using == 
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  4553
     (i.e. identity test - not equality test)."
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  4554
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  4555
    |index|
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  4556
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  4557
    index := self lastIdentityIndexOf:anElement startingAt:start.
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  4558
    (index == 0) ifTrue:[^ exceptionBlock value].
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  4559
    ^ index
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  4560
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  4561
    "
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  4562
     args:    anElement      : <object>
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  4563
              start          : <integer>
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  4564
              exceptionBlock : <valueImplementor>
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  4565
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  4566
     returns: elementIndex         - if found
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  4567
              exceptionBlock value - if not found
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  4568
    "
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  4569
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  4570
    "
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  4571
     #(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
  4572
     #(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
  4573
     #(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
  4574
     #(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
  4575
    "
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  4576
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  4577
    "Modified: / 20.5.1998 / 15:06:21 / cg"
f91f61ea3b5c changed returnValue of nextIndexOf: / prevIndexOf
Claus Gittinger <cg@exept.de>
parents: 3452
diff changeset
  4578
    "Created: / 20.5.1998 / 15:07:42 / cg"
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  4579
! !
a27a279701f8 Initial revision
claus
parents:
diff changeset
  4580
a27a279701f8 Initial revision
claus
parents:
diff changeset
  4581
!SequenceableCollection methodsFor:'sorting & reordering'!
a27a279701f8 Initial revision
claus
parents:
diff changeset
  4582
5358
79b21b5a4783 added #isSorted;
Claus Gittinger <cg@exept.de>
parents: 5320
diff changeset
  4583
mergeSort
79b21b5a4783 added #isSorted;
Claus Gittinger <cg@exept.de>
parents: 5320
diff changeset
  4584
    "sort the collection using a mergeSort algorithm. 
79b21b5a4783 added #isSorted;
Claus Gittinger <cg@exept.de>
parents: 5320
diff changeset
  4585
     The elements are compared using'<' 
79b21b5a4783 added #isSorted;
Claus Gittinger <cg@exept.de>
parents: 5320
diff changeset
  4586
     i.e. they should offer a magnitude-like protocol.
79b21b5a4783 added #isSorted;
Claus Gittinger <cg@exept.de>
parents: 5320
diff changeset
  4587
79b21b5a4783 added #isSorted;
Claus Gittinger <cg@exept.de>
parents: 5320
diff changeset
  4588
     The implementation uses the mergesort algorithm, which may not be
79b21b5a4783 added #isSorted;
Claus Gittinger <cg@exept.de>
parents: 5320
diff changeset
  4589
     the best possible for all situations 
79b21b5a4783 added #isSorted;
Claus Gittinger <cg@exept.de>
parents: 5320
diff changeset
  4590
     See also #quickSort and #randomizedSort for other sort algorithms
79b21b5a4783 added #isSorted;
Claus Gittinger <cg@exept.de>
parents: 5320
diff changeset
  4591
     with different worst- and average case behavior)"
79b21b5a4783 added #isSorted;
Claus Gittinger <cg@exept.de>
parents: 5320
diff changeset
  4592
79b21b5a4783 added #isSorted;
Claus Gittinger <cg@exept.de>
parents: 5320
diff changeset
  4593
    |stop|
79b21b5a4783 added #isSorted;
Claus Gittinger <cg@exept.de>
parents: 5320
diff changeset
  4594
79b21b5a4783 added #isSorted;
Claus Gittinger <cg@exept.de>
parents: 5320
diff changeset
  4595
    stop := self size.
79b21b5a4783 added #isSorted;
Claus Gittinger <cg@exept.de>
parents: 5320
diff changeset
  4596
    (stop > 1) ifTrue:[
79b21b5a4783 added #isSorted;
Claus Gittinger <cg@exept.de>
parents: 5320
diff changeset
  4597
        self mergeSortFrom:1 to:stop by:[:a :b | a < b ]
79b21b5a4783 added #isSorted;
Claus Gittinger <cg@exept.de>
parents: 5320
diff changeset
  4598
    ]
79b21b5a4783 added #isSorted;
Claus Gittinger <cg@exept.de>
parents: 5320
diff changeset
  4599
79b21b5a4783 added #isSorted;
Claus Gittinger <cg@exept.de>
parents: 5320
diff changeset
  4600
    "
79b21b5a4783 added #isSorted;
Claus Gittinger <cg@exept.de>
parents: 5320
diff changeset
  4601
     #(1 16 7 98 3 19 4 0) mergeSort
79b21b5a4783 added #isSorted;
Claus Gittinger <cg@exept.de>
parents: 5320
diff changeset
  4602
79b21b5a4783 added #isSorted;
Claus Gittinger <cg@exept.de>
parents: 5320
diff changeset
  4603
     |data|
79b21b5a4783 added #isSorted;
Claus Gittinger <cg@exept.de>
parents: 5320
diff changeset
  4604
     data := Random new next:100000.
79b21b5a4783 added #isSorted;
Claus Gittinger <cg@exept.de>
parents: 5320
diff changeset
  4605
     'merge random  ' print. (Time millisecondsToRun:[data mergeSort]) printNL.
79b21b5a4783 added #isSorted;
Claus Gittinger <cg@exept.de>
parents: 5320
diff changeset
  4606
     'merge sorted  ' print. (Time millisecondsToRun:[data mergeSort]) printNL.
79b21b5a4783 added #isSorted;
Claus Gittinger <cg@exept.de>
parents: 5320
diff changeset
  4607
     data reverse. 
79b21b5a4783 added #isSorted;
Claus Gittinger <cg@exept.de>
parents: 5320
diff changeset
  4608
     'merge reverse ' print. (Time millisecondsToRun:[data mergeSort]) printNL.
79b21b5a4783 added #isSorted;
Claus Gittinger <cg@exept.de>
parents: 5320
diff changeset
  4609
79b21b5a4783 added #isSorted;
Claus Gittinger <cg@exept.de>
parents: 5320
diff changeset
  4610
     data := Random new next:100000.
79b21b5a4783 added #isSorted;
Claus Gittinger <cg@exept.de>
parents: 5320
diff changeset
  4611
     'quick random  ' print. (Time millisecondsToRun:[data sort]) printNL.
79b21b5a4783 added #isSorted;
Claus Gittinger <cg@exept.de>
parents: 5320
diff changeset
  4612
     'quick sorted  ' print. (Time millisecondsToRun:[data sort]) printNL.
79b21b5a4783 added #isSorted;
Claus Gittinger <cg@exept.de>
parents: 5320
diff changeset
  4613
     data reverse. 
79b21b5a4783 added #isSorted;
Claus Gittinger <cg@exept.de>
parents: 5320
diff changeset
  4614
     'quick reverse ' print. (Time millisecondsToRun:[data sort]) printNL.
79b21b5a4783 added #isSorted;
Claus Gittinger <cg@exept.de>
parents: 5320
diff changeset
  4615
79b21b5a4783 added #isSorted;
Claus Gittinger <cg@exept.de>
parents: 5320
diff changeset
  4616
     data := Random new next:100000.
79b21b5a4783 added #isSorted;
Claus Gittinger <cg@exept.de>
parents: 5320
diff changeset
  4617
     'quickr random  ' print. (Time millisecondsToRun:[data randomizedSort]) printNL.
79b21b5a4783 added #isSorted;
Claus Gittinger <cg@exept.de>
parents: 5320
diff changeset
  4618
     'quickr sorted  ' print. (Time millisecondsToRun:[data randomizedSort]) printNL.
79b21b5a4783 added #isSorted;
Claus Gittinger <cg@exept.de>
parents: 5320
diff changeset
  4619
     data reverse. 
79b21b5a4783 added #isSorted;
Claus Gittinger <cg@exept.de>
parents: 5320
diff changeset
  4620
     'quickr reverse ' print. (Time millisecondsToRun:[data randomizedSort]) printNL.
79b21b5a4783 added #isSorted;
Claus Gittinger <cg@exept.de>
parents: 5320
diff changeset
  4621
    "
79b21b5a4783 added #isSorted;
Claus Gittinger <cg@exept.de>
parents: 5320
diff changeset
  4622
79b21b5a4783 added #isSorted;
Claus Gittinger <cg@exept.de>
parents: 5320
diff changeset
  4623
!
79b21b5a4783 added #isSorted;
Claus Gittinger <cg@exept.de>
parents: 5320
diff changeset
  4624
79b21b5a4783 added #isSorted;
Claus Gittinger <cg@exept.de>
parents: 5320
diff changeset
  4625
mergeSortFrom: startIndex to: stopIndex by: aBlock
79b21b5a4783 added #isSorted;
Claus Gittinger <cg@exept.de>
parents: 5320
diff changeset
  4626
    "Sort the given range of indices using the mergesort algorithm. 
79b21b5a4783 added #isSorted;
Claus Gittinger <cg@exept.de>
parents: 5320
diff changeset
  4627
     Mergesort is a worst-case O(N log N) sorting algorithm that usually does only half 
79b21b5a4783 added #isSorted;
Claus Gittinger <cg@exept.de>
parents: 5320
diff changeset
  4628
     as many comparisons as heapsort or quicksort."
79b21b5a4783 added #isSorted;
Claus Gittinger <cg@exept.de>
parents: 5320
diff changeset
  4629
79b21b5a4783 added #isSorted;
Claus Gittinger <cg@exept.de>
parents: 5320
diff changeset
  4630
    "Details: recursively split the range to be sorted into two halves, 
79b21b5a4783 added #isSorted;
Claus Gittinger <cg@exept.de>
parents: 5320
diff changeset
  4631
     mergesort each half, then merge the two halves together. 
79b21b5a4783 added #isSorted;
Claus Gittinger <cg@exept.de>
parents: 5320
diff changeset
  4632
     An extra copy of the data is used as temporary storage and successive merge phases copy data back 
79b21b5a4783 added #isSorted;
Claus Gittinger <cg@exept.de>
parents: 5320
diff changeset
  4633
     and forth between the receiver and this copy. 
79b21b5a4783 added #isSorted;
Claus Gittinger <cg@exept.de>
parents: 5320
diff changeset
  4634
     The recursion is set up so that the final merge is performed into the receiver, 
79b21b5a4783 added #isSorted;
Claus Gittinger <cg@exept.de>
parents: 5320
diff changeset
  4635
     resulting in the receiver being completely sorted."
79b21b5a4783 added #isSorted;
Claus Gittinger <cg@exept.de>
parents: 5320
diff changeset
  4636
79b21b5a4783 added #isSorted;
Claus Gittinger <cg@exept.de>
parents: 5320
diff changeset
  4637
    | temp |
79b21b5a4783 added #isSorted;
Claus Gittinger <cg@exept.de>
parents: 5320
diff changeset
  4638
79b21b5a4783 added #isSorted;
Claus Gittinger <cg@exept.de>
parents: 5320
diff changeset
  4639
    self size <= 1 ifTrue: [^ self].  "nothing to do"
79b21b5a4783 added #isSorted;
Claus Gittinger <cg@exept.de>
parents: 5320
diff changeset
  4640
    startIndex = stopIndex ifTrue: [^ self].
79b21b5a4783 added #isSorted;
Claus Gittinger <cg@exept.de>
parents: 5320
diff changeset
  4641
    (startIndex >= 1 and: [startIndex < stopIndex])
79b21b5a4783 added #isSorted;
Claus Gittinger <cg@exept.de>
parents: 5320
diff changeset
  4642
            ifFalse: [self error: 'bad start index'].
79b21b5a4783 added #isSorted;
Claus Gittinger <cg@exept.de>
parents: 5320
diff changeset
  4643
    stopIndex <= self size
79b21b5a4783 added #isSorted;
Claus Gittinger <cg@exept.de>
parents: 5320
diff changeset
  4644
            ifFalse: [self error: 'bad stop index'].
79b21b5a4783 added #isSorted;
Claus Gittinger <cg@exept.de>
parents: 5320
diff changeset
  4645
    temp := self clone.
79b21b5a4783 added #isSorted;
Claus Gittinger <cg@exept.de>
parents: 5320
diff changeset
  4646
    self mergeSortFrom: startIndex to: stopIndex src: temp dst: self by: aBlock.
79b21b5a4783 added #isSorted;
Claus Gittinger <cg@exept.de>
parents: 5320
diff changeset
  4647
79b21b5a4783 added #isSorted;
Claus Gittinger <cg@exept.de>
parents: 5320
diff changeset
  4648
    "
79b21b5a4783 added #isSorted;
Claus Gittinger <cg@exept.de>
parents: 5320
diff changeset
  4649
     #(1 16 7 98 3 19 4 0) mergeSort
79b21b5a4783 added #isSorted;
Claus Gittinger <cg@exept.de>
parents: 5320
diff changeset
  4650
79b21b5a4783 added #isSorted;
Claus Gittinger <cg@exept.de>
parents: 5320
diff changeset
  4651
     |data|
79b21b5a4783 added #isSorted;
Claus Gittinger <cg@exept.de>
parents: 5320
diff changeset
  4652
     data := Random new next:100000.
79b21b5a4783 added #isSorted;
Claus Gittinger <cg@exept.de>
parents: 5320
diff changeset
  4653
     'random  ' print. (Time millisecondsToRun:[data mergeSort]) printNL.
79b21b5a4783 added #isSorted;
Claus Gittinger <cg@exept.de>
parents: 5320
diff changeset
  4654
     'sorted  ' print. (Time millisecondsToRun:[data mergeSort]) printNL.
79b21b5a4783 added #isSorted;
Claus Gittinger <cg@exept.de>
parents: 5320
diff changeset
  4655
     data reverse. 
79b21b5a4783 added #isSorted;
Claus Gittinger <cg@exept.de>
parents: 5320
diff changeset
  4656
     'reverse ' print. (Time millisecondsToRun:[data mergeSort]) printNL.
79b21b5a4783 added #isSorted;
Claus Gittinger <cg@exept.de>
parents: 5320
diff changeset
  4657
    "
79b21b5a4783 added #isSorted;
Claus Gittinger <cg@exept.de>
parents: 5320
diff changeset
  4658
79b21b5a4783 added #isSorted;
Claus Gittinger <cg@exept.de>
parents: 5320
diff changeset
  4659
!
79b21b5a4783 added #isSorted;
Claus Gittinger <cg@exept.de>
parents: 5320
diff changeset
  4660
2881
452f9154d0dc comments; added #randomizedQuickSort.
Claus Gittinger <cg@exept.de>
parents: 2860
diff changeset
  4661
randomizedSort
452f9154d0dc comments; added #randomizedQuickSort.
Claus Gittinger <cg@exept.de>
parents: 2860
diff changeset
  4662
    "sort the collection inplace. The elements are compared using
452f9154d0dc comments; added #randomizedQuickSort.
Claus Gittinger <cg@exept.de>
parents: 2860
diff changeset
  4663
     '<' i.e. they should offer a magnitude-like protocol.
452f9154d0dc comments; added #randomizedQuickSort.
Claus Gittinger <cg@exept.de>
parents: 2860
diff changeset
  4664
452f9154d0dc comments; added #randomizedQuickSort.
Claus Gittinger <cg@exept.de>
parents: 2860
diff changeset
  4665
     This uses the randomized quicksort algorithm, 
452f9154d0dc comments; added #randomizedQuickSort.
Claus Gittinger <cg@exept.de>
parents: 2860
diff changeset
  4666
     which has a better worstCase behavior than quickSort
452f9154d0dc comments; added #randomizedQuickSort.
Claus Gittinger <cg@exept.de>
parents: 2860
diff changeset
  4667
     (bit worse bestCase & averageCase behavior).
452f9154d0dc comments; added #randomizedQuickSort.
Claus Gittinger <cg@exept.de>
parents: 2860
diff changeset
  4668
     See: Knuth or Cormen,Leiserson,Rivest pg. 163"
452f9154d0dc comments; added #randomizedQuickSort.
Claus Gittinger <cg@exept.de>
parents: 2860
diff changeset
  4669
452f9154d0dc comments; added #randomizedQuickSort.
Claus Gittinger <cg@exept.de>
parents: 2860
diff changeset
  4670
    |stop|
452f9154d0dc comments; added #randomizedQuickSort.
Claus Gittinger <cg@exept.de>
parents: 2860
diff changeset
  4671
452f9154d0dc comments; added #randomizedQuickSort.
Claus Gittinger <cg@exept.de>
parents: 2860
diff changeset
  4672
    stop := self size.
452f9154d0dc comments; added #randomizedQuickSort.
Claus Gittinger <cg@exept.de>
parents: 2860
diff changeset
  4673
    (stop > 1) ifTrue:[
452f9154d0dc comments; added #randomizedQuickSort.
Claus Gittinger <cg@exept.de>
parents: 2860
diff changeset
  4674
        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
  4675
    ]
452f9154d0dc comments; added #randomizedQuickSort.
Claus Gittinger <cg@exept.de>
parents: 2860
diff changeset
  4676
452f9154d0dc comments; added #randomizedQuickSort.
Claus Gittinger <cg@exept.de>
parents: 2860
diff changeset
  4677
    "Modified: 21.8.1997 / 18:31:21 / cg"
452f9154d0dc comments; added #randomizedQuickSort.
Claus Gittinger <cg@exept.de>
parents: 2860
diff changeset
  4678
!
452f9154d0dc comments; added #randomizedQuickSort.
Claus Gittinger <cg@exept.de>
parents: 2860
diff changeset
  4679
452f9154d0dc comments; added #randomizedQuickSort.
Claus Gittinger <cg@exept.de>
parents: 2860
diff changeset
  4680
randomizedSort:sortBlock
452f9154d0dc comments; added #randomizedQuickSort.
Claus Gittinger <cg@exept.de>
parents: 2860
diff changeset
  4681
    "sort the collection inplace using the 2-arg block sortBlock
452f9154d0dc comments; added #randomizedQuickSort.
Claus Gittinger <cg@exept.de>
parents: 2860
diff changeset
  4682
     for comparison. This allows any sort criteria to be implemented.
452f9154d0dc comments; added #randomizedQuickSort.
Claus Gittinger <cg@exept.de>
parents: 2860
diff changeset
  4683
452f9154d0dc comments; added #randomizedQuickSort.
Claus Gittinger <cg@exept.de>
parents: 2860
diff changeset
  4684
     This uses the randomized quicksort algorithm, 
452f9154d0dc comments; added #randomizedQuickSort.
Claus Gittinger <cg@exept.de>
parents: 2860
diff changeset
  4685
     which has a better worstCase behavior than quickSort
452f9154d0dc comments; added #randomizedQuickSort.
Claus Gittinger <cg@exept.de>
parents: 2860
diff changeset
  4686
     (bit worse bestCase & averageCase behavior).
452f9154d0dc comments; added #randomizedQuickSort.
Claus Gittinger <cg@exept.de>
parents: 2860
diff changeset
  4687
     See: Knuth or Cormen,Leiserson,Rivest pg. 163"
452f9154d0dc comments; added #randomizedQuickSort.
Claus Gittinger <cg@exept.de>
parents: 2860
diff changeset
  4688
452f9154d0dc comments; added #randomizedQuickSort.
Claus Gittinger <cg@exept.de>
parents: 2860
diff changeset
  4689
    |stop|
452f9154d0dc comments; added #randomizedQuickSort.
Claus Gittinger <cg@exept.de>
parents: 2860
diff changeset
  4690
452f9154d0dc comments; added #randomizedQuickSort.
Claus Gittinger <cg@exept.de>
parents: 2860
diff changeset
  4691
    stop := self size.
452f9154d0dc comments; added #randomizedQuickSort.
Claus Gittinger <cg@exept.de>
parents: 2860
diff changeset
  4692
    (stop > 1) ifTrue:[
452f9154d0dc comments; added #randomizedQuickSort.
Claus Gittinger <cg@exept.de>
parents: 2860
diff changeset
  4693
        self randomizedQuickSortFrom:1 to:stop sortBlock:sortBlock with:nil
452f9154d0dc comments; added #randomizedQuickSort.
Claus Gittinger <cg@exept.de>
parents: 2860
diff changeset
  4694
    ]
452f9154d0dc comments; added #randomizedQuickSort.
Claus Gittinger <cg@exept.de>
parents: 2860
diff changeset
  4695
452f9154d0dc comments; added #randomizedQuickSort.
Claus Gittinger <cg@exept.de>
parents: 2860
diff changeset
  4696
    "Created: 21.8.1997 / 18:16:50 / cg"
452f9154d0dc comments; added #randomizedQuickSort.
Claus Gittinger <cg@exept.de>
parents: 2860
diff changeset
  4697
    "Modified: 21.8.1997 / 18:31:24 / cg"
452f9154d0dc comments; added #randomizedQuickSort.
Claus Gittinger <cg@exept.de>
parents: 2860
diff changeset
  4698
!
452f9154d0dc comments; added #randomizedQuickSort.
Claus Gittinger <cg@exept.de>
parents: 2860
diff changeset
  4699
452f9154d0dc comments; added #randomizedQuickSort.
Claus Gittinger <cg@exept.de>
parents: 2860
diff changeset
  4700
randomizedSort:sortBlock with:aCollection
452f9154d0dc comments; added #randomizedQuickSort.
Claus Gittinger <cg@exept.de>
parents: 2860
diff changeset
  4701
    "sort the collection inplace using the 2-arg block sortBlock
452f9154d0dc comments; added #randomizedQuickSort.
Claus Gittinger <cg@exept.de>
parents: 2860
diff changeset
  4702
     for comparison. Also reorder the elements in aCollection.
452f9154d0dc comments; added #randomizedQuickSort.
Claus Gittinger <cg@exept.de>
parents: 2860
diff changeset
  4703
     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
  4704
452f9154d0dc comments; added #randomizedQuickSort.
Claus Gittinger <cg@exept.de>
parents: 2860
diff changeset
  4705
     This uses the randomized quicksort algorithm, 
452f9154d0dc comments; added #randomizedQuickSort.
Claus Gittinger <cg@exept.de>
parents: 2860
diff changeset
  4706
     which has a better worstCase behavior than quickSort
452f9154d0dc comments; added #randomizedQuickSort.
Claus Gittinger <cg@exept.de>
parents: 2860
diff changeset
  4707
     (bit worse bestCase & averageCase behavior).
452f9154d0dc comments; added #randomizedQuickSort.
Claus Gittinger <cg@exept.de>
parents: 2860
diff changeset
  4708
     See: Knuth or Cormen,Leiserson,Rivest pg. 163"
452f9154d0dc comments; added #randomizedQuickSort.
Claus Gittinger <cg@exept.de>
parents: 2860
diff changeset
  4709
452f9154d0dc comments; added #randomizedQuickSort.
Claus Gittinger <cg@exept.de>
parents: 2860
diff changeset
  4710
    |stop|
452f9154d0dc comments; added #randomizedQuickSort.
Claus Gittinger <cg@exept.de>
parents: 2860
diff changeset
  4711
452f9154d0dc comments; added #randomizedQuickSort.
Claus Gittinger <cg@exept.de>
parents: 2860
diff changeset
  4712
    stop := self size.
452f9154d0dc comments; added #randomizedQuickSort.
Claus Gittinger <cg@exept.de>
parents: 2860
diff changeset
  4713
    (stop > 1) ifTrue:[
452f9154d0dc comments; added #randomizedQuickSort.
Claus Gittinger <cg@exept.de>
parents: 2860
diff changeset
  4714
        self randomizedQuickSortFrom:1 to:stop sortBlock:sortBlock with:aCollection
452f9154d0dc comments; added #randomizedQuickSort.
Claus Gittinger <cg@exept.de>
parents: 2860
diff changeset
  4715
    ]
452f9154d0dc comments; added #randomizedQuickSort.
Claus Gittinger <cg@exept.de>
parents: 2860
diff changeset
  4716
452f9154d0dc comments; added #randomizedQuickSort.
Claus Gittinger <cg@exept.de>
parents: 2860
diff changeset
  4717
    "Created: 21.8.1997 / 18:20:53 / cg"
452f9154d0dc comments; added #randomizedQuickSort.
Claus Gittinger <cg@exept.de>
parents: 2860
diff changeset
  4718
    "Modified: 21.8.1997 / 18:31:27 / cg"
452f9154d0dc comments; added #randomizedQuickSort.
Claus Gittinger <cg@exept.de>
parents: 2860
diff changeset
  4719
!
452f9154d0dc comments; added #randomizedQuickSort.
Claus Gittinger <cg@exept.de>
parents: 2860
diff changeset
  4720
452f9154d0dc comments; added #randomizedQuickSort.
Claus Gittinger <cg@exept.de>
parents: 2860
diff changeset
  4721
randomizedSortWith:aCollection
452f9154d0dc comments; added #randomizedQuickSort.
Claus Gittinger <cg@exept.de>
parents: 2860
diff changeset
  4722
    "sort the receiver collection inplace, using '<' to compare elements.
452f9154d0dc comments; added #randomizedQuickSort.
Claus Gittinger <cg@exept.de>
parents: 2860
diff changeset
  4723
     Also, the elements of aCollection are reordered with it.
452f9154d0dc comments; added #randomizedQuickSort.
Claus Gittinger <cg@exept.de>
parents: 2860
diff changeset
  4724
     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
  4725
452f9154d0dc comments; added #randomizedQuickSort.
Claus Gittinger <cg@exept.de>
parents: 2860
diff changeset
  4726
     This uses the randomized quicksort algorithm, 
452f9154d0dc comments; added #randomizedQuickSort.
Claus Gittinger <cg@exept.de>
parents: 2860
diff changeset
  4727
     which has a better worstCase behavior than quickSort
452f9154d0dc comments; added #randomizedQuickSort.
Claus Gittinger <cg@exept.de>
parents: 2860
diff changeset
  4728
     (bit worse bestCase & averageCase behavior).
452f9154d0dc comments; added #randomizedQuickSort.
Claus Gittinger <cg@exept.de>
parents: 2860
diff changeset
  4729
     See: Knuth or Cormen,Leiserson,Rivest pg. 163"
452f9154d0dc comments; added #randomizedQuickSort.
Claus Gittinger <cg@exept.de>
parents: 2860
diff changeset
  4730
452f9154d0dc comments; added #randomizedQuickSort.
Claus Gittinger <cg@exept.de>
parents: 2860
diff changeset
  4731
    |stop|
452f9154d0dc comments; added #randomizedQuickSort.
Claus Gittinger <cg@exept.de>
parents: 2860
diff changeset
  4732
452f9154d0dc comments; added #randomizedQuickSort.
Claus Gittinger <cg@exept.de>
parents: 2860
diff changeset
  4733
    stop := self size.
452f9154d0dc comments; added #randomizedQuickSort.
Claus Gittinger <cg@exept.de>
parents: 2860
diff changeset
  4734
    (stop > 1) ifTrue:[
452f9154d0dc comments; added #randomizedQuickSort.
Claus Gittinger <cg@exept.de>
parents: 2860
diff changeset
  4735
        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
  4736
    ]
452f9154d0dc comments; added #randomizedQuickSort.
Claus Gittinger <cg@exept.de>
parents: 2860
diff changeset
  4737
452f9154d0dc comments; added #randomizedQuickSort.
Claus Gittinger <cg@exept.de>
parents: 2860
diff changeset
  4738
    "Created: 21.8.1997 / 18:22:25 / cg"
452f9154d0dc comments; added #randomizedQuickSort.
Claus Gittinger <cg@exept.de>
parents: 2860
diff changeset
  4739
    "Modified: 21.8.1997 / 18:31:31 / cg"
452f9154d0dc comments; added #randomizedQuickSort.
Claus Gittinger <cg@exept.de>
parents: 2860
diff changeset
  4740
!
452f9154d0dc comments; added #randomizedQuickSort.
Claus Gittinger <cg@exept.de>
parents: 2860
diff changeset
  4741
602
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  4742
reverse
2610
a2ed6babbb0f comment
Claus Gittinger <cg@exept.de>
parents: 2417
diff changeset
  4743
    "destructively reverse the order of the elements inplace"
602
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  4744
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  4745
    |lowIndex "{ Class: SmallInteger }"
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  4746
     hiIndex  "{ Class: SmallInteger }"
929
674de4c05dcb added findFirst:startingAt: and findLast:startingAt:
Claus Gittinger <cg@exept.de>
parents: 911
diff changeset
  4747
     t1 t2|
602
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  4748
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  4749
    hiIndex := self size.
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  4750
    lowIndex := 1.
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  4751
    [lowIndex < hiIndex] whileTrue:[
1495
f0226967f2a2 added a Class: Smallinteger hint
Claus Gittinger <cg@exept.de>
parents: 1422
diff changeset
  4752
	t1 := self at:lowIndex.  t2 := self at:hiIndex.
f0226967f2a2 added a Class: Smallinteger hint
Claus Gittinger <cg@exept.de>
parents: 1422
diff changeset
  4753
	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
  4754
602
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  4755
	lowIndex := lowIndex + 1.
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  4756
	hiIndex := hiIndex - 1
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  4757
    ]
1495
f0226967f2a2 added a Class: Smallinteger hint
Claus Gittinger <cg@exept.de>
parents: 1422
diff changeset
  4758
69
4564b6328136 *** empty log message ***
claus
parents: 61
diff changeset
  4759
    "
602
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  4760
     #(4 5 6 7 7) reverse
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  4761
     #(1 4 7 10 2 5) asOrderedCollection reverse
69
4564b6328136 *** empty log message ***
claus
parents: 61
diff changeset
  4762
    "
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  4763
!
a27a279701f8 Initial revision
claus
parents:
diff changeset
  4764
5004
73e1c3d1fd7a checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4986
diff changeset
  4765
reversed
73e1c3d1fd7a checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4986
diff changeset
  4766
    "return a copy with elements in reverse order"
73e1c3d1fd7a checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4986
diff changeset
  4767
73e1c3d1fd7a checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4986
diff changeset
  4768
    ^ self copy reverse
73e1c3d1fd7a checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4986
diff changeset
  4769
73e1c3d1fd7a checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4986
diff changeset
  4770
    "
73e1c3d1fd7a checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4986
diff changeset
  4771
     #(4 5 6 7 7) reversed           
73e1c3d1fd7a checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4986
diff changeset
  4772
     #(1 4 7 10 2 5) asOrderedCollection reversed
73e1c3d1fd7a checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4986
diff changeset
  4773
    "
73e1c3d1fd7a checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4986
diff changeset
  4774
!
73e1c3d1fd7a checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4986
diff changeset
  4775
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  4776
sort
a27a279701f8 Initial revision
claus
parents:
diff changeset
  4777
    "sort the collection inplace. The elements are compared using
2069
f6183117f922 comments
Claus Gittinger <cg@exept.de>
parents: 1673
diff changeset
  4778
     '<' i.e. they should offer a magnitude-like protocol.
2881
452f9154d0dc comments; added #randomizedQuickSort.
Claus Gittinger <cg@exept.de>
parents: 2860
diff changeset
  4779
159
514c749165c3 *** empty log message ***
claus
parents: 118
diff changeset
  4780
     The implementation uses the quicksort algorithm, which may not be
2881
452f9154d0dc comments; added #randomizedQuickSort.
Claus Gittinger <cg@exept.de>
parents: 2860
diff changeset
  4781
     the best possible for all situations (quickSort has O-square worst
452f9154d0dc comments; added #randomizedQuickSort.
Claus Gittinger <cg@exept.de>
parents: 2860
diff changeset
  4782
     case behavior). See also #randomizedSort for a version with better
452f9154d0dc comments; added #randomizedQuickSort.
Claus Gittinger <cg@exept.de>
parents: 2860
diff changeset
  4783
     worstCase behavior (but worse average & bestCase behavior)"
13
62303f84ff5f *** empty log message ***
claus
parents: 5
diff changeset
  4784
32
ee1a621c696c *** empty log message ***
claus
parents: 13
diff changeset
  4785
    |stop|
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  4786
32
ee1a621c696c *** empty log message ***
claus
parents: 13
diff changeset
  4787
    stop := self size.
ee1a621c696c *** empty log message ***
claus
parents: 13
diff changeset
  4788
    (stop > 1) ifTrue:[
2069
f6183117f922 comments
Claus Gittinger <cg@exept.de>
parents: 1673
diff changeset
  4789
        self quickSortFrom:1 to:stop
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  4790
    ]
a27a279701f8 Initial revision
claus
parents:
diff changeset
  4791
95
d22739a0c6e9 *** empty log message ***
claus
parents: 88
diff changeset
  4792
    "
d22739a0c6e9 *** empty log message ***
claus
parents: 88
diff changeset
  4793
     #(1 16 7 98 3 19 4 0) sort
d22739a0c6e9 *** empty log message ***
claus
parents: 88
diff changeset
  4794
d22739a0c6e9 *** empty log message ***
claus
parents: 88
diff changeset
  4795
     |data|
d22739a0c6e9 *** empty log message ***
claus
parents: 88
diff changeset
  4796
     data := Random new next:100000.
d22739a0c6e9 *** empty log message ***
claus
parents: 88
diff changeset
  4797
     'random  ' print. (Time millisecondsToRun:[data sort]) printNL.
d22739a0c6e9 *** empty log message ***
claus
parents: 88
diff changeset
  4798
     'sorted  ' print. (Time millisecondsToRun:[data sort]) printNL.
d22739a0c6e9 *** empty log message ***
claus
parents: 88
diff changeset
  4799
     data reverse. 
d22739a0c6e9 *** empty log message ***
claus
parents: 88
diff changeset
  4800
     'reverse ' print. (Time millisecondsToRun:[data sort]) printNL.
d22739a0c6e9 *** empty log message ***
claus
parents: 88
diff changeset
  4801
    "
2069
f6183117f922 comments
Claus Gittinger <cg@exept.de>
parents: 1673
diff changeset
  4802
2881
452f9154d0dc comments; added #randomizedQuickSort.
Claus Gittinger <cg@exept.de>
parents: 2860
diff changeset
  4803
    "Modified: 21.8.1997 / 18:31:52 / cg"
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  4804
!
a27a279701f8 Initial revision
claus
parents:
diff changeset
  4805
a27a279701f8 Initial revision
claus
parents:
diff changeset
  4806
sort:sortBlock
a27a279701f8 Initial revision
claus
parents:
diff changeset
  4807
    "sort the collection inplace using the 2-arg block sortBlock
2881
452f9154d0dc comments; added #randomizedQuickSort.
Claus Gittinger <cg@exept.de>
parents: 2860
diff changeset
  4808
     for comparison. This allows any sort criteria to be implemented.
452f9154d0dc comments; added #randomizedQuickSort.
Claus Gittinger <cg@exept.de>
parents: 2860
diff changeset
  4809
452f9154d0dc comments; added #randomizedQuickSort.
Claus Gittinger <cg@exept.de>
parents: 2860
diff changeset
  4810
     The implementation uses the quicksort algorithm, which may not be
452f9154d0dc comments; added #randomizedQuickSort.
Claus Gittinger <cg@exept.de>
parents: 2860
diff changeset
  4811
     the best possible for all situations (quickSort has O-square worst
452f9154d0dc comments; added #randomizedQuickSort.
Claus Gittinger <cg@exept.de>
parents: 2860
diff changeset
  4812
     case behavior). See also #randomizedSort: for a version with better
452f9154d0dc comments; added #randomizedQuickSort.
Claus Gittinger <cg@exept.de>
parents: 2860
diff changeset
  4813
     worstCase behavior (but worse average & bestCase behavior)"
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  4814
32
ee1a621c696c *** empty log message ***
claus
parents: 13
diff changeset
  4815
    |stop|
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  4816
32
ee1a621c696c *** empty log message ***
claus
parents: 13
diff changeset
  4817
    stop := self size.
ee1a621c696c *** empty log message ***
claus
parents: 13
diff changeset
  4818
    (stop > 1) ifTrue:[
3055
0832fba4c740 support 3-arg sort, passing a collationPolicy
Claus Gittinger <cg@exept.de>
parents: 3044
diff changeset
  4819
        sortBlock numArgs == 3 ifTrue:[
0832fba4c740 support 3-arg sort, passing a collationPolicy
Claus Gittinger <cg@exept.de>
parents: 3044
diff changeset
  4820
            "/ TODO: pass a collating policy to aBlock
0832fba4c740 support 3-arg sort, passing a collationPolicy
Claus Gittinger <cg@exept.de>
parents: 3044
diff changeset
  4821
            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
  4822
        ] ifFalse:[
0832fba4c740 support 3-arg sort, passing a collationPolicy
Claus Gittinger <cg@exept.de>
parents: 3044
diff changeset
  4823
            self quickSortFrom:1 to:stop sortBlock:sortBlock
0832fba4c740 support 3-arg sort, passing a collationPolicy
Claus Gittinger <cg@exept.de>
parents: 3044
diff changeset
  4824
        ]
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  4825
    ]
a27a279701f8 Initial revision
claus
parents:
diff changeset
  4826
95
d22739a0c6e9 *** empty log message ***
claus
parents: 88
diff changeset
  4827
    "
2069
f6183117f922 comments
Claus Gittinger <cg@exept.de>
parents: 1673
diff changeset
  4828
     #(1 16 7 98 3 19 4 0) sort:[:a :b | a < b] 
f6183117f922 comments
Claus Gittinger <cg@exept.de>
parents: 1673
diff changeset
  4829
     #(1 16 7 98 3 19 4 0) sort:[:a :b | a > b] 
f6183117f922 comments
Claus Gittinger <cg@exept.de>
parents: 1673
diff changeset
  4830
     #(1 -1 16 -16 7 -7 98 -98) sort:[:a :b | a < b] 
f6183117f922 comments
Claus Gittinger <cg@exept.de>
parents: 1673
diff changeset
  4831
     #(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
  4832
    "
2069
f6183117f922 comments
Claus Gittinger <cg@exept.de>
parents: 1673
diff changeset
  4833
3055
0832fba4c740 support 3-arg sort, passing a collationPolicy
Claus Gittinger <cg@exept.de>
parents: 3044
diff changeset
  4834
    "Modified: / 27.10.1997 / 20:03:22 / cg"
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  4835
!
a27a279701f8 Initial revision
claus
parents:
diff changeset
  4836
a27a279701f8 Initial revision
claus
parents:
diff changeset
  4837
sort:sortBlock with:aCollection
a27a279701f8 Initial revision
claus
parents:
diff changeset
  4838
    "sort the collection inplace using the 2-arg block sortBlock
159
514c749165c3 *** empty log message ***
claus
parents: 118
diff changeset
  4839
     for comparison. Also reorder the elements in aCollection.
2881
452f9154d0dc comments; added #randomizedQuickSort.
Claus Gittinger <cg@exept.de>
parents: 2860
diff changeset
  4840
     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
  4841
452f9154d0dc comments; added #randomizedQuickSort.
Claus Gittinger <cg@exept.de>
parents: 2860
diff changeset
  4842
     The implementation uses the quicksort algorithm, which may not be
452f9154d0dc comments; added #randomizedQuickSort.
Claus Gittinger <cg@exept.de>
parents: 2860
diff changeset
  4843
     the best possible for all situations (quickSort has O-square worst
452f9154d0dc comments; added #randomizedQuickSort.
Claus Gittinger <cg@exept.de>
parents: 2860
diff changeset
  4844
     case behavior). See also #randomizedSort: for a version with better
452f9154d0dc comments; added #randomizedQuickSort.
Claus Gittinger <cg@exept.de>
parents: 2860
diff changeset
  4845
     worstCase behavior (but worse average & bestCase behavior)"
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  4846
32
ee1a621c696c *** empty log message ***
claus
parents: 13
diff changeset
  4847
    |stop|
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  4848
32
ee1a621c696c *** empty log message ***
claus
parents: 13
diff changeset
  4849
    stop := self size.
ee1a621c696c *** empty log message ***
claus
parents: 13
diff changeset
  4850
    (stop > 1) ifTrue:[
2069
f6183117f922 comments
Claus Gittinger <cg@exept.de>
parents: 1673
diff changeset
  4851
        self quickSortFrom:1 to:stop sortBlock:sortBlock with:aCollection
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  4852
    ]
a27a279701f8 Initial revision
claus
parents:
diff changeset
  4853
69
4564b6328136 *** empty log message ***
claus
parents: 61
diff changeset
  4854
    "
4564b6328136 *** empty log message ***
claus
parents: 61
diff changeset
  4855
     |c1 c2|
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  4856
     c1 := #(1 16 7 9).
a27a279701f8 Initial revision
claus
parents:
diff changeset
  4857
     c2 := #('one' 'sixteen' 'seven' 'nine').
a27a279701f8 Initial revision
claus
parents:
diff changeset
  4858
     c1 sort:[:a :b | a > b] with:c2.
95
d22739a0c6e9 *** empty log message ***
claus
parents: 88
diff changeset
  4859
     c1 printNL.
d22739a0c6e9 *** empty log message ***
claus
parents: 88
diff changeset
  4860
     c2 printNL
69
4564b6328136 *** empty log message ***
claus
parents: 61
diff changeset
  4861
    "
2069
f6183117f922 comments
Claus Gittinger <cg@exept.de>
parents: 1673
diff changeset
  4862
2881
452f9154d0dc comments; added #randomizedQuickSort.
Claus Gittinger <cg@exept.de>
parents: 2860
diff changeset
  4863
    "Modified: 21.8.1997 / 18:32:11 / cg"
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  4864
!
a27a279701f8 Initial revision
claus
parents:
diff changeset
  4865
602
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  4866
sortWith:aCollection
2069
f6183117f922 comments
Claus Gittinger <cg@exept.de>
parents: 1673
diff changeset
  4867
    "sort the receiver collection inplace, using '<' to compare elements.
f6183117f922 comments
Claus Gittinger <cg@exept.de>
parents: 1673
diff changeset
  4868
     Also, the elements of aCollection are reordered with it.
2881
452f9154d0dc comments; added #randomizedQuickSort.
Claus Gittinger <cg@exept.de>
parents: 2860
diff changeset
  4869
     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
  4870
452f9154d0dc comments; added #randomizedQuickSort.
Claus Gittinger <cg@exept.de>
parents: 2860
diff changeset
  4871
     The implementation uses the quicksort algorithm, which may not be
452f9154d0dc comments; added #randomizedQuickSort.
Claus Gittinger <cg@exept.de>
parents: 2860
diff changeset
  4872
     the best possible for all situations (quickSort has O-square worst
452f9154d0dc comments; added #randomizedQuickSort.
Claus Gittinger <cg@exept.de>
parents: 2860
diff changeset
  4873
     case behavior). See also #randomizedSort: for a version with better
452f9154d0dc comments; added #randomizedQuickSort.
Claus Gittinger <cg@exept.de>
parents: 2860
diff changeset
  4874
     worstCase behavior (but worse average & bestCase behavior)"
602
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  4875
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  4876
    |stop|
356
claus
parents: 348
diff changeset
  4877
claus
parents: 348
diff changeset
  4878
    stop := self size.
602
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  4879
    (stop > 1) ifTrue:[
2069
f6183117f922 comments
Claus Gittinger <cg@exept.de>
parents: 1673
diff changeset
  4880
        self quickSortFrom:1 to:stop with:aCollection
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  4881
    ]
77
6c38ca59927f *** empty log message ***
claus
parents: 69
diff changeset
  4882
2881
452f9154d0dc comments; added #randomizedQuickSort.
Claus Gittinger <cg@exept.de>
parents: 2860
diff changeset
  4883
    "Modified: 21.8.1997 / 18:32:21 / cg"
424
claus
parents: 422
diff changeset
  4884
!
claus
parents: 422
diff changeset
  4885
602
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  4886
topologicalSort:sortBlock
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  4887
    "sort the collection inplace using a sloooow sort algorithm.
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  4888
     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
  4889
     in special situations.
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  4890
     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
  4891
     a>c (for example, to sort classes by inheritance)
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  4892
2881
452f9154d0dc comments; added #randomizedQuickSort.
Claus Gittinger <cg@exept.de>
parents: 2860
diff changeset
  4893
     In all other situations, use #sort; which implements the quicksort algorithm.
77
6c38ca59927f *** empty log message ***
claus
parents: 69
diff changeset
  4894
    "
602
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  4895
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  4896
    |smallestIndex "{ Class: SmallInteger }"
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  4897
     end           "{ Class: SmallInteger }"
1495
f0226967f2a2 added a Class: Smallinteger hint
Claus Gittinger <cg@exept.de>
parents: 1422
diff changeset
  4898
     index2        "{ Class: SmallInteger }"
602
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  4899
     smallest thisOne|
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  4900
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  4901
    "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
  4902
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  4903
    end := self size.
862
007dccfb6cb0 fix topologicalSort:
Stefan Vogel <sv@exept.de>
parents: 628
diff changeset
  4904
    1 to:end-1 do:[:index |
2881
452f9154d0dc comments; added #randomizedQuickSort.
Claus Gittinger <cg@exept.de>
parents: 2860
diff changeset
  4905
        smallest := self at:index.
452f9154d0dc comments; added #randomizedQuickSort.
Claus Gittinger <cg@exept.de>
parents: 2860
diff changeset
  4906
        smallestIndex := index.
452f9154d0dc comments; added #randomizedQuickSort.
Claus Gittinger <cg@exept.de>
parents: 2860
diff changeset
  4907
452f9154d0dc comments; added #randomizedQuickSort.
Claus Gittinger <cg@exept.de>
parents: 2860
diff changeset
  4908
        index2 := index + 1.
452f9154d0dc comments; added #randomizedQuickSort.
Claus Gittinger <cg@exept.de>
parents: 2860
diff changeset
  4909
        [
452f9154d0dc comments; added #randomizedQuickSort.
Claus Gittinger <cg@exept.de>
parents: 2860
diff changeset
  4910
            thisOne := self at:index2.
452f9154d0dc comments; added #randomizedQuickSort.
Claus Gittinger <cg@exept.de>
parents: 2860
diff changeset
  4911
            (index2 ~~ smallestIndex 
452f9154d0dc comments; added #randomizedQuickSort.
Claus Gittinger <cg@exept.de>
parents: 2860
diff changeset
  4912
            and:[sortBlock value:thisOne value:smallest]) ifTrue:[
452f9154d0dc comments; added #randomizedQuickSort.
Claus Gittinger <cg@exept.de>
parents: 2860
diff changeset
  4913
                smallestIndex := index2.
452f9154d0dc comments; added #randomizedQuickSort.
Claus Gittinger <cg@exept.de>
parents: 2860
diff changeset
  4914
                smallest := thisOne.
452f9154d0dc comments; added #randomizedQuickSort.
Claus Gittinger <cg@exept.de>
parents: 2860
diff changeset
  4915
                index2 := index + 1.
452f9154d0dc comments; added #randomizedQuickSort.
Claus Gittinger <cg@exept.de>
parents: 2860
diff changeset
  4916
            ] ifFalse:[
5391
47cae5f97981 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5372
diff changeset
  4917
                index2 := index2 + 1.
2881
452f9154d0dc comments; added #randomizedQuickSort.
Claus Gittinger <cg@exept.de>
parents: 2860
diff changeset
  4918
            ].
452f9154d0dc comments; added #randomizedQuickSort.
Claus Gittinger <cg@exept.de>
parents: 2860
diff changeset
  4919
        ] doWhile:[index2 <= end].
862
007dccfb6cb0 fix topologicalSort:
Stefan Vogel <sv@exept.de>
parents: 628
diff changeset
  4920
007dccfb6cb0 fix topologicalSort:
Stefan Vogel <sv@exept.de>
parents: 628
diff changeset
  4921
"/        (index + 1) to:end do:[:index2 |
007dccfb6cb0 fix topologicalSort:
Stefan Vogel <sv@exept.de>
parents: 628
diff changeset
  4922
"/            thisOne := self at:index2.
007dccfb6cb0 fix topologicalSort:
Stefan Vogel <sv@exept.de>
parents: 628
diff changeset
  4923
"/            (sortBlock value:thisOne value:smallest) ifTrue:[
007dccfb6cb0 fix topologicalSort:
Stefan Vogel <sv@exept.de>
parents: 628
diff changeset
  4924
"/                smallestIndex := index2.
007dccfb6cb0 fix topologicalSort:
Stefan Vogel <sv@exept.de>
parents: 628
diff changeset
  4925
"/                smallest := thisOne
007dccfb6cb0 fix topologicalSort:
Stefan Vogel <sv@exept.de>
parents: 628
diff changeset
  4926
"/            ].
007dccfb6cb0 fix topologicalSort:
Stefan Vogel <sv@exept.de>
parents: 628
diff changeset
  4927
"/        ].
1495
f0226967f2a2 added a Class: Smallinteger hint
Claus Gittinger <cg@exept.de>
parents: 1422
diff changeset
  4928
2881
452f9154d0dc comments; added #randomizedQuickSort.
Claus Gittinger <cg@exept.de>
parents: 2860
diff changeset
  4929
        (smallestIndex ~~ index) ifTrue:[
452f9154d0dc comments; added #randomizedQuickSort.
Claus Gittinger <cg@exept.de>
parents: 2860
diff changeset
  4930
            thisOne := self at:index.
452f9154d0dc comments; added #randomizedQuickSort.
Claus Gittinger <cg@exept.de>
parents: 2860
diff changeset
  4931
            self at:index put:smallest.
452f9154d0dc comments; added #randomizedQuickSort.
Claus Gittinger <cg@exept.de>
parents: 2860
diff changeset
  4932
            self at:smallestIndex put:thisOne
452f9154d0dc comments; added #randomizedQuickSort.
Claus Gittinger <cg@exept.de>
parents: 2860
diff changeset
  4933
        ].
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  4934
    ]
95
d22739a0c6e9 *** empty log message ***
claus
parents: 88
diff changeset
  4935
77
6c38ca59927f *** empty log message ***
claus
parents: 69
diff changeset
  4936
    "
602
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  4937
     #(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
  4938
     #(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
  4939
     Smalltalk allClasses asArray topologicalSort:[:a :b | b isSubclassOf:a] 
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  4940
     Smalltalk allClasses asArray sort:[:a :b | b isSubclassOf:a] 
77
6c38ca59927f *** empty log message ***
claus
parents: 69
diff changeset
  4941
    "
2881
452f9154d0dc comments; added #randomizedQuickSort.
Claus Gittinger <cg@exept.de>
parents: 2860
diff changeset
  4942
452f9154d0dc comments; added #randomizedQuickSort.
Claus Gittinger <cg@exept.de>
parents: 2860
diff changeset
  4943
    "Modified: 21.8.1997 / 18:30:49 / cg"
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  4944
! !
602
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 586
diff changeset
  4945
2069
f6183117f922 comments
Claus Gittinger <cg@exept.de>
parents: 1673
diff changeset
  4946
!SequenceableCollection class methodsFor:'documentation'!
628
7aa563e4c64a version at the end
Claus Gittinger <cg@exept.de>
parents: 602
diff changeset
  4947
7aa563e4c64a version at the end
Claus Gittinger <cg@exept.de>
parents: 602
diff changeset
  4948
version
5471
a57eeb01c5ab General encoding method (#encodeOn:with:)
Stefan Vogel <sv@exept.de>
parents: 5446
diff changeset
  4949
    ^ '$Header: /cvs/stx/stx/libbasic/SequenceableCollection.st,v 1.136 2000-07-18 09:03:14 stefan Exp $'
628
7aa563e4c64a version at the end
Claus Gittinger <cg@exept.de>
parents: 602
diff changeset
  4950
! !
4197
8ae90a572914 raise a special signal, when a literalencodings class
Claus Gittinger <cg@exept.de>
parents: 4154
diff changeset
  4951
SequenceableCollection initialize!