RunArray.st
author Claus Gittinger <cg@exept.de>
Sat, 02 May 2020 21:40:13 +0200
changeset 5476 7355a4b11cb6
parent 4956 f5404f992dc1
permissions -rw-r--r--
#FEATURE by cg class: Socket class added: #newTCPclientToHost:port:domain:domainOrder:withTimeout: changed: #newTCPclientToHost:port:domain:withTimeout:
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
297
9526ea90d4f9 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
     1
"
9526ea90d4f9 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
     2
 This class is not covered by or part of the ST/X licence.
9526ea90d4f9 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
     3
9526ea90d4f9 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
     4
9526ea90d4f9 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
     5
 COPYRIGHT.
9526ea90d4f9 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
     6
 The above file is a Manchester Goodie protected by copyright.
9526ea90d4f9 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
     7
 These conditions are imposed on the whole Goodie, and on any significant
9526ea90d4f9 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
     8
 part of it which is separately transmitted or stored:
9526ea90d4f9 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
     9
	* You must ensure that every copy includes this notice, and that
9526ea90d4f9 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    10
	  source and author(s) of the material are acknowledged.
9526ea90d4f9 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    11
	* These conditions must be imposed on anyone who receives a copy.
9526ea90d4f9 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    12
	* The material shall not be used for commercial gain without the prior
9526ea90d4f9 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    13
	  written consent of the author(s).
9526ea90d4f9 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    14
 Further information on the copyright conditions may be obtained by
9526ea90d4f9 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    15
 sending electronic mail:
9526ea90d4f9 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    16
	To: goodies-lib@cs.man.ac.uk
9526ea90d4f9 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    17
	Subject: copyright
9526ea90d4f9 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    18
 or by writing to The Smalltalk Goodies Library Manager, Dept of
9526ea90d4f9 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    19
 Computer Science, The University, Manchester M13 9PL, UK
9526ea90d4f9 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    20
9526ea90d4f9 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    21
 (C) Copyright 1993 University of Manchester
9526ea90d4f9 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    22
 For more information about the Manchester Goodies Library (from which 
9526ea90d4f9 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    23
 this file was distributed) send e-mail:
9526ea90d4f9 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    24
	To: goodies-lib@cs.man.ac.uk
9526ea90d4f9 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    25
	Subject: help 
9526ea90d4f9 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    26
"
892
90a4022c52a1 faster compare
Claus Gittinger <cg@exept.de>
parents: 871
diff changeset
    27
"{ Package: 'stx:libbasic2' }"
90a4022c52a1 faster compare
Claus Gittinger <cg@exept.de>
parents: 871
diff changeset
    28
3593
3476aa995618 class: RunArray
Claus Gittinger <cg@exept.de>
parents: 3323
diff changeset
    29
"{ NameSpace: Smalltalk }"
3476aa995618 class: RunArray
Claus Gittinger <cg@exept.de>
parents: 3323
diff changeset
    30
297
9526ea90d4f9 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    31
SequenceableCollection subclass:#RunArray
299
2b891872f0af comments
Claus Gittinger <cg@exept.de>
parents: 298
diff changeset
    32
	instanceVariableNames:'contentsArray'
297
9526ea90d4f9 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    33
	classVariableNames:''
9526ea90d4f9 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    34
	poolDictionaries:''
9526ea90d4f9 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    35
	category:'Collections-Sequenceable'
9526ea90d4f9 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    36
!
9526ea90d4f9 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    37
9526ea90d4f9 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    38
RunArray comment:'This implements an ordered collection which uses runs to minimise the amount
9526ea90d4f9 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    39
 of data that it holds. Basically it should be used if you know that an ordered
9526ea90d4f9 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    40
 collections is giong to contain a lot of runs of eactly the same data. Implemented
9526ea90d4f9 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    41
 to allow simultation playback, since the ordered collctions which that generates
9526ea90d4f9 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    42
 are so big that the complier falls over, though most of it is extremely repetetive.
9526ea90d4f9 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    43
 This should be totally abstracted. The user should not be a ble to see the difference
9526ea90d4f9 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    44
 between an ordered collection and a ComrpessedOrderedCollection.  This has a
9526ea90d4f9 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    45
 lot in common with RunArray, and the two should probably share implementation.
9526ea90d4f9 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    46
 but I could not do some of the things I wanted with the RunArray code, so this
9526ea90d4f9 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    47
 is all done on its own.
9526ea90d4f9 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    48
	Some of this could be made faster by adding a cache of the start and finish
9526ea90d4f9 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    49
 indices of each run, but since I envisage that most additions etc. will be to
9526ea90d4f9 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    50
 and from the end those are not included. In addition I have implemented the
9526ea90d4f9 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    51
 bare essentials of this for what I need it for - i.e. add to the end and take
966
dd7e0a32bcc1 Use <resource:#obsolete>
Stefan Vogel <sv@exept.de>
parents: 906
diff changeset
    52
 off the beginning.'
dd7e0a32bcc1 Use <resource:#obsolete>
Stefan Vogel <sv@exept.de>
parents: 906
diff changeset
    53
!
297
9526ea90d4f9 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    54
9526ea90d4f9 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    55
!RunArray class methodsFor:'documentation'!
9526ea90d4f9 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    56
9526ea90d4f9 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    57
copyright
9526ea90d4f9 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    58
"
9526ea90d4f9 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    59
 This class is not covered by or part of the ST/X licence.
9526ea90d4f9 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    60
9526ea90d4f9 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    61
9526ea90d4f9 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    62
 COPYRIGHT.
9526ea90d4f9 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    63
 The above file is a Manchester Goodie protected by copyright.
9526ea90d4f9 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    64
 These conditions are imposed on the whole Goodie, and on any significant
9526ea90d4f9 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    65
 part of it which is separately transmitted or stored:
9526ea90d4f9 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    66
	* You must ensure that every copy includes this notice, and that
9526ea90d4f9 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    67
	  source and author(s) of the material are acknowledged.
9526ea90d4f9 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    68
	* These conditions must be imposed on anyone who receives a copy.
9526ea90d4f9 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    69
	* The material shall not be used for commercial gain without the prior
9526ea90d4f9 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    70
	  written consent of the author(s).
9526ea90d4f9 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    71
 Further information on the copyright conditions may be obtained by
9526ea90d4f9 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    72
 sending electronic mail:
9526ea90d4f9 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    73
	To: goodies-lib@cs.man.ac.uk
9526ea90d4f9 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    74
	Subject: copyright
9526ea90d4f9 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    75
 or by writing to The Smalltalk Goodies Library Manager, Dept of
9526ea90d4f9 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    76
 Computer Science, The University, Manchester M13 9PL, UK
9526ea90d4f9 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    77
9526ea90d4f9 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    78
 (C) Copyright 1993 University of Manchester
9526ea90d4f9 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    79
 For more information about the Manchester Goodies Library (from which 
9526ea90d4f9 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    80
 this file was distributed) send e-mail:
9526ea90d4f9 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    81
	To: goodies-lib@cs.man.ac.uk
9526ea90d4f9 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    82
	Subject: help 
9526ea90d4f9 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    83
"
9526ea90d4f9 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    84
9526ea90d4f9 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    85
9526ea90d4f9 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    86
!
9526ea90d4f9 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    87
9526ea90d4f9 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    88
documentation
9526ea90d4f9 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    89
"
9526ea90d4f9 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    90
    This implements an array which uses runs to minimise the amount
588
677527917896 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 450
diff changeset
    91
    of data that it physically holds. 
677527917896 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 450
diff changeset
    92
    A run consists of a count/object pair, which (when the collection
677527917896 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 450
diff changeset
    93
    is accessed), is treated as if the object was contained count-times 
677527917896 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 450
diff changeset
    94
    in the runArray.
677527917896 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 450
diff changeset
    95
677527917896 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 450
diff changeset
    96
    Basically it can be used if you know that your collection is 
677527917896 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 450
diff changeset
    97
    going to contain a lot of runs of exactly the same data. 
297
9526ea90d4f9 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    98
298
8a87aeffa1c0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 297
diff changeset
    99
    RunArrays are used by the Text class to keep character attributes
8a87aeffa1c0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 297
diff changeset
   100
    (which we expect to remain constant for longer character ranges).
297
9526ea90d4f9 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   101
588
677527917896 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 450
diff changeset
   102
    [notice:]
677527917896 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 450
diff changeset
   103
        there is ONLY a space saving if there are really runs 
677527917896 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 450
diff changeset
   104
        (i.e. multiple elements which compare same).
677527917896 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 450
diff changeset
   105
        The break-even is when runs have an average size of 2 elements,
677527917896 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 450
diff changeset
   106
        if average runs are shorter, other collections (i.e. Array or
677527917896 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 450
diff changeset
   107
        OrderedCollection) are more compact.
677527917896 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 450
diff changeset
   108
4005
688fdfafab0d #OTHER by mawalch
mawalch
parents: 4002
diff changeset
   109
        Also note that indexed access (i.e. #at: / #at:put:) may be
588
677527917896 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 450
diff changeset
   110
        very inefficient (as opposed to enumeration, which is reasonably
677527917896 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 450
diff changeset
   111
        fast).
677527917896 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 450
diff changeset
   112
        The reason is that for indexed access the runs have to be walked.
677527917896 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 450
diff changeset
   113
        When storing into a runArray, runs may have to be splitted or merged,
677527917896 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 450
diff changeset
   114
        depending on where the store is done (within a run).
677527917896 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 450
diff changeset
   115
        This may lead to a resize operation.
677527917896 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 450
diff changeset
   116
        You have been warned.
297
9526ea90d4f9 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   117
298
8a87aeffa1c0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 297
diff changeset
   118
    [instance variables:]
588
677527917896 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 450
diff changeset
   119
        contentsArray    <Array>         contains the runs, consisting of
677527917896 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 450
diff changeset
   120
                                         alternating length/value entries.
298
8a87aeffa1c0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 297
diff changeset
   121
8a87aeffa1c0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 297
diff changeset
   122
    [implementation note:]
8a87aeffa1c0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 297
diff changeset
   123
        structure-wise, it would have been more intuitive, to keep
8a87aeffa1c0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 297
diff changeset
   124
        instances of Run objects (as done in CompressedOrderedCollection)
8a87aeffa1c0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 297
diff changeset
   125
        instead of alternating length/values in the `runs' collection.
588
677527917896 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 450
diff changeset
   126
        However, doing this means that lots of additional memory is required,
677527917896 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 450
diff changeset
   127
        since for every run, another object (consisting of 12bytes header)
677527917896 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 450
diff changeset
   128
        would be needed.
677527917896 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 450
diff changeset
   129
        Here, we choose the more space efficient way - after all, space saving
677527917896 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 450
diff changeset
   130
        is the only reason this class was built for.
297
9526ea90d4f9 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   131
9526ea90d4f9 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   132
    [author:]
9526ea90d4f9 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   133
        Claus Gittinger
9526ea90d4f9 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   134
9526ea90d4f9 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   135
    [see also:]
298
8a87aeffa1c0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 297
diff changeset
   136
        Array OrderedCollection CompressedOrderedCollection
297
9526ea90d4f9 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   137
"
9526ea90d4f9 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   138
!
9526ea90d4f9 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   139
9526ea90d4f9 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   140
examples
9526ea90d4f9 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   141
"
9526ea90d4f9 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   142
  this eats up a lot of memory ...
9526ea90d4f9 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   143
  ... but its relatively fast:
298
8a87aeffa1c0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 297
diff changeset
   144
                                                                        [exBegin]
297
9526ea90d4f9 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   145
    |coll|
9526ea90d4f9 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   146
9526ea90d4f9 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   147
    coll := OrderedCollection new.
350
93d5932c76e6 showCr: -> showCR:
Claus Gittinger <cg@exept.de>
parents: 334
diff changeset
   148
    Transcript showCR:(    
298
8a87aeffa1c0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 297
diff changeset
   149
        Time millisecondsToRun:[
8a87aeffa1c0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 297
diff changeset
   150
            100000 timesRepeat:[coll add:'hello'].
8a87aeffa1c0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 297
diff changeset
   151
            100000 timesRepeat:[coll add:'world'].
8a87aeffa1c0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 297
diff changeset
   152
        ]
297
9526ea90d4f9 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   153
    ).
9526ea90d4f9 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   154
    coll inspect.
298
8a87aeffa1c0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 297
diff changeset
   155
                                                                        [exEnd]
297
9526ea90d4f9 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   156
9526ea90d4f9 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   157
9526ea90d4f9 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   158
  this is very space efficient ...
298
8a87aeffa1c0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 297
diff changeset
   159
  ... (and even slightly faster):
8a87aeffa1c0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 297
diff changeset
   160
                                                                        [exBegin]
297
9526ea90d4f9 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   161
    |coll|
9526ea90d4f9 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   162
9526ea90d4f9 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   163
    coll := RunArray new.
350
93d5932c76e6 showCr: -> showCR:
Claus Gittinger <cg@exept.de>
parents: 334
diff changeset
   164
    Transcript showCR:(    
298
8a87aeffa1c0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 297
diff changeset
   165
        Time millisecondsToRun:[
8a87aeffa1c0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 297
diff changeset
   166
            100000 timesRepeat:[coll add:'hello'].
8a87aeffa1c0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 297
diff changeset
   167
            100000 timesRepeat:[coll add:'world'].
8a87aeffa1c0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 297
diff changeset
   168
        ]
297
9526ea90d4f9 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   169
    ).
9526ea90d4f9 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   170
    coll inspect.
298
8a87aeffa1c0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 297
diff changeset
   171
                                                                        [exEnd]
297
9526ea90d4f9 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   172
9526ea90d4f9 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   173
298
8a87aeffa1c0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 297
diff changeset
   174
  this is very space efficient ...
8a87aeffa1c0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 297
diff changeset
   175
  ... AND much faster:
8a87aeffa1c0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 297
diff changeset
   176
                                                                        [exBegin]
297
9526ea90d4f9 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   177
    |coll|
9526ea90d4f9 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   178
9526ea90d4f9 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   179
    coll := RunArray new.
350
93d5932c76e6 showCr: -> showCR:
Claus Gittinger <cg@exept.de>
parents: 334
diff changeset
   180
    Transcript showCR:(    
298
8a87aeffa1c0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 297
diff changeset
   181
        Time millisecondsToRun:[
8a87aeffa1c0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 297
diff changeset
   182
            coll add:'hello' withOccurrences:100000.
8a87aeffa1c0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 297
diff changeset
   183
            coll add:'world' withOccurrences:100000.
8a87aeffa1c0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 297
diff changeset
   184
        ]
297
9526ea90d4f9 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   185
    ).
9526ea90d4f9 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   186
    coll inspect.
298
8a87aeffa1c0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 297
diff changeset
   187
                                                                        [exEnd]
297
9526ea90d4f9 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   188
9526ea90d4f9 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   189
300
4855b70c63b6 example
Claus Gittinger <cg@exept.de>
parents: 299
diff changeset
   190
  single-element runs;
4855b70c63b6 example
Claus Gittinger <cg@exept.de>
parents: 299
diff changeset
   191
  this is very space INEFFICIENT (requires twice as much) ...
4855b70c63b6 example
Claus Gittinger <cg@exept.de>
parents: 299
diff changeset
   192
  ... and MUCH slower:
298
8a87aeffa1c0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 297
diff changeset
   193
                                                                        [exBegin]
297
9526ea90d4f9 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   194
    |coll|
9526ea90d4f9 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   195
9526ea90d4f9 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   196
    coll := RunArray new.
350
93d5932c76e6 showCr: -> showCR:
Claus Gittinger <cg@exept.de>
parents: 334
diff changeset
   197
    Transcript showCR:(    
298
8a87aeffa1c0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 297
diff changeset
   198
        Time millisecondsToRun:[
8a87aeffa1c0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 297
diff changeset
   199
            1 to:1000 do:[:i | coll add:i].
8a87aeffa1c0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 297
diff changeset
   200
        ]
8a87aeffa1c0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 297
diff changeset
   201
    ).
8a87aeffa1c0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 297
diff changeset
   202
                                                                        [exEnd]
300
4855b70c63b6 example
Claus Gittinger <cg@exept.de>
parents: 299
diff changeset
   203
  compare to:
4855b70c63b6 example
Claus Gittinger <cg@exept.de>
parents: 299
diff changeset
   204
                                                                        [exBegin]
4855b70c63b6 example
Claus Gittinger <cg@exept.de>
parents: 299
diff changeset
   205
    |coll|
4855b70c63b6 example
Claus Gittinger <cg@exept.de>
parents: 299
diff changeset
   206
4855b70c63b6 example
Claus Gittinger <cg@exept.de>
parents: 299
diff changeset
   207
    coll := OrderedCollection new.
350
93d5932c76e6 showCr: -> showCR:
Claus Gittinger <cg@exept.de>
parents: 334
diff changeset
   208
    Transcript showCR:(    
300
4855b70c63b6 example
Claus Gittinger <cg@exept.de>
parents: 299
diff changeset
   209
        Time millisecondsToRun:[
4855b70c63b6 example
Claus Gittinger <cg@exept.de>
parents: 299
diff changeset
   210
            1 to:1000 do:[:i | coll add:i].
4855b70c63b6 example
Claus Gittinger <cg@exept.de>
parents: 299
diff changeset
   211
        ]
4855b70c63b6 example
Claus Gittinger <cg@exept.de>
parents: 299
diff changeset
   212
    ).
4855b70c63b6 example
Claus Gittinger <cg@exept.de>
parents: 299
diff changeset
   213
                                                                        [exEnd]
4855b70c63b6 example
Claus Gittinger <cg@exept.de>
parents: 299
diff changeset
   214
297
9526ea90d4f9 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   215
"
9526ea90d4f9 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   216
! !
9526ea90d4f9 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   217
9526ea90d4f9 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   218
!RunArray class methodsFor:'instance creation'!
9526ea90d4f9 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   219
630
55973d9fee59 added #from: instance creation method.
Claus Gittinger <cg@exept.de>
parents: 588
diff changeset
   220
from:aSequencableCollection
55973d9fee59 added #from: instance creation method.
Claus Gittinger <cg@exept.de>
parents: 588
diff changeset
   221
    "return a new runArray, containing the elements from aSequencableCollection"
55973d9fee59 added #from: instance creation method.
Claus Gittinger <cg@exept.de>
parents: 588
diff changeset
   222
55973d9fee59 added #from: instance creation method.
Claus Gittinger <cg@exept.de>
parents: 588
diff changeset
   223
    ^ self basicNew setElementsFrom:aSequencableCollection
55973d9fee59 added #from: instance creation method.
Claus Gittinger <cg@exept.de>
parents: 588
diff changeset
   224
55973d9fee59 added #from: instance creation method.
Claus Gittinger <cg@exept.de>
parents: 588
diff changeset
   225
    "
55973d9fee59 added #from: instance creation method.
Claus Gittinger <cg@exept.de>
parents: 588
diff changeset
   226
     RunArray from:#(1 2 3 3 3 4 5 5 6 6 6 6 6 6)
55973d9fee59 added #from: instance creation method.
Claus Gittinger <cg@exept.de>
parents: 588
diff changeset
   227
    "
55973d9fee59 added #from: instance creation method.
Claus Gittinger <cg@exept.de>
parents: 588
diff changeset
   228
55973d9fee59 added #from: instance creation method.
Claus Gittinger <cg@exept.de>
parents: 588
diff changeset
   229
    "Created: / 7.4.1998 / 09:12:45 / cg"
55973d9fee59 added #from: instance creation method.
Claus Gittinger <cg@exept.de>
parents: 588
diff changeset
   230
    "Modified: / 7.4.1998 / 09:15:53 / cg"
55973d9fee59 added #from: instance creation method.
Claus Gittinger <cg@exept.de>
parents: 588
diff changeset
   231
!
55973d9fee59 added #from: instance creation method.
Claus Gittinger <cg@exept.de>
parents: 588
diff changeset
   232
588
677527917896 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 450
diff changeset
   233
new:count
677527917896 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 450
diff changeset
   234
    "return a new runArray, containing count elements - all nil"
297
9526ea90d4f9 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   235
588
677527917896 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 450
diff changeset
   236
    ^ self basicNew setElement:nil occurrences:count
302
223e660708b2 added #new:withAll:
Claus Gittinger <cg@exept.de>
parents: 300
diff changeset
   237
588
677527917896 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 450
diff changeset
   238
    "Modified: / 30.10.1997 / 14:36:05 / cg"
302
223e660708b2 added #new:withAll:
Claus Gittinger <cg@exept.de>
parents: 300
diff changeset
   239
!
223e660708b2 added #new:withAll:
Claus Gittinger <cg@exept.de>
parents: 300
diff changeset
   240
588
677527917896 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 450
diff changeset
   241
new:count withAll:anObject
677527917896 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 450
diff changeset
   242
    "create a new runArray with count elements, all being anObject"
302
223e660708b2 added #new:withAll:
Claus Gittinger <cg@exept.de>
parents: 300
diff changeset
   243
588
677527917896 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 450
diff changeset
   244
    ^ self basicNew setElement:anObject occurrences:count
302
223e660708b2 added #new:withAll:
Claus Gittinger <cg@exept.de>
parents: 300
diff changeset
   245
223e660708b2 added #new:withAll:
Claus Gittinger <cg@exept.de>
parents: 300
diff changeset
   246
    "
223e660708b2 added #new:withAll:
Claus Gittinger <cg@exept.de>
parents: 300
diff changeset
   247
     RunArray new:100 withAll:#hello
223e660708b2 added #new:withAll:
Claus Gittinger <cg@exept.de>
parents: 300
diff changeset
   248
    "
223e660708b2 added #new:withAll:
Claus Gittinger <cg@exept.de>
parents: 300
diff changeset
   249
588
677527917896 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 450
diff changeset
   250
    "Modified: / 30.10.1997 / 14:36:38 / cg"
871
b44445dc4ac6 new instCreation method
Claus Gittinger <cg@exept.de>
parents: 630
diff changeset
   251
!
b44445dc4ac6 new instCreation method
Claus Gittinger <cg@exept.de>
parents: 630
diff changeset
   252
b44445dc4ac6 new instCreation method
Claus Gittinger <cg@exept.de>
parents: 630
diff changeset
   253
runs:runs values:values
b44445dc4ac6 new instCreation method
Claus Gittinger <cg@exept.de>
parents: 630
diff changeset
   254
    "return a new runArray, containing elements defined by pairs from
b44445dc4ac6 new instCreation method
Claus Gittinger <cg@exept.de>
parents: 630
diff changeset
   255
     runs and values"
b44445dc4ac6 new instCreation method
Claus Gittinger <cg@exept.de>
parents: 630
diff changeset
   256
1325
1c503fd677a7 runs values for VW compatibility
Claus Gittinger <cg@exept.de>
parents: 966
diff changeset
   257
    ^ self basicNew setRuns:runs setValues:values
871
b44445dc4ac6 new instCreation method
Claus Gittinger <cg@exept.de>
parents: 630
diff changeset
   258
b44445dc4ac6 new instCreation method
Claus Gittinger <cg@exept.de>
parents: 630
diff changeset
   259
    "
b44445dc4ac6 new instCreation method
Claus Gittinger <cg@exept.de>
parents: 630
diff changeset
   260
     RunArray runs:#(2 3 4) values:#($a $b $c)
b44445dc4ac6 new instCreation method
Claus Gittinger <cg@exept.de>
parents: 630
diff changeset
   261
    "
297
9526ea90d4f9 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   262
! !
9526ea90d4f9 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   263
1325
1c503fd677a7 runs values for VW compatibility
Claus Gittinger <cg@exept.de>
parents: 966
diff changeset
   264
!RunArray methodsFor:'Compatibility-ST80'!
1c503fd677a7 runs values for VW compatibility
Claus Gittinger <cg@exept.de>
parents: 966
diff changeset
   265
1c503fd677a7 runs values for VW compatibility
Claus Gittinger <cg@exept.de>
parents: 966
diff changeset
   266
runs
1c503fd677a7 runs values for VW compatibility
Claus Gittinger <cg@exept.de>
parents: 966
diff changeset
   267
    contentsArray isNil ifTrue:[ ^ #() ].
1c503fd677a7 runs values for VW compatibility
Claus Gittinger <cg@exept.de>
parents: 966
diff changeset
   268
    ^ contentsArray pairWiseCollect:[:n :v | n ]
1c503fd677a7 runs values for VW compatibility
Claus Gittinger <cg@exept.de>
parents: 966
diff changeset
   269
1c503fd677a7 runs values for VW compatibility
Claus Gittinger <cg@exept.de>
parents: 966
diff changeset
   270
    "
1c503fd677a7 runs values for VW compatibility
Claus Gittinger <cg@exept.de>
parents: 966
diff changeset
   271
     |c|
1c503fd677a7 runs values for VW compatibility
Claus Gittinger <cg@exept.de>
parents: 966
diff changeset
   272
1c503fd677a7 runs values for VW compatibility
Claus Gittinger <cg@exept.de>
parents: 966
diff changeset
   273
     c := RunArray new.
1c503fd677a7 runs values for VW compatibility
Claus Gittinger <cg@exept.de>
parents: 966
diff changeset
   274
     c add:1 withOccurrences:1000.
1c503fd677a7 runs values for VW compatibility
Claus Gittinger <cg@exept.de>
parents: 966
diff changeset
   275
     c add:2 withOccurrences:1000.
1c503fd677a7 runs values for VW compatibility
Claus Gittinger <cg@exept.de>
parents: 966
diff changeset
   276
     c runs.
1c503fd677a7 runs values for VW compatibility
Claus Gittinger <cg@exept.de>
parents: 966
diff changeset
   277
    "
1c503fd677a7 runs values for VW compatibility
Claus Gittinger <cg@exept.de>
parents: 966
diff changeset
   278
!
1c503fd677a7 runs values for VW compatibility
Claus Gittinger <cg@exept.de>
parents: 966
diff changeset
   279
1c503fd677a7 runs values for VW compatibility
Claus Gittinger <cg@exept.de>
parents: 966
diff changeset
   280
values
1c503fd677a7 runs values for VW compatibility
Claus Gittinger <cg@exept.de>
parents: 966
diff changeset
   281
    contentsArray isNil ifTrue:[ ^ #() ].
1c503fd677a7 runs values for VW compatibility
Claus Gittinger <cg@exept.de>
parents: 966
diff changeset
   282
    ^ contentsArray pairWiseCollect:[:n :v | v ]
1c503fd677a7 runs values for VW compatibility
Claus Gittinger <cg@exept.de>
parents: 966
diff changeset
   283
1c503fd677a7 runs values for VW compatibility
Claus Gittinger <cg@exept.de>
parents: 966
diff changeset
   284
    "
1c503fd677a7 runs values for VW compatibility
Claus Gittinger <cg@exept.de>
parents: 966
diff changeset
   285
     |c|
1c503fd677a7 runs values for VW compatibility
Claus Gittinger <cg@exept.de>
parents: 966
diff changeset
   286
1c503fd677a7 runs values for VW compatibility
Claus Gittinger <cg@exept.de>
parents: 966
diff changeset
   287
     c := RunArray new.
1c503fd677a7 runs values for VW compatibility
Claus Gittinger <cg@exept.de>
parents: 966
diff changeset
   288
     c add:1 withOccurrences:1000.
1c503fd677a7 runs values for VW compatibility
Claus Gittinger <cg@exept.de>
parents: 966
diff changeset
   289
     c add:2 withOccurrences:1000.
1c503fd677a7 runs values for VW compatibility
Claus Gittinger <cg@exept.de>
parents: 966
diff changeset
   290
     c values.    
1c503fd677a7 runs values for VW compatibility
Claus Gittinger <cg@exept.de>
parents: 966
diff changeset
   291
    "
1c503fd677a7 runs values for VW compatibility
Claus Gittinger <cg@exept.de>
parents: 966
diff changeset
   292
! !
1c503fd677a7 runs values for VW compatibility
Claus Gittinger <cg@exept.de>
parents: 966
diff changeset
   293
297
9526ea90d4f9 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   294
!RunArray methodsFor:'accessing'!
9526ea90d4f9 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   295
352
e6902ee52702 added #copyFrom:to:
Claus Gittinger <cg@exept.de>
parents: 350
diff changeset
   296
at:index 
e6902ee52702 added #copyFrom:to:
Claus Gittinger <cg@exept.de>
parents: 350
diff changeset
   297
    "Answer the element at index. 
297
9526ea90d4f9 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   298
     at: is used by a knowledgeable client to access an existing element 
299
2b891872f0af comments
Claus Gittinger <cg@exept.de>
parents: 298
diff changeset
   299
     This is a pretty dumb thing to do to a runArray and it is 
297
9526ea90d4f9 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   300
     not at all efficient (think of that as a discouragement)."
9526ea90d4f9 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   301
9526ea90d4f9 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   302
    |position "{ Class: SmallInteger }"
9526ea90d4f9 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   303
     nRuns    "{ Class: SmallInteger }"|
9526ea90d4f9 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   304
352
e6902ee52702 added #copyFrom:to:
Claus Gittinger <cg@exept.de>
parents: 350
diff changeset
   305
    (index > 0) ifTrue:[
297
9526ea90d4f9 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   306
        position := 1.
299
2b891872f0af comments
Claus Gittinger <cg@exept.de>
parents: 298
diff changeset
   307
        nRuns := contentsArray size.
297
9526ea90d4f9 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   308
        1 to:nRuns by:2 do:[:runIndex |
9526ea90d4f9 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   309
            |runLen|
9526ea90d4f9 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   310
299
2b891872f0af comments
Claus Gittinger <cg@exept.de>
parents: 298
diff changeset
   311
            runLen := contentsArray at:runIndex.
352
e6902ee52702 added #copyFrom:to:
Claus Gittinger <cg@exept.de>
parents: 350
diff changeset
   312
            index >= position ifTrue:[
e6902ee52702 added #copyFrom:to:
Claus Gittinger <cg@exept.de>
parents: 350
diff changeset
   313
                index < (position + runLen) ifTrue:[
299
2b891872f0af comments
Claus Gittinger <cg@exept.de>
parents: 298
diff changeset
   314
                    ^ contentsArray at:(runIndex + 1)
297
9526ea90d4f9 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   315
                ].
9526ea90d4f9 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   316
            ].
9526ea90d4f9 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   317
            position := position + runLen
9526ea90d4f9 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   318
        ]
9526ea90d4f9 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   319
    ].
352
e6902ee52702 added #copyFrom:to:
Claus Gittinger <cg@exept.de>
parents: 350
diff changeset
   320
    ^ self subscriptBoundsError:index
297
9526ea90d4f9 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   321
9526ea90d4f9 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   322
    "
9526ea90d4f9 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   323
     |c|
9526ea90d4f9 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   324
9526ea90d4f9 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   325
     c := RunArray new.
9526ea90d4f9 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   326
     c add:1; add:1; add:1; add:2; add:2; add:3; add:3; add:4; add:5.
9526ea90d4f9 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   327
     c at:1. 
9526ea90d4f9 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   328
     c at:2. 
9526ea90d4f9 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   329
     c at:3. 
9526ea90d4f9 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   330
     c at:4.  
9526ea90d4f9 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   331
     c at:5. 
9526ea90d4f9 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   332
     c at:6. 
9526ea90d4f9 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   333
     c at:7. 
9526ea90d4f9 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   334
     c at:8.  
9526ea90d4f9 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   335
     c at:9.  
9526ea90d4f9 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   336
     c at:10.  
9526ea90d4f9 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   337
    "
9526ea90d4f9 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   338
352
e6902ee52702 added #copyFrom:to:
Claus Gittinger <cg@exept.de>
parents: 350
diff changeset
   339
    "Modified: 18.5.1996 / 14:54:52 / cg"
297
9526ea90d4f9 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   340
!
9526ea90d4f9 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   341
9526ea90d4f9 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   342
at:index put:anObject 
9526ea90d4f9 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   343
    "Put anObject at element index anInteger.      
588
677527917896 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 450
diff changeset
   344
     at:put: can not be used to append, front or back, to a runArray.      
677527917896 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 450
diff changeset
   345
     It is used by a knowledgeable client to replace an element. 
299
2b891872f0af comments
Claus Gittinger <cg@exept.de>
parents: 298
diff changeset
   346
     This is a pretty dumb thing to do to a runArray and it is 
2b891872f0af comments
Claus Gittinger <cg@exept.de>
parents: 298
diff changeset
   347
     very inefficient, since we have to check if runs are to be merged or
2b891872f0af comments
Claus Gittinger <cg@exept.de>
parents: 298
diff changeset
   348
     splitted."
297
9526ea90d4f9 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   349
9526ea90d4f9 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   350
    |runSz runIndex runOffset len l1 l2 prevIdx nextIdx
450
efbbe6d6c6f5 removed unused vars
Claus Gittinger <cg@exept.de>
parents: 352
diff changeset
   351
     val newRuns prevLen prevVal nextLen nextVal idx|
297
9526ea90d4f9 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   352
299
2b891872f0af comments
Claus Gittinger <cg@exept.de>
parents: 298
diff changeset
   353
    runSz := contentsArray size.
297
9526ea90d4f9 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   354
9526ea90d4f9 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   355
    runIndex := nil.
9526ea90d4f9 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   356
    (index > 0) ifTrue:[
9526ea90d4f9 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   357
        runOffset := 1.
9526ea90d4f9 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   358
        idx := 1.
9526ea90d4f9 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   359
        [runIndex isNil and:[idx < runSz]] whileTrue:[
299
2b891872f0af comments
Claus Gittinger <cg@exept.de>
parents: 298
diff changeset
   360
            len := contentsArray at:idx.
297
9526ea90d4f9 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   361
            nextIdx := runOffset + len.
9526ea90d4f9 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   362
            index >= runOffset ifTrue:[
9526ea90d4f9 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   363
                index < nextIdx ifTrue:[
9526ea90d4f9 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   364
                    runIndex := idx.
4191
fca4937adf70 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 4097
diff changeset
   365
                    nextIdx := runOffset. "/ don't advance
297
9526ea90d4f9 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   366
                ].
9526ea90d4f9 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   367
            ].
9526ea90d4f9 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   368
            runOffset := nextIdx.
9526ea90d4f9 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   369
            idx := idx + 2.
9526ea90d4f9 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   370
        ]
9526ea90d4f9 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   371
    ].
9526ea90d4f9 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   372
    runIndex isNil ifTrue:[
352
e6902ee52702 added #copyFrom:to:
Claus Gittinger <cg@exept.de>
parents: 350
diff changeset
   373
        ^ self subscriptBoundsError:index
297
9526ea90d4f9 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   374
    ].
9526ea90d4f9 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   375
299
2b891872f0af comments
Claus Gittinger <cg@exept.de>
parents: 298
diff changeset
   376
    val := contentsArray at:(runIndex + 1).
297
9526ea90d4f9 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   377
9526ea90d4f9 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   378
    "/ easiest: value there is the same ...
9526ea90d4f9 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   379
9526ea90d4f9 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   380
    val = anObject ifTrue:[
9526ea90d4f9 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   381
        ^ anObject
9526ea90d4f9 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   382
    ].
9526ea90d4f9 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   383
9526ea90d4f9 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   384
    "/ if the length is 1, this is an island ...
9526ea90d4f9 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   385
    "/ ... which is either easy, or requires a merge.
9526ea90d4f9 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   386
299
2b891872f0af comments
Claus Gittinger <cg@exept.de>
parents: 298
diff changeset
   387
    len := contentsArray at:runIndex.
297
9526ea90d4f9 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   388
    len = 1 ifTrue:[
9526ea90d4f9 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   389
        "/ check if it can be merged into the next or previous run
9526ea90d4f9 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   390
9526ea90d4f9 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   391
        runIndex > 1 ifTrue:[
9526ea90d4f9 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   392
            prevIdx := runIndex - 2.
299
2b891872f0af comments
Claus Gittinger <cg@exept.de>
parents: 298
diff changeset
   393
            prevVal := contentsArray at:(prevIdx + 1).
297
9526ea90d4f9 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   394
            prevVal = anObject ifTrue:[
9526ea90d4f9 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   395
                "/ can merge it into previous
9526ea90d4f9 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   396
299
2b891872f0af comments
Claus Gittinger <cg@exept.de>
parents: 298
diff changeset
   397
                prevLen := contentsArray at:prevIdx.
297
9526ea90d4f9 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   398
9526ea90d4f9 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   399
                "/ check if merge into next is also possible (filling an island)
9526ea90d4f9 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   400
                
9526ea90d4f9 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   401
                runIndex < (runSz - 1) ifTrue:[
9526ea90d4f9 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   402
                    nextIdx := runIndex + 2.
299
2b891872f0af comments
Claus Gittinger <cg@exept.de>
parents: 298
diff changeset
   403
                    nextVal := contentsArray at:(nextIdx + 1).
297
9526ea90d4f9 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   404
                    nextVal = anObject ifTrue:[
9526ea90d4f9 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   405
                        "/ can merge with both.
9526ea90d4f9 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   406
                        
299
2b891872f0af comments
Claus Gittinger <cg@exept.de>
parents: 298
diff changeset
   407
                        nextLen := contentsArray at:nextIdx.
297
9526ea90d4f9 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   408
299
2b891872f0af comments
Claus Gittinger <cg@exept.de>
parents: 298
diff changeset
   409
                        contentsArray at:prevIdx put:prevLen+nextLen+1.
297
9526ea90d4f9 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   410
                        runSz := (runSz - 4).
9526ea90d4f9 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   411
                        newRuns := Array new:runSz.
299
2b891872f0af comments
Claus Gittinger <cg@exept.de>
parents: 298
diff changeset
   412
                        newRuns replaceFrom:1 to:(prevIdx + 1) with:contentsArray startingAt:1.
2b891872f0af comments
Claus Gittinger <cg@exept.de>
parents: 298
diff changeset
   413
                        newRuns replaceFrom:runIndex to:runSz with:contentsArray startingAt:nextIdx+2.
2b891872f0af comments
Claus Gittinger <cg@exept.de>
parents: 298
diff changeset
   414
                        contentsArray := newRuns.
297
9526ea90d4f9 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   415
                        ^ anObject
9526ea90d4f9 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   416
                    ]
9526ea90d4f9 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   417
                ].
9526ea90d4f9 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   418
299
2b891872f0af comments
Claus Gittinger <cg@exept.de>
parents: 298
diff changeset
   419
                contentsArray at:prevIdx put:prevLen+1.
297
9526ea90d4f9 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   420
9526ea90d4f9 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   421
                runSz := (runSz - 2).
9526ea90d4f9 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   422
                newRuns := Array new:runSz.
299
2b891872f0af comments
Claus Gittinger <cg@exept.de>
parents: 298
diff changeset
   423
                newRuns replaceFrom:1 to:(runIndex - 1) with:contentsArray startingAt:1.
2b891872f0af comments
Claus Gittinger <cg@exept.de>
parents: 298
diff changeset
   424
                newRuns replaceFrom:runIndex to:runSz with:contentsArray startingAt:runIndex+2.
2b891872f0af comments
Claus Gittinger <cg@exept.de>
parents: 298
diff changeset
   425
                contentsArray := newRuns.
297
9526ea90d4f9 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   426
9526ea90d4f9 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   427
                ^ anObject
9526ea90d4f9 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   428
            ].
9526ea90d4f9 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   429
        ].
9526ea90d4f9 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   430
9526ea90d4f9 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   431
        "/ check if merge into next is possible
9526ea90d4f9 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   432
305
9d20b26c1e1a fix & added #runsDo:
Claus Gittinger <cg@exept.de>
parents: 303
diff changeset
   433
        runIndex < (runSz-1) ifTrue:[
297
9526ea90d4f9 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   434
            nextIdx := runIndex + 2.
299
2b891872f0af comments
Claus Gittinger <cg@exept.de>
parents: 298
diff changeset
   435
            nextVal := contentsArray at:nextIdx+1.
297
9526ea90d4f9 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   436
            nextVal = anObject ifTrue:[
299
2b891872f0af comments
Claus Gittinger <cg@exept.de>
parents: 298
diff changeset
   437
                nextLen := contentsArray at:nextIdx.
2b891872f0af comments
Claus Gittinger <cg@exept.de>
parents: 298
diff changeset
   438
                contentsArray at:nextIdx put:nextLen + 1.
297
9526ea90d4f9 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   439
9526ea90d4f9 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   440
                runSz := (runSz - 2).
9526ea90d4f9 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   441
                newRuns := Array new:runSz.
299
2b891872f0af comments
Claus Gittinger <cg@exept.de>
parents: 298
diff changeset
   442
                newRuns replaceFrom:1 to:(runIndex - 1) with:contentsArray startingAt:1.
2b891872f0af comments
Claus Gittinger <cg@exept.de>
parents: 298
diff changeset
   443
                newRuns replaceFrom:runIndex to:runSz with:contentsArray startingAt:nextIdx.
2b891872f0af comments
Claus Gittinger <cg@exept.de>
parents: 298
diff changeset
   444
                contentsArray := newRuns.
297
9526ea90d4f9 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   445
                ^ anObject
9526ea90d4f9 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   446
            ].
9526ea90d4f9 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   447
        ].
9526ea90d4f9 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   448
9526ea90d4f9 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   449
        "/ no merge; island remains
9526ea90d4f9 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   450
299
2b891872f0af comments
Claus Gittinger <cg@exept.de>
parents: 298
diff changeset
   451
        contentsArray at:(runIndex+1) put:anObject.
297
9526ea90d4f9 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   452
        ^ anObject
9526ea90d4f9 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   453
    ].
9526ea90d4f9 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   454
9526ea90d4f9 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   455
    runOffset == index ifTrue:[
9526ea90d4f9 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   456
        "/ at the beginning of that run ...
9526ea90d4f9 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   457
4318
cede8d1a3efc #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 4246
diff changeset
   458
        "/ check if it's better added to the previous run ...
297
9526ea90d4f9 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   459
9526ea90d4f9 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   460
        runIndex > 1 ifTrue:[
9526ea90d4f9 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   461
            prevIdx := runIndex - 2.
299
2b891872f0af comments
Claus Gittinger <cg@exept.de>
parents: 298
diff changeset
   462
            prevVal := contentsArray at:prevIdx+1.
297
9526ea90d4f9 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   463
            prevVal = anObject ifTrue:[
299
2b891872f0af comments
Claus Gittinger <cg@exept.de>
parents: 298
diff changeset
   464
                prevLen := contentsArray at:prevIdx.
2b891872f0af comments
Claus Gittinger <cg@exept.de>
parents: 298
diff changeset
   465
                contentsArray at:prevIdx put:prevLen + 1.
2b891872f0af comments
Claus Gittinger <cg@exept.de>
parents: 298
diff changeset
   466
                contentsArray at:runIndex put:len - 1.
297
9526ea90d4f9 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   467
                ^ anObject.
9526ea90d4f9 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   468
            ].
9526ea90d4f9 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   469
        ].
9526ea90d4f9 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   470
9526ea90d4f9 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   471
        "/ must cut off 1 & insert a new run before ..
9526ea90d4f9 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   472
299
2b891872f0af comments
Claus Gittinger <cg@exept.de>
parents: 298
diff changeset
   473
        contentsArray at:runIndex put:len - 1.
297
9526ea90d4f9 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   474
9526ea90d4f9 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   475
        runSz := (runSz + 2).
9526ea90d4f9 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   476
        newRuns := Array new:runSz.
299
2b891872f0af comments
Claus Gittinger <cg@exept.de>
parents: 298
diff changeset
   477
        newRuns replaceFrom:1 to:(runIndex - 1) with:contentsArray startingAt:1.
2b891872f0af comments
Claus Gittinger <cg@exept.de>
parents: 298
diff changeset
   478
        newRuns replaceFrom:runIndex+2 to:runSz with:contentsArray startingAt:runIndex.
2b891872f0af comments
Claus Gittinger <cg@exept.de>
parents: 298
diff changeset
   479
        contentsArray := newRuns.
297
9526ea90d4f9 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   480
299
2b891872f0af comments
Claus Gittinger <cg@exept.de>
parents: 298
diff changeset
   481
        contentsArray at:runIndex   put:1.
2b891872f0af comments
Claus Gittinger <cg@exept.de>
parents: 298
diff changeset
   482
        contentsArray at:runIndex+1 put:anObject.
297
9526ea90d4f9 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   483
        ^ anObject
9526ea90d4f9 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   484
    ].
9526ea90d4f9 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   485
9526ea90d4f9 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   486
    (runOffset + len - 1) == index ifTrue:[
9526ea90d4f9 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   487
        "/ at the end ...
9526ea90d4f9 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   488
9526ea90d4f9 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   489
        "/ check if its better added to the next run ...
9526ea90d4f9 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   490
306
Claus Gittinger <cg@exept.de>
parents: 305
diff changeset
   491
        runIndex < (runSz-1) ifTrue:[
297
9526ea90d4f9 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   492
            nextIdx := runIndex + 2.
299
2b891872f0af comments
Claus Gittinger <cg@exept.de>
parents: 298
diff changeset
   493
            nextVal := contentsArray at:nextIdx+1.
297
9526ea90d4f9 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   494
            nextVal = anObject ifTrue:[
299
2b891872f0af comments
Claus Gittinger <cg@exept.de>
parents: 298
diff changeset
   495
                nextLen := contentsArray at:nextIdx.
2b891872f0af comments
Claus Gittinger <cg@exept.de>
parents: 298
diff changeset
   496
                contentsArray at:nextIdx put:nextLen + 1.
2b891872f0af comments
Claus Gittinger <cg@exept.de>
parents: 298
diff changeset
   497
                contentsArray at:runIndex put:len - 1.
297
9526ea90d4f9 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   498
                ^ anObject.
9526ea90d4f9 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   499
            ].
9526ea90d4f9 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   500
        ].
9526ea90d4f9 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   501
9526ea90d4f9 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   502
        "/ must cut off 1 & insert a new run after ..
9526ea90d4f9 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   503
299
2b891872f0af comments
Claus Gittinger <cg@exept.de>
parents: 298
diff changeset
   504
        contentsArray at:runIndex put:len - 1.
297
9526ea90d4f9 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   505
9526ea90d4f9 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   506
        runSz := (runSz + 2).
9526ea90d4f9 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   507
        newRuns := Array new:runSz.
299
2b891872f0af comments
Claus Gittinger <cg@exept.de>
parents: 298
diff changeset
   508
        newRuns replaceFrom:1 to:(runIndex + 1) with:contentsArray startingAt:1.
2b891872f0af comments
Claus Gittinger <cg@exept.de>
parents: 298
diff changeset
   509
        newRuns replaceFrom:runIndex+4 to:runSz with:contentsArray startingAt:runIndex+2.
2b891872f0af comments
Claus Gittinger <cg@exept.de>
parents: 298
diff changeset
   510
        contentsArray := newRuns.
297
9526ea90d4f9 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   511
299
2b891872f0af comments
Claus Gittinger <cg@exept.de>
parents: 298
diff changeset
   512
        contentsArray at:runIndex+2 put:1.
2b891872f0af comments
Claus Gittinger <cg@exept.de>
parents: 298
diff changeset
   513
        contentsArray at:runIndex+2+1 put:anObject.
297
9526ea90d4f9 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   514
        ^ anObject
9526ea90d4f9 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   515
    ].
9526ea90d4f9 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   516
9526ea90d4f9 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   517
    "/ hardest - split run into two, insert new run in-between
9526ea90d4f9 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   518
9526ea90d4f9 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   519
    runSz := (runSz + 4).
9526ea90d4f9 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   520
    newRuns := Array new:runSz.
9526ea90d4f9 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   521
9526ea90d4f9 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   522
    runIndex > 1 ifTrue:[
299
2b891872f0af comments
Claus Gittinger <cg@exept.de>
parents: 298
diff changeset
   523
        newRuns replaceFrom:1 to:runIndex-1 with:contentsArray.
297
9526ea90d4f9 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   524
    ].
305
9d20b26c1e1a fix & added #runsDo:
Claus Gittinger <cg@exept.de>
parents: 303
diff changeset
   525
    newRuns replaceFrom:runIndex+6 to:runSz with:contentsArray startingAt:runIndex+2.
297
9526ea90d4f9 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   526
9526ea90d4f9 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   527
    l2 := len - (index - runOffset).
9526ea90d4f9 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   528
    l1 := len - l2.
9526ea90d4f9 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   529
    l2 := l2 - 1.
9526ea90d4f9 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   530
9526ea90d4f9 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   531
    newRuns at:runIndex   put:l1.
9526ea90d4f9 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   532
    newRuns at:runIndex+1 put:val.
9526ea90d4f9 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   533
9526ea90d4f9 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   534
    newRuns at:runIndex+4 put:l2.
9526ea90d4f9 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   535
    newRuns at:runIndex+5 put:val.
9526ea90d4f9 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   536
9526ea90d4f9 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   537
    "/ insert
9526ea90d4f9 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   538
    newRuns at:runIndex+2 put:1.
9526ea90d4f9 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   539
    newRuns at:runIndex+3 put:anObject.
9526ea90d4f9 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   540
299
2b891872f0af comments
Claus Gittinger <cg@exept.de>
parents: 298
diff changeset
   541
    contentsArray := newRuns.
297
9526ea90d4f9 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   542
    ^ anObject
9526ea90d4f9 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   543
9526ea90d4f9 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   544
    "
9526ea90d4f9 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   545
     |c|
9526ea90d4f9 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   546
9526ea90d4f9 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   547
     Transcript cr.
9526ea90d4f9 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   548
9526ea90d4f9 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   549
     c := RunArray new.
9526ea90d4f9 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   550
     c add:1; add:1; add:1; add:2; add:2; add:3; add:3; add:4; add:5; yourself.
350
93d5932c76e6 showCr: -> showCR:
Claus Gittinger <cg@exept.de>
parents: 334
diff changeset
   551
     Transcript showCR:c.   
297
9526ea90d4f9 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   552
9526ea90d4f9 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   553
     c at:1 put:$a.
350
93d5932c76e6 showCr: -> showCR:
Claus Gittinger <cg@exept.de>
parents: 334
diff changeset
   554
     Transcript showCR:c.   
297
9526ea90d4f9 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   555
     c.
9526ea90d4f9 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   556
9526ea90d4f9 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   557
     c at:3 put:$a.
350
93d5932c76e6 showCr: -> showCR:
Claus Gittinger <cg@exept.de>
parents: 334
diff changeset
   558
     Transcript showCR:c.   
297
9526ea90d4f9 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   559
     c.
9526ea90d4f9 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   560
9526ea90d4f9 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   561
     c at:4 put:$a.   
350
93d5932c76e6 showCr: -> showCR:
Claus Gittinger <cg@exept.de>
parents: 334
diff changeset
   562
     Transcript showCR:c.   
297
9526ea90d4f9 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   563
     c.
9526ea90d4f9 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   564
9526ea90d4f9 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   565
     c at:5 put:$a.   
350
93d5932c76e6 showCr: -> showCR:
Claus Gittinger <cg@exept.de>
parents: 334
diff changeset
   566
     Transcript showCR:c.   
297
9526ea90d4f9 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   567
     c.
9526ea90d4f9 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   568
9526ea90d4f9 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   569
     c at:2 put:$0.   
350
93d5932c76e6 showCr: -> showCR:
Claus Gittinger <cg@exept.de>
parents: 334
diff changeset
   570
     Transcript showCR:c.   
297
9526ea90d4f9 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   571
     c.
9526ea90d4f9 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   572
9526ea90d4f9 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   573
     c at:2 put:$a.   
350
93d5932c76e6 showCr: -> showCR:
Claus Gittinger <cg@exept.de>
parents: 334
diff changeset
   574
     Transcript showCR:c.   
297
9526ea90d4f9 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   575
     c.
9526ea90d4f9 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   576
350
93d5932c76e6 showCr: -> showCR:
Claus Gittinger <cg@exept.de>
parents: 334
diff changeset
   577
     Transcript showCR:c.   
297
9526ea90d4f9 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   578
    "
9526ea90d4f9 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   579
4318
cede8d1a3efc #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 4246
diff changeset
   580
    "Modified: / 30-10-1997 / 14:38:45 / cg"
cede8d1a3efc #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 4246
diff changeset
   581
    "Modified (format): / 13-02-2017 / 20:29:58 / cg"
3117
21453eeba760 class: RunArray
Claus Gittinger <cg@exept.de>
parents: 3008
diff changeset
   582
!
21453eeba760 class: RunArray
Claus Gittinger <cg@exept.de>
parents: 3008
diff changeset
   583
21453eeba760 class: RunArray
Claus Gittinger <cg@exept.de>
parents: 3008
diff changeset
   584
atAllPut:anObject 
21453eeba760 class: RunArray
Claus Gittinger <cg@exept.de>
parents: 3008
diff changeset
   585
    "replace all elements of the collection by the argument, anObject.
4921
e5f2b1b5a28d #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 4805
diff changeset
   586
     Return the receiver.
3117
21453eeba760 class: RunArray
Claus Gittinger <cg@exept.de>
parents: 3008
diff changeset
   587
     Notice: This operation modifies the receiver, NOT a copy;
21453eeba760 class: RunArray
Claus Gittinger <cg@exept.de>
parents: 3008
diff changeset
   588
     therefore the change may affect all others referencing the receiver."
21453eeba760 class: RunArray
Claus Gittinger <cg@exept.de>
parents: 3008
diff changeset
   589
21453eeba760 class: RunArray
Claus Gittinger <cg@exept.de>
parents: 3008
diff changeset
   590
    contentsArray := Array with:(self size) with:anObject
21453eeba760 class: RunArray
Claus Gittinger <cg@exept.de>
parents: 3008
diff changeset
   591
21453eeba760 class: RunArray
Claus Gittinger <cg@exept.de>
parents: 3008
diff changeset
   592
    "
21453eeba760 class: RunArray
Claus Gittinger <cg@exept.de>
parents: 3008
diff changeset
   593
     |c|
21453eeba760 class: RunArray
Claus Gittinger <cg@exept.de>
parents: 3008
diff changeset
   594
21453eeba760 class: RunArray
Claus Gittinger <cg@exept.de>
parents: 3008
diff changeset
   595
     c := RunArray new:20.
21453eeba760 class: RunArray
Claus Gittinger <cg@exept.de>
parents: 3008
diff changeset
   596
     c atAllPut:1.
21453eeba760 class: RunArray
Claus Gittinger <cg@exept.de>
parents: 3008
diff changeset
   597
     Transcript showCR:c.   
21453eeba760 class: RunArray
Claus Gittinger <cg@exept.de>
parents: 3008
diff changeset
   598
    "
4921
e5f2b1b5a28d #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 4805
diff changeset
   599
e5f2b1b5a28d #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 4805
diff changeset
   600
    "Modified (comment): / 26-03-2019 / 11:53:28 / Claus Gittinger"
297
9526ea90d4f9 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   601
! !
9526ea90d4f9 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   602
904
f4791de2295b category change
Claus Gittinger <cg@exept.de>
parents: 895
diff changeset
   603
!RunArray methodsFor:'adding & removing'!
297
9526ea90d4f9 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   604
9526ea90d4f9 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   605
add:newObject
2930
2fed91d4a44e comment/format in: #add:
Claus Gittinger <cg@exept.de>
parents: 2520
diff changeset
   606
    "add newObject at the end.
2fed91d4a44e comment/format in: #add:
Claus Gittinger <cg@exept.de>
parents: 2520
diff changeset
   607
     Returns the object (sigh)"
297
9526ea90d4f9 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   608
9526ea90d4f9 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   609
    ^ self add:newObject withOccurrences:1.
9526ea90d4f9 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   610
9526ea90d4f9 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   611
    "
9526ea90d4f9 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   612
     |c|
9526ea90d4f9 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   613
9526ea90d4f9 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   614
     c := RunArray new.
9526ea90d4f9 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   615
     c add:1; add:1; add:1; add:2; add:2; add:3; add:3; add:4; add:5; yourself.
9526ea90d4f9 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   616
    "
9526ea90d4f9 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   617
9526ea90d4f9 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   618
    "Modified: 10.5.1996 / 17:01:20 / cg"
9526ea90d4f9 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   619
!
9526ea90d4f9 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   620
9526ea90d4f9 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   621
add:newObject withOccurrences:n
9526ea90d4f9 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   622
    "add newObject n times at the end; returns the object (sigh)"
9526ea90d4f9 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   623
9526ea90d4f9 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   624
    |lastIdx runSz newRuns|
9526ea90d4f9 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   625
299
2b891872f0af comments
Claus Gittinger <cg@exept.de>
parents: 298
diff changeset
   626
    contentsArray notNil ifTrue:[
297
9526ea90d4f9 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   627
        "/ check for merge
9526ea90d4f9 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   628
299
2b891872f0af comments
Claus Gittinger <cg@exept.de>
parents: 298
diff changeset
   629
        runSz := contentsArray size.
297
9526ea90d4f9 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   630
299
2b891872f0af comments
Claus Gittinger <cg@exept.de>
parents: 298
diff changeset
   631
        (contentsArray at:runSz) = newObject ifTrue:[
297
9526ea90d4f9 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   632
            lastIdx := runSz - 1.
299
2b891872f0af comments
Claus Gittinger <cg@exept.de>
parents: 298
diff changeset
   633
            contentsArray at:lastIdx put:(contentsArray at:lastIdx) + n.
297
9526ea90d4f9 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   634
            ^ newObject
9526ea90d4f9 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   635
        ].
4775
03b9f6efd595 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 4756
diff changeset
   636
        (newRuns := contentsArray) isOrderedCollection ifFalse:[
03b9f6efd595 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 4756
diff changeset
   637
            newRuns := contentsArray asOrderedCollection.
03b9f6efd595 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 4756
diff changeset
   638
        ].
03b9f6efd595 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 4756
diff changeset
   639
        newRuns add:n; add:newObject.
299
2b891872f0af comments
Claus Gittinger <cg@exept.de>
parents: 298
diff changeset
   640
        contentsArray := newRuns.
297
9526ea90d4f9 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   641
    ] ifFalse:[
4775
03b9f6efd595 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 4756
diff changeset
   642
        contentsArray := OrderedCollection with:n with:newObject.
297
9526ea90d4f9 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   643
    ].
9526ea90d4f9 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   644
    ^ newObject
9526ea90d4f9 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   645
9526ea90d4f9 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   646
    "
9526ea90d4f9 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   647
     |c|
9526ea90d4f9 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   648
9526ea90d4f9 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   649
     c := RunArray new.
9526ea90d4f9 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   650
     c add:1 withOccurrences:1000; yourself.
2049
310eea860aa2 changed #add:withOccurrences: - comment
Stefan Vogel <sv@exept.de>
parents: 1855
diff changeset
   651
     c add:1 withOccurrences:500; yourself.
297
9526ea90d4f9 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   652
     c add:2 withOccurrences:1000; yourself.
9526ea90d4f9 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   653
    "
9526ea90d4f9 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   654
4775
03b9f6efd595 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 4756
diff changeset
   655
    "Modified: / 11-05-1996 / 13:34:37 / cg"
03b9f6efd595 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 4756
diff changeset
   656
    "Modified: / 11-12-2018 / 11:51:28 / Claus Gittinger"
03b9f6efd595 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 4756
diff changeset
   657
!
03b9f6efd595 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 4756
diff changeset
   658
03b9f6efd595 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 4756
diff changeset
   659
addAll:aCollection
03b9f6efd595 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 4756
diff changeset
   660
    "add all elements of the argument, aCollection to the receiver.
03b9f6efd595 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 4756
diff changeset
   661
     Returns the argument, aCollection (sigh)."
03b9f6efd595 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 4756
diff changeset
   662
03b9f6efd595 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 4756
diff changeset
   663
    aCollection class == RunArray ifTrue:[
03b9f6efd595 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 4756
diff changeset
   664
        contentsArray isOrderedCollection ifFalse:[
03b9f6efd595 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 4756
diff changeset
   665
            contentsArray := (contentsArray ? #()) asOrderedCollection.
03b9f6efd595 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 4756
diff changeset
   666
        ].
03b9f6efd595 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 4756
diff changeset
   667
        contentsArray addAll:(aCollection getContentsArray).
03b9f6efd595 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 4756
diff changeset
   668
        ^ aCollection
03b9f6efd595 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 4756
diff changeset
   669
    ].        
03b9f6efd595 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 4756
diff changeset
   670
    ^ super addAll:aCollection.
03b9f6efd595 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 4756
diff changeset
   671
03b9f6efd595 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 4756
diff changeset
   672
    "Created: / 11-12-2018 / 11:41:45 / Claus Gittinger"
297
9526ea90d4f9 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   673
! !
9526ea90d4f9 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   674
892
90a4022c52a1 faster compare
Claus Gittinger <cg@exept.de>
parents: 871
diff changeset
   675
!RunArray methodsFor:'comparing'!
90a4022c52a1 faster compare
Claus Gittinger <cg@exept.de>
parents: 871
diff changeset
   676
90a4022c52a1 faster compare
Claus Gittinger <cg@exept.de>
parents: 871
diff changeset
   677
= aCollection
90a4022c52a1 faster compare
Claus Gittinger <cg@exept.de>
parents: 871
diff changeset
   678
    "return true, if the argument contains the same elements as the receiver.
90a4022c52a1 faster compare
Claus Gittinger <cg@exept.de>
parents: 871
diff changeset
   679
     Optimized, especially for the common case, that collection is another runArray"
90a4022c52a1 faster compare
Claus Gittinger <cg@exept.de>
parents: 871
diff changeset
   680
90a4022c52a1 faster compare
Claus Gittinger <cg@exept.de>
parents: 871
diff changeset
   681
    |otherContents idx1 idx2 runCount1 runValue1 runCount2 runValue2|
90a4022c52a1 faster compare
Claus Gittinger <cg@exept.de>
parents: 871
diff changeset
   682
4756
a11c5fef5ba8 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 4571
diff changeset
   683
    aCollection size == self size ifFalse:[^ false].
a11c5fef5ba8 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 4571
diff changeset
   684
    
4246
c4093b605f67 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 4191
diff changeset
   685
    aCollection class ~~ self class ifTrue:[
c4093b605f67 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 4191
diff changeset
   686
        idx1 := 1.
892
90a4022c52a1 faster compare
Claus Gittinger <cg@exept.de>
parents: 871
diff changeset
   687
        aCollection isSequenceable ifTrue:[
90a4022c52a1 faster compare
Claus Gittinger <cg@exept.de>
parents: 871
diff changeset
   688
            self do:[:element |
90a4022c52a1 faster compare
Claus Gittinger <cg@exept.de>
parents: 871
diff changeset
   689
                idx1 > aCollection size ifTrue:[^ false].
90a4022c52a1 faster compare
Claus Gittinger <cg@exept.de>
parents: 871
diff changeset
   690
                element = (aCollection at:idx1) ifFalse:[^ false].
90a4022c52a1 faster compare
Claus Gittinger <cg@exept.de>
parents: 871
diff changeset
   691
                idx1 := idx1+1.
90a4022c52a1 faster compare
Claus Gittinger <cg@exept.de>
parents: 871
diff changeset
   692
            ].
4246
c4093b605f67 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 4191
diff changeset
   693
            ^ idx1 > aCollection size.
892
90a4022c52a1 faster compare
Claus Gittinger <cg@exept.de>
parents: 871
diff changeset
   694
        ].
90a4022c52a1 faster compare
Claus Gittinger <cg@exept.de>
parents: 871
diff changeset
   695
90a4022c52a1 faster compare
Claus Gittinger <cg@exept.de>
parents: 871
diff changeset
   696
        runCount1 := 0.
90a4022c52a1 faster compare
Claus Gittinger <cg@exept.de>
parents: 871
diff changeset
   697
        aCollection do:[:element |
90a4022c52a1 faster compare
Claus Gittinger <cg@exept.de>
parents: 871
diff changeset
   698
            runCount1 == 0 ifTrue:[
3002
9a77642609b5 class: RunArray
Claus Gittinger <cg@exept.de>
parents: 2971
diff changeset
   699
                idx1 >= contentsArray size ifTrue:[^ false].
892
90a4022c52a1 faster compare
Claus Gittinger <cg@exept.de>
parents: 871
diff changeset
   700
90a4022c52a1 faster compare
Claus Gittinger <cg@exept.de>
parents: 871
diff changeset
   701
                runCount1 := contentsArray at:idx1.
90a4022c52a1 faster compare
Claus Gittinger <cg@exept.de>
parents: 871
diff changeset
   702
                runValue1 := contentsArray at:idx1+1.
90a4022c52a1 faster compare
Claus Gittinger <cg@exept.de>
parents: 871
diff changeset
   703
                idx1 := idx1+2.
90a4022c52a1 faster compare
Claus Gittinger <cg@exept.de>
parents: 871
diff changeset
   704
            ].
90a4022c52a1 faster compare
Claus Gittinger <cg@exept.de>
parents: 871
diff changeset
   705
            runValue1 = element ifFalse:[^ false].
90a4022c52a1 faster compare
Claus Gittinger <cg@exept.de>
parents: 871
diff changeset
   706
            runCount1 := runCount1 - 1.
90a4022c52a1 faster compare
Claus Gittinger <cg@exept.de>
parents: 871
diff changeset
   707
        ].
90a4022c52a1 faster compare
Claus Gittinger <cg@exept.de>
parents: 871
diff changeset
   708
        runCount1 ~~ 0 ifTrue:[^ false].
4246
c4093b605f67 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 4191
diff changeset
   709
        ^ idx1 >= contentsArray size.
892
90a4022c52a1 faster compare
Claus Gittinger <cg@exept.de>
parents: 871
diff changeset
   710
    ].
4246
c4093b605f67 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 4191
diff changeset
   711
892
90a4022c52a1 faster compare
Claus Gittinger <cg@exept.de>
parents: 871
diff changeset
   712
    otherContents := aCollection getContentsArray.
90a4022c52a1 faster compare
Claus Gittinger <cg@exept.de>
parents: 871
diff changeset
   713
    otherContents = contentsArray ifTrue:[^ true].
90a4022c52a1 faster compare
Claus Gittinger <cg@exept.de>
parents: 871
diff changeset
   714
4246
c4093b605f67 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 4191
diff changeset
   715
    idx1 := idx2 := 1.
c4093b605f67 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 4191
diff changeset
   716
    runCount1 := runCount2 := 0.
892
90a4022c52a1 faster compare
Claus Gittinger <cg@exept.de>
parents: 871
diff changeset
   717
3208
61e00bd988d2 [true] whileTrue: -> #loop
Stefan Vogel <sv@exept.de>
parents: 3117
diff changeset
   718
    [
895
Claus Gittinger <cg@exept.de>
parents: 892
diff changeset
   719
        runCount1 == 0 ifTrue:[
3002
9a77642609b5 class: RunArray
Claus Gittinger <cg@exept.de>
parents: 2971
diff changeset
   720
            idx1 >= contentsArray size ifTrue:[
895
Claus Gittinger <cg@exept.de>
parents: 892
diff changeset
   721
                idx2+1 <= otherContents size ifTrue:[^ false].
4246
c4093b605f67 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 4191
diff changeset
   722
                ^ runCount2 == 0.
895
Claus Gittinger <cg@exept.de>
parents: 892
diff changeset
   723
            ].
Claus Gittinger <cg@exept.de>
parents: 892
diff changeset
   724
            runCount1 := contentsArray at:idx1.
Claus Gittinger <cg@exept.de>
parents: 892
diff changeset
   725
            runValue1 := contentsArray at:idx1+1.
Claus Gittinger <cg@exept.de>
parents: 892
diff changeset
   726
            idx1 := idx1+2.
Claus Gittinger <cg@exept.de>
parents: 892
diff changeset
   727
        ].        
Claus Gittinger <cg@exept.de>
parents: 892
diff changeset
   728
        runCount2 == 0 ifTrue:[
3002
9a77642609b5 class: RunArray
Claus Gittinger <cg@exept.de>
parents: 2971
diff changeset
   729
            idx2 >= otherContents size ifTrue:[
895
Claus Gittinger <cg@exept.de>
parents: 892
diff changeset
   730
                ^ false
Claus Gittinger <cg@exept.de>
parents: 892
diff changeset
   731
            ].
Claus Gittinger <cg@exept.de>
parents: 892
diff changeset
   732
            runCount2 := otherContents at:idx2.
Claus Gittinger <cg@exept.de>
parents: 892
diff changeset
   733
            runValue2 := otherContents at:idx2+1.
Claus Gittinger <cg@exept.de>
parents: 892
diff changeset
   734
            idx2 := idx2+2.
Claus Gittinger <cg@exept.de>
parents: 892
diff changeset
   735
        ].        
Claus Gittinger <cg@exept.de>
parents: 892
diff changeset
   736
892
90a4022c52a1 faster compare
Claus Gittinger <cg@exept.de>
parents: 871
diff changeset
   737
        runValue1 = runValue2 ifFalse:[^ false].
895
Claus Gittinger <cg@exept.de>
parents: 892
diff changeset
   738
        runCount1 > runCount2 ifTrue:[
Claus Gittinger <cg@exept.de>
parents: 892
diff changeset
   739
            runCount1 := runCount1 - runCount2.
Claus Gittinger <cg@exept.de>
parents: 892
diff changeset
   740
            runCount2 := 0.
892
90a4022c52a1 faster compare
Claus Gittinger <cg@exept.de>
parents: 871
diff changeset
   741
        ] ifFalse:[
895
Claus Gittinger <cg@exept.de>
parents: 892
diff changeset
   742
            runCount2 := runCount2 - runCount1.
Claus Gittinger <cg@exept.de>
parents: 892
diff changeset
   743
            runCount1 := 0.
Claus Gittinger <cg@exept.de>
parents: 892
diff changeset
   744
        ].
3208
61e00bd988d2 [true] whileTrue: -> #loop
Stefan Vogel <sv@exept.de>
parents: 3117
diff changeset
   745
    ] loop.
892
90a4022c52a1 faster compare
Claus Gittinger <cg@exept.de>
parents: 871
diff changeset
   746
90a4022c52a1 faster compare
Claus Gittinger <cg@exept.de>
parents: 871
diff changeset
   747
    "
90a4022c52a1 faster compare
Claus Gittinger <cg@exept.de>
parents: 871
diff changeset
   748
     'hello' asText sameStringAndEmphasisAs: 'hello' asText
90a4022c52a1 faster compare
Claus Gittinger <cg@exept.de>
parents: 871
diff changeset
   749
     'hello' asText sameStringAndEmphasisAs: 'hello' asText allBold
90a4022c52a1 faster compare
Claus Gittinger <cg@exept.de>
parents: 871
diff changeset
   750
     'hello' asText allBold sameStringAndEmphasisAs: 'hello' asText allBold
90a4022c52a1 faster compare
Claus Gittinger <cg@exept.de>
parents: 871
diff changeset
   751
     'hello1' asText allBold sameStringAndEmphasisAs: 'hello' asText allBold  
90a4022c52a1 faster compare
Claus Gittinger <cg@exept.de>
parents: 871
diff changeset
   752
     'hello' asText allBold sameStringAndEmphasisAs: 'hello1' asText allBold  
90a4022c52a1 faster compare
Claus Gittinger <cg@exept.de>
parents: 871
diff changeset
   753
     ('hello' asText allBold , ' ') sameStringAndEmphasisAs: 'hello ' asText allBold  
90a4022c52a1 faster compare
Claus Gittinger <cg@exept.de>
parents: 871
diff changeset
   754
     ('hello ' asText allBold) sameStringAndEmphasisAs: ('hello' asText allBold , ' ')  
90a4022c52a1 faster compare
Claus Gittinger <cg@exept.de>
parents: 871
diff changeset
   755
     ('hello' asText allBold , ' ') sameStringAndEmphasisAs: ('hello' asText allBold , ' ')  
90a4022c52a1 faster compare
Claus Gittinger <cg@exept.de>
parents: 871
diff changeset
   756
     'hello' asRunArray = 'hello' asRunArray 
90a4022c52a1 faster compare
Claus Gittinger <cg@exept.de>
parents: 871
diff changeset
   757
     'hello1' asRunArray = 'hello' asRunArray 
90a4022c52a1 faster compare
Claus Gittinger <cg@exept.de>
parents: 871
diff changeset
   758
     'hello' asRunArray = 'hello1' asRunArray 
90a4022c52a1 faster compare
Claus Gittinger <cg@exept.de>
parents: 871
diff changeset
   759
     'hello' asRunArray = 'hello' asArray      
90a4022c52a1 faster compare
Claus Gittinger <cg@exept.de>
parents: 871
diff changeset
   760
     'hello1' asRunArray = 'hello' asArray     
90a4022c52a1 faster compare
Claus Gittinger <cg@exept.de>
parents: 871
diff changeset
   761
     'hello' asRunArray = 'hello1' asArray     
90a4022c52a1 faster compare
Claus Gittinger <cg@exept.de>
parents: 871
diff changeset
   762
    "
90a4022c52a1 faster compare
Claus Gittinger <cg@exept.de>
parents: 871
diff changeset
   763
! !
90a4022c52a1 faster compare
Claus Gittinger <cg@exept.de>
parents: 871
diff changeset
   764
297
9526ea90d4f9 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   765
!RunArray methodsFor:'converting'!
9526ea90d4f9 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   766
3008
60b373aca4cf class: RunArray
Claus Gittinger <cg@exept.de>
parents: 3002
diff changeset
   767
asArray
60b373aca4cf class: RunArray
Claus Gittinger <cg@exept.de>
parents: 3002
diff changeset
   768
    "return a new array, containing the receiver's elements."
60b373aca4cf class: RunArray
Claus Gittinger <cg@exept.de>
parents: 3002
diff changeset
   769
60b373aca4cf class: RunArray
Claus Gittinger <cg@exept.de>
parents: 3002
diff changeset
   770
    |newCollection dstIndex|
60b373aca4cf class: RunArray
Claus Gittinger <cg@exept.de>
parents: 3002
diff changeset
   771
4097
605d5ca97200 #OTHER by stefan
Stefan Vogel <sv@exept.de>
parents: 4005
diff changeset
   772
    contentsArray isNil ifTrue:[^ #()].
3008
60b373aca4cf class: RunArray
Claus Gittinger <cg@exept.de>
parents: 3002
diff changeset
   773
60b373aca4cf class: RunArray
Claus Gittinger <cg@exept.de>
parents: 3002
diff changeset
   774
    newCollection := Array new:(self size).
60b373aca4cf class: RunArray
Claus Gittinger <cg@exept.de>
parents: 3002
diff changeset
   775
    dstIndex := 1.
60b373aca4cf class: RunArray
Claus Gittinger <cg@exept.de>
parents: 3002
diff changeset
   776
    contentsArray pairWiseDo:[:len :value |
60b373aca4cf class: RunArray
Claus Gittinger <cg@exept.de>
parents: 3002
diff changeset
   777
        newCollection from:dstIndex to:(dstIndex + len - 1) put:value.
60b373aca4cf class: RunArray
Claus Gittinger <cg@exept.de>
parents: 3002
diff changeset
   778
        dstIndex := dstIndex + len.
60b373aca4cf class: RunArray
Claus Gittinger <cg@exept.de>
parents: 3002
diff changeset
   779
    ].
60b373aca4cf class: RunArray
Claus Gittinger <cg@exept.de>
parents: 3002
diff changeset
   780
    ^ newCollection
60b373aca4cf class: RunArray
Claus Gittinger <cg@exept.de>
parents: 3002
diff changeset
   781
60b373aca4cf class: RunArray
Claus Gittinger <cg@exept.de>
parents: 3002
diff changeset
   782
    "
60b373aca4cf class: RunArray
Claus Gittinger <cg@exept.de>
parents: 3002
diff changeset
   783
     |r|
60b373aca4cf class: RunArray
Claus Gittinger <cg@exept.de>
parents: 3002
diff changeset
   784
60b373aca4cf class: RunArray
Claus Gittinger <cg@exept.de>
parents: 3002
diff changeset
   785
     r := RunArray withAll:#(1 2 3 3 3 3 4 4 4 5 6 7 7 7 7 7 7 7).
60b373aca4cf class: RunArray
Claus Gittinger <cg@exept.de>
parents: 3002
diff changeset
   786
     Transcript showCR:r.
60b373aca4cf class: RunArray
Claus Gittinger <cg@exept.de>
parents: 3002
diff changeset
   787
     Transcript showCR:r asArray.
60b373aca4cf class: RunArray
Claus Gittinger <cg@exept.de>
parents: 3002
diff changeset
   788
     Transcript showCR:r asRunArray.
60b373aca4cf class: RunArray
Claus Gittinger <cg@exept.de>
parents: 3002
diff changeset
   789
    "
60b373aca4cf class: RunArray
Claus Gittinger <cg@exept.de>
parents: 3002
diff changeset
   790
!
60b373aca4cf class: RunArray
Claus Gittinger <cg@exept.de>
parents: 3002
diff changeset
   791
297
9526ea90d4f9 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   792
asOrderedCollection
2971
feb675d4296d class: RunArray
Claus Gittinger <cg@exept.de>
parents: 2960
diff changeset
   793
    "return a new orderedCollection, containing the receiver's elements."
297
9526ea90d4f9 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   794
9526ea90d4f9 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   795
    |newCollection|
9526ea90d4f9 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   796
299
2b891872f0af comments
Claus Gittinger <cg@exept.de>
parents: 298
diff changeset
   797
    contentsArray isNil ifTrue:[^ OrderedCollection new].
2b891872f0af comments
Claus Gittinger <cg@exept.de>
parents: 298
diff changeset
   798
2b891872f0af comments
Claus Gittinger <cg@exept.de>
parents: 298
diff changeset
   799
    newCollection := OrderedCollection new:(self size).
2b891872f0af comments
Claus Gittinger <cg@exept.de>
parents: 298
diff changeset
   800
    contentsArray pairWiseDo:[:len :value |
2b891872f0af comments
Claus Gittinger <cg@exept.de>
parents: 298
diff changeset
   801
        newCollection add:value withOccurrences:len
2b891872f0af comments
Claus Gittinger <cg@exept.de>
parents: 298
diff changeset
   802
    ].
297
9526ea90d4f9 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   803
    ^ newCollection
9526ea90d4f9 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   804
299
2b891872f0af comments
Claus Gittinger <cg@exept.de>
parents: 298
diff changeset
   805
    "
2b891872f0af comments
Claus Gittinger <cg@exept.de>
parents: 298
diff changeset
   806
     |r|
2b891872f0af comments
Claus Gittinger <cg@exept.de>
parents: 298
diff changeset
   807
2b891872f0af comments
Claus Gittinger <cg@exept.de>
parents: 298
diff changeset
   808
     r := RunArray withAll:#(1 2 3 3 3 3 4 4 4 5 6 7 7 7 7 7 7 7).
350
93d5932c76e6 showCr: -> showCR:
Claus Gittinger <cg@exept.de>
parents: 334
diff changeset
   809
     Transcript showCR:r.
93d5932c76e6 showCr: -> showCR:
Claus Gittinger <cg@exept.de>
parents: 334
diff changeset
   810
     Transcript showCR:r asOrderedCollection
299
2b891872f0af comments
Claus Gittinger <cg@exept.de>
parents: 298
diff changeset
   811
    "
2b891872f0af comments
Claus Gittinger <cg@exept.de>
parents: 298
diff changeset
   812
2b891872f0af comments
Claus Gittinger <cg@exept.de>
parents: 298
diff changeset
   813
    "Modified: 11.5.1996 / 13:34:59 / cg"
334
023ca84ef961 faster #findFirst:
Claus Gittinger <cg@exept.de>
parents: 306
diff changeset
   814
!
023ca84ef961 faster #findFirst:
Claus Gittinger <cg@exept.de>
parents: 306
diff changeset
   815
023ca84ef961 faster #findFirst:
Claus Gittinger <cg@exept.de>
parents: 306
diff changeset
   816
asRunArray
630
55973d9fee59 added #from: instance creation method.
Claus Gittinger <cg@exept.de>
parents: 588
diff changeset
   817
    "return the receiver itself"
334
023ca84ef961 faster #findFirst:
Claus Gittinger <cg@exept.de>
parents: 306
diff changeset
   818
023ca84ef961 faster #findFirst:
Claus Gittinger <cg@exept.de>
parents: 306
diff changeset
   819
    ^ self
023ca84ef961 faster #findFirst:
Claus Gittinger <cg@exept.de>
parents: 306
diff changeset
   820
630
55973d9fee59 added #from: instance creation method.
Claus Gittinger <cg@exept.de>
parents: 588
diff changeset
   821
    "Modified: / 7.4.1998 / 09:50:29 / cg"
297
9526ea90d4f9 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   822
! !
9526ea90d4f9 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   823
352
e6902ee52702 added #copyFrom:to:
Claus Gittinger <cg@exept.de>
parents: 350
diff changeset
   824
!RunArray methodsFor:'copying'!
e6902ee52702 added #copyFrom:to:
Claus Gittinger <cg@exept.de>
parents: 350
diff changeset
   825
e6902ee52702 added #copyFrom:to:
Claus Gittinger <cg@exept.de>
parents: 350
diff changeset
   826
copyFrom:start to:stop
e6902ee52702 added #copyFrom:to:
Claus Gittinger <cg@exept.de>
parents: 350
diff changeset
   827
    "return a new collection, containing the elements from start to stop"
e6902ee52702 added #copyFrom:to:
Claus Gittinger <cg@exept.de>
parents: 350
diff changeset
   828
4776
7259a694e36d #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 4775
diff changeset
   829
    |srcIdx endIdx runStart runNext newRuns idx copying len val|
352
e6902ee52702 added #copyFrom:to:
Claus Gittinger <cg@exept.de>
parents: 350
diff changeset
   830
e6902ee52702 added #copyFrom:to:
Claus Gittinger <cg@exept.de>
parents: 350
diff changeset
   831
    (contentsArray notNil 
e6902ee52702 added #copyFrom:to:
Claus Gittinger <cg@exept.de>
parents: 350
diff changeset
   832
    and:[stop >= start]) ifTrue:[
e6902ee52702 added #copyFrom:to:
Claus Gittinger <cg@exept.de>
parents: 350
diff changeset
   833
        newRuns := self species new.
e6902ee52702 added #copyFrom:to:
Claus Gittinger <cg@exept.de>
parents: 350
diff changeset
   834
        runStart := 1.
e6902ee52702 added #copyFrom:to:
Claus Gittinger <cg@exept.de>
parents: 350
diff changeset
   835
        idx := start.
e6902ee52702 added #copyFrom:to:
Claus Gittinger <cg@exept.de>
parents: 350
diff changeset
   836
        copying := false.
4776
7259a694e36d #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 4775
diff changeset
   837
        srcIdx := 1.
7259a694e36d #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 4775
diff changeset
   838
        endIdx := contentsArray size.
7259a694e36d #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 4775
diff changeset
   839
        [srcIdx < endIdx] whileTrue:[
7259a694e36d #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 4775
diff changeset
   840
            len := contentsArray at:srcIdx.
7259a694e36d #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 4775
diff changeset
   841
            val := contentsArray at:srcIdx+1.
7259a694e36d #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 4775
diff changeset
   842
            srcIdx := srcIdx + 2.
7259a694e36d #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 4775
diff changeset
   843
            
352
e6902ee52702 added #copyFrom:to:
Claus Gittinger <cg@exept.de>
parents: 350
diff changeset
   844
            runNext := runStart + len.
e6902ee52702 added #copyFrom:to:
Claus Gittinger <cg@exept.de>
parents: 350
diff changeset
   845
        
e6902ee52702 added #copyFrom:to:
Claus Gittinger <cg@exept.de>
parents: 350
diff changeset
   846
            copying ifFalse:[
e6902ee52702 added #copyFrom:to:
Claus Gittinger <cg@exept.de>
parents: 350
diff changeset
   847
                idx >= runStart ifTrue:[
e6902ee52702 added #copyFrom:to:
Claus Gittinger <cg@exept.de>
parents: 350
diff changeset
   848
                    copying := true
e6902ee52702 added #copyFrom:to:
Claus Gittinger <cg@exept.de>
parents: 350
diff changeset
   849
                ]
e6902ee52702 added #copyFrom:to:
Claus Gittinger <cg@exept.de>
parents: 350
diff changeset
   850
            ].
e6902ee52702 added #copyFrom:to:
Claus Gittinger <cg@exept.de>
parents: 350
diff changeset
   851
            copying ifTrue:[
e6902ee52702 added #copyFrom:to:
Claus Gittinger <cg@exept.de>
parents: 350
diff changeset
   852
                idx < runNext ifTrue:[
e6902ee52702 added #copyFrom:to:
Claus Gittinger <cg@exept.de>
parents: 350
diff changeset
   853
                    "/ found the first run
e6902ee52702 added #copyFrom:to:
Claus Gittinger <cg@exept.de>
parents: 350
diff changeset
   854
e6902ee52702 added #copyFrom:to:
Claus Gittinger <cg@exept.de>
parents: 350
diff changeset
   855
                    stop < runNext ifTrue:[
e6902ee52702 added #copyFrom:to:
Claus Gittinger <cg@exept.de>
parents: 350
diff changeset
   856
                        newRuns add:val withOccurrences:(stop-idx+1).
e6902ee52702 added #copyFrom:to:
Claus Gittinger <cg@exept.de>
parents: 350
diff changeset
   857
                        ^ newRuns
e6902ee52702 added #copyFrom:to:
Claus Gittinger <cg@exept.de>
parents: 350
diff changeset
   858
                    ].
e6902ee52702 added #copyFrom:to:
Claus Gittinger <cg@exept.de>
parents: 350
diff changeset
   859
e6902ee52702 added #copyFrom:to:
Claus Gittinger <cg@exept.de>
parents: 350
diff changeset
   860
                    newRuns add:val withOccurrences:(runNext-idx).
e6902ee52702 added #copyFrom:to:
Claus Gittinger <cg@exept.de>
parents: 350
diff changeset
   861
                    idx := runNext.
e6902ee52702 added #copyFrom:to:
Claus Gittinger <cg@exept.de>
parents: 350
diff changeset
   862
                ].
e6902ee52702 added #copyFrom:to:
Claus Gittinger <cg@exept.de>
parents: 350
diff changeset
   863
            ].
e6902ee52702 added #copyFrom:to:
Claus Gittinger <cg@exept.de>
parents: 350
diff changeset
   864
            runStart := runNext.
e6902ee52702 added #copyFrom:to:
Claus Gittinger <cg@exept.de>
parents: 350
diff changeset
   865
        ]
e6902ee52702 added #copyFrom:to:
Claus Gittinger <cg@exept.de>
parents: 350
diff changeset
   866
    ].
e6902ee52702 added #copyFrom:to:
Claus Gittinger <cg@exept.de>
parents: 350
diff changeset
   867
e6902ee52702 added #copyFrom:to:
Claus Gittinger <cg@exept.de>
parents: 350
diff changeset
   868
    ^ super copyFrom:start to:stop  "/ for the error report
e6902ee52702 added #copyFrom:to:
Claus Gittinger <cg@exept.de>
parents: 350
diff changeset
   869
e6902ee52702 added #copyFrom:to:
Claus Gittinger <cg@exept.de>
parents: 350
diff changeset
   870
    "
e6902ee52702 added #copyFrom:to:
Claus Gittinger <cg@exept.de>
parents: 350
diff changeset
   871
     |r|
e6902ee52702 added #copyFrom:to:
Claus Gittinger <cg@exept.de>
parents: 350
diff changeset
   872
     r := RunArray withAll:#(1 2 3 3 3 3 4 4 4 5 6 7 7 7 7 7 7 7).
e6902ee52702 added #copyFrom:to:
Claus Gittinger <cg@exept.de>
parents: 350
diff changeset
   873
     r copyFrom:1 to:10  
e6902ee52702 added #copyFrom:to:
Claus Gittinger <cg@exept.de>
parents: 350
diff changeset
   874
e6902ee52702 added #copyFrom:to:
Claus Gittinger <cg@exept.de>
parents: 350
diff changeset
   875
     |r|
e6902ee52702 added #copyFrom:to:
Claus Gittinger <cg@exept.de>
parents: 350
diff changeset
   876
     r := RunArray withAll:#(1 2 3 3 3 3 3 3 4 5 6 7 7 7 7 7 7 7).
e6902ee52702 added #copyFrom:to:
Claus Gittinger <cg@exept.de>
parents: 350
diff changeset
   877
     r copyFrom:4 to:10       
e6902ee52702 added #copyFrom:to:
Claus Gittinger <cg@exept.de>
parents: 350
diff changeset
   878
e6902ee52702 added #copyFrom:to:
Claus Gittinger <cg@exept.de>
parents: 350
diff changeset
   879
     |r|
e6902ee52702 added #copyFrom:to:
Claus Gittinger <cg@exept.de>
parents: 350
diff changeset
   880
     r := RunArray withAll:#(1 2 3 3 3 3 3 3 4 5 6 7 7 7 7 7 7 7).
e6902ee52702 added #copyFrom:to:
Claus Gittinger <cg@exept.de>
parents: 350
diff changeset
   881
     r copyFrom:1 to:20      
e6902ee52702 added #copyFrom:to:
Claus Gittinger <cg@exept.de>
parents: 350
diff changeset
   882
    "
e6902ee52702 added #copyFrom:to:
Claus Gittinger <cg@exept.de>
parents: 350
diff changeset
   883
4776
7259a694e36d #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 4775
diff changeset
   884
    "Modified: / 18-05-1996 / 19:28:47 / cg"
7259a694e36d #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 4775
diff changeset
   885
    "Modified: / 11-12-2018 / 20:59:27 / Claus Gittinger"
4956
f5404f992dc1 #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 4921
diff changeset
   886
! !
f5404f992dc1 #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 4921
diff changeset
   887
f5404f992dc1 #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 4921
diff changeset
   888
!RunArray methodsFor:'copying-private'!
3597
6b1167c90973 class: RunArray
Claus Gittinger <cg@exept.de>
parents: 3593
diff changeset
   889
6b1167c90973 class: RunArray
Claus Gittinger <cg@exept.de>
parents: 3593
diff changeset
   890
postCopy
6b1167c90973 class: RunArray
Claus Gittinger <cg@exept.de>
parents: 3593
diff changeset
   891
    contentsArray := contentsArray copy.
352
e6902ee52702 added #copyFrom:to:
Claus Gittinger <cg@exept.de>
parents: 350
diff changeset
   892
! !
e6902ee52702 added #copyFrom:to:
Claus Gittinger <cg@exept.de>
parents: 350
diff changeset
   893
297
9526ea90d4f9 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   894
!RunArray methodsFor:'enumerating'!
9526ea90d4f9 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   895
3117
21453eeba760 class: RunArray
Claus Gittinger <cg@exept.de>
parents: 3008
diff changeset
   896
conform:aBlock 
21453eeba760 class: RunArray
Claus Gittinger <cg@exept.de>
parents: 3008
diff changeset
   897
    "return true, if every element conforms to some condition.
21453eeba760 class: RunArray
Claus Gittinger <cg@exept.de>
parents: 3008
diff changeset
   898
     I.e. return false, if aBlock returns false for any element;
21453eeba760 class: RunArray
Claus Gittinger <cg@exept.de>
parents: 3008
diff changeset
   899
     true otherwise. Returns true for empty receivers."
21453eeba760 class: RunArray
Claus Gittinger <cg@exept.de>
parents: 3008
diff changeset
   900
21453eeba760 class: RunArray
Claus Gittinger <cg@exept.de>
parents: 3008
diff changeset
   901
    "/ redefined to not check individual elements, but runs
21453eeba760 class: RunArray
Claus Gittinger <cg@exept.de>
parents: 3008
diff changeset
   902
    contentsArray notNil ifTrue:[
21453eeba760 class: RunArray
Claus Gittinger <cg@exept.de>
parents: 3008
diff changeset
   903
        contentsArray pairWiseDo:[:len :val | 
21453eeba760 class: RunArray
Claus Gittinger <cg@exept.de>
parents: 3008
diff changeset
   904
            (aBlock value:val) ifFalse:[^ false].
21453eeba760 class: RunArray
Claus Gittinger <cg@exept.de>
parents: 3008
diff changeset
   905
        ]
21453eeba760 class: RunArray
Claus Gittinger <cg@exept.de>
parents: 3008
diff changeset
   906
    ].
21453eeba760 class: RunArray
Claus Gittinger <cg@exept.de>
parents: 3008
diff changeset
   907
    ^ true
21453eeba760 class: RunArray
Claus Gittinger <cg@exept.de>
parents: 3008
diff changeset
   908
!
21453eeba760 class: RunArray
Claus Gittinger <cg@exept.de>
parents: 3008
diff changeset
   909
3593
3476aa995618 class: RunArray
Claus Gittinger <cg@exept.de>
parents: 3323
diff changeset
   910
contains:aBlock 
3476aa995618 class: RunArray
Claus Gittinger <cg@exept.de>
parents: 3323
diff changeset
   911
    "Return true, if aBlock returns true for any of the receiver's elements"
3476aa995618 class: RunArray
Claus Gittinger <cg@exept.de>
parents: 3323
diff changeset
   912
3476aa995618 class: RunArray
Claus Gittinger <cg@exept.de>
parents: 3323
diff changeset
   913
    contentsArray notNil ifTrue:[
3476aa995618 class: RunArray
Claus Gittinger <cg@exept.de>
parents: 3323
diff changeset
   914
        contentsArray pairWiseDo:[:len :val | 
3476aa995618 class: RunArray
Claus Gittinger <cg@exept.de>
parents: 3323
diff changeset
   915
            (aBlock value:val) ifTrue:[^ true].
3476aa995618 class: RunArray
Claus Gittinger <cg@exept.de>
parents: 3323
diff changeset
   916
        ].
3476aa995618 class: RunArray
Claus Gittinger <cg@exept.de>
parents: 3323
diff changeset
   917
    ].    
3476aa995618 class: RunArray
Claus Gittinger <cg@exept.de>
parents: 3323
diff changeset
   918
    ^ false
3476aa995618 class: RunArray
Claus Gittinger <cg@exept.de>
parents: 3323
diff changeset
   919
!
3476aa995618 class: RunArray
Claus Gittinger <cg@exept.de>
parents: 3323
diff changeset
   920
297
9526ea90d4f9 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   921
do:aBlock 
9526ea90d4f9 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   922
    "Evaluate aBlock with each of the receiver's elements as the 
9526ea90d4f9 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   923
    argument. "
9526ea90d4f9 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   924
299
2b891872f0af comments
Claus Gittinger <cg@exept.de>
parents: 298
diff changeset
   925
    contentsArray notNil ifTrue:[
2b891872f0af comments
Claus Gittinger <cg@exept.de>
parents: 298
diff changeset
   926
        contentsArray pairWiseDo:[:len :val | 
588
677527917896 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 450
diff changeset
   927
            len timesRepeat:[aBlock value:val]
297
9526ea90d4f9 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   928
        ]
9526ea90d4f9 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   929
    ]
9526ea90d4f9 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   930
588
677527917896 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 450
diff changeset
   931
    "Modified: / 30.10.1997 / 15:53:37 / cg"
305
9d20b26c1e1a fix & added #runsDo:
Claus Gittinger <cg@exept.de>
parents: 303
diff changeset
   932
!
9d20b26c1e1a fix & added #runsDo:
Claus Gittinger <cg@exept.de>
parents: 303
diff changeset
   933
9d20b26c1e1a fix & added #runsDo:
Claus Gittinger <cg@exept.de>
parents: 303
diff changeset
   934
runsDo:aBlock 
3593
3476aa995618 class: RunArray
Claus Gittinger <cg@exept.de>
parents: 3323
diff changeset
   935
    "Evaluate aBlock with each of the receiver's runs, 
3476aa995618 class: RunArray
Claus Gittinger <cg@exept.de>
parents: 3323
diff changeset
   936
     passing length and value as arguments."
305
9d20b26c1e1a fix & added #runsDo:
Claus Gittinger <cg@exept.de>
parents: 303
diff changeset
   937
9d20b26c1e1a fix & added #runsDo:
Claus Gittinger <cg@exept.de>
parents: 303
diff changeset
   938
    contentsArray notNil ifTrue:[
9d20b26c1e1a fix & added #runsDo:
Claus Gittinger <cg@exept.de>
parents: 303
diff changeset
   939
        contentsArray pairWiseDo:aBlock
9d20b26c1e1a fix & added #runsDo:
Claus Gittinger <cg@exept.de>
parents: 303
diff changeset
   940
    ]
9d20b26c1e1a fix & added #runsDo:
Claus Gittinger <cg@exept.de>
parents: 303
diff changeset
   941
9d20b26c1e1a fix & added #runsDo:
Claus Gittinger <cg@exept.de>
parents: 303
diff changeset
   942
    "Modified: 11.5.1996 / 13:35:03 / cg"
9d20b26c1e1a fix & added #runsDo:
Claus Gittinger <cg@exept.de>
parents: 303
diff changeset
   943
    "Created: 12.5.1996 / 11:06:51 / cg"
2960
c197b9f70ccf class: RunArray
Claus Gittinger <cg@exept.de>
parents: 2930
diff changeset
   944
!
c197b9f70ccf class: RunArray
Claus Gittinger <cg@exept.de>
parents: 2930
diff changeset
   945
c197b9f70ccf class: RunArray
Claus Gittinger <cg@exept.de>
parents: 2930
diff changeset
   946
withStartStopAndValueDo:aThreeArgBlock
c197b9f70ccf class: RunArray
Claus Gittinger <cg@exept.de>
parents: 2930
diff changeset
   947
    "Evaluate aBlock with each of the receiver's runs, passing
c197b9f70ccf class: RunArray
Claus Gittinger <cg@exept.de>
parents: 2930
diff changeset
   948
     start, end and attributes as arguments."
c197b9f70ccf class: RunArray
Claus Gittinger <cg@exept.de>
parents: 2930
diff changeset
   949
c197b9f70ccf class: RunArray
Claus Gittinger <cg@exept.de>
parents: 2930
diff changeset
   950
    |idx|
c197b9f70ccf class: RunArray
Claus Gittinger <cg@exept.de>
parents: 2930
diff changeset
   951
c197b9f70ccf class: RunArray
Claus Gittinger <cg@exept.de>
parents: 2930
diff changeset
   952
    contentsArray notNil ifTrue:[
c197b9f70ccf class: RunArray
Claus Gittinger <cg@exept.de>
parents: 2930
diff changeset
   953
        idx := 1.
c197b9f70ccf class: RunArray
Claus Gittinger <cg@exept.de>
parents: 2930
diff changeset
   954
        contentsArray pairWiseDo:[:count :emp |
c197b9f70ccf class: RunArray
Claus Gittinger <cg@exept.de>
parents: 2930
diff changeset
   955
            aThreeArgBlock value:idx value:(idx+count-1) value:emp     
c197b9f70ccf class: RunArray
Claus Gittinger <cg@exept.de>
parents: 2930
diff changeset
   956
        ]
c197b9f70ccf class: RunArray
Claus Gittinger <cg@exept.de>
parents: 2930
diff changeset
   957
    ]
297
9526ea90d4f9 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   958
! !
9526ea90d4f9 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   959
3593
3476aa995618 class: RunArray
Claus Gittinger <cg@exept.de>
parents: 3323
diff changeset
   960
303
b30b08669004 example
Claus Gittinger <cg@exept.de>
parents: 302
diff changeset
   961
!RunArray methodsFor:'printing & storing'!
297
9526ea90d4f9 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   962
2127
dc0da410f2d7 new: #displayOn:
Stefan Vogel <sv@exept.de>
parents: 2049
diff changeset
   963
displayOn:aGCOrStream 
dc0da410f2d7 new: #displayOn:
Stefan Vogel <sv@exept.de>
parents: 2049
diff changeset
   964
    "Append to aStream an expression which, if evaluated, will generate   
dc0da410f2d7 new: #displayOn:
Stefan Vogel <sv@exept.de>
parents: 2049
diff changeset
   965
    an object similar to the receiver."
dc0da410f2d7 new: #displayOn:
Stefan Vogel <sv@exept.de>
parents: 2049
diff changeset
   966
dc0da410f2d7 new: #displayOn:
Stefan Vogel <sv@exept.de>
parents: 2049
diff changeset
   967
    "/ what a kludge - Dolphin and Squeak mean: printOn: a stream;
4349
797fa75798d0 #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 4318
diff changeset
   968
    "/ old ST80 means: draw-yourself on a GC.
3323
f1239164bea5 displayOn: cleanup
Claus Gittinger <cg@exept.de>
parents: 3208
diff changeset
   969
    (aGCOrStream isStream) ifTrue:[
2127
dc0da410f2d7 new: #displayOn:
Stefan Vogel <sv@exept.de>
parents: 2049
diff changeset
   970
        aGCOrStream nextPutAll: '(RunArray new'.
dc0da410f2d7 new: #displayOn:
Stefan Vogel <sv@exept.de>
parents: 2049
diff changeset
   971
        contentsArray notNil ifTrue:[
dc0da410f2d7 new: #displayOn:
Stefan Vogel <sv@exept.de>
parents: 2049
diff changeset
   972
            contentsArray pairWiseDo:[:len :val | 
dc0da410f2d7 new: #displayOn:
Stefan Vogel <sv@exept.de>
parents: 2049
diff changeset
   973
                aGCOrStream nextPutAll: ' add:'. val displayOn:aGCOrStream. 
dc0da410f2d7 new: #displayOn:
Stefan Vogel <sv@exept.de>
parents: 2049
diff changeset
   974
                len == 1 ifFalse:[
dc0da410f2d7 new: #displayOn:
Stefan Vogel <sv@exept.de>
parents: 2049
diff changeset
   975
                    aGCOrStream nextPutAll:' withOccurrences:'. len printOn:aGCOrStream.
dc0da410f2d7 new: #displayOn:
Stefan Vogel <sv@exept.de>
parents: 2049
diff changeset
   976
                ].
dc0da410f2d7 new: #displayOn:
Stefan Vogel <sv@exept.de>
parents: 2049
diff changeset
   977
                aGCOrStream nextPutAll:';'
dc0da410f2d7 new: #displayOn:
Stefan Vogel <sv@exept.de>
parents: 2049
diff changeset
   978
            ].
dc0da410f2d7 new: #displayOn:
Stefan Vogel <sv@exept.de>
parents: 2049
diff changeset
   979
            aGCOrStream nextPutAll:' yourself'
dc0da410f2d7 new: #displayOn:
Stefan Vogel <sv@exept.de>
parents: 2049
diff changeset
   980
        ].
dc0da410f2d7 new: #displayOn:
Stefan Vogel <sv@exept.de>
parents: 2049
diff changeset
   981
        aGCOrStream nextPutAll:')'.
dc0da410f2d7 new: #displayOn:
Stefan Vogel <sv@exept.de>
parents: 2049
diff changeset
   982
        ^ self.
dc0da410f2d7 new: #displayOn:
Stefan Vogel <sv@exept.de>
parents: 2049
diff changeset
   983
    ].
dc0da410f2d7 new: #displayOn:
Stefan Vogel <sv@exept.de>
parents: 2049
diff changeset
   984
    ^ self displayOn:aGCOrStream x:0 y:0.
dc0da410f2d7 new: #displayOn:
Stefan Vogel <sv@exept.de>
parents: 2049
diff changeset
   985
dc0da410f2d7 new: #displayOn:
Stefan Vogel <sv@exept.de>
parents: 2049
diff changeset
   986
    "
dc0da410f2d7 new: #displayOn:
Stefan Vogel <sv@exept.de>
parents: 2049
diff changeset
   987
     (RunArray new 
dc0da410f2d7 new: #displayOn:
Stefan Vogel <sv@exept.de>
parents: 2049
diff changeset
   988
        add:1; 
dc0da410f2d7 new: #displayOn:
Stefan Vogel <sv@exept.de>
parents: 2049
diff changeset
   989
        add:1; 
dc0da410f2d7 new: #displayOn:
Stefan Vogel <sv@exept.de>
parents: 2049
diff changeset
   990
        add:2; 
dc0da410f2d7 new: #displayOn:
Stefan Vogel <sv@exept.de>
parents: 2049
diff changeset
   991
        add:3; 
dc0da410f2d7 new: #displayOn:
Stefan Vogel <sv@exept.de>
parents: 2049
diff changeset
   992
        add:4 withOccurrences:100; 
dc0da410f2d7 new: #displayOn:
Stefan Vogel <sv@exept.de>
parents: 2049
diff changeset
   993
        add:5; 
dc0da410f2d7 new: #displayOn:
Stefan Vogel <sv@exept.de>
parents: 2049
diff changeset
   994
        yourself) displayString 
dc0da410f2d7 new: #displayOn:
Stefan Vogel <sv@exept.de>
parents: 2049
diff changeset
   995
dc0da410f2d7 new: #displayOn:
Stefan Vogel <sv@exept.de>
parents: 2049
diff changeset
   996
     RunArray new displayString 
dc0da410f2d7 new: #displayOn:
Stefan Vogel <sv@exept.de>
parents: 2049
diff changeset
   997
    "
4349
797fa75798d0 #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 4318
diff changeset
   998
797fa75798d0 #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 4318
diff changeset
   999
    "Modified (comment): / 22-02-2017 / 16:49:50 / cg"
2127
dc0da410f2d7 new: #displayOn:
Stefan Vogel <sv@exept.de>
parents: 2049
diff changeset
  1000
!
dc0da410f2d7 new: #displayOn:
Stefan Vogel <sv@exept.de>
parents: 2049
diff changeset
  1001
297
9526ea90d4f9 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1002
storeOn:aStream 
9526ea90d4f9 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1003
    "Append to aStream an expression which, if evaluated, will generate   
9526ea90d4f9 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1004
    an object similar to the receiver."
9526ea90d4f9 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1005
9526ea90d4f9 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1006
    aStream nextPutAll: '(RunArray new'.
299
2b891872f0af comments
Claus Gittinger <cg@exept.de>
parents: 298
diff changeset
  1007
    contentsArray notNil ifTrue:[
2b891872f0af comments
Claus Gittinger <cg@exept.de>
parents: 298
diff changeset
  1008
        contentsArray pairWiseDo:[:len :val | 
2127
dc0da410f2d7 new: #displayOn:
Stefan Vogel <sv@exept.de>
parents: 2049
diff changeset
  1009
            aStream nextPutAll: ' add:'. val storeOn:aStream. 
297
9526ea90d4f9 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1010
            len == 1 ifFalse:[
2127
dc0da410f2d7 new: #displayOn:
Stefan Vogel <sv@exept.de>
parents: 2049
diff changeset
  1011
                aStream nextPutAll:' withOccurrences:'. len printOn:aStream.
297
9526ea90d4f9 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1012
            ].
9526ea90d4f9 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1013
            aStream nextPutAll:';'
9526ea90d4f9 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1014
        ].
9526ea90d4f9 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1015
        aStream nextPutAll:' yourself'
9526ea90d4f9 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1016
    ].
9526ea90d4f9 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1017
    aStream nextPutAll:')'
9526ea90d4f9 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1018
9526ea90d4f9 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1019
    "
9526ea90d4f9 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1020
     (RunArray new 
9526ea90d4f9 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1021
        add:1; 
9526ea90d4f9 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1022
        add:1; 
9526ea90d4f9 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1023
        add:2; 
9526ea90d4f9 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1024
        add:3; 
303
b30b08669004 example
Claus Gittinger <cg@exept.de>
parents: 302
diff changeset
  1025
        add:4 withOccurrences:100; 
297
9526ea90d4f9 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1026
        add:5; 
303
b30b08669004 example
Claus Gittinger <cg@exept.de>
parents: 302
diff changeset
  1027
        yourself) storeString 
297
9526ea90d4f9 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1028
9526ea90d4f9 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1029
     RunArray new storeString 
9526ea90d4f9 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1030
    "
299
2b891872f0af comments
Claus Gittinger <cg@exept.de>
parents: 298
diff changeset
  1031
303
b30b08669004 example
Claus Gittinger <cg@exept.de>
parents: 302
diff changeset
  1032
    "Modified: 11.5.1996 / 14:28:38 / cg"
297
9526ea90d4f9 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1033
! !
9526ea90d4f9 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1034
9526ea90d4f9 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1035
!RunArray methodsFor:'private'!
9526ea90d4f9 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1036
9526ea90d4f9 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1037
find:oldObject 
9526ea90d4f9 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1038
    "If I contain oldObject return its index, otherwise create an error   
588
677527917896 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 450
diff changeset
  1039
     notifier. It will answer with the position of the very first element of  
677527917896 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 450
diff changeset
  1040
     that value.
677527917896 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 450
diff changeset
  1041
     OBSOLETE: this is a leftover from earlier times; use #indexOf:ifAbsent:"
297
9526ea90d4f9 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1042
966
dd7e0a32bcc1 Use <resource:#obsolete>
Stefan Vogel <sv@exept.de>
parents: 906
diff changeset
  1043
    <resource:#obsolete>
dd7e0a32bcc1 Use <resource:#obsolete>
Stefan Vogel <sv@exept.de>
parents: 906
diff changeset
  1044
588
677527917896 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 450
diff changeset
  1045
    |idx|
297
9526ea90d4f9 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1046
588
677527917896 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 450
diff changeset
  1047
    self obsoleteMethodWarning:'use #indexOf:ifAbsent:'.
677527917896 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 450
diff changeset
  1048
    idx := self indexOf:oldObject ifAbsent:0.
677527917896 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 450
diff changeset
  1049
    idx ~~ 0 ifTrue:[^ idx].
677527917896 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 450
diff changeset
  1050
    ^ self errorValueNotFound:oldObject
297
9526ea90d4f9 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1051
9526ea90d4f9 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1052
    "
9526ea90d4f9 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1053
     |c|
9526ea90d4f9 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1054
9526ea90d4f9 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1055
     c := RunArray new.
9526ea90d4f9 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1056
     c add:1; add:1; add:1; add:2; add:2; add:3; add:3; add:4; add:5.
9526ea90d4f9 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1057
     c find:2.
9526ea90d4f9 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1058
9526ea90d4f9 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1059
     c find:99
9526ea90d4f9 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1060
    "
9526ea90d4f9 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1061
588
677527917896 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 450
diff changeset
  1062
    "Modified: / 30.10.1997 / 15:51:38 / cg"
297
9526ea90d4f9 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1063
!
9526ea90d4f9 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1064
9526ea90d4f9 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1065
find:oldObject ifAbsent:exceptionBlock 
9526ea90d4f9 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1066
    "If I contain oldObject return its index, otherwise execute the 
9526ea90d4f9 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1067
     exception block. It will answer with the position of the very first 
588
677527917896 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 450
diff changeset
  1068
     element of that value.
677527917896 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 450
diff changeset
  1069
     OBSOLETE: this is a leftover from earlier times; use #indexOf:ifAbsent:"
297
9526ea90d4f9 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1070
966
dd7e0a32bcc1 Use <resource:#obsolete>
Stefan Vogel <sv@exept.de>
parents: 906
diff changeset
  1071
    <resource:#obsolete>
dd7e0a32bcc1 Use <resource:#obsolete>
Stefan Vogel <sv@exept.de>
parents: 906
diff changeset
  1072
588
677527917896 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 450
diff changeset
  1073
    self obsoleteMethodWarning:'use #indexOf:'.
677527917896 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 450
diff changeset
  1074
    ^ self indexOf:oldObject ifAbsent:exceptionBlock
297
9526ea90d4f9 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1075
588
677527917896 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 450
diff changeset
  1076
    "Modified: / 30.10.1997 / 15:49:54 / cg"
297
9526ea90d4f9 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1077
!
9526ea90d4f9 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1078
892
90a4022c52a1 faster compare
Claus Gittinger <cg@exept.de>
parents: 871
diff changeset
  1079
getContentsArray
90a4022c52a1 faster compare
Claus Gittinger <cg@exept.de>
parents: 871
diff changeset
  1080
    ^ contentsArray
90a4022c52a1 faster compare
Claus Gittinger <cg@exept.de>
parents: 871
diff changeset
  1081
!
90a4022c52a1 faster compare
Claus Gittinger <cg@exept.de>
parents: 871
diff changeset
  1082
297
9526ea90d4f9 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1083
runIndexAndStartIndexForIndex:anIndex
9526ea90d4f9 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1084
    "given a logical index, find the index of that run and the logical index
9526ea90d4f9 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1085
     of the first item in that run."
9526ea90d4f9 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1086
9526ea90d4f9 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1087
    |position nRuns "{ Class: SmallInteger }"|
9526ea90d4f9 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1088
9526ea90d4f9 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1089
    position := 1.
299
2b891872f0af comments
Claus Gittinger <cg@exept.de>
parents: 298
diff changeset
  1090
    nRuns := contentsArray size.
297
9526ea90d4f9 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1091
    1 to:nRuns by:2 do:[:runIndex | 
9526ea90d4f9 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1092
        |runLen runLast|
9526ea90d4f9 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1093
299
2b891872f0af comments
Claus Gittinger <cg@exept.de>
parents: 298
diff changeset
  1094
        runLen := contentsArray at:runIndex.
297
9526ea90d4f9 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1095
        anIndex >= position ifTrue:[
9526ea90d4f9 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1096
            runLast := position + runLen - 1.
9526ea90d4f9 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1097
            anIndex <= runLast ifTrue:[
9526ea90d4f9 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1098
                ^ Array with:runIndex with:position 
9526ea90d4f9 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1099
            ].
9526ea90d4f9 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1100
        ].
9526ea90d4f9 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1101
        position := position + runLen
9526ea90d4f9 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1102
    ].
9526ea90d4f9 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1103
9526ea90d4f9 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1104
    ^ #(0 0)
9526ea90d4f9 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1105
9526ea90d4f9 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1106
    "Created: 10.5.1996 / 17:12:28 / cg"
299
2b891872f0af comments
Claus Gittinger <cg@exept.de>
parents: 298
diff changeset
  1107
    "Modified: 11.5.1996 / 13:35:21 / cg"
302
223e660708b2 added #new:withAll:
Claus Gittinger <cg@exept.de>
parents: 300
diff changeset
  1108
!
223e660708b2 added #new:withAll:
Claus Gittinger <cg@exept.de>
parents: 300
diff changeset
  1109
223e660708b2 added #new:withAll:
Claus Gittinger <cg@exept.de>
parents: 300
diff changeset
  1110
setElement:newObject occurrences:n
223e660708b2 added #new:withAll:
Claus Gittinger <cg@exept.de>
parents: 300
diff changeset
  1111
    "private instance setup"
223e660708b2 added #new:withAll:
Claus Gittinger <cg@exept.de>
parents: 300
diff changeset
  1112
223e660708b2 added #new:withAll:
Claus Gittinger <cg@exept.de>
parents: 300
diff changeset
  1113
    contentsArray := Array with:n with:newObject.
223e660708b2 added #new:withAll:
Claus Gittinger <cg@exept.de>
parents: 300
diff changeset
  1114
223e660708b2 added #new:withAll:
Claus Gittinger <cg@exept.de>
parents: 300
diff changeset
  1115
    "Created: 11.5.1996 / 14:05:58 / cg"
630
55973d9fee59 added #from: instance creation method.
Claus Gittinger <cg@exept.de>
parents: 588
diff changeset
  1116
!
55973d9fee59 added #from: instance creation method.
Claus Gittinger <cg@exept.de>
parents: 588
diff changeset
  1117
55973d9fee59 added #from: instance creation method.
Claus Gittinger <cg@exept.de>
parents: 588
diff changeset
  1118
setElementsFrom:aCollection
55973d9fee59 added #from: instance creation method.
Claus Gittinger <cg@exept.de>
parents: 588
diff changeset
  1119
    "set my elements from aCollection"
55973d9fee59 added #from: instance creation method.
Claus Gittinger <cg@exept.de>
parents: 588
diff changeset
  1120
55973d9fee59 added #from: instance creation method.
Claus Gittinger <cg@exept.de>
parents: 588
diff changeset
  1121
    |nRuns last runLen first dIdx|
55973d9fee59 added #from: instance creation method.
Claus Gittinger <cg@exept.de>
parents: 588
diff changeset
  1122
55973d9fee59 added #from: instance creation method.
Claus Gittinger <cg@exept.de>
parents: 588
diff changeset
  1123
    aCollection size == 0 ifTrue:[^ self].
55973d9fee59 added #from: instance creation method.
Claus Gittinger <cg@exept.de>
parents: 588
diff changeset
  1124
55973d9fee59 added #from: instance creation method.
Claus Gittinger <cg@exept.de>
parents: 588
diff changeset
  1125
    nRuns := 0.
55973d9fee59 added #from: instance creation method.
Claus Gittinger <cg@exept.de>
parents: 588
diff changeset
  1126
    first := true.
55973d9fee59 added #from: instance creation method.
Claus Gittinger <cg@exept.de>
parents: 588
diff changeset
  1127
    aCollection do:[:element |
55973d9fee59 added #from: instance creation method.
Claus Gittinger <cg@exept.de>
parents: 588
diff changeset
  1128
        first ifTrue:[
55973d9fee59 added #from: instance creation method.
Claus Gittinger <cg@exept.de>
parents: 588
diff changeset
  1129
            nRuns := nRuns + 1.
55973d9fee59 added #from: instance creation method.
Claus Gittinger <cg@exept.de>
parents: 588
diff changeset
  1130
            last := element.
55973d9fee59 added #from: instance creation method.
Claus Gittinger <cg@exept.de>
parents: 588
diff changeset
  1131
            first := false.
55973d9fee59 added #from: instance creation method.
Claus Gittinger <cg@exept.de>
parents: 588
diff changeset
  1132
        ] ifFalse:[
55973d9fee59 added #from: instance creation method.
Claus Gittinger <cg@exept.de>
parents: 588
diff changeset
  1133
            element ~~ last ifTrue:[
55973d9fee59 added #from: instance creation method.
Claus Gittinger <cg@exept.de>
parents: 588
diff changeset
  1134
                nRuns := nRuns + 1.
55973d9fee59 added #from: instance creation method.
Claus Gittinger <cg@exept.de>
parents: 588
diff changeset
  1135
                last := element.
55973d9fee59 added #from: instance creation method.
Claus Gittinger <cg@exept.de>
parents: 588
diff changeset
  1136
            ]
55973d9fee59 added #from: instance creation method.
Claus Gittinger <cg@exept.de>
parents: 588
diff changeset
  1137
        ]
55973d9fee59 added #from: instance creation method.
Claus Gittinger <cg@exept.de>
parents: 588
diff changeset
  1138
    ].
55973d9fee59 added #from: instance creation method.
Claus Gittinger <cg@exept.de>
parents: 588
diff changeset
  1139
55973d9fee59 added #from: instance creation method.
Claus Gittinger <cg@exept.de>
parents: 588
diff changeset
  1140
    "/ now, we know how many runs there are ...
55973d9fee59 added #from: instance creation method.
Claus Gittinger <cg@exept.de>
parents: 588
diff changeset
  1141
    contentsArray := Array new:(nRuns*2).
55973d9fee59 added #from: instance creation method.
Claus Gittinger <cg@exept.de>
parents: 588
diff changeset
  1142
55973d9fee59 added #from: instance creation method.
Claus Gittinger <cg@exept.de>
parents: 588
diff changeset
  1143
    nRuns := 0.
55973d9fee59 added #from: instance creation method.
Claus Gittinger <cg@exept.de>
parents: 588
diff changeset
  1144
    runLen := 0.
55973d9fee59 added #from: instance creation method.
Claus Gittinger <cg@exept.de>
parents: 588
diff changeset
  1145
    dIdx := 1.
55973d9fee59 added #from: instance creation method.
Claus Gittinger <cg@exept.de>
parents: 588
diff changeset
  1146
    aCollection do:[:element |
55973d9fee59 added #from: instance creation method.
Claus Gittinger <cg@exept.de>
parents: 588
diff changeset
  1147
        runLen == 0 ifTrue:[
55973d9fee59 added #from: instance creation method.
Claus Gittinger <cg@exept.de>
parents: 588
diff changeset
  1148
            last := element.
55973d9fee59 added #from: instance creation method.
Claus Gittinger <cg@exept.de>
parents: 588
diff changeset
  1149
            runLen := 1.
55973d9fee59 added #from: instance creation method.
Claus Gittinger <cg@exept.de>
parents: 588
diff changeset
  1150
        ] ifFalse:[
55973d9fee59 added #from: instance creation method.
Claus Gittinger <cg@exept.de>
parents: 588
diff changeset
  1151
            element == last ifTrue:[
55973d9fee59 added #from: instance creation method.
Claus Gittinger <cg@exept.de>
parents: 588
diff changeset
  1152
                runLen := runLen + 1.
55973d9fee59 added #from: instance creation method.
Claus Gittinger <cg@exept.de>
parents: 588
diff changeset
  1153
            ] ifFalse:[
55973d9fee59 added #from: instance creation method.
Claus Gittinger <cg@exept.de>
parents: 588
diff changeset
  1154
                contentsArray at:dIdx   put:runLen.
55973d9fee59 added #from: instance creation method.
Claus Gittinger <cg@exept.de>
parents: 588
diff changeset
  1155
                contentsArray at:dIdx+1 put:last.
55973d9fee59 added #from: instance creation method.
Claus Gittinger <cg@exept.de>
parents: 588
diff changeset
  1156
                dIdx := dIdx + 2.
55973d9fee59 added #from: instance creation method.
Claus Gittinger <cg@exept.de>
parents: 588
diff changeset
  1157
                runLen := 1.
55973d9fee59 added #from: instance creation method.
Claus Gittinger <cg@exept.de>
parents: 588
diff changeset
  1158
                last := element.
55973d9fee59 added #from: instance creation method.
Claus Gittinger <cg@exept.de>
parents: 588
diff changeset
  1159
            ]
55973d9fee59 added #from: instance creation method.
Claus Gittinger <cg@exept.de>
parents: 588
diff changeset
  1160
        ]
55973d9fee59 added #from: instance creation method.
Claus Gittinger <cg@exept.de>
parents: 588
diff changeset
  1161
    ].
55973d9fee59 added #from: instance creation method.
Claus Gittinger <cg@exept.de>
parents: 588
diff changeset
  1162
    runLen ~~ 0 ifTrue:[
55973d9fee59 added #from: instance creation method.
Claus Gittinger <cg@exept.de>
parents: 588
diff changeset
  1163
        contentsArray at:dIdx   put:runLen.
55973d9fee59 added #from: instance creation method.
Claus Gittinger <cg@exept.de>
parents: 588
diff changeset
  1164
        contentsArray at:dIdx+1 put:last.
55973d9fee59 added #from: instance creation method.
Claus Gittinger <cg@exept.de>
parents: 588
diff changeset
  1165
    ].
55973d9fee59 added #from: instance creation method.
Claus Gittinger <cg@exept.de>
parents: 588
diff changeset
  1166
55973d9fee59 added #from: instance creation method.
Claus Gittinger <cg@exept.de>
parents: 588
diff changeset
  1167
    "
55973d9fee59 added #from: instance creation method.
Claus Gittinger <cg@exept.de>
parents: 588
diff changeset
  1168
     RunArray from:#(1 2 3 3 3 4 5 5 6 6 6 6 6 6)
55973d9fee59 added #from: instance creation method.
Claus Gittinger <cg@exept.de>
parents: 588
diff changeset
  1169
    "
55973d9fee59 added #from: instance creation method.
Claus Gittinger <cg@exept.de>
parents: 588
diff changeset
  1170
4571
2a2de2cb4b1b #DOCUMENTATION by mawalch
mawalch
parents: 4349
diff changeset
  1171
    "Modified: / 07-04-1998 / 09:33:57 / cg"
2a2de2cb4b1b #DOCUMENTATION by mawalch
mawalch
parents: 4349
diff changeset
  1172
    "Modified (comment): / 25-01-2018 / 20:42:15 / mawalch"
4775
03b9f6efd595 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 4756
diff changeset
  1173
    "Modified (comment): / 11-12-2018 / 11:50:37 / Claus Gittinger"
871
b44445dc4ac6 new instCreation method
Claus Gittinger <cg@exept.de>
parents: 630
diff changeset
  1174
!
b44445dc4ac6 new instCreation method
Claus Gittinger <cg@exept.de>
parents: 630
diff changeset
  1175
b44445dc4ac6 new instCreation method
Claus Gittinger <cg@exept.de>
parents: 630
diff changeset
  1176
setElementsFromRuns:runs values:values
1451
2b4bb1522872 Mark obsolete methods
Stefan Vogel <sv@exept.de>
parents: 1325
diff changeset
  1177
    <resource:#obsolete>
1325
1c503fd677a7 runs values for VW compatibility
Claus Gittinger <cg@exept.de>
parents: 966
diff changeset
  1178
    self obsoleteMethodWarning:'use #setRuns:setValues: for VW compatibility'.
1c503fd677a7 runs values for VW compatibility
Claus Gittinger <cg@exept.de>
parents: 966
diff changeset
  1179
    self setRuns:runs setValues:values
1c503fd677a7 runs values for VW compatibility
Claus Gittinger <cg@exept.de>
parents: 966
diff changeset
  1180
!
1c503fd677a7 runs values for VW compatibility
Claus Gittinger <cg@exept.de>
parents: 966
diff changeset
  1181
1c503fd677a7 runs values for VW compatibility
Claus Gittinger <cg@exept.de>
parents: 966
diff changeset
  1182
setRuns:runs setValues:values
871
b44445dc4ac6 new instCreation method
Claus Gittinger <cg@exept.de>
parents: 630
diff changeset
  1183
    |idx|
b44445dc4ac6 new instCreation method
Claus Gittinger <cg@exept.de>
parents: 630
diff changeset
  1184
b44445dc4ac6 new instCreation method
Claus Gittinger <cg@exept.de>
parents: 630
diff changeset
  1185
    contentsArray := Array new:(runs size * 2).
b44445dc4ac6 new instCreation method
Claus Gittinger <cg@exept.de>
parents: 630
diff changeset
  1186
    idx := 1.
b44445dc4ac6 new instCreation method
Claus Gittinger <cg@exept.de>
parents: 630
diff changeset
  1187
    runs with:values do:[:length :value |
b44445dc4ac6 new instCreation method
Claus Gittinger <cg@exept.de>
parents: 630
diff changeset
  1188
        contentsArray at:idx put:length.
b44445dc4ac6 new instCreation method
Claus Gittinger <cg@exept.de>
parents: 630
diff changeset
  1189
        contentsArray at:idx+1 put:value.
b44445dc4ac6 new instCreation method
Claus Gittinger <cg@exept.de>
parents: 630
diff changeset
  1190
        idx := idx + 2.
b44445dc4ac6 new instCreation method
Claus Gittinger <cg@exept.de>
parents: 630
diff changeset
  1191
    ].
297
9526ea90d4f9 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1192
! !
9526ea90d4f9 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1193
904
f4791de2295b category change
Claus Gittinger <cg@exept.de>
parents: 895
diff changeset
  1194
!RunArray methodsFor:'private-growing'!
f4791de2295b category change
Claus Gittinger <cg@exept.de>
parents: 895
diff changeset
  1195
f4791de2295b category change
Claus Gittinger <cg@exept.de>
parents: 895
diff changeset
  1196
grow:howBig
f4791de2295b category change
Claus Gittinger <cg@exept.de>
parents: 895
diff changeset
  1197
    "grow or shrink the receiver to contain howBig elements.
f4791de2295b category change
Claus Gittinger <cg@exept.de>
parents: 895
diff changeset
  1198
     If growing, new slots will be filled (logically) with nil."
f4791de2295b category change
Claus Gittinger <cg@exept.de>
parents: 895
diff changeset
  1199
f4791de2295b category change
Claus Gittinger <cg@exept.de>
parents: 895
diff changeset
  1200
    |sz info runIndex runOffset runSz newRuns|
f4791de2295b category change
Claus Gittinger <cg@exept.de>
parents: 895
diff changeset
  1201
f4791de2295b category change
Claus Gittinger <cg@exept.de>
parents: 895
diff changeset
  1202
    sz := self size.
f4791de2295b category change
Claus Gittinger <cg@exept.de>
parents: 895
diff changeset
  1203
f4791de2295b category change
Claus Gittinger <cg@exept.de>
parents: 895
diff changeset
  1204
    howBig == sz ifTrue:[^ self].
f4791de2295b category change
Claus Gittinger <cg@exept.de>
parents: 895
diff changeset
  1205
f4791de2295b category change
Claus Gittinger <cg@exept.de>
parents: 895
diff changeset
  1206
    howBig == 0 ifTrue:[
f4791de2295b category change
Claus Gittinger <cg@exept.de>
parents: 895
diff changeset
  1207
        contentsArray := nil.
f4791de2295b category change
Claus Gittinger <cg@exept.de>
parents: 895
diff changeset
  1208
        ^ self.
f4791de2295b category change
Claus Gittinger <cg@exept.de>
parents: 895
diff changeset
  1209
    ].
f4791de2295b category change
Claus Gittinger <cg@exept.de>
parents: 895
diff changeset
  1210
f4791de2295b category change
Claus Gittinger <cg@exept.de>
parents: 895
diff changeset
  1211
    contentsArray isNil ifTrue:[
f4791de2295b category change
Claus Gittinger <cg@exept.de>
parents: 895
diff changeset
  1212
        contentsArray := Array with:howBig with:nil.
f4791de2295b category change
Claus Gittinger <cg@exept.de>
parents: 895
diff changeset
  1213
        ^ self
f4791de2295b category change
Claus Gittinger <cg@exept.de>
parents: 895
diff changeset
  1214
    ].
f4791de2295b category change
Claus Gittinger <cg@exept.de>
parents: 895
diff changeset
  1215
f4791de2295b category change
Claus Gittinger <cg@exept.de>
parents: 895
diff changeset
  1216
    runSz := contentsArray size.
f4791de2295b category change
Claus Gittinger <cg@exept.de>
parents: 895
diff changeset
  1217
f4791de2295b category change
Claus Gittinger <cg@exept.de>
parents: 895
diff changeset
  1218
    howBig > sz ifTrue:[
f4791de2295b category change
Claus Gittinger <cg@exept.de>
parents: 895
diff changeset
  1219
        newRuns := Array new:(runSz + 2).
f4791de2295b category change
Claus Gittinger <cg@exept.de>
parents: 895
diff changeset
  1220
        newRuns replaceFrom:1 to:runSz with:contentsArray startingAt:1.
f4791de2295b category change
Claus Gittinger <cg@exept.de>
parents: 895
diff changeset
  1221
        newRuns at:(runSz+1) put:(howBig - sz).
f4791de2295b category change
Claus Gittinger <cg@exept.de>
parents: 895
diff changeset
  1222
        contentsArray := newRuns.
f4791de2295b category change
Claus Gittinger <cg@exept.de>
parents: 895
diff changeset
  1223
        ^ self
f4791de2295b category change
Claus Gittinger <cg@exept.de>
parents: 895
diff changeset
  1224
    ].
f4791de2295b category change
Claus Gittinger <cg@exept.de>
parents: 895
diff changeset
  1225
f4791de2295b category change
Claus Gittinger <cg@exept.de>
parents: 895
diff changeset
  1226
    "/ shrinking; possibly cut of a run
f4791de2295b category change
Claus Gittinger <cg@exept.de>
parents: 895
diff changeset
  1227
f4791de2295b category change
Claus Gittinger <cg@exept.de>
parents: 895
diff changeset
  1228
    info := self runIndexAndStartIndexForIndex:howBig.
f4791de2295b category change
Claus Gittinger <cg@exept.de>
parents: 895
diff changeset
  1229
    runIndex := info at:1.
f4791de2295b category change
Claus Gittinger <cg@exept.de>
parents: 895
diff changeset
  1230
    runOffset := info at:2.
f4791de2295b category change
Claus Gittinger <cg@exept.de>
parents: 895
diff changeset
  1231
f4791de2295b category change
Claus Gittinger <cg@exept.de>
parents: 895
diff changeset
  1232
    howBig == (runOffset - 1) ifTrue:[
f4791de2295b category change
Claus Gittinger <cg@exept.de>
parents: 895
diff changeset
  1233
        "/ we are lucky - new size is up-to previous run
f4791de2295b category change
Claus Gittinger <cg@exept.de>
parents: 895
diff changeset
  1234
f4791de2295b category change
Claus Gittinger <cg@exept.de>
parents: 895
diff changeset
  1235
        contentsArray := contentsArray copyFrom:1 to:runIndex-1.
f4791de2295b category change
Claus Gittinger <cg@exept.de>
parents: 895
diff changeset
  1236
    ] ifFalse:[
f4791de2295b category change
Claus Gittinger <cg@exept.de>
parents: 895
diff changeset
  1237
        contentsArray := contentsArray copyFrom:1 to:(runIndex+1).
f4791de2295b category change
Claus Gittinger <cg@exept.de>
parents: 895
diff changeset
  1238
        contentsArray at:runIndex put:(howBig - runOffset + 1)
f4791de2295b category change
Claus Gittinger <cg@exept.de>
parents: 895
diff changeset
  1239
    ].
f4791de2295b category change
Claus Gittinger <cg@exept.de>
parents: 895
diff changeset
  1240
f4791de2295b category change
Claus Gittinger <cg@exept.de>
parents: 895
diff changeset
  1241
    "
f4791de2295b category change
Claus Gittinger <cg@exept.de>
parents: 895
diff changeset
  1242
     |c|
f4791de2295b category change
Claus Gittinger <cg@exept.de>
parents: 895
diff changeset
  1243
f4791de2295b category change
Claus Gittinger <cg@exept.de>
parents: 895
diff changeset
  1244
     c := RunArray new.
f4791de2295b category change
Claus Gittinger <cg@exept.de>
parents: 895
diff changeset
  1245
     c addAll:#(1 2 3 4 4 4 4 5 5 5 1 2 3); yourself.
f4791de2295b category change
Claus Gittinger <cg@exept.de>
parents: 895
diff changeset
  1246
f4791de2295b category change
Claus Gittinger <cg@exept.de>
parents: 895
diff changeset
  1247
     c grow:50; yourself.
f4791de2295b category change
Claus Gittinger <cg@exept.de>
parents: 895
diff changeset
  1248
f4791de2295b category change
Claus Gittinger <cg@exept.de>
parents: 895
diff changeset
  1249
     c grow:7; yourself.
f4791de2295b category change
Claus Gittinger <cg@exept.de>
parents: 895
diff changeset
  1250
f4791de2295b category change
Claus Gittinger <cg@exept.de>
parents: 895
diff changeset
  1251
     c grow:6; yourself.
f4791de2295b category change
Claus Gittinger <cg@exept.de>
parents: 895
diff changeset
  1252
f4791de2295b category change
Claus Gittinger <cg@exept.de>
parents: 895
diff changeset
  1253
     c grow:0; yourself.
f4791de2295b category change
Claus Gittinger <cg@exept.de>
parents: 895
diff changeset
  1254
    "
f4791de2295b category change
Claus Gittinger <cg@exept.de>
parents: 895
diff changeset
  1255
f4791de2295b category change
Claus Gittinger <cg@exept.de>
parents: 895
diff changeset
  1256
    "Modified: 11.5.1996 / 13:34:53 / cg"
f4791de2295b category change
Claus Gittinger <cg@exept.de>
parents: 895
diff changeset
  1257
! !
f4791de2295b category change
Claus Gittinger <cg@exept.de>
parents: 895
diff changeset
  1258
906
30c1ab2aee8d category change
Claus Gittinger <cg@exept.de>
parents: 904
diff changeset
  1259
!RunArray methodsFor:'queries'!
30c1ab2aee8d category change
Claus Gittinger <cg@exept.de>
parents: 904
diff changeset
  1260
4805
6e49b5b5f8c3 #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 4776
diff changeset
  1261
includes:anElement
6e49b5b5f8c3 #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 4776
diff changeset
  1262
    "return true, if the receiver includes an element which is equal
6e49b5b5f8c3 #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 4776
diff changeset
  1263
     to the argument, anElement; false otherwise.
6e49b5b5f8c3 #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 4776
diff changeset
  1264
     Redefined to prevent the inherited loop over individual accesses via #at:,
6e49b5b5f8c3 #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 4776
diff changeset
  1265
     which would be very inefficient."
6e49b5b5f8c3 #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 4776
diff changeset
  1266
6e49b5b5f8c3 #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 4776
diff changeset
  1267
    contentsArray notNil ifTrue:[
6e49b5b5f8c3 #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 4776
diff changeset
  1268
        contentsArray pairWiseDo:[:len :val |
6e49b5b5f8c3 #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 4776
diff changeset
  1269
            (anElement = val) ifTrue:[
6e49b5b5f8c3 #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 4776
diff changeset
  1270
                ^ true
6e49b5b5f8c3 #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 4776
diff changeset
  1271
            ].
6e49b5b5f8c3 #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 4776
diff changeset
  1272
        ].
6e49b5b5f8c3 #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 4776
diff changeset
  1273
    ].
6e49b5b5f8c3 #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 4776
diff changeset
  1274
    ^ false
6e49b5b5f8c3 #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 4776
diff changeset
  1275
6e49b5b5f8c3 #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 4776
diff changeset
  1276
    "Modified: / 14.5.1996 / 15:54:45 / cg"
6e49b5b5f8c3 #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 4776
diff changeset
  1277
    "Created: / 30.10.1997 / 15:38:02 / cg"
6e49b5b5f8c3 #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 4776
diff changeset
  1278
!
6e49b5b5f8c3 #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 4776
diff changeset
  1279
6e49b5b5f8c3 #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 4776
diff changeset
  1280
includesIdentical:anElement
6e49b5b5f8c3 #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 4776
diff changeset
  1281
    "return true, if the receiver includes the argument, anElement; false otherwise.
6e49b5b5f8c3 #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 4776
diff changeset
  1282
     Redefined to prevent the inherited loop over individual accesses via #at:,
6e49b5b5f8c3 #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 4776
diff changeset
  1283
     which would be very inefficient."
6e49b5b5f8c3 #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 4776
diff changeset
  1284
6e49b5b5f8c3 #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 4776
diff changeset
  1285
    contentsArray notNil ifTrue:[
6e49b5b5f8c3 #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 4776
diff changeset
  1286
        contentsArray pairWiseDo:[:len :val |
6e49b5b5f8c3 #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 4776
diff changeset
  1287
            (anElement == val) ifTrue:[
6e49b5b5f8c3 #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 4776
diff changeset
  1288
                ^ true
6e49b5b5f8c3 #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 4776
diff changeset
  1289
            ].
6e49b5b5f8c3 #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 4776
diff changeset
  1290
        ].
6e49b5b5f8c3 #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 4776
diff changeset
  1291
    ].
6e49b5b5f8c3 #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 4776
diff changeset
  1292
    ^ false
6e49b5b5f8c3 #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 4776
diff changeset
  1293
6e49b5b5f8c3 #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 4776
diff changeset
  1294
    "Created: / 30.10.1997 / 15:38:30 / cg"
6e49b5b5f8c3 #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 4776
diff changeset
  1295
!
6e49b5b5f8c3 #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 4776
diff changeset
  1296
6e49b5b5f8c3 #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 4776
diff changeset
  1297
isEmpty
6e49b5b5f8c3 #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 4776
diff changeset
  1298
    "Am I empty or not. Returns a boolean"
6e49b5b5f8c3 #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 4776
diff changeset
  1299
6e49b5b5f8c3 #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 4776
diff changeset
  1300
    ^ contentsArray size == 0
6e49b5b5f8c3 #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 4776
diff changeset
  1301
6e49b5b5f8c3 #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 4776
diff changeset
  1302
    "Modified: 11.5.1996 / 13:35:17 / cg"
6e49b5b5f8c3 #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 4776
diff changeset
  1303
!
6e49b5b5f8c3 #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 4776
diff changeset
  1304
906
30c1ab2aee8d category change
Claus Gittinger <cg@exept.de>
parents: 904
diff changeset
  1305
size
30c1ab2aee8d category change
Claus Gittinger <cg@exept.de>
parents: 904
diff changeset
  1306
    "Answer how many elements the receiver contains.
4002
2fcb2003e3df #DOCUMENTATION by stefan
Stefan Vogel <sv@exept.de>
parents: 3597
diff changeset
  1307
     This is not the number of runs (but the simulated number of elements)."
906
30c1ab2aee8d category change
Claus Gittinger <cg@exept.de>
parents: 904
diff changeset
  1308
30c1ab2aee8d category change
Claus Gittinger <cg@exept.de>
parents: 904
diff changeset
  1309
    |n     "{ Class: SmallInteger }"
30c1ab2aee8d category change
Claus Gittinger <cg@exept.de>
parents: 904
diff changeset
  1310
     runSz "{ Class: SmallInteger }"|
30c1ab2aee8d category change
Claus Gittinger <cg@exept.de>
parents: 904
diff changeset
  1311
30c1ab2aee8d category change
Claus Gittinger <cg@exept.de>
parents: 904
diff changeset
  1312
    n := 0.
30c1ab2aee8d category change
Claus Gittinger <cg@exept.de>
parents: 904
diff changeset
  1313
    runSz := contentsArray size.
30c1ab2aee8d category change
Claus Gittinger <cg@exept.de>
parents: 904
diff changeset
  1314
    1 to:runSz by:2 do:[:i |
30c1ab2aee8d category change
Claus Gittinger <cg@exept.de>
parents: 904
diff changeset
  1315
        n := n + (contentsArray at:i)
30c1ab2aee8d category change
Claus Gittinger <cg@exept.de>
parents: 904
diff changeset
  1316
    ].
30c1ab2aee8d category change
Claus Gittinger <cg@exept.de>
parents: 904
diff changeset
  1317
    ^ n
30c1ab2aee8d category change
Claus Gittinger <cg@exept.de>
parents: 904
diff changeset
  1318
30c1ab2aee8d category change
Claus Gittinger <cg@exept.de>
parents: 904
diff changeset
  1319
    "Modified: 11.5.1996 / 13:34:27 / cg"
30c1ab2aee8d category change
Claus Gittinger <cg@exept.de>
parents: 904
diff changeset
  1320
! !
30c1ab2aee8d category change
Claus Gittinger <cg@exept.de>
parents: 904
diff changeset
  1321
334
023ca84ef961 faster #findFirst:
Claus Gittinger <cg@exept.de>
parents: 306
diff changeset
  1322
!RunArray methodsFor:'searching'!
023ca84ef961 faster #findFirst:
Claus Gittinger <cg@exept.de>
parents: 306
diff changeset
  1323
2147
b2f5a09a6174 findFirst: refactored
Claus Gittinger <cg@exept.de>
parents: 2127
diff changeset
  1324
findFirst:aBlock ifNone:exceptionalValue
1855
5cc78011495f comment
Claus Gittinger <cg@exept.de>
parents: 1752
diff changeset
  1325
    "find the index of the first element, for which evaluation of the argument, aBlock
334
023ca84ef961 faster #findFirst:
Claus Gittinger <cg@exept.de>
parents: 306
diff changeset
  1326
     returns true; return its index or 0 if none detected.
023ca84ef961 faster #findFirst:
Claus Gittinger <cg@exept.de>
parents: 306
diff changeset
  1327
     Notice, that not all elements are processed here 
023ca84ef961 faster #findFirst:
Claus Gittinger <cg@exept.de>
parents: 306
diff changeset
  1328
     (the block is only evaluated for each runs first element)."
023ca84ef961 faster #findFirst:
Claus Gittinger <cg@exept.de>
parents: 306
diff changeset
  1329
023ca84ef961 faster #findFirst:
Claus Gittinger <cg@exept.de>
parents: 306
diff changeset
  1330
    |idx|
023ca84ef961 faster #findFirst:
Claus Gittinger <cg@exept.de>
parents: 306
diff changeset
  1331
023ca84ef961 faster #findFirst:
Claus Gittinger <cg@exept.de>
parents: 306
diff changeset
  1332
    idx := 1.
023ca84ef961 faster #findFirst:
Claus Gittinger <cg@exept.de>
parents: 306
diff changeset
  1333
    contentsArray notNil ifTrue:[
023ca84ef961 faster #findFirst:
Claus Gittinger <cg@exept.de>
parents: 306
diff changeset
  1334
        contentsArray pairWiseDo:[:len :val | 
023ca84ef961 faster #findFirst:
Claus Gittinger <cg@exept.de>
parents: 306
diff changeset
  1335
            (aBlock value:val) ifTrue:[^ idx].
023ca84ef961 faster #findFirst:
Claus Gittinger <cg@exept.de>
parents: 306
diff changeset
  1336
            idx := idx + len.
023ca84ef961 faster #findFirst:
Claus Gittinger <cg@exept.de>
parents: 306
diff changeset
  1337
        ]
023ca84ef961 faster #findFirst:
Claus Gittinger <cg@exept.de>
parents: 306
diff changeset
  1338
    ].
2147
b2f5a09a6174 findFirst: refactored
Claus Gittinger <cg@exept.de>
parents: 2127
diff changeset
  1339
    ^ exceptionalValue value
334
023ca84ef961 faster #findFirst:
Claus Gittinger <cg@exept.de>
parents: 306
diff changeset
  1340
023ca84ef961 faster #findFirst:
Claus Gittinger <cg@exept.de>
parents: 306
diff changeset
  1341
    "
023ca84ef961 faster #findFirst:
Claus Gittinger <cg@exept.de>
parents: 306
diff changeset
  1342
     (RunArray new 
023ca84ef961 faster #findFirst:
Claus Gittinger <cg@exept.de>
parents: 306
diff changeset
  1343
        add:1 withOccurrences:100;
023ca84ef961 faster #findFirst:
Claus Gittinger <cg@exept.de>
parents: 306
diff changeset
  1344
        add:2 withOccurrences:100;
023ca84ef961 faster #findFirst:
Claus Gittinger <cg@exept.de>
parents: 306
diff changeset
  1345
        add:3 withOccurrences:100;
023ca84ef961 faster #findFirst:
Claus Gittinger <cg@exept.de>
parents: 306
diff changeset
  1346
        add:4 withOccurrences:100;
023ca84ef961 faster #findFirst:
Claus Gittinger <cg@exept.de>
parents: 306
diff changeset
  1347
        yourself) findFirst:[:el | el == 3] 
023ca84ef961 faster #findFirst:
Claus Gittinger <cg@exept.de>
parents: 306
diff changeset
  1348
    "
023ca84ef961 faster #findFirst:
Claus Gittinger <cg@exept.de>
parents: 306
diff changeset
  1349
023ca84ef961 faster #findFirst:
Claus Gittinger <cg@exept.de>
parents: 306
diff changeset
  1350
    "Modified: 14.5.1996 / 15:54:45 / cg"
588
677527917896 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 450
diff changeset
  1351
!
677527917896 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 450
diff changeset
  1352
677527917896 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 450
diff changeset
  1353
identityIndexOf:anElement startingAt:start
677527917896 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 450
diff changeset
  1354
    "search for identical anElement, return the index or 0 if not found.
677527917896 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 450
diff changeset
  1355
     Redefined to prevent a loop over individual accesses via #at:,
677527917896 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 450
diff changeset
  1356
     which would be very inefficient."
677527917896 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 450
diff changeset
  1357
677527917896 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 450
diff changeset
  1358
    |idx "{ Class: SmallInteger }" |
677527917896 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 450
diff changeset
  1359
677527917896 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 450
diff changeset
  1360
    contentsArray notNil ifTrue:[
677527917896 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 450
diff changeset
  1361
677527917896 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 450
diff changeset
  1362
        idx := 1.
677527917896 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 450
diff changeset
  1363
        contentsArray pairWiseDo:[:len :val |
677527917896 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 450
diff changeset
  1364
            |nextRunIdx "{ Class: SmallInteger }"|
677527917896 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 450
diff changeset
  1365
677527917896 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 450
diff changeset
  1366
            nextRunIdx := idx + len.
677527917896 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 450
diff changeset
  1367
            nextRunIdx > start ifTrue:[
677527917896 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 450
diff changeset
  1368
                (anElement == val) ifTrue:[
677527917896 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 450
diff changeset
  1369
                    ^ idx max:start
677527917896 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 450
diff changeset
  1370
                ]
677527917896 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 450
diff changeset
  1371
            ].
677527917896 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 450
diff changeset
  1372
            idx := nextRunIdx.
677527917896 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 450
diff changeset
  1373
        ].
677527917896 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 450
diff changeset
  1374
    ].
677527917896 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 450
diff changeset
  1375
    ^ 0
677527917896 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 450
diff changeset
  1376
677527917896 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 450
diff changeset
  1377
    "Modified: / 14.5.1996 / 15:54:45 / cg"
677527917896 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 450
diff changeset
  1378
    "Created: / 30.10.1997 / 15:33:18 / cg"
677527917896 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 450
diff changeset
  1379
!
677527917896 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 450
diff changeset
  1380
677527917896 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 450
diff changeset
  1381
indexOf:anElement startingAt:start
677527917896 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 450
diff changeset
  1382
    "search for equal anElement, return the index or 0 if not found.
677527917896 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 450
diff changeset
  1383
     Redefined to prevent a loop over individual accesses via #at:,
677527917896 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 450
diff changeset
  1384
     which would be very inefficient."
677527917896 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 450
diff changeset
  1385
677527917896 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 450
diff changeset
  1386
    |idx "{ Class: SmallInteger }" |
677527917896 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 450
diff changeset
  1387
677527917896 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 450
diff changeset
  1388
    contentsArray notNil ifTrue:[
677527917896 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 450
diff changeset
  1389
677527917896 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 450
diff changeset
  1390
        idx := 1.
677527917896 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 450
diff changeset
  1391
        contentsArray pairWiseDo:[:len :val |
677527917896 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 450
diff changeset
  1392
            |nextRunIdx "{ Class: SmallInteger }"|
677527917896 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 450
diff changeset
  1393
677527917896 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 450
diff changeset
  1394
            nextRunIdx := idx + len.
677527917896 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 450
diff changeset
  1395
            nextRunIdx > start ifTrue:[
677527917896 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 450
diff changeset
  1396
                (anElement = val) ifTrue:[
677527917896 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 450
diff changeset
  1397
                    ^ idx max:start
677527917896 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 450
diff changeset
  1398
                ]
677527917896 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 450
diff changeset
  1399
            ].
677527917896 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 450
diff changeset
  1400
            idx := nextRunIdx.
677527917896 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 450
diff changeset
  1401
        ].
677527917896 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 450
diff changeset
  1402
    ].
677527917896 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 450
diff changeset
  1403
    ^ 0
677527917896 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 450
diff changeset
  1404
677527917896 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 450
diff changeset
  1405
    "
677527917896 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 450
diff changeset
  1406
     |r|
677527917896 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 450
diff changeset
  1407
     r := RunArray new. 
677527917896 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 450
diff changeset
  1408
     r add:1 withOccurrences:100.
677527917896 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 450
diff changeset
  1409
     r add:2 withOccurrences:100.
677527917896 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 450
diff changeset
  1410
     r add:3 withOccurrences:100.
677527917896 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 450
diff changeset
  1411
     r add:4 withOccurrences:100.
677527917896 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 450
diff changeset
  1412
     r indexOf:2 startingAt:50.  
677527917896 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 450
diff changeset
  1413
     r indexOf:2 startingAt:100.  
677527917896 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 450
diff changeset
  1414
     r indexOf:2 startingAt:101.  
677527917896 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 450
diff changeset
  1415
     r indexOf:2 startingAt:150.  
677527917896 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 450
diff changeset
  1416
     r indexOf:2 startingAt:200.  
677527917896 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 450
diff changeset
  1417
     r indexOf:2 startingAt:201.   
677527917896 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 450
diff changeset
  1418
     r indexOf:2 startingAt:202.   
677527917896 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 450
diff changeset
  1419
    "
677527917896 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 450
diff changeset
  1420
677527917896 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 450
diff changeset
  1421
    "Modified: / 30.10.1997 / 15:33:29 / cg"
677527917896 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 450
diff changeset
  1422
! !
677527917896 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 450
diff changeset
  1423
297
9526ea90d4f9 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1424
!RunArray class methodsFor:'documentation'!
9526ea90d4f9 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1425
9526ea90d4f9 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1426
version
3593
3476aa995618 class: RunArray
Claus Gittinger <cg@exept.de>
parents: 3323
diff changeset
  1427
    ^ '$Header$'
2520
9ce886539987 category of: #inspectorClass
Claus Gittinger <cg@exept.de>
parents: 2147
diff changeset
  1428
!
9ce886539987 category of: #inspectorClass
Claus Gittinger <cg@exept.de>
parents: 2147
diff changeset
  1429
9ce886539987 category of: #inspectorClass
Claus Gittinger <cg@exept.de>
parents: 2147
diff changeset
  1430
version_CVS
3593
3476aa995618 class: RunArray
Claus Gittinger <cg@exept.de>
parents: 3323
diff changeset
  1431
    ^ '$Header$'
297
9526ea90d4f9 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1432
! !
2930
2fed91d4a44e comment/format in: #add:
Claus Gittinger <cg@exept.de>
parents: 2520
diff changeset
  1433