OrderedCollection.st
author Jan Vrany <jan.vrany@labware.com>
Wed, 23 Jun 2021 12:50:05 +0100
branchjv
changeset 25430 acd92449dc30
parent 20362 fea6b00ed63a
child 25445 1623217d2268
permissions -rw-r--r--
`Process`: revert `#interruptWith:` Commit 3b02b0f1f647: Cherry-picked `Semaphore`, `EventSemaphore, `Process` and `ProcessorScheduler` changes `Process >> #interruptWith:` but this - for not yet known reason - breaks stx:libjava tests. This commit reverts the code to version before that commit, fixing tests.
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
     1
"
5
67342904af11 *** empty log message ***
claus
parents: 3
diff changeset
     2
 COPYRIGHT (c) 1989 by Claus Gittinger
159
514c749165c3 *** empty log message ***
claus
parents: 114
diff changeset
     3
	      All Rights Reserved
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
     4
a27a279701f8 Initial revision
claus
parents:
diff changeset
     5
 This software is furnished under a license and may be used
a27a279701f8 Initial revision
claus
parents:
diff changeset
     6
 only in accordance with the terms of that license and with the
a27a279701f8 Initial revision
claus
parents:
diff changeset
     7
 inclusion of the above copyright notice.   This software may not
a27a279701f8 Initial revision
claus
parents:
diff changeset
     8
 be provided or otherwise made available to, or used by, any
a27a279701f8 Initial revision
claus
parents:
diff changeset
     9
 other person.  No title to or ownership of the software is
a27a279701f8 Initial revision
claus
parents:
diff changeset
    10
 hereby transferred.
a27a279701f8 Initial revision
claus
parents:
diff changeset
    11
"
5401
81ea19e6843c test for class
ps
parents: 4862
diff changeset
    12
"{ Package: 'stx:libbasic' }"
81ea19e6843c test for class
ps
parents: 4862
diff changeset
    13
17705
76b6ce4a59cd class: OrderedCollection
Claus Gittinger <cg@exept.de>
parents: 17167
diff changeset
    14
"{ NameSpace: Smalltalk }"
76b6ce4a59cd class: OrderedCollection
Claus Gittinger <cg@exept.de>
parents: 17167
diff changeset
    15
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
    16
SequenceableCollection subclass:#OrderedCollection
1071
5875a6eedd28 added #includesIdentical:
Claus Gittinger <cg@exept.de>
parents: 679
diff changeset
    17
	instanceVariableNames:'contentsArray firstIndex lastIndex'
18879
5d1bbfc1761d #FEATURE
Stefan Vogel <sv@exept.de>
parents: 18811
diff changeset
    18
	classVariableNames:'MinContentsArraySize'
1071
5875a6eedd28 added #includesIdentical:
Claus Gittinger <cg@exept.de>
parents: 679
diff changeset
    19
	poolDictionaries:''
5875a6eedd28 added #includesIdentical:
Claus Gittinger <cg@exept.de>
parents: 679
diff changeset
    20
	category:'Collections-Sequenceable'
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
    21
!
a27a279701f8 Initial revision
claus
parents:
diff changeset
    22
33
50cf0f6bc0ad *** empty log message ***
claus
parents: 13
diff changeset
    23
!OrderedCollection class methodsFor:'documentation'!
50cf0f6bc0ad *** empty log message ***
claus
parents: 13
diff changeset
    24
88
81dacba7a63a *** empty log message ***
claus
parents: 77
diff changeset
    25
copyright
81dacba7a63a *** empty log message ***
claus
parents: 77
diff changeset
    26
"
81dacba7a63a *** empty log message ***
claus
parents: 77
diff changeset
    27
 COPYRIGHT (c) 1989 by Claus Gittinger
159
514c749165c3 *** empty log message ***
claus
parents: 114
diff changeset
    28
	      All Rights Reserved
88
81dacba7a63a *** empty log message ***
claus
parents: 77
diff changeset
    29
81dacba7a63a *** empty log message ***
claus
parents: 77
diff changeset
    30
 This software is furnished under a license and may be used
81dacba7a63a *** empty log message ***
claus
parents: 77
diff changeset
    31
 only in accordance with the terms of that license and with the
81dacba7a63a *** empty log message ***
claus
parents: 77
diff changeset
    32
 inclusion of the above copyright notice.   This software may not
81dacba7a63a *** empty log message ***
claus
parents: 77
diff changeset
    33
 be provided or otherwise made available to, or used by, any
81dacba7a63a *** empty log message ***
claus
parents: 77
diff changeset
    34
 other person.  No title to or ownership of the software is
81dacba7a63a *** empty log message ***
claus
parents: 77
diff changeset
    35
 hereby transferred.
81dacba7a63a *** empty log message ***
claus
parents: 77
diff changeset
    36
"
81dacba7a63a *** empty log message ***
claus
parents: 77
diff changeset
    37
!
81dacba7a63a *** empty log message ***
claus
parents: 77
diff changeset
    38
33
50cf0f6bc0ad *** empty log message ***
claus
parents: 13
diff changeset
    39
documentation
50cf0f6bc0ad *** empty log message ***
claus
parents: 13
diff changeset
    40
"
20341
72ed68b0d0ec little code cleanup
Claus Gittinger <cg@exept.de>
parents: 20026
diff changeset
    41
    OrderedCollections (OCs) have their elements ordered as they were added.
18182
8504bb241a13 class: OrderedCollection
Claus Gittinger <cg@exept.de>
parents: 18177
diff changeset
    42
    In addition, they provide all indexing access protocol
1387
Claus Gittinger <cg@exept.de>
parents: 1367
diff changeset
    43
    and bulk copying (much like Arrays).
Claus Gittinger <cg@exept.de>
parents: 1367
diff changeset
    44
20341
72ed68b0d0ec little code cleanup
Claus Gittinger <cg@exept.de>
parents: 20026
diff changeset
    45
    Insertion and removal at both ends is possible and also usually fast
18182
8504bb241a13 class: OrderedCollection
Claus Gittinger <cg@exept.de>
parents: 18177
diff changeset
    46
    - therefore they can be used for queues and stacks.
20341
72ed68b0d0ec little code cleanup
Claus Gittinger <cg@exept.de>
parents: 20026
diff changeset
    47
1387
Claus Gittinger <cg@exept.de>
parents: 1367
diff changeset
    48
    [Instance variables:]
20341
72ed68b0d0ec little code cleanup
Claus Gittinger <cg@exept.de>
parents: 20026
diff changeset
    49
	contentsArray   <Array>         the actual contents
1387
Claus Gittinger <cg@exept.de>
parents: 1367
diff changeset
    50
20341
72ed68b0d0ec little code cleanup
Claus Gittinger <cg@exept.de>
parents: 20026
diff changeset
    51
	firstIndex      <SmallInteger>  index of first valid element
1387
Claus Gittinger <cg@exept.de>
parents: 1367
diff changeset
    52
20341
72ed68b0d0ec little code cleanup
Claus Gittinger <cg@exept.de>
parents: 20026
diff changeset
    53
	lastIndex       <SmallInteger>  index of last valid element
1387
Claus Gittinger <cg@exept.de>
parents: 1367
diff changeset
    54
Claus Gittinger <cg@exept.de>
parents: 1367
diff changeset
    55
    [performance hint:]
20341
72ed68b0d0ec little code cleanup
Claus Gittinger <cg@exept.de>
parents: 20026
diff changeset
    56
	They overallocate a few slots to make insertion at either end often O(1),
72ed68b0d0ec little code cleanup
Claus Gittinger <cg@exept.de>
parents: 20026
diff changeset
    57
	but sometimes O(n), where n is the current size of the collection
72ed68b0d0ec little code cleanup
Claus Gittinger <cg@exept.de>
parents: 20026
diff changeset
    58
	(i.e. they have reallocate the underlying element buffer and therefore copy the
72ed68b0d0ec little code cleanup
Claus Gittinger <cg@exept.de>
parents: 20026
diff changeset
    59
	 elements into a new one. However, this reallocation is not done on every insert,
72ed68b0d0ec little code cleanup
Claus Gittinger <cg@exept.de>
parents: 20026
diff changeset
    60
	 and if elements are deleted and others reinserted, the buffer is usually already able
72ed68b0d0ec little code cleanup
Claus Gittinger <cg@exept.de>
parents: 20026
diff changeset
    61
	 to hold the new element)
19096
dc826aced958 #DOCUMENTATION
Claus Gittinger <cg@exept.de>
parents: 18879
diff changeset
    62
20341
72ed68b0d0ec little code cleanup
Claus Gittinger <cg@exept.de>
parents: 20026
diff changeset
    63
	Insertion in the middle is O(n), and therefore slower, because elements have to be
72ed68b0d0ec little code cleanup
Claus Gittinger <cg@exept.de>
parents: 20026
diff changeset
    64
	shuffled towards either end, in order to make space for the new element.
72ed68b0d0ec little code cleanup
Claus Gittinger <cg@exept.de>
parents: 20026
diff changeset
    65
	Therefore, it is often cheaper, to instantiate a new object, and copy over the
72ed68b0d0ec little code cleanup
Claus Gittinger <cg@exept.de>
parents: 20026
diff changeset
    66
	elements.
72ed68b0d0ec little code cleanup
Claus Gittinger <cg@exept.de>
parents: 20026
diff changeset
    67
	see SegmentedOrderedCollection for a collection, which is specialized for this
72ed68b0d0ec little code cleanup
Claus Gittinger <cg@exept.de>
parents: 20026
diff changeset
    68
	kind of usage with many elements.
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
    69
1387
Claus Gittinger <cg@exept.de>
parents: 1367
diff changeset
    70
    [beginners bug hint:]
20341
72ed68b0d0ec little code cleanup
Claus Gittinger <cg@exept.de>
parents: 20026
diff changeset
    71
	notice that:
72ed68b0d0ec little code cleanup
Claus Gittinger <cg@exept.de>
parents: 20026
diff changeset
    72
	    Array new:n
72ed68b0d0ec little code cleanup
Claus Gittinger <cg@exept.de>
parents: 20026
diff changeset
    73
	is quite different from:
72ed68b0d0ec little code cleanup
Claus Gittinger <cg@exept.de>
parents: 20026
diff changeset
    74
	    OrderedCollection new:n
1290
15ba3221b89b documentation
Claus Gittinger <cg@exept.de>
parents: 1221
diff changeset
    75
20341
72ed68b0d0ec little code cleanup
Claus Gittinger <cg@exept.de>
parents: 20026
diff changeset
    76
	The later creates an OC which is prepared to hold <n> elements,
72ed68b0d0ec little code cleanup
Claus Gittinger <cg@exept.de>
parents: 20026
diff changeset
    77
	but has a logical size of 0 (zero). To get an OC containing <n> nils,
72ed68b0d0ec little code cleanup
Claus Gittinger <cg@exept.de>
parents: 20026
diff changeset
    78
	use:
72ed68b0d0ec little code cleanup
Claus Gittinger <cg@exept.de>
parents: 20026
diff changeset
    79
	     (OrderedCollection new) grow:n
72ed68b0d0ec little code cleanup
Claus Gittinger <cg@exept.de>
parents: 20026
diff changeset
    80
	or the syntactic sugar for that:
72ed68b0d0ec little code cleanup
Claus Gittinger <cg@exept.de>
parents: 20026
diff changeset
    81
	     OrderedCollection newWithSize:n
1387
Claus Gittinger <cg@exept.de>
parents: 1367
diff changeset
    82
20341
72ed68b0d0ec little code cleanup
Claus Gittinger <cg@exept.de>
parents: 20026
diff changeset
    83
	I know, this is confusing for beginners and was a bad semantic decision.
72ed68b0d0ec little code cleanup
Claus Gittinger <cg@exept.de>
parents: 20026
diff changeset
    84
	However, that's the way the standard was defined and how all Smalltalk's behave,
72ed68b0d0ec little code cleanup
Claus Gittinger <cg@exept.de>
parents: 20026
diff changeset
    85
	so we can't change that here.
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
    86
4064
fd3d2922fb8b documentation
Claus Gittinger <cg@exept.de>
parents: 3968
diff changeset
    87
    [memory requirements:]
20341
72ed68b0d0ec little code cleanup
Claus Gittinger <cg@exept.de>
parents: 20026
diff changeset
    88
	OBJ-HEADER + (3 * ptr-size)
72ed68b0d0ec little code cleanup
Claus Gittinger <cg@exept.de>
parents: 20026
diff changeset
    89
		   + (size-roundedUpToNextPowerOf2 * ptr-size)
4064
fd3d2922fb8b documentation
Claus Gittinger <cg@exept.de>
parents: 3968
diff changeset
    90
19096
dc826aced958 #DOCUMENTATION
Claus Gittinger <cg@exept.de>
parents: 18879
diff changeset
    91
    [complexity:]
20341
72ed68b0d0ec little code cleanup
Claus Gittinger <cg@exept.de>
parents: 20026
diff changeset
    92
	access by index: O(1)
72ed68b0d0ec little code cleanup
Claus Gittinger <cg@exept.de>
parents: 20026
diff changeset
    93
	insertion at either end: mostly O(1)
72ed68b0d0ec little code cleanup
Claus Gittinger <cg@exept.de>
parents: 20026
diff changeset
    94
	removal at either end: O(1)
72ed68b0d0ec little code cleanup
Claus Gittinger <cg@exept.de>
parents: 20026
diff changeset
    95
	insertion in the middle: O(n)
72ed68b0d0ec little code cleanup
Claus Gittinger <cg@exept.de>
parents: 20026
diff changeset
    96
	searching: O(n)
72ed68b0d0ec little code cleanup
Claus Gittinger <cg@exept.de>
parents: 20026
diff changeset
    97
	min/max: O(n)
72ed68b0d0ec little code cleanup
Claus Gittinger <cg@exept.de>
parents: 20026
diff changeset
    98
1290
15ba3221b89b documentation
Claus Gittinger <cg@exept.de>
parents: 1221
diff changeset
    99
    [see also:]
20341
72ed68b0d0ec little code cleanup
Claus Gittinger <cg@exept.de>
parents: 20026
diff changeset
   100
	Array
1290
15ba3221b89b documentation
Claus Gittinger <cg@exept.de>
parents: 1221
diff changeset
   101
15ba3221b89b documentation
Claus Gittinger <cg@exept.de>
parents: 1221
diff changeset
   102
    [author:]
20341
72ed68b0d0ec little code cleanup
Claus Gittinger <cg@exept.de>
parents: 20026
diff changeset
   103
	Claus Gittinger
33
50cf0f6bc0ad *** empty log message ***
claus
parents: 13
diff changeset
   104
"
1321
52e043fb7eaf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1290
diff changeset
   105
!
52e043fb7eaf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1290
diff changeset
   106
52e043fb7eaf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1290
diff changeset
   107
examples
52e043fb7eaf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1290
diff changeset
   108
"
1387
Claus Gittinger <cg@exept.de>
parents: 1367
diff changeset
   109
  using OC as a stack:
20341
72ed68b0d0ec little code cleanup
Claus Gittinger <cg@exept.de>
parents: 20026
diff changeset
   110
									[exBegin]
1387
Claus Gittinger <cg@exept.de>
parents: 1367
diff changeset
   111
    |stack top|
1321
52e043fb7eaf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1290
diff changeset
   112
1387
Claus Gittinger <cg@exept.de>
parents: 1367
diff changeset
   113
    stack := OrderedCollection new.
1321
52e043fb7eaf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1290
diff changeset
   114
1387
Claus Gittinger <cg@exept.de>
parents: 1367
diff changeset
   115
    1 to:10 do:[:i |
20341
72ed68b0d0ec little code cleanup
Claus Gittinger <cg@exept.de>
parents: 20026
diff changeset
   116
	stack add:i
1387
Claus Gittinger <cg@exept.de>
parents: 1367
diff changeset
   117
    ].
1321
52e043fb7eaf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1290
diff changeset
   118
1387
Claus Gittinger <cg@exept.de>
parents: 1367
diff changeset
   119
    10 timesRepeat:[
20341
72ed68b0d0ec little code cleanup
Claus Gittinger <cg@exept.de>
parents: 20026
diff changeset
   120
	top := stack removeLast.
72ed68b0d0ec little code cleanup
Claus Gittinger <cg@exept.de>
parents: 20026
diff changeset
   121
	Transcript showCR:top
1387
Claus Gittinger <cg@exept.de>
parents: 1367
diff changeset
   122
    ]
20341
72ed68b0d0ec little code cleanup
Claus Gittinger <cg@exept.de>
parents: 20026
diff changeset
   123
									[exEnd]
1387
Claus Gittinger <cg@exept.de>
parents: 1367
diff changeset
   124
  using OC as a queue (you should use Queue right away ..):
20341
72ed68b0d0ec little code cleanup
Claus Gittinger <cg@exept.de>
parents: 20026
diff changeset
   125
									[exBegin]
1387
Claus Gittinger <cg@exept.de>
parents: 1367
diff changeset
   126
    |queue dequeued|
1321
52e043fb7eaf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1290
diff changeset
   127
1387
Claus Gittinger <cg@exept.de>
parents: 1367
diff changeset
   128
    queue := OrderedCollection new.
1321
52e043fb7eaf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1290
diff changeset
   129
1387
Claus Gittinger <cg@exept.de>
parents: 1367
diff changeset
   130
    1 to:10 do:[:i |
20341
72ed68b0d0ec little code cleanup
Claus Gittinger <cg@exept.de>
parents: 20026
diff changeset
   131
	queue addLast:i
1387
Claus Gittinger <cg@exept.de>
parents: 1367
diff changeset
   132
    ].
1321
52e043fb7eaf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1290
diff changeset
   133
1387
Claus Gittinger <cg@exept.de>
parents: 1367
diff changeset
   134
    10 timesRepeat:[
20341
72ed68b0d0ec little code cleanup
Claus Gittinger <cg@exept.de>
parents: 20026
diff changeset
   135
	dequeued := queue removeFirst.
72ed68b0d0ec little code cleanup
Claus Gittinger <cg@exept.de>
parents: 20026
diff changeset
   136
	Transcript showCR:dequeued
1387
Claus Gittinger <cg@exept.de>
parents: 1367
diff changeset
   137
    ]
20341
72ed68b0d0ec little code cleanup
Claus Gittinger <cg@exept.de>
parents: 20026
diff changeset
   138
									[exEnd]
1324
Claus Gittinger <cg@exept.de>
parents: 1321
diff changeset
   139
Claus Gittinger <cg@exept.de>
parents: 1321
diff changeset
   140
1387
Claus Gittinger <cg@exept.de>
parents: 1367
diff changeset
   141
  examples to support the performance hint (see documentation)
1324
Claus Gittinger <cg@exept.de>
parents: 1321
diff changeset
   142
Claus Gittinger <cg@exept.de>
parents: 1321
diff changeset
   143
    timing removal of all odd elements in a collection of 10000:
Claus Gittinger <cg@exept.de>
parents: 1321
diff changeset
   144
    (940 ms on P5/133)
20341
72ed68b0d0ec little code cleanup
Claus Gittinger <cg@exept.de>
parents: 20026
diff changeset
   145
									[exBegin]
72ed68b0d0ec little code cleanup
Claus Gittinger <cg@exept.de>
parents: 20026
diff changeset
   146
	|coll time|
1324
Claus Gittinger <cg@exept.de>
parents: 1321
diff changeset
   147
20341
72ed68b0d0ec little code cleanup
Claus Gittinger <cg@exept.de>
parents: 20026
diff changeset
   148
	coll := (1 to:10000) asOrderedCollection.
72ed68b0d0ec little code cleanup
Claus Gittinger <cg@exept.de>
parents: 20026
diff changeset
   149
	time := Time millisecondsToRun:[
72ed68b0d0ec little code cleanup
Claus Gittinger <cg@exept.de>
parents: 20026
diff changeset
   150
	    coll removeAllSuchThat:[:el | el even]
72ed68b0d0ec little code cleanup
Claus Gittinger <cg@exept.de>
parents: 20026
diff changeset
   151
	].
72ed68b0d0ec little code cleanup
Claus Gittinger <cg@exept.de>
parents: 20026
diff changeset
   152
	Transcript show:'time is '; show:time; showCR:' ms'.
72ed68b0d0ec little code cleanup
Claus Gittinger <cg@exept.de>
parents: 20026
diff changeset
   153
									[exEnd]
1324
Claus Gittinger <cg@exept.de>
parents: 1321
diff changeset
   154
1387
Claus Gittinger <cg@exept.de>
parents: 1367
diff changeset
   155
    tuning the removal by doing it reverse
Claus Gittinger <cg@exept.de>
parents: 1367
diff changeset
   156
    (less copying in #removeAtIndex:) speeds it up by a factor of 2:
20341
72ed68b0d0ec little code cleanup
Claus Gittinger <cg@exept.de>
parents: 20026
diff changeset
   157
									[exBegin]
72ed68b0d0ec little code cleanup
Claus Gittinger <cg@exept.de>
parents: 20026
diff changeset
   158
	|coll time|
1324
Claus Gittinger <cg@exept.de>
parents: 1321
diff changeset
   159
20341
72ed68b0d0ec little code cleanup
Claus Gittinger <cg@exept.de>
parents: 20026
diff changeset
   160
	coll := (1 to:10000) asOrderedCollection.
72ed68b0d0ec little code cleanup
Claus Gittinger <cg@exept.de>
parents: 20026
diff changeset
   161
	time := Time millisecondsToRun:[
72ed68b0d0ec little code cleanup
Claus Gittinger <cg@exept.de>
parents: 20026
diff changeset
   162
	    coll size to:1 by:-1 do:[:index |
72ed68b0d0ec little code cleanup
Claus Gittinger <cg@exept.de>
parents: 20026
diff changeset
   163
		(coll at:index) even ifTrue:[
72ed68b0d0ec little code cleanup
Claus Gittinger <cg@exept.de>
parents: 20026
diff changeset
   164
		    coll removeAtIndex:index
72ed68b0d0ec little code cleanup
Claus Gittinger <cg@exept.de>
parents: 20026
diff changeset
   165
		]
72ed68b0d0ec little code cleanup
Claus Gittinger <cg@exept.de>
parents: 20026
diff changeset
   166
	    ]
72ed68b0d0ec little code cleanup
Claus Gittinger <cg@exept.de>
parents: 20026
diff changeset
   167
	].
72ed68b0d0ec little code cleanup
Claus Gittinger <cg@exept.de>
parents: 20026
diff changeset
   168
	Transcript show:'time is '; show:time; showCR:' ms'.
72ed68b0d0ec little code cleanup
Claus Gittinger <cg@exept.de>
parents: 20026
diff changeset
   169
									[exEnd]
1324
Claus Gittinger <cg@exept.de>
parents: 1321
diff changeset
   170
1387
Claus Gittinger <cg@exept.de>
parents: 1367
diff changeset
   171
    rebuilding a new collection:
1324
Claus Gittinger <cg@exept.de>
parents: 1321
diff changeset
   172
    (64 ms on P5/133)
20341
72ed68b0d0ec little code cleanup
Claus Gittinger <cg@exept.de>
parents: 20026
diff changeset
   173
									[exBegin]
72ed68b0d0ec little code cleanup
Claus Gittinger <cg@exept.de>
parents: 20026
diff changeset
   174
	|coll time|
1324
Claus Gittinger <cg@exept.de>
parents: 1321
diff changeset
   175
20341
72ed68b0d0ec little code cleanup
Claus Gittinger <cg@exept.de>
parents: 20026
diff changeset
   176
	coll := (1 to:10000) asOrderedCollection.
72ed68b0d0ec little code cleanup
Claus Gittinger <cg@exept.de>
parents: 20026
diff changeset
   177
	time := Time millisecondsToRun:[
72ed68b0d0ec little code cleanup
Claus Gittinger <cg@exept.de>
parents: 20026
diff changeset
   178
	    coll := coll select:[:el | el odd]
72ed68b0d0ec little code cleanup
Claus Gittinger <cg@exept.de>
parents: 20026
diff changeset
   179
	].
72ed68b0d0ec little code cleanup
Claus Gittinger <cg@exept.de>
parents: 20026
diff changeset
   180
	Transcript show:'time is '; show:time; showCR:' ms'.
72ed68b0d0ec little code cleanup
Claus Gittinger <cg@exept.de>
parents: 20026
diff changeset
   181
									[exEnd]
11271
5b75b4a7fb35 tuned makeRoomAtIndex:
Claus Gittinger <cg@exept.de>
parents: 11269
diff changeset
   182
5b75b4a7fb35 tuned makeRoomAtIndex:
Claus Gittinger <cg@exept.de>
parents: 11269
diff changeset
   183
    adding at the end (fast):
20341
72ed68b0d0ec little code cleanup
Claus Gittinger <cg@exept.de>
parents: 20026
diff changeset
   184
									[exBegin]
72ed68b0d0ec little code cleanup
Claus Gittinger <cg@exept.de>
parents: 20026
diff changeset
   185
	|coll time|
11271
5b75b4a7fb35 tuned makeRoomAtIndex:
Claus Gittinger <cg@exept.de>
parents: 11269
diff changeset
   186
20341
72ed68b0d0ec little code cleanup
Claus Gittinger <cg@exept.de>
parents: 20026
diff changeset
   187
	coll := OrderedCollection new.
72ed68b0d0ec little code cleanup
Claus Gittinger <cg@exept.de>
parents: 20026
diff changeset
   188
	time := TimeDuration toRun:[
72ed68b0d0ec little code cleanup
Claus Gittinger <cg@exept.de>
parents: 20026
diff changeset
   189
	    (1 to:100000) do:[:el | coll add:el].
72ed68b0d0ec little code cleanup
Claus Gittinger <cg@exept.de>
parents: 20026
diff changeset
   190
	].
72ed68b0d0ec little code cleanup
Claus Gittinger <cg@exept.de>
parents: 20026
diff changeset
   191
	Transcript show:'time is '; showCR:time.
72ed68b0d0ec little code cleanup
Claus Gittinger <cg@exept.de>
parents: 20026
diff changeset
   192
	self assert:(coll = (1 to:100000)).
72ed68b0d0ec little code cleanup
Claus Gittinger <cg@exept.de>
parents: 20026
diff changeset
   193
	self assert:(coll asBag = (1 to:100000) asBag).
72ed68b0d0ec little code cleanup
Claus Gittinger <cg@exept.de>
parents: 20026
diff changeset
   194
									[exEnd]
11271
5b75b4a7fb35 tuned makeRoomAtIndex:
Claus Gittinger <cg@exept.de>
parents: 11269
diff changeset
   195
    adding at front (fast):
20341
72ed68b0d0ec little code cleanup
Claus Gittinger <cg@exept.de>
parents: 20026
diff changeset
   196
									[exBegin]
72ed68b0d0ec little code cleanup
Claus Gittinger <cg@exept.de>
parents: 20026
diff changeset
   197
	|coll time|
11271
5b75b4a7fb35 tuned makeRoomAtIndex:
Claus Gittinger <cg@exept.de>
parents: 11269
diff changeset
   198
20341
72ed68b0d0ec little code cleanup
Claus Gittinger <cg@exept.de>
parents: 20026
diff changeset
   199
	coll := OrderedCollection new.
72ed68b0d0ec little code cleanup
Claus Gittinger <cg@exept.de>
parents: 20026
diff changeset
   200
	time := TimeDuration toRun:[
72ed68b0d0ec little code cleanup
Claus Gittinger <cg@exept.de>
parents: 20026
diff changeset
   201
	    (1 to:100000) reverseDo:[:el | coll addFirst:el].
72ed68b0d0ec little code cleanup
Claus Gittinger <cg@exept.de>
parents: 20026
diff changeset
   202
	].
72ed68b0d0ec little code cleanup
Claus Gittinger <cg@exept.de>
parents: 20026
diff changeset
   203
	Transcript show:'time is '; showCR:time.
72ed68b0d0ec little code cleanup
Claus Gittinger <cg@exept.de>
parents: 20026
diff changeset
   204
	self assert:(coll = (1 to:100000)).
72ed68b0d0ec little code cleanup
Claus Gittinger <cg@exept.de>
parents: 20026
diff changeset
   205
	self assert:(coll asBag = (1 to:100000) asBag).
72ed68b0d0ec little code cleanup
Claus Gittinger <cg@exept.de>
parents: 20026
diff changeset
   206
									[exEnd]
11271
5b75b4a7fb35 tuned makeRoomAtIndex:
Claus Gittinger <cg@exept.de>
parents: 11269
diff changeset
   207
    inserting in the middle (slow):
20341
72ed68b0d0ec little code cleanup
Claus Gittinger <cg@exept.de>
parents: 20026
diff changeset
   208
									[exBegin]
72ed68b0d0ec little code cleanup
Claus Gittinger <cg@exept.de>
parents: 20026
diff changeset
   209
	|coll time|
11271
5b75b4a7fb35 tuned makeRoomAtIndex:
Claus Gittinger <cg@exept.de>
parents: 11269
diff changeset
   210
20341
72ed68b0d0ec little code cleanup
Claus Gittinger <cg@exept.de>
parents: 20026
diff changeset
   211
	coll := OrderedCollection new.
72ed68b0d0ec little code cleanup
Claus Gittinger <cg@exept.de>
parents: 20026
diff changeset
   212
	time := TimeDuration toRun:[
72ed68b0d0ec little code cleanup
Claus Gittinger <cg@exept.de>
parents: 20026
diff changeset
   213
	    (1 to:100000) do:[:el | coll add:el beforeIndex:(coll size // 2)+1 ].
72ed68b0d0ec little code cleanup
Claus Gittinger <cg@exept.de>
parents: 20026
diff changeset
   214
	].
72ed68b0d0ec little code cleanup
Claus Gittinger <cg@exept.de>
parents: 20026
diff changeset
   215
	Transcript show:'time is '; showCR:time.
72ed68b0d0ec little code cleanup
Claus Gittinger <cg@exept.de>
parents: 20026
diff changeset
   216
	self assert:(coll asBag = (1 to:100000) asBag).
72ed68b0d0ec little code cleanup
Claus Gittinger <cg@exept.de>
parents: 20026
diff changeset
   217
									[exEnd]
1321
52e043fb7eaf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1290
diff changeset
   218
"
33
50cf0f6bc0ad *** empty log message ***
claus
parents: 13
diff changeset
   219
! !
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   220
18879
5d1bbfc1761d #FEATURE
Stefan Vogel <sv@exept.de>
parents: 18811
diff changeset
   221
!OrderedCollection class methodsFor:'initialization'!
5d1bbfc1761d #FEATURE
Stefan Vogel <sv@exept.de>
parents: 18811
diff changeset
   222
5d1bbfc1761d #FEATURE
Stefan Vogel <sv@exept.de>
parents: 18811
diff changeset
   223
initialize
19990
c819e0a71d64 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 19865
diff changeset
   224
    MinContentsArraySize := 4. "the minimum size of a non-empty contentsArray"
18879
5d1bbfc1761d #FEATURE
Stefan Vogel <sv@exept.de>
parents: 18811
diff changeset
   225
! !
5d1bbfc1761d #FEATURE
Stefan Vogel <sv@exept.de>
parents: 18811
diff changeset
   226
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   227
!OrderedCollection class methodsFor:'instance creation'!
a27a279701f8 Initial revision
claus
parents:
diff changeset
   228
a27a279701f8 Initial revision
claus
parents:
diff changeset
   229
new
1106
a101113cc0a8 commentary
Claus Gittinger <cg@exept.de>
parents: 1090
diff changeset
   230
    "create a new, empty OrderedCollection"
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   231
19991
7675defcd5c2 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 19990
diff changeset
   232
    ^ self basicNew initContents:0
18879
5d1bbfc1761d #FEATURE
Stefan Vogel <sv@exept.de>
parents: 18811
diff changeset
   233
5d1bbfc1761d #FEATURE
Stefan Vogel <sv@exept.de>
parents: 18811
diff changeset
   234
    "
20341
72ed68b0d0ec little code cleanup
Claus Gittinger <cg@exept.de>
parents: 20026
diff changeset
   235
	self new
18879
5d1bbfc1761d #FEATURE
Stefan Vogel <sv@exept.de>
parents: 18811
diff changeset
   236
20341
72ed68b0d0ec little code cleanup
Claus Gittinger <cg@exept.de>
parents: 20026
diff changeset
   237
	|nEmpty|
72ed68b0d0ec little code cleanup
Claus Gittinger <cg@exept.de>
parents: 20026
diff changeset
   238
	nEmpty := 0.
72ed68b0d0ec little code cleanup
Claus Gittinger <cg@exept.de>
parents: 20026
diff changeset
   239
	self allInstancesDo:[:e| e size == 0 ifTrue:[nEmpty := nEmpty + 1]].
72ed68b0d0ec little code cleanup
Claus Gittinger <cg@exept.de>
parents: 20026
diff changeset
   240
	nEmpty
18879
5d1bbfc1761d #FEATURE
Stefan Vogel <sv@exept.de>
parents: 18811
diff changeset
   241
20341
72ed68b0d0ec little code cleanup
Claus Gittinger <cg@exept.de>
parents: 20026
diff changeset
   242
	|nEmpty|
72ed68b0d0ec little code cleanup
Claus Gittinger <cg@exept.de>
parents: 20026
diff changeset
   243
	nEmpty := OrderedCollection new.
72ed68b0d0ec little code cleanup
Claus Gittinger <cg@exept.de>
parents: 20026
diff changeset
   244
	self allInstancesDo:[:e| (e size == 0 and:[e contentsArray size ~~ 0]) ifTrue:[nEmpty add:e]].
72ed68b0d0ec little code cleanup
Claus Gittinger <cg@exept.de>
parents: 20026
diff changeset
   245
	nEmpty
18879
5d1bbfc1761d #FEATURE
Stefan Vogel <sv@exept.de>
parents: 18811
diff changeset
   246
    "
1106
a101113cc0a8 commentary
Claus Gittinger <cg@exept.de>
parents: 1090
diff changeset
   247
a101113cc0a8 commentary
Claus Gittinger <cg@exept.de>
parents: 1090
diff changeset
   248
    "Modified: 19.3.1996 / 17:53:12 / cg"
293
31df3850e98c *** empty log message ***
claus
parents: 282
diff changeset
   249
!
31df3850e98c *** empty log message ***
claus
parents: 282
diff changeset
   250
606
7a9ab63a6757 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   251
new:size
1106
a101113cc0a8 commentary
Claus Gittinger <cg@exept.de>
parents: 1090
diff changeset
   252
    "create a new, empty OrderedCollection with a preallocated physical
20341
72ed68b0d0ec little code cleanup
Claus Gittinger <cg@exept.de>
parents: 20026
diff changeset
   253
     size.
72ed68b0d0ec little code cleanup
Claus Gittinger <cg@exept.de>
parents: 20026
diff changeset
   254
     NOTICE:
72ed68b0d0ec little code cleanup
Claus Gittinger <cg@exept.de>
parents: 20026
diff changeset
   255
	the logical size of the returned collection is 0 (i.e. it is empty).
72ed68b0d0ec little code cleanup
Claus Gittinger <cg@exept.de>
parents: 20026
diff changeset
   256
	This may be confusing, in that it is different from what Array>>new:
72ed68b0d0ec little code cleanup
Claus Gittinger <cg@exept.de>
parents: 20026
diff changeset
   257
	returns. However, that's the way OrderedCollections work in every other
72ed68b0d0ec little code cleanup
Claus Gittinger <cg@exept.de>
parents: 20026
diff changeset
   258
	Smalltalk, so here it should as well.
72ed68b0d0ec little code cleanup
Claus Gittinger <cg@exept.de>
parents: 20026
diff changeset
   259
     See also newWithSize:, which might do what you really want.
1106
a101113cc0a8 commentary
Claus Gittinger <cg@exept.de>
parents: 1090
diff changeset
   260
     "
606
7a9ab63a6757 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   261
19991
7675defcd5c2 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 19990
diff changeset
   262
    ^ self basicNew initContents:size
1106
a101113cc0a8 commentary
Claus Gittinger <cg@exept.de>
parents: 1090
diff changeset
   263
a101113cc0a8 commentary
Claus Gittinger <cg@exept.de>
parents: 1090
diff changeset
   264
    "Modified: 19.3.1996 / 17:53:47 / cg"
4427
8833e118ff25 added #newFrom:
Claus Gittinger <cg@exept.de>
parents: 4153
diff changeset
   265
!
8833e118ff25 added #newFrom:
Claus Gittinger <cg@exept.de>
parents: 4153
diff changeset
   266
6700
e4254778c239 new:withAll: redefined to work around the wierd new: behavior.
Claus Gittinger <cg@exept.de>
parents: 6088
diff changeset
   267
new:size withAll:element
e4254778c239 new:withAll: redefined to work around the wierd new: behavior.
Claus Gittinger <cg@exept.de>
parents: 6088
diff changeset
   268
    "return a new collection of size, where all elements are
e4254778c239 new:withAll: redefined to work around the wierd new: behavior.
Claus Gittinger <cg@exept.de>
parents: 6088
diff changeset
   269
     initialized to element."
e4254778c239 new:withAll: redefined to work around the wierd new: behavior.
Claus Gittinger <cg@exept.de>
parents: 6088
diff changeset
   270
e4254778c239 new:withAll: redefined to work around the wierd new: behavior.
Claus Gittinger <cg@exept.de>
parents: 6088
diff changeset
   271
    |newCollection|
e4254778c239 new:withAll: redefined to work around the wierd new: behavior.
Claus Gittinger <cg@exept.de>
parents: 6088
diff changeset
   272
16707
5edef6701e69 class: OrderedCollection
Claus Gittinger <cg@exept.de>
parents: 16305
diff changeset
   273
    newCollection := self newWithSize:size.
6700
e4254778c239 new:withAll: redefined to work around the wierd new: behavior.
Claus Gittinger <cg@exept.de>
parents: 6088
diff changeset
   274
    newCollection atAllPut:element.
e4254778c239 new:withAll: redefined to work around the wierd new: behavior.
Claus Gittinger <cg@exept.de>
parents: 6088
diff changeset
   275
    ^ newCollection
e4254778c239 new:withAll: redefined to work around the wierd new: behavior.
Claus Gittinger <cg@exept.de>
parents: 6088
diff changeset
   276
e4254778c239 new:withAll: redefined to work around the wierd new: behavior.
Claus Gittinger <cg@exept.de>
parents: 6088
diff changeset
   277
    "
20341
72ed68b0d0ec little code cleanup
Claus Gittinger <cg@exept.de>
parents: 20026
diff changeset
   278
     OrderedCollection new:10 withAll:1234
6700
e4254778c239 new:withAll: redefined to work around the wierd new: behavior.
Claus Gittinger <cg@exept.de>
parents: 6088
diff changeset
   279
    "
e4254778c239 new:withAll: redefined to work around the wierd new: behavior.
Claus Gittinger <cg@exept.de>
parents: 6088
diff changeset
   280
!
e4254778c239 new:withAll: redefined to work around the wierd new: behavior.
Claus Gittinger <cg@exept.de>
parents: 6088
diff changeset
   281
4427
8833e118ff25 added #newFrom:
Claus Gittinger <cg@exept.de>
parents: 4153
diff changeset
   282
newFrom:aCollection
8833e118ff25 added #newFrom:
Claus Gittinger <cg@exept.de>
parents: 4153
diff changeset
   283
    "return a new OrderedCollection filled with all elements from the argument,
8833e118ff25 added #newFrom:
Claus Gittinger <cg@exept.de>
parents: 4153
diff changeset
   284
     aCollection"
8833e118ff25 added #newFrom:
Claus Gittinger <cg@exept.de>
parents: 4153
diff changeset
   285
8833e118ff25 added #newFrom:
Claus Gittinger <cg@exept.de>
parents: 4153
diff changeset
   286
    |newColl|
8833e118ff25 added #newFrom:
Claus Gittinger <cg@exept.de>
parents: 4153
diff changeset
   287
8833e118ff25 added #newFrom:
Claus Gittinger <cg@exept.de>
parents: 4153
diff changeset
   288
    newColl := self new:(aCollection size).
8833e118ff25 added #newFrom:
Claus Gittinger <cg@exept.de>
parents: 4153
diff changeset
   289
    newColl addAll:aCollection.
8833e118ff25 added #newFrom:
Claus Gittinger <cg@exept.de>
parents: 4153
diff changeset
   290
    ^ newColl
8833e118ff25 added #newFrom:
Claus Gittinger <cg@exept.de>
parents: 4153
diff changeset
   291
8833e118ff25 added #newFrom:
Claus Gittinger <cg@exept.de>
parents: 4153
diff changeset
   292
    "
8833e118ff25 added #newFrom:
Claus Gittinger <cg@exept.de>
parents: 4153
diff changeset
   293
     OrderedCollection newFrom:#(1 2 3 4)
8833e118ff25 added #newFrom:
Claus Gittinger <cg@exept.de>
parents: 4153
diff changeset
   294
     OrderedCollection newFrom:(Set with:1 with:2 with:3)
8833e118ff25 added #newFrom:
Claus Gittinger <cg@exept.de>
parents: 4153
diff changeset
   295
    "
17167
6b129633ca35 class: OrderedCollection
Claus Gittinger <cg@exept.de>
parents: 16713
diff changeset
   296
!
6b129633ca35 class: OrderedCollection
Claus Gittinger <cg@exept.de>
parents: 16713
diff changeset
   297
6b129633ca35 class: OrderedCollection
Claus Gittinger <cg@exept.de>
parents: 16713
diff changeset
   298
newLikelyToRemainEmpty
6b129633ca35 class: OrderedCollection
Claus Gittinger <cg@exept.de>
parents: 16713
diff changeset
   299
    "create a new, empty OrderedCollection, for which we already know
6b129633ca35 class: OrderedCollection
Claus Gittinger <cg@exept.de>
parents: 16713
diff changeset
   300
     that it is very likely to remain empty.
6b129633ca35 class: OrderedCollection
Claus Gittinger <cg@exept.de>
parents: 16713
diff changeset
   301
     Use this for collections which may sometimes get elements added, but usually not.
19991
7675defcd5c2 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 19990
diff changeset
   302
     This is now obsolete and the same as new:
7675defcd5c2 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 19990
diff changeset
   303
     as the algorithm is now clever enough to deal efficiently with this situation"
17167
6b129633ca35 class: OrderedCollection
Claus Gittinger <cg@exept.de>
parents: 16713
diff changeset
   304
19991
7675defcd5c2 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 19990
diff changeset
   305
    ^ self new:0
17167
6b129633ca35 class: OrderedCollection
Claus Gittinger <cg@exept.de>
parents: 16713
diff changeset
   306
6b129633ca35 class: OrderedCollection
Claus Gittinger <cg@exept.de>
parents: 16713
diff changeset
   307
    "
6b129633ca35 class: OrderedCollection
Claus Gittinger <cg@exept.de>
parents: 16713
diff changeset
   308
     self newLikelyToRemainEmpty size
6b129633ca35 class: OrderedCollection
Claus Gittinger <cg@exept.de>
parents: 16713
diff changeset
   309
     self newLikelyToRemainEmpty add:1; size
6b129633ca35 class: OrderedCollection
Claus Gittinger <cg@exept.de>
parents: 16713
diff changeset
   310
     self newLikelyToRemainEmpty addAll:#(1 2); size
6b129633ca35 class: OrderedCollection
Claus Gittinger <cg@exept.de>
parents: 16713
diff changeset
   311
    "
293
31df3850e98c *** empty log message ***
claus
parents: 282
diff changeset
   312
! !
31df3850e98c *** empty log message ***
claus
parents: 282
diff changeset
   313
20026
c4063e226888 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 19991
diff changeset
   314
606
7a9ab63a6757 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   315
!OrderedCollection methodsFor:'accessing'!
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   316
606
7a9ab63a6757 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   317
at:anInteger
7a9ab63a6757 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   318
    "return the element at index, anInteger"
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   319
3107
ce4b0a4b3b3a checkin from browser
Claus Gittinger <cg@exept.de>
parents: 3095
diff changeset
   320
    |idx "{ Class: SmallInteger }"|
387
claus
parents: 384
diff changeset
   321
606
7a9ab63a6757 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   322
    idx := anInteger + firstIndex - 1.
7a9ab63a6757 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   323
    ((anInteger < 1) or:[idx > lastIndex]) ifTrue:[
20341
72ed68b0d0ec little code cleanup
Claus Gittinger <cg@exept.de>
parents: 20026
diff changeset
   324
	^ self subscriptBoundsError:anInteger
3107
ce4b0a4b3b3a checkin from browser
Claus Gittinger <cg@exept.de>
parents: 3095
diff changeset
   325
    ].
ce4b0a4b3b3a checkin from browser
Claus Gittinger <cg@exept.de>
parents: 3095
diff changeset
   326
    ^ contentsArray basicAt:idx
ce4b0a4b3b3a checkin from browser
Claus Gittinger <cg@exept.de>
parents: 3095
diff changeset
   327
ce4b0a4b3b3a checkin from browser
Claus Gittinger <cg@exept.de>
parents: 3095
diff changeset
   328
    "Modified: / 12.11.1997 / 17:56:05 / cg"
360
claus
parents: 349
diff changeset
   329
!
claus
parents: 349
diff changeset
   330
18811
54e839ea9d44 #BUGFIX
Claus Gittinger <cg@exept.de>
parents: 18379
diff changeset
   331
at:anInteger ifAbsent:exceptionValue
54e839ea9d44 #BUGFIX
Claus Gittinger <cg@exept.de>
parents: 18379
diff changeset
   332
    "return the element at index, anInteger.
54e839ea9d44 #BUGFIX
Claus Gittinger <cg@exept.de>
parents: 18379
diff changeset
   333
     If the index is invalid, return the value from exceptionValue"
54e839ea9d44 #BUGFIX
Claus Gittinger <cg@exept.de>
parents: 18379
diff changeset
   334
54e839ea9d44 #BUGFIX
Claus Gittinger <cg@exept.de>
parents: 18379
diff changeset
   335
    |idx "{ Class: SmallInteger }"|
54e839ea9d44 #BUGFIX
Claus Gittinger <cg@exept.de>
parents: 18379
diff changeset
   336
54e839ea9d44 #BUGFIX
Claus Gittinger <cg@exept.de>
parents: 18379
diff changeset
   337
    idx := anInteger + firstIndex - 1.
54e839ea9d44 #BUGFIX
Claus Gittinger <cg@exept.de>
parents: 18379
diff changeset
   338
    ((anInteger < 1) or:[idx > lastIndex]) ifTrue:[
20341
72ed68b0d0ec little code cleanup
Claus Gittinger <cg@exept.de>
parents: 20026
diff changeset
   339
	^ exceptionValue value
18811
54e839ea9d44 #BUGFIX
Claus Gittinger <cg@exept.de>
parents: 18379
diff changeset
   340
    ].
54e839ea9d44 #BUGFIX
Claus Gittinger <cg@exept.de>
parents: 18379
diff changeset
   341
    ^ contentsArray basicAt:idx
54e839ea9d44 #BUGFIX
Claus Gittinger <cg@exept.de>
parents: 18379
diff changeset
   342
!
54e839ea9d44 #BUGFIX
Claus Gittinger <cg@exept.de>
parents: 18379
diff changeset
   343
606
7a9ab63a6757 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   344
at:anInteger put:anObject
1221
46d72af387e9 commentary
Claus Gittinger <cg@exept.de>
parents: 1170
diff changeset
   345
    "set the element at index, to be anInteger.
46d72af387e9 commentary
Claus Gittinger <cg@exept.de>
parents: 1170
diff changeset
   346
     Return anObject (sigh)."
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   347
3107
ce4b0a4b3b3a checkin from browser
Claus Gittinger <cg@exept.de>
parents: 3095
diff changeset
   348
    |idx "{ Class: SmallInteger }"|
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   349
606
7a9ab63a6757 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   350
    idx := anInteger + firstIndex - 1.
7a9ab63a6757 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   351
    ((anInteger < 1) or:[idx > lastIndex]) ifTrue:[
20341
72ed68b0d0ec little code cleanup
Claus Gittinger <cg@exept.de>
parents: 20026
diff changeset
   352
	^ self subscriptBoundsError:anInteger
3107
ce4b0a4b3b3a checkin from browser
Claus Gittinger <cg@exept.de>
parents: 3095
diff changeset
   353
    ].
ce4b0a4b3b3a checkin from browser
Claus Gittinger <cg@exept.de>
parents: 3095
diff changeset
   354
    ^ contentsArray basicAt:idx put:anObject
1221
46d72af387e9 commentary
Claus Gittinger <cg@exept.de>
parents: 1170
diff changeset
   355
3107
ce4b0a4b3b3a checkin from browser
Claus Gittinger <cg@exept.de>
parents: 3095
diff changeset
   356
    "Modified: / 12.11.1997 / 17:56:32 / cg"
202
40ca7cc6fb9c *** empty log message ***
claus
parents: 159
diff changeset
   357
!
40ca7cc6fb9c *** empty log message ***
claus
parents: 159
diff changeset
   358
606
7a9ab63a6757 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   359
first
7a9ab63a6757 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   360
    "return the first element"
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   361
606
7a9ab63a6757 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   362
    firstIndex <= lastIndex ifTrue:[
7a9ab63a6757 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   363
	^ contentsArray at:firstIndex
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   364
    ].
606
7a9ab63a6757 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   365
    "error if collection is empty"
7a9ab63a6757 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   366
    ^ self emptyCollectionError
2
claus
parents: 1
diff changeset
   367
93
e31220cb391f *** empty log message ***
claus
parents: 88
diff changeset
   368
    "
606
7a9ab63a6757 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   369
     (OrderedCollection withAll:#(1 2 3 4 5)) first
7a9ab63a6757 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   370
     (SortedCollection withAll:#(5 4 3 2 1)) first
93
e31220cb391f *** empty log message ***
claus
parents: 88
diff changeset
   371
    "
13
62303f84ff5f *** empty log message ***
claus
parents: 10
diff changeset
   372
!
62303f84ff5f *** empty log message ***
claus
parents: 10
diff changeset
   373
606
7a9ab63a6757 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   374
last
7a9ab63a6757 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   375
    "return the last element"
68
59faa75185ba *** empty log message ***
claus
parents: 56
diff changeset
   376
606
7a9ab63a6757 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   377
    firstIndex <= lastIndex ifTrue:[
7a9ab63a6757 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   378
	^ contentsArray at:lastIndex
7a9ab63a6757 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   379
    ].
7a9ab63a6757 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   380
    "error if collection is empty"
7a9ab63a6757 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   381
    ^ self emptyCollectionError
68
59faa75185ba *** empty log message ***
claus
parents: 56
diff changeset
   382
93
e31220cb391f *** empty log message ***
claus
parents: 88
diff changeset
   383
    "
606
7a9ab63a6757 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   384
     (OrderedCollection withAll:#(1 2 3 4 5)) last
7a9ab63a6757 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   385
     (SortedCollection withAll:#(5 4 3 2 1)) last
93
e31220cb391f *** empty log message ***
claus
parents: 88
diff changeset
   386
    "
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   387
! !
a27a279701f8 Initial revision
claus
parents:
diff changeset
   388
a27a279701f8 Initial revision
claus
parents:
diff changeset
   389
!OrderedCollection methodsFor:'adding & removing'!
a27a279701f8 Initial revision
claus
parents:
diff changeset
   390
606
7a9ab63a6757 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   391
add:anObject
7a9ab63a6757 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   392
    "add the argument, anObject to the end of the collection
7a9ab63a6757 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   393
     Return the argument, anObject."
7a9ab63a6757 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   394
7a9ab63a6757 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   395
    |idx "{ Class:SmallInteger }"|
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   396
606
7a9ab63a6757 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   397
    idx := lastIndex.
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   398
606
7a9ab63a6757 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   399
    (idx == contentsArray size) ifTrue:[
20341
72ed68b0d0ec little code cleanup
Claus Gittinger <cg@exept.de>
parents: 20026
diff changeset
   400
	self makeRoomAtLast.
72ed68b0d0ec little code cleanup
Claus Gittinger <cg@exept.de>
parents: 20026
diff changeset
   401
	idx := lastIndex.
42
e33491f6f260 *** empty log message ***
claus
parents: 40
diff changeset
   402
    ].
3107
ce4b0a4b3b3a checkin from browser
Claus Gittinger <cg@exept.de>
parents: 3095
diff changeset
   403
    lastIndex := idx := idx + 1.
ce4b0a4b3b3a checkin from browser
Claus Gittinger <cg@exept.de>
parents: 3095
diff changeset
   404
    contentsArray basicAt:idx put:anObject.
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   405
    ^ anObject
42
e33491f6f260 *** empty log message ***
claus
parents: 40
diff changeset
   406
348
claus
parents: 345
diff changeset
   407
    "
606
7a9ab63a6757 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   408
     |c|
7a9ab63a6757 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   409
     c := #(4 3 2 1) asOrderedCollection.
7a9ab63a6757 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   410
     c add:'here'
348
claus
parents: 345
diff changeset
   411
    "
1161
aad722dea51a return values compatible to ST-80; added comments; fixed & tuned #makeRoomAtIndex:
Claus Gittinger <cg@exept.de>
parents: 1157
diff changeset
   412
3107
ce4b0a4b3b3a checkin from browser
Claus Gittinger <cg@exept.de>
parents: 3095
diff changeset
   413
    "Modified: / 12.11.1997 / 17:49:47 / cg"
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   414
!
a27a279701f8 Initial revision
claus
parents:
diff changeset
   415
606
7a9ab63a6757 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   416
add:newObject after:oldObject
7a9ab63a6757 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   417
    "insert the argument, newObject after oldObject.
7a9ab63a6757 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   418
     If oldObject is not in the receiver, report an error,
7a9ab63a6757 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   419
     otherwise return the argument, anObject."
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   420
606
7a9ab63a6757 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   421
    |idx|
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   422
606
7a9ab63a6757 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   423
    idx := self indexOf:oldObject.
7a9ab63a6757 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   424
    idx ~~ 0 ifTrue:[
20341
72ed68b0d0ec little code cleanup
Claus Gittinger <cg@exept.de>
parents: 20026
diff changeset
   425
	self add:newObject beforeIndex:(idx + 1).
72ed68b0d0ec little code cleanup
Claus Gittinger <cg@exept.de>
parents: 20026
diff changeset
   426
	^ newObject
42
e33491f6f260 *** empty log message ***
claus
parents: 40
diff changeset
   427
    ].
1161
aad722dea51a return values compatible to ST-80; added comments; fixed & tuned #makeRoomAtIndex:
Claus Gittinger <cg@exept.de>
parents: 1157
diff changeset
   428
    ^ self errorValueNotFound:oldObject
42
e33491f6f260 *** empty log message ***
claus
parents: 40
diff changeset
   429
348
claus
parents: 345
diff changeset
   430
    "
606
7a9ab63a6757 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   431
     |c|
7a9ab63a6757 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   432
     c := #(4 3 2 1) asOrderedCollection.
20341
72ed68b0d0ec little code cleanup
Claus Gittinger <cg@exept.de>
parents: 20026
diff changeset
   433
     c add:'here' after:3; yourself.
606
7a9ab63a6757 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   434
    "
7a9ab63a6757 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   435
    "
7a9ab63a6757 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   436
     |c|
7a9ab63a6757 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   437
     c := #(4 3 2 1) asOrderedCollection.
20341
72ed68b0d0ec little code cleanup
Claus Gittinger <cg@exept.de>
parents: 20026
diff changeset
   438
     c add:'here' after:1; yourself.
606
7a9ab63a6757 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   439
    "
7a9ab63a6757 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   440
    "
7a9ab63a6757 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   441
     |c|
7a9ab63a6757 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   442
     c := #(4 3 2 1) asOrderedCollection.
20341
72ed68b0d0ec little code cleanup
Claus Gittinger <cg@exept.de>
parents: 20026
diff changeset
   443
     c add:'here' after:5; yourself
606
7a9ab63a6757 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   444
    "
1161
aad722dea51a return values compatible to ST-80; added comments; fixed & tuned #makeRoomAtIndex:
Claus Gittinger <cg@exept.de>
parents: 1157
diff changeset
   445
aad722dea51a return values compatible to ST-80; added comments; fixed & tuned #makeRoomAtIndex:
Claus Gittinger <cg@exept.de>
parents: 1157
diff changeset
   446
    "Modified: 12.4.1996 / 13:51:56 / cg"
606
7a9ab63a6757 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   447
!
7a9ab63a6757 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   448
7a9ab63a6757 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   449
add:anObject afterIndex:index
7a9ab63a6757 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   450
    "insert the argument, anObject to become located at index.
1161
aad722dea51a return values compatible to ST-80; added comments; fixed & tuned #makeRoomAtIndex:
Claus Gittinger <cg@exept.de>
parents: 1157
diff changeset
   451
     Return the receiver (sigh - ST-80 compatibility)."
606
7a9ab63a6757 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   452
7a9ab63a6757 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   453
    ^ self add:anObject beforeIndex:(index + 1)
7a9ab63a6757 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   454
7a9ab63a6757 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   455
    "
7a9ab63a6757 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   456
     |c|
7a9ab63a6757 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   457
     c := #(4 3 2 1) asOrderedCollection.
20341
72ed68b0d0ec little code cleanup
Claus Gittinger <cg@exept.de>
parents: 20026
diff changeset
   458
     c add:'here' afterIndex:2
1161
aad722dea51a return values compatible to ST-80; added comments; fixed & tuned #makeRoomAtIndex:
Claus Gittinger <cg@exept.de>
parents: 1157
diff changeset
   459
    "
aad722dea51a return values compatible to ST-80; added comments; fixed & tuned #makeRoomAtIndex:
Claus Gittinger <cg@exept.de>
parents: 1157
diff changeset
   460
    "
aad722dea51a return values compatible to ST-80; added comments; fixed & tuned #makeRoomAtIndex:
Claus Gittinger <cg@exept.de>
parents: 1157
diff changeset
   461
     |c|
aad722dea51a return values compatible to ST-80; added comments; fixed & tuned #makeRoomAtIndex:
Claus Gittinger <cg@exept.de>
parents: 1157
diff changeset
   462
     c := #(4 3 2 1) asOrderedCollection.
20341
72ed68b0d0ec little code cleanup
Claus Gittinger <cg@exept.de>
parents: 20026
diff changeset
   463
     c add:'here' afterIndex:4
348
claus
parents: 345
diff changeset
   464
    "
1161
aad722dea51a return values compatible to ST-80; added comments; fixed & tuned #makeRoomAtIndex:
Claus Gittinger <cg@exept.de>
parents: 1157
diff changeset
   465
    "
aad722dea51a return values compatible to ST-80; added comments; fixed & tuned #makeRoomAtIndex:
Claus Gittinger <cg@exept.de>
parents: 1157
diff changeset
   466
     |c|
aad722dea51a return values compatible to ST-80; added comments; fixed & tuned #makeRoomAtIndex:
Claus Gittinger <cg@exept.de>
parents: 1157
diff changeset
   467
     c := #(4 3 2 1) asOrderedCollection.
20341
72ed68b0d0ec little code cleanup
Claus Gittinger <cg@exept.de>
parents: 20026
diff changeset
   468
     c add:'here' afterIndex:0
1161
aad722dea51a return values compatible to ST-80; added comments; fixed & tuned #makeRoomAtIndex:
Claus Gittinger <cg@exept.de>
parents: 1157
diff changeset
   469
    "
aad722dea51a return values compatible to ST-80; added comments; fixed & tuned #makeRoomAtIndex:
Claus Gittinger <cg@exept.de>
parents: 1157
diff changeset
   470
    "
aad722dea51a return values compatible to ST-80; added comments; fixed & tuned #makeRoomAtIndex:
Claus Gittinger <cg@exept.de>
parents: 1157
diff changeset
   471
     |c|
aad722dea51a return values compatible to ST-80; added comments; fixed & tuned #makeRoomAtIndex:
Claus Gittinger <cg@exept.de>
parents: 1157
diff changeset
   472
     c := #(4 3 2 1) asOrderedCollection.
20341
72ed68b0d0ec little code cleanup
Claus Gittinger <cg@exept.de>
parents: 20026
diff changeset
   473
     c add:'here' afterIndex:5
1161
aad722dea51a return values compatible to ST-80; added comments; fixed & tuned #makeRoomAtIndex:
Claus Gittinger <cg@exept.de>
parents: 1157
diff changeset
   474
    "
aad722dea51a return values compatible to ST-80; added comments; fixed & tuned #makeRoomAtIndex:
Claus Gittinger <cg@exept.de>
parents: 1157
diff changeset
   475
aad722dea51a return values compatible to ST-80; added comments; fixed & tuned #makeRoomAtIndex:
Claus Gittinger <cg@exept.de>
parents: 1157
diff changeset
   476
    "Modified: 12.4.1996 / 13:52:41 / cg"
348
claus
parents: 345
diff changeset
   477
!
claus
parents: 345
diff changeset
   478
606
7a9ab63a6757 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   479
add:newObject before:oldObject
7a9ab63a6757 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   480
    "insert the argument, newObject before oldObject.
7a9ab63a6757 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   481
     If oldObject is not in the receiver, report an error,
7a9ab63a6757 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   482
     otherwise return the argument, anObject."
348
claus
parents: 345
diff changeset
   483
606
7a9ab63a6757 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   484
    |idx|
348
claus
parents: 345
diff changeset
   485
606
7a9ab63a6757 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   486
    idx := self indexOf:oldObject.
7a9ab63a6757 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   487
    idx ~~ 0 ifTrue:[
20341
72ed68b0d0ec little code cleanup
Claus Gittinger <cg@exept.de>
parents: 20026
diff changeset
   488
	self add:newObject beforeIndex:idx.
72ed68b0d0ec little code cleanup
Claus Gittinger <cg@exept.de>
parents: 20026
diff changeset
   489
	^ newObject
348
claus
parents: 345
diff changeset
   490
    ].
1161
aad722dea51a return values compatible to ST-80; added comments; fixed & tuned #makeRoomAtIndex:
Claus Gittinger <cg@exept.de>
parents: 1157
diff changeset
   491
    ^ self errorValueNotFound:oldObject
348
claus
parents: 345
diff changeset
   492
claus
parents: 345
diff changeset
   493
    "
606
7a9ab63a6757 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   494
     |c|
7a9ab63a6757 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   495
     c := #(4 3 2 1) asOrderedCollection.
7a9ab63a6757 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   496
     c add:'here' before:3.
20341
72ed68b0d0ec little code cleanup
Claus Gittinger <cg@exept.de>
parents: 20026
diff changeset
   497
     c add:'here' before:5
348
claus
parents: 345
diff changeset
   498
    "
1161
aad722dea51a return values compatible to ST-80; added comments; fixed & tuned #makeRoomAtIndex:
Claus Gittinger <cg@exept.de>
parents: 1157
diff changeset
   499
aad722dea51a return values compatible to ST-80; added comments; fixed & tuned #makeRoomAtIndex:
Claus Gittinger <cg@exept.de>
parents: 1157
diff changeset
   500
    "Modified: 12.4.1996 / 13:25:47 / cg"
348
claus
parents: 345
diff changeset
   501
!
claus
parents: 345
diff changeset
   502
606
7a9ab63a6757 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   503
add:anObject beforeIndex:index
7a9ab63a6757 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   504
    "insert the argument, anObject to become located at index.
1161
aad722dea51a return values compatible to ST-80; added comments; fixed & tuned #makeRoomAtIndex:
Claus Gittinger <cg@exept.de>
parents: 1157
diff changeset
   505
     Return the receiver (sigh - ST-80 compatibility)."
aad722dea51a return values compatible to ST-80; added comments; fixed & tuned #makeRoomAtIndex:
Claus Gittinger <cg@exept.de>
parents: 1157
diff changeset
   506
3236
b5f80b416cff check for valid subscript in #add:beforeIndex:
Claus Gittinger <cg@exept.de>
parents: 3109
diff changeset
   507
    |idx physicalIndex|
348
claus
parents: 345
diff changeset
   508
3236
b5f80b416cff check for valid subscript in #add:beforeIndex:
Claus Gittinger <cg@exept.de>
parents: 3109
diff changeset
   509
    physicalIndex := index + firstIndex - 1.
b5f80b416cff check for valid subscript in #add:beforeIndex:
Claus Gittinger <cg@exept.de>
parents: 3109
diff changeset
   510
    physicalIndex > lastIndex ifTrue:[
20341
72ed68b0d0ec little code cleanup
Claus Gittinger <cg@exept.de>
parents: 20026
diff changeset
   511
	"can only add to the end of the collection"
72ed68b0d0ec little code cleanup
Claus Gittinger <cg@exept.de>
parents: 20026
diff changeset
   512
	physicalIndex == (lastIndex+1) ifTrue:[
72ed68b0d0ec little code cleanup
Claus Gittinger <cg@exept.de>
parents: 20026
diff changeset
   513
	    idx := lastIndex.
72ed68b0d0ec little code cleanup
Claus Gittinger <cg@exept.de>
parents: 20026
diff changeset
   514
	    (idx == contentsArray size) ifTrue:[
72ed68b0d0ec little code cleanup
Claus Gittinger <cg@exept.de>
parents: 20026
diff changeset
   515
		self makeRoomAtLast.
72ed68b0d0ec little code cleanup
Claus Gittinger <cg@exept.de>
parents: 20026
diff changeset
   516
		idx := lastIndex.
72ed68b0d0ec little code cleanup
Claus Gittinger <cg@exept.de>
parents: 20026
diff changeset
   517
	    ].
72ed68b0d0ec little code cleanup
Claus Gittinger <cg@exept.de>
parents: 20026
diff changeset
   518
	    lastIndex := idx := idx + 1.
72ed68b0d0ec little code cleanup
Claus Gittinger <cg@exept.de>
parents: 20026
diff changeset
   519
	] ifFalse:[
72ed68b0d0ec little code cleanup
Claus Gittinger <cg@exept.de>
parents: 20026
diff changeset
   520
	    ^ self subscriptBoundsError:index.
72ed68b0d0ec little code cleanup
Claus Gittinger <cg@exept.de>
parents: 20026
diff changeset
   521
	]
10839
285fa5534f61 #add:beforeIndex: take care for redefinitions of #add: in subclasses sending #add:beforeIndex:
Stefan Vogel <sv@exept.de>
parents: 10799
diff changeset
   522
    ] ifFalse:[
20341
72ed68b0d0ec little code cleanup
Claus Gittinger <cg@exept.de>
parents: 20026
diff changeset
   523
	"notice: this may change firstIndex"
72ed68b0d0ec little code cleanup
Claus Gittinger <cg@exept.de>
parents: 20026
diff changeset
   524
	idx := self makeRoomAtIndex:physicalIndex.
3236
b5f80b416cff check for valid subscript in #add:beforeIndex:
Claus Gittinger <cg@exept.de>
parents: 3109
diff changeset
   525
    ].
3107
ce4b0a4b3b3a checkin from browser
Claus Gittinger <cg@exept.de>
parents: 3095
diff changeset
   526
    contentsArray basicAt:idx put:anObject.
348
claus
parents: 345
diff changeset
   527
claus
parents: 345
diff changeset
   528
    "
606
7a9ab63a6757 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   529
     |c|
7a9ab63a6757 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   530
     c := #(4 3 2 1) asOrderedCollection.
20341
72ed68b0d0ec little code cleanup
Claus Gittinger <cg@exept.de>
parents: 20026
diff changeset
   531
     c add:'here' beforeIndex:3
606
7a9ab63a6757 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   532
    "
7a9ab63a6757 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   533
    "
7a9ab63a6757 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   534
     |c|
7a9ab63a6757 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   535
     c := #(4 3 2 1) asOrderedCollection.
20341
72ed68b0d0ec little code cleanup
Claus Gittinger <cg@exept.de>
parents: 20026
diff changeset
   536
     c add:'here' beforeIndex:1
606
7a9ab63a6757 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   537
    "
7a9ab63a6757 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   538
    "
7a9ab63a6757 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   539
     |c|
7a9ab63a6757 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   540
     c := #(4 3 2 1) asOrderedCollection.
20341
72ed68b0d0ec little code cleanup
Claus Gittinger <cg@exept.de>
parents: 20026
diff changeset
   541
     c add:'here' beforeIndex:5
348
claus
parents: 345
diff changeset
   542
    "
1161
aad722dea51a return values compatible to ST-80; added comments; fixed & tuned #makeRoomAtIndex:
Claus Gittinger <cg@exept.de>
parents: 1157
diff changeset
   543
3236
b5f80b416cff check for valid subscript in #add:beforeIndex:
Claus Gittinger <cg@exept.de>
parents: 3109
diff changeset
   544
    "Modified: / 28.1.1998 / 17:17:48 / cg"
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   545
!
a27a279701f8 Initial revision
claus
parents:
diff changeset
   546
3109
2ac640e610aa reimplement #addAll:aCollection
ca
parents: 3107
diff changeset
   547
addAll:aCollection
20341
72ed68b0d0ec little code cleanup
Claus Gittinger <cg@exept.de>
parents: 20026
diff changeset
   548
    "add all elements of the argument, aCollection to the receiver.
7752
134213bdebd8 comment
Claus Gittinger <cg@exept.de>
parents: 7260
diff changeset
   549
     Returns the argument, aCollection (sigh)."
3109
2ac640e610aa reimplement #addAll:aCollection
ca
parents: 3107
diff changeset
   550
2ac640e610aa reimplement #addAll:aCollection
ca
parents: 3107
diff changeset
   551
    self addAll:aCollection beforeIndex:(1 + self size).
2ac640e610aa reimplement #addAll:aCollection
ca
parents: 3107
diff changeset
   552
    ^ aCollection
2ac640e610aa reimplement #addAll:aCollection
ca
parents: 3107
diff changeset
   553
!
2ac640e610aa reimplement #addAll:aCollection
ca
parents: 3107
diff changeset
   554
15442
5ae3f8265977 class: OrderedCollection
Claus Gittinger <cg@exept.de>
parents: 15401
diff changeset
   555
addAll:aCollection afterIndex:index
5ae3f8265977 class: OrderedCollection
Claus Gittinger <cg@exept.de>
parents: 15401
diff changeset
   556
    "insert the argument, anObject to become located after index.
5ae3f8265977 class: OrderedCollection
Claus Gittinger <cg@exept.de>
parents: 15401
diff changeset
   557
     Return the receiver (sigh - ST-80 compatibility)."
5ae3f8265977 class: OrderedCollection
Claus Gittinger <cg@exept.de>
parents: 15401
diff changeset
   558
5ae3f8265977 class: OrderedCollection
Claus Gittinger <cg@exept.de>
parents: 15401
diff changeset
   559
    ^ self addAll:aCollection beforeIndex:(index + 1)
5ae3f8265977 class: OrderedCollection
Claus Gittinger <cg@exept.de>
parents: 15401
diff changeset
   560
5ae3f8265977 class: OrderedCollection
Claus Gittinger <cg@exept.de>
parents: 15401
diff changeset
   561
    "
5ae3f8265977 class: OrderedCollection
Claus Gittinger <cg@exept.de>
parents: 15401
diff changeset
   562
     |c|
5ae3f8265977 class: OrderedCollection
Claus Gittinger <cg@exept.de>
parents: 15401
diff changeset
   563
     c := #(4 3 2 1) asOrderedCollection.
20341
72ed68b0d0ec little code cleanup
Claus Gittinger <cg@exept.de>
parents: 20026
diff changeset
   564
     c addAll:#(10 20 30) afterIndex:2
15442
5ae3f8265977 class: OrderedCollection
Claus Gittinger <cg@exept.de>
parents: 15401
diff changeset
   565
    "
5ae3f8265977 class: OrderedCollection
Claus Gittinger <cg@exept.de>
parents: 15401
diff changeset
   566
    "
5ae3f8265977 class: OrderedCollection
Claus Gittinger <cg@exept.de>
parents: 15401
diff changeset
   567
     |c|
5ae3f8265977 class: OrderedCollection
Claus Gittinger <cg@exept.de>
parents: 15401
diff changeset
   568
     c := #(4 3 2 1) asOrderedCollection.
20341
72ed68b0d0ec little code cleanup
Claus Gittinger <cg@exept.de>
parents: 20026
diff changeset
   569
     c addAll:#(10 20 30) afterIndex:4
15442
5ae3f8265977 class: OrderedCollection
Claus Gittinger <cg@exept.de>
parents: 15401
diff changeset
   570
    "
5ae3f8265977 class: OrderedCollection
Claus Gittinger <cg@exept.de>
parents: 15401
diff changeset
   571
    "
5ae3f8265977 class: OrderedCollection
Claus Gittinger <cg@exept.de>
parents: 15401
diff changeset
   572
     |c|
5ae3f8265977 class: OrderedCollection
Claus Gittinger <cg@exept.de>
parents: 15401
diff changeset
   573
     c := #(4 3 2 1) asOrderedCollection.
20341
72ed68b0d0ec little code cleanup
Claus Gittinger <cg@exept.de>
parents: 20026
diff changeset
   574
     c addAll:#(10 20 30) afterIndex:0
15442
5ae3f8265977 class: OrderedCollection
Claus Gittinger <cg@exept.de>
parents: 15401
diff changeset
   575
    "
5ae3f8265977 class: OrderedCollection
Claus Gittinger <cg@exept.de>
parents: 15401
diff changeset
   576
5ae3f8265977 class: OrderedCollection
Claus Gittinger <cg@exept.de>
parents: 15401
diff changeset
   577
    "Modified: 12.4.1996 / 13:52:41 / cg"
5ae3f8265977 class: OrderedCollection
Claus Gittinger <cg@exept.de>
parents: 15401
diff changeset
   578
!
5ae3f8265977 class: OrderedCollection
Claus Gittinger <cg@exept.de>
parents: 15401
diff changeset
   579
2222
e6fa084818ec added #addAll:beforeIndex:
Claus Gittinger <cg@exept.de>
parents: 2166
diff changeset
   580
addAll:aCollection beforeIndex:index
e6fa084818ec added #addAll:beforeIndex:
Claus Gittinger <cg@exept.de>
parents: 2166
diff changeset
   581
    "insert all elements of the argument, anObject to become located at index.
e6fa084818ec added #addAll:beforeIndex:
Claus Gittinger <cg@exept.de>
parents: 2166
diff changeset
   582
     The collection may be unordered, but then order of the sliced-in elements
e6fa084818ec added #addAll:beforeIndex:
Claus Gittinger <cg@exept.de>
parents: 2166
diff changeset
   583
     is undefined.
e6fa084818ec added #addAll:beforeIndex:
Claus Gittinger <cg@exept.de>
parents: 2166
diff changeset
   584
     Return the receiver."
e6fa084818ec added #addAll:beforeIndex:
Claus Gittinger <cg@exept.de>
parents: 2166
diff changeset
   585
e6fa084818ec added #addAll:beforeIndex:
Claus Gittinger <cg@exept.de>
parents: 2166
diff changeset
   586
    |idx count|
e6fa084818ec added #addAll:beforeIndex:
Claus Gittinger <cg@exept.de>
parents: 2166
diff changeset
   587
e6fa084818ec added #addAll:beforeIndex:
Claus Gittinger <cg@exept.de>
parents: 2166
diff changeset
   588
    aCollection isSequenceable ifTrue:[
20341
72ed68b0d0ec little code cleanup
Claus Gittinger <cg@exept.de>
parents: 20026
diff changeset
   589
	"/ we are lucky - that thing can count & do bulk copies
2222
e6fa084818ec added #addAll:beforeIndex:
Claus Gittinger <cg@exept.de>
parents: 2166
diff changeset
   590
20341
72ed68b0d0ec little code cleanup
Claus Gittinger <cg@exept.de>
parents: 20026
diff changeset
   591
	count := aCollection size.
72ed68b0d0ec little code cleanup
Claus Gittinger <cg@exept.de>
parents: 20026
diff changeset
   592
	idx := self makeRoomAtIndex:(index + firstIndex - 1) for:count.
72ed68b0d0ec little code cleanup
Claus Gittinger <cg@exept.de>
parents: 20026
diff changeset
   593
	"/ notice: the above may change firstIndex
72ed68b0d0ec little code cleanup
Claus Gittinger <cg@exept.de>
parents: 20026
diff changeset
   594
	contentsArray replaceFrom:idx to:(idx + count - 1) with:aCollection startingAt:1.
72ed68b0d0ec little code cleanup
Claus Gittinger <cg@exept.de>
parents: 20026
diff changeset
   595
	^ self
2222
e6fa084818ec added #addAll:beforeIndex:
Claus Gittinger <cg@exept.de>
parents: 2166
diff changeset
   596
    ].
e6fa084818ec added #addAll:beforeIndex:
Claus Gittinger <cg@exept.de>
parents: 2166
diff changeset
   597
e6fa084818ec added #addAll:beforeIndex:
Claus Gittinger <cg@exept.de>
parents: 2166
diff changeset
   598
    idx := index.
e6fa084818ec added #addAll:beforeIndex:
Claus Gittinger <cg@exept.de>
parents: 2166
diff changeset
   599
    aCollection do:[:element |
20341
72ed68b0d0ec little code cleanup
Claus Gittinger <cg@exept.de>
parents: 20026
diff changeset
   600
	self add:element beforeIndex:idx.
72ed68b0d0ec little code cleanup
Claus Gittinger <cg@exept.de>
parents: 20026
diff changeset
   601
	idx := idx + 1.
2222
e6fa084818ec added #addAll:beforeIndex:
Claus Gittinger <cg@exept.de>
parents: 2166
diff changeset
   602
    ].
e6fa084818ec added #addAll:beforeIndex:
Claus Gittinger <cg@exept.de>
parents: 2166
diff changeset
   603
e6fa084818ec added #addAll:beforeIndex:
Claus Gittinger <cg@exept.de>
parents: 2166
diff changeset
   604
    "
e6fa084818ec added #addAll:beforeIndex:
Claus Gittinger <cg@exept.de>
parents: 2166
diff changeset
   605
     |c|
e6fa084818ec added #addAll:beforeIndex:
Claus Gittinger <cg@exept.de>
parents: 2166
diff changeset
   606
     c := #(1 2 3 4) asOrderedCollection.
20341
72ed68b0d0ec little code cleanup
Claus Gittinger <cg@exept.de>
parents: 20026
diff changeset
   607
     c addAll:'here' beforeIndex:3
2222
e6fa084818ec added #addAll:beforeIndex:
Claus Gittinger <cg@exept.de>
parents: 2166
diff changeset
   608
    "
e6fa084818ec added #addAll:beforeIndex:
Claus Gittinger <cg@exept.de>
parents: 2166
diff changeset
   609
    "
e6fa084818ec added #addAll:beforeIndex:
Claus Gittinger <cg@exept.de>
parents: 2166
diff changeset
   610
     |c|
e6fa084818ec added #addAll:beforeIndex:
Claus Gittinger <cg@exept.de>
parents: 2166
diff changeset
   611
     c := #(1 2 3 4) asOrderedCollection.
2549
9ca8a3fcdaa7 fixed #addAll:beforeIndex:
Claus Gittinger <cg@exept.de>
parents: 2364
diff changeset
   612
     c removeFirst.
20341
72ed68b0d0ec little code cleanup
Claus Gittinger <cg@exept.de>
parents: 20026
diff changeset
   613
     c addAll:'here' beforeIndex:3
2549
9ca8a3fcdaa7 fixed #addAll:beforeIndex:
Claus Gittinger <cg@exept.de>
parents: 2364
diff changeset
   614
    "
9ca8a3fcdaa7 fixed #addAll:beforeIndex:
Claus Gittinger <cg@exept.de>
parents: 2364
diff changeset
   615
    "
9ca8a3fcdaa7 fixed #addAll:beforeIndex:
Claus Gittinger <cg@exept.de>
parents: 2364
diff changeset
   616
     |c|
9ca8a3fcdaa7 fixed #addAll:beforeIndex:
Claus Gittinger <cg@exept.de>
parents: 2364
diff changeset
   617
     c := #(1 2 3 4) asOrderedCollection.
20341
72ed68b0d0ec little code cleanup
Claus Gittinger <cg@exept.de>
parents: 20026
diff changeset
   618
     c addAll:'here' beforeIndex:1
2222
e6fa084818ec added #addAll:beforeIndex:
Claus Gittinger <cg@exept.de>
parents: 2166
diff changeset
   619
    "
e6fa084818ec added #addAll:beforeIndex:
Claus Gittinger <cg@exept.de>
parents: 2166
diff changeset
   620
    "
e6fa084818ec added #addAll:beforeIndex:
Claus Gittinger <cg@exept.de>
parents: 2166
diff changeset
   621
     |c|
e6fa084818ec added #addAll:beforeIndex:
Claus Gittinger <cg@exept.de>
parents: 2166
diff changeset
   622
     c := #(1 2 3 4) asOrderedCollection.
20341
72ed68b0d0ec little code cleanup
Claus Gittinger <cg@exept.de>
parents: 20026
diff changeset
   623
     c addAll:'here' beforeIndex:5
2222
e6fa084818ec added #addAll:beforeIndex:
Claus Gittinger <cg@exept.de>
parents: 2166
diff changeset
   624
    "
e6fa084818ec added #addAll:beforeIndex:
Claus Gittinger <cg@exept.de>
parents: 2166
diff changeset
   625
e6fa084818ec added #addAll:beforeIndex:
Claus Gittinger <cg@exept.de>
parents: 2166
diff changeset
   626
    "
e6fa084818ec added #addAll:beforeIndex:
Claus Gittinger <cg@exept.de>
parents: 2166
diff changeset
   627
     |c|
e6fa084818ec added #addAll:beforeIndex:
Claus Gittinger <cg@exept.de>
parents: 2166
diff changeset
   628
     c := #(1 2 3 4) asOrderedCollection.
e6fa084818ec added #addAll:beforeIndex:
Claus Gittinger <cg@exept.de>
parents: 2166
diff changeset
   629
     c addAll:('hello' asSet) beforeIndex:3
e6fa084818ec added #addAll:beforeIndex:
Claus Gittinger <cg@exept.de>
parents: 2166
diff changeset
   630
    "
e6fa084818ec added #addAll:beforeIndex:
Claus Gittinger <cg@exept.de>
parents: 2166
diff changeset
   631
2549
9ca8a3fcdaa7 fixed #addAll:beforeIndex:
Claus Gittinger <cg@exept.de>
parents: 2364
diff changeset
   632
    "Modified: 15.4.1997 / 12:43:59 / cg"
2222
e6fa084818ec added #addAll:beforeIndex:
Claus Gittinger <cg@exept.de>
parents: 2166
diff changeset
   633
!
e6fa084818ec added #addAll:beforeIndex:
Claus Gittinger <cg@exept.de>
parents: 2166
diff changeset
   634
606
7a9ab63a6757 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   635
addFirst:anObject
7a9ab63a6757 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   636
    "add the argument, anObject to the beginning of the collection.
7a9ab63a6757 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   637
     Return the argument, anObject."
56
be0ed17e6f85 *** empty log message ***
claus
parents: 42
diff changeset
   638
3107
ce4b0a4b3b3a checkin from browser
Claus Gittinger <cg@exept.de>
parents: 3095
diff changeset
   639
    |idx "{ Class:SmallInteger }"|
ce4b0a4b3b3a checkin from browser
Claus Gittinger <cg@exept.de>
parents: 3095
diff changeset
   640
ce4b0a4b3b3a checkin from browser
Claus Gittinger <cg@exept.de>
parents: 3095
diff changeset
   641
    (idx := firstIndex) == 1 ifTrue:[
20341
72ed68b0d0ec little code cleanup
Claus Gittinger <cg@exept.de>
parents: 20026
diff changeset
   642
	self makeRoomAtFront.
72ed68b0d0ec little code cleanup
Claus Gittinger <cg@exept.de>
parents: 20026
diff changeset
   643
	idx := firstIndex.
348
claus
parents: 345
diff changeset
   644
    ].
3107
ce4b0a4b3b3a checkin from browser
Claus Gittinger <cg@exept.de>
parents: 3095
diff changeset
   645
    firstIndex := idx := idx - 1.
ce4b0a4b3b3a checkin from browser
Claus Gittinger <cg@exept.de>
parents: 3095
diff changeset
   646
    contentsArray basicAt:idx put:anObject.
606
7a9ab63a6757 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   647
    ^ anObject
56
be0ed17e6f85 *** empty log message ***
claus
parents: 42
diff changeset
   648
be0ed17e6f85 *** empty log message ***
claus
parents: 42
diff changeset
   649
    "
606
7a9ab63a6757 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   650
     |c|
7a9ab63a6757 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   651
     c := #(1 2 3 4) asOrderedCollection.
7a9ab63a6757 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   652
     c addFirst:'here'.
7a9ab63a6757 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   653
     c
7a9ab63a6757 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   654
    "
7a9ab63a6757 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   655
7a9ab63a6757 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   656
    "
7a9ab63a6757 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   657
     |c|
7a9ab63a6757 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   658
     c := #() asOrderedCollection.
7a9ab63a6757 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   659
     c addFirst:'here'.
7a9ab63a6757 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   660
     c
56
be0ed17e6f85 *** empty log message ***
claus
parents: 42
diff changeset
   661
    "
3107
ce4b0a4b3b3a checkin from browser
Claus Gittinger <cg@exept.de>
parents: 3095
diff changeset
   662
ce4b0a4b3b3a checkin from browser
Claus Gittinger <cg@exept.de>
parents: 3095
diff changeset
   663
    "Modified: / 12.11.1997 / 17:58:05 / cg"
ce4b0a4b3b3a checkin from browser
Claus Gittinger <cg@exept.de>
parents: 3095
diff changeset
   664
!
ce4b0a4b3b3a checkin from browser
Claus Gittinger <cg@exept.de>
parents: 3095
diff changeset
   665
3368
5b84482d26c9 added #clearContents:
ca
parents: 3236
diff changeset
   666
clearContents
5b84482d26c9 added #clearContents:
ca
parents: 3236
diff changeset
   667
    "remove all elements from the collection but keep the contentsArray.
20341
72ed68b0d0ec little code cleanup
Claus Gittinger <cg@exept.de>
parents: 20026
diff changeset
   668
     Useful for huge lists, if the contents will be rebuild soon (using #add:)
3368
5b84482d26c9 added #clearContents:
ca
parents: 3236
diff changeset
   669
     to a size which is similar to the lists current size.
16304
2d8de035fd7a class: OrderedCollection
Claus Gittinger <cg@exept.de>
parents: 15757
diff changeset
   670
     Destructive: modifies the receiver.
3368
5b84482d26c9 added #clearContents:
ca
parents: 3236
diff changeset
   671
     Returns the receiver."
5b84482d26c9 added #clearContents:
ca
parents: 3236
diff changeset
   672
5b84482d26c9 added #clearContents:
ca
parents: 3236
diff changeset
   673
    "/ clear those references, to give the garbage collector
5b84482d26c9 added #clearContents:
ca
parents: 3236
diff changeset
   674
    "/ a chance ...
5b84482d26c9 added #clearContents:
ca
parents: 3236
diff changeset
   675
5b84482d26c9 added #clearContents:
ca
parents: 3236
diff changeset
   676
    firstIndex >= lastIndex ifTrue:[
20341
72ed68b0d0ec little code cleanup
Claus Gittinger <cg@exept.de>
parents: 20026
diff changeset
   677
	contentsArray from:firstIndex to:lastIndex put:nil.
3368
5b84482d26c9 added #clearContents:
ca
parents: 3236
diff changeset
   678
    ].
5b84482d26c9 added #clearContents:
ca
parents: 3236
diff changeset
   679
    firstIndex := 1.
5b84482d26c9 added #clearContents:
ca
parents: 3236
diff changeset
   680
    lastIndex := 0.
5b84482d26c9 added #clearContents:
ca
parents: 3236
diff changeset
   681
5b84482d26c9 added #clearContents:
ca
parents: 3236
diff changeset
   682
    "/ this is the same as:
5b84482d26c9 added #clearContents:
ca
parents: 3236
diff changeset
   683
    "/ self initContents:(self size)
5b84482d26c9 added #clearContents:
ca
parents: 3236
diff changeset
   684
5b84482d26c9 added #clearContents:
ca
parents: 3236
diff changeset
   685
    "Modified: 12.4.1996 / 13:34:19 / cg"
5b84482d26c9 added #clearContents:
ca
parents: 3236
diff changeset
   686
!
5b84482d26c9 added #clearContents:
ca
parents: 3236
diff changeset
   687
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   688
remove:anObject ifAbsent:exceptionBlock
2348
523e9d6e0049 added #removeIdentical:ifAbsent:
Claus Gittinger <cg@exept.de>
parents: 2222
diff changeset
   689
    "remove the first element which is equal to anObject;
20341
72ed68b0d0ec little code cleanup
Claus Gittinger <cg@exept.de>
parents: 20026
diff changeset
   690
     if found, remove and return it;
2348
523e9d6e0049 added #removeIdentical:ifAbsent:
Claus Gittinger <cg@exept.de>
parents: 2222
diff changeset
   691
     if not, return the value from evaluating exceptionBlock.
16304
2d8de035fd7a class: OrderedCollection
Claus Gittinger <cg@exept.de>
parents: 15757
diff changeset
   692
     Destructive: modifies the receiver.
2362
23574f29c8af checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2361
diff changeset
   693
     Uses equality compare (=) to search for the element."
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   694
2354
652d17daeeb5 faster remove: if its the first or last element
Claus Gittinger <cg@exept.de>
parents: 2348
diff changeset
   695
    |index retVal|
652d17daeeb5 faster remove: if its the first or last element
Claus Gittinger <cg@exept.de>
parents: 2348
diff changeset
   696
12035
b927a2b293f8 changed:
Claus Gittinger <cg@exept.de>
parents: 11330
diff changeset
   697
    index := self indexOf:anObject.
2354
652d17daeeb5 faster remove: if its the first or last element
Claus Gittinger <cg@exept.de>
parents: 2348
diff changeset
   698
    index ~~ 0 ifTrue:[
20341
72ed68b0d0ec little code cleanup
Claus Gittinger <cg@exept.de>
parents: 20026
diff changeset
   699
	retVal := contentsArray at:index+firstIndex-1.
72ed68b0d0ec little code cleanup
Claus Gittinger <cg@exept.de>
parents: 20026
diff changeset
   700
	self removeFromIndex:index toIndex:index.
72ed68b0d0ec little code cleanup
Claus Gittinger <cg@exept.de>
parents: 20026
diff changeset
   701
	^ retVal
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   702
    ].
a27a279701f8 Initial revision
claus
parents:
diff changeset
   703
    ^ exceptionBlock value
348
claus
parents: 345
diff changeset
   704
claus
parents: 345
diff changeset
   705
    "
12035
b927a2b293f8 changed:
Claus Gittinger <cg@exept.de>
parents: 11330
diff changeset
   706
     #(1 2 3 4 5) asOrderedCollection remove:9 ifAbsent:[self halt]; yourself
20341
72ed68b0d0ec little code cleanup
Claus Gittinger <cg@exept.de>
parents: 20026
diff changeset
   707
     #(1 2 3 4 5) asOrderedCollection remove:3 ifAbsent:[self halt]; yourself
1496
bea70dc24829 commentary
Claus Gittinger <cg@exept.de>
parents: 1422
diff changeset
   708
20341
72ed68b0d0ec little code cleanup
Claus Gittinger <cg@exept.de>
parents: 20026
diff changeset
   709
     #(1 2 3 4 5 6 7 8 9) asOrderedCollection remove:3 ifAbsent:'oops'
72ed68b0d0ec little code cleanup
Claus Gittinger <cg@exept.de>
parents: 20026
diff changeset
   710
     #(1 2 3 4 5) asOrderedCollection remove:9 ifAbsent:'oops'
72ed68b0d0ec little code cleanup
Claus Gittinger <cg@exept.de>
parents: 20026
diff changeset
   711
     #(1.0 2.0 3.0 4.0 5.0) asOrderedCollection remove:4 ifAbsent:'oops'
72ed68b0d0ec little code cleanup
Claus Gittinger <cg@exept.de>
parents: 20026
diff changeset
   712
     #(1.0 2.0 3.0 4.0 5.0) asOrderedCollection removeIdentical:4 ifAbsent:'oops'
348
claus
parents: 345
diff changeset
   713
    "
2348
523e9d6e0049 added #removeIdentical:ifAbsent:
Claus Gittinger <cg@exept.de>
parents: 2222
diff changeset
   714
2362
23574f29c8af checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2361
diff changeset
   715
    "Modified: 8.2.1997 / 19:17:19 / cg"
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   716
!
a27a279701f8 Initial revision
claus
parents:
diff changeset
   717
114
0353ec6749c8 added faster removeAll
claus
parents: 93
diff changeset
   718
removeAll
1161
aad722dea51a return values compatible to ST-80; added comments; fixed & tuned #makeRoomAtIndex:
Claus Gittinger <cg@exept.de>
parents: 1157
diff changeset
   719
    "remove all elements from the collection.
16304
2d8de035fd7a class: OrderedCollection
Claus Gittinger <cg@exept.de>
parents: 15757
diff changeset
   720
     Returns the receiver.
2d8de035fd7a class: OrderedCollection
Claus Gittinger <cg@exept.de>
parents: 15757
diff changeset
   721
     Destructive: modifies the receiver."
114
0353ec6749c8 added faster removeAll
claus
parents: 93
diff changeset
   722
18879
5d1bbfc1761d #FEATURE
Stefan Vogel <sv@exept.de>
parents: 18811
diff changeset
   723
    self initContents:0
1161
aad722dea51a return values compatible to ST-80; added comments; fixed & tuned #makeRoomAtIndex:
Claus Gittinger <cg@exept.de>
parents: 1157
diff changeset
   724
aad722dea51a return values compatible to ST-80; added comments; fixed & tuned #makeRoomAtIndex:
Claus Gittinger <cg@exept.de>
parents: 1157
diff changeset
   725
    "Modified: 12.4.1996 / 13:34:19 / cg"
114
0353ec6749c8 added faster removeAll
claus
parents: 93
diff changeset
   726
!
0353ec6749c8 added faster removeAll
claus
parents: 93
diff changeset
   727
348
claus
parents: 345
diff changeset
   728
removeAllSuchThat:aBlock
claus
parents: 345
diff changeset
   729
    "remove all elements that meet a test criteria as specified in aBlock.
claus
parents: 345
diff changeset
   730
     The argument, aBlock is evaluated for successive elements and all those,
1161
aad722dea51a return values compatible to ST-80; added comments; fixed & tuned #makeRoomAtIndex:
Claus Gittinger <cg@exept.de>
parents: 1157
diff changeset
   731
     for which it returns true, are removed.
16304
2d8de035fd7a class: OrderedCollection
Claus Gittinger <cg@exept.de>
parents: 15757
diff changeset
   732
     Destructive: modifies the receiver.
1496
bea70dc24829 commentary
Claus Gittinger <cg@exept.de>
parents: 1422
diff changeset
   733
     Return a collection containing the removed elements.
bea70dc24829 commentary
Claus Gittinger <cg@exept.de>
parents: 1422
diff changeset
   734
20341
72ed68b0d0ec little code cleanup
Claus Gittinger <cg@exept.de>
parents: 20026
diff changeset
   735
     Performance:
72ed68b0d0ec little code cleanup
Claus Gittinger <cg@exept.de>
parents: 20026
diff changeset
   736
	this is an O(N) algorithm (the receiver's elements are scanned once)."
348
claus
parents: 345
diff changeset
   737
1161
aad722dea51a return values compatible to ST-80; added comments; fixed & tuned #makeRoomAtIndex:
Claus Gittinger <cg@exept.de>
parents: 1157
diff changeset
   738
    "/ this is a q&d implementation (possibly slow).
348
claus
parents: 345
diff changeset
   739
20341
72ed68b0d0ec little code cleanup
Claus Gittinger <cg@exept.de>
parents: 20026
diff changeset
   740
    |removed element
19831
5e0f261a1daa #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 19792
diff changeset
   741
     srcIndex "{ Class: SmallInteger }"
19865
6b114e3b40b9 #TUNING by stefan
Stefan Vogel <sv@exept.de>
parents: 19836
diff changeset
   742
     dstIndex "{ Class: SmallInteger }"
6b114e3b40b9 #TUNING by stefan
Stefan Vogel <sv@exept.de>
parents: 19836
diff changeset
   743
     lastIdx "{ Class: SmallInteger }"|
348
claus
parents: 345
diff changeset
   744
19831
5e0f261a1daa #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 19792
diff changeset
   745
    "/ first search forward to the first element which has
5e0f261a1daa #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 19792
diff changeset
   746
    "/ to be removed (meets the criteria)
5e0f261a1daa #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 19792
diff changeset
   747
    srcIndex := firstIndex.
19865
6b114e3b40b9 #TUNING by stefan
Stefan Vogel <sv@exept.de>
parents: 19836
diff changeset
   748
    lastIdx := lastIndex.
6b114e3b40b9 #TUNING by stefan
Stefan Vogel <sv@exept.de>
parents: 19836
diff changeset
   749
20341
72ed68b0d0ec little code cleanup
Claus Gittinger <cg@exept.de>
parents: 20026
diff changeset
   750
    [
72ed68b0d0ec little code cleanup
Claus Gittinger <cg@exept.de>
parents: 20026
diff changeset
   751
	srcIndex > lastIdx
72ed68b0d0ec little code cleanup
Claus Gittinger <cg@exept.de>
parents: 20026
diff changeset
   752
	or:[ aBlock value:(contentsArray at:srcIndex) ]
19831
5e0f261a1daa #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 19792
diff changeset
   753
    ] whileFalse:[
20341
72ed68b0d0ec little code cleanup
Claus Gittinger <cg@exept.de>
parents: 20026
diff changeset
   754
	srcIndex := srcIndex + 1.
19831
5e0f261a1daa #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 19792
diff changeset
   755
    ].
19865
6b114e3b40b9 #TUNING by stefan
Stefan Vogel <sv@exept.de>
parents: 19836
diff changeset
   756
    srcIndex > lastIdx ifTrue:[
20341
72ed68b0d0ec little code cleanup
Claus Gittinger <cg@exept.de>
parents: 20026
diff changeset
   757
	"/ nothing removed
72ed68b0d0ec little code cleanup
Claus Gittinger <cg@exept.de>
parents: 20026
diff changeset
   758
	^ #()
19831
5e0f261a1daa #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 19792
diff changeset
   759
    ].
5e0f261a1daa #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 19792
diff changeset
   760
5e0f261a1daa #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 19792
diff changeset
   761
    "/ now srcIndex is the index of element, which is the first to be removed
5e0f261a1daa #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 19792
diff changeset
   762
    removed := OrderedCollection new.
5e0f261a1daa #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 19792
diff changeset
   763
    removed add:(contentsArray at:srcIndex).
20341
72ed68b0d0ec little code cleanup
Claus Gittinger <cg@exept.de>
parents: 20026
diff changeset
   764
19831
5e0f261a1daa #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 19792
diff changeset
   765
    dstIndex := srcIndex.
5e0f261a1daa #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 19792
diff changeset
   766
    srcIndex := srcIndex + 1.
20341
72ed68b0d0ec little code cleanup
Claus Gittinger <cg@exept.de>
parents: 20026
diff changeset
   767
19865
6b114e3b40b9 #TUNING by stefan
Stefan Vogel <sv@exept.de>
parents: 19836
diff changeset
   768
    srcIndex to:lastIdx do:[:idx|
20341
72ed68b0d0ec little code cleanup
Claus Gittinger <cg@exept.de>
parents: 20026
diff changeset
   769
	element := contentsArray at:idx.
72ed68b0d0ec little code cleanup
Claus Gittinger <cg@exept.de>
parents: 20026
diff changeset
   770
	(aBlock value:element) ifTrue:[
72ed68b0d0ec little code cleanup
Claus Gittinger <cg@exept.de>
parents: 20026
diff changeset
   771
	    removed add:element
72ed68b0d0ec little code cleanup
Claus Gittinger <cg@exept.de>
parents: 20026
diff changeset
   772
	] ifFalse:[
72ed68b0d0ec little code cleanup
Claus Gittinger <cg@exept.de>
parents: 20026
diff changeset
   773
	    contentsArray at:dstIndex put:element.
72ed68b0d0ec little code cleanup
Claus Gittinger <cg@exept.de>
parents: 20026
diff changeset
   774
	    dstIndex := dstIndex + 1.
72ed68b0d0ec little code cleanup
Claus Gittinger <cg@exept.de>
parents: 20026
diff changeset
   775
	].
348
claus
parents: 345
diff changeset
   776
    ].
19865
6b114e3b40b9 #TUNING by stefan
Stefan Vogel <sv@exept.de>
parents: 19836
diff changeset
   777
    contentsArray from:dstIndex to:lastIdx put:nil.
16304
2d8de035fd7a class: OrderedCollection
Claus Gittinger <cg@exept.de>
parents: 15757
diff changeset
   778
    lastIndex := dstIndex - 1.
348
claus
parents: 345
diff changeset
   779
    ^ removed
claus
parents: 345
diff changeset
   780
claus
parents: 345
diff changeset
   781
    "
claus
parents: 345
diff changeset
   782
     |coll|
claus
parents: 345
diff changeset
   783
claus
parents: 345
diff changeset
   784
     coll := OrderedCollection withAll:(1 to:10).
19831
5e0f261a1daa #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 19792
diff changeset
   785
     Transcript show:'removed: '; showCR:(coll removeAllSuchThat:[:el | el even]).
5e0f261a1daa #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 19792
diff changeset
   786
     Transcript show:'coll: '; showCR:coll
348
claus
parents: 345
diff changeset
   787
    "
19831
5e0f261a1daa #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 19792
diff changeset
   788
16304
2d8de035fd7a class: OrderedCollection
Claus Gittinger <cg@exept.de>
parents: 15757
diff changeset
   789
    "
2d8de035fd7a class: OrderedCollection
Claus Gittinger <cg@exept.de>
parents: 15757
diff changeset
   790
     |coll1 coll2|
2d8de035fd7a class: OrderedCollection
Claus Gittinger <cg@exept.de>
parents: 15757
diff changeset
   791
19831
5e0f261a1daa #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 19792
diff changeset
   792
     Transcript showCR:'no element removed:'.
5e0f261a1daa #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 19792
diff changeset
   793
16304
2d8de035fd7a class: OrderedCollection
Claus Gittinger <cg@exept.de>
parents: 15757
diff changeset
   794
     coll1 := OrderedCollection withAll:(1 to:1000).
19831
5e0f261a1daa #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 19792
diff changeset
   795
     Transcript show:'  (1000) - '; showCR:(
20341
72ed68b0d0ec little code cleanup
Claus Gittinger <cg@exept.de>
parents: 20026
diff changeset
   796
	Time millisecondsToRun:[
72ed68b0d0ec little code cleanup
Claus Gittinger <cg@exept.de>
parents: 20026
diff changeset
   797
	    100 timesRepeat:[ coll1 copy removeAllSuchThat:[:el | el == 500] ]
72ed68b0d0ec little code cleanup
Claus Gittinger <cg@exept.de>
parents: 20026
diff changeset
   798
	]).
19831
5e0f261a1daa #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 19792
diff changeset
   799
5e0f261a1daa #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 19792
diff changeset
   800
     coll2 := OrderedCollection withAll:(1 to:10000).
5e0f261a1daa #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 19792
diff changeset
   801
     Transcript show:'  (10000) - '; showCR:(
20341
72ed68b0d0ec little code cleanup
Claus Gittinger <cg@exept.de>
parents: 20026
diff changeset
   802
	Time millisecondsToRun:[
72ed68b0d0ec little code cleanup
Claus Gittinger <cg@exept.de>
parents: 20026
diff changeset
   803
	    100 timesRepeat:[ coll2 copy removeAllSuchThat:[:el | el == 5000] ]
72ed68b0d0ec little code cleanup
Claus Gittinger <cg@exept.de>
parents: 20026
diff changeset
   804
	]).
19831
5e0f261a1daa #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 19792
diff changeset
   805
5e0f261a1daa #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 19792
diff changeset
   806
     coll2 := OrderedCollection withAll:(1 to:50000).
5e0f261a1daa #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 19792
diff changeset
   807
     Transcript show:'  (50000) - '; showCR:(
20341
72ed68b0d0ec little code cleanup
Claus Gittinger <cg@exept.de>
parents: 20026
diff changeset
   808
	Time millisecondsToRun:[
72ed68b0d0ec little code cleanup
Claus Gittinger <cg@exept.de>
parents: 20026
diff changeset
   809
	    100 timesRepeat:[ coll2 copy removeAllSuchThat:[:el | el == 25000] ]
72ed68b0d0ec little code cleanup
Claus Gittinger <cg@exept.de>
parents: 20026
diff changeset
   810
	]).
19831
5e0f261a1daa #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 19792
diff changeset
   811
5e0f261a1daa #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 19792
diff changeset
   812
     Transcript showCR:'small number of elements removed:'.
5e0f261a1daa #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 19792
diff changeset
   813
5e0f261a1daa #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 19792
diff changeset
   814
     coll1 := OrderedCollection withAll:(1 to:1000).
5e0f261a1daa #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 19792
diff changeset
   815
     Transcript show:'  (1000) - '; showCR:(
20341
72ed68b0d0ec little code cleanup
Claus Gittinger <cg@exept.de>
parents: 20026
diff changeset
   816
	Time millisecondsToRun:[
72ed68b0d0ec little code cleanup
Claus Gittinger <cg@exept.de>
parents: 20026
diff changeset
   817
	    100 timesRepeat:[ coll1 copy removeAllSuchThat:[:el | el between:500 and:550] ]
72ed68b0d0ec little code cleanup
Claus Gittinger <cg@exept.de>
parents: 20026
diff changeset
   818
	]).
19831
5e0f261a1daa #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 19792
diff changeset
   819
5e0f261a1daa #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 19792
diff changeset
   820
     coll2 := OrderedCollection withAll:(1 to:10000).
5e0f261a1daa #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 19792
diff changeset
   821
     Transcript show:'  (10000) - '; showCR:(
20341
72ed68b0d0ec little code cleanup
Claus Gittinger <cg@exept.de>
parents: 20026
diff changeset
   822
	Time millisecondsToRun:[
72ed68b0d0ec little code cleanup
Claus Gittinger <cg@exept.de>
parents: 20026
diff changeset
   823
	    100 timesRepeat:[ coll2 copy removeAllSuchThat:[:el | el between:5000 and:5050] ]
72ed68b0d0ec little code cleanup
Claus Gittinger <cg@exept.de>
parents: 20026
diff changeset
   824
	]).
19831
5e0f261a1daa #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 19792
diff changeset
   825
5e0f261a1daa #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 19792
diff changeset
   826
     coll2 := OrderedCollection withAll:(1 to:50000).
5e0f261a1daa #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 19792
diff changeset
   827
     Transcript show:'  (50000) - '; showCR:(
20341
72ed68b0d0ec little code cleanup
Claus Gittinger <cg@exept.de>
parents: 20026
diff changeset
   828
	Time millisecondsToRun:[
72ed68b0d0ec little code cleanup
Claus Gittinger <cg@exept.de>
parents: 20026
diff changeset
   829
	    100 timesRepeat:[ coll2 copy removeAllSuchThat:[:el | el between:25000 and:25050] ]
72ed68b0d0ec little code cleanup
Claus Gittinger <cg@exept.de>
parents: 20026
diff changeset
   830
	]).
19831
5e0f261a1daa #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 19792
diff changeset
   831
5e0f261a1daa #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 19792
diff changeset
   832
     Transcript showCR:'many elements removed:'.
5e0f261a1daa #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 19792
diff changeset
   833
5e0f261a1daa #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 19792
diff changeset
   834
     coll1 := OrderedCollection withAll:(1 to:1000).
5e0f261a1daa #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 19792
diff changeset
   835
     Transcript show:'  (1000) - '; showCR:(
20341
72ed68b0d0ec little code cleanup
Claus Gittinger <cg@exept.de>
parents: 20026
diff changeset
   836
	Time millisecondsToRun:[
72ed68b0d0ec little code cleanup
Claus Gittinger <cg@exept.de>
parents: 20026
diff changeset
   837
	    100 timesRepeat:[ coll1 copy removeAllSuchThat:[:el | el even] ]
72ed68b0d0ec little code cleanup
Claus Gittinger <cg@exept.de>
parents: 20026
diff changeset
   838
	]).
16304
2d8de035fd7a class: OrderedCollection
Claus Gittinger <cg@exept.de>
parents: 15757
diff changeset
   839
2d8de035fd7a class: OrderedCollection
Claus Gittinger <cg@exept.de>
parents: 15757
diff changeset
   840
     coll2 := OrderedCollection withAll:(1 to:10000).
19831
5e0f261a1daa #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 19792
diff changeset
   841
     Transcript show:'  (10000) - '; showCR:(
20341
72ed68b0d0ec little code cleanup
Claus Gittinger <cg@exept.de>
parents: 20026
diff changeset
   842
	Time millisecondsToRun:[
72ed68b0d0ec little code cleanup
Claus Gittinger <cg@exept.de>
parents: 20026
diff changeset
   843
	    100 timesRepeat:[ coll2 copy removeAllSuchThat:[:el | el even] ]
72ed68b0d0ec little code cleanup
Claus Gittinger <cg@exept.de>
parents: 20026
diff changeset
   844
	]).
16304
2d8de035fd7a class: OrderedCollection
Claus Gittinger <cg@exept.de>
parents: 15757
diff changeset
   845
2d8de035fd7a class: OrderedCollection
Claus Gittinger <cg@exept.de>
parents: 15757
diff changeset
   846
     coll2 := OrderedCollection withAll:(1 to:50000).
19831
5e0f261a1daa #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 19792
diff changeset
   847
     Transcript show:'  (50000) - '; showCR:(
20341
72ed68b0d0ec little code cleanup
Claus Gittinger <cg@exept.de>
parents: 20026
diff changeset
   848
	Time millisecondsToRun:[
72ed68b0d0ec little code cleanup
Claus Gittinger <cg@exept.de>
parents: 20026
diff changeset
   849
	    100 timesRepeat:[ coll2 copy removeAllSuchThat:[:el | el even] ]
72ed68b0d0ec little code cleanup
Claus Gittinger <cg@exept.de>
parents: 20026
diff changeset
   850
	]).
16304
2d8de035fd7a class: OrderedCollection
Claus Gittinger <cg@exept.de>
parents: 15757
diff changeset
   851
    "
19831
5e0f261a1daa #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 19792
diff changeset
   852
    "
20341
72ed68b0d0ec little code cleanup
Claus Gittinger <cg@exept.de>
parents: 20026
diff changeset
   853
		    compiled bytecode bytecode/new (no jitter)
72ed68b0d0ec little code cleanup
Claus Gittinger <cg@exept.de>
parents: 20026
diff changeset
   854
	no element removed:
72ed68b0d0ec little code cleanup
Claus Gittinger <cg@exept.de>
parents: 20026
diff changeset
   855
	  (1000)  -  10          20         20
72ed68b0d0ec little code cleanup
Claus Gittinger <cg@exept.de>
parents: 20026
diff changeset
   856
	  (10000) -  70         240        200
72ed68b0d0ec little code cleanup
Claus Gittinger <cg@exept.de>
parents: 20026
diff changeset
   857
	  (50000) - 390        1190        940
72ed68b0d0ec little code cleanup
Claus Gittinger <cg@exept.de>
parents: 20026
diff changeset
   858
	small number of elements removed:
72ed68b0d0ec little code cleanup
Claus Gittinger <cg@exept.de>
parents: 20026
diff changeset
   859
	  (1000)  -  10          30         20
72ed68b0d0ec little code cleanup
Claus Gittinger <cg@exept.de>
parents: 20026
diff changeset
   860
	  (10000) - 160         300        260
72ed68b0d0ec little code cleanup
Claus Gittinger <cg@exept.de>
parents: 20026
diff changeset
   861
	  (50000) - 700        1540       1180
72ed68b0d0ec little code cleanup
Claus Gittinger <cg@exept.de>
parents: 20026
diff changeset
   862
	many elements removed:
72ed68b0d0ec little code cleanup
Claus Gittinger <cg@exept.de>
parents: 20026
diff changeset
   863
	  (1000)  -  10          20         30
72ed68b0d0ec little code cleanup
Claus Gittinger <cg@exept.de>
parents: 20026
diff changeset
   864
	  (10000) - 130         290        260
72ed68b0d0ec little code cleanup
Claus Gittinger <cg@exept.de>
parents: 20026
diff changeset
   865
	  (50000) - 720        1470       1300
72ed68b0d0ec little code cleanup
Claus Gittinger <cg@exept.de>
parents: 20026
diff changeset
   866
    "
2362
23574f29c8af checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2361
diff changeset
   867
    "Modified: 8.2.1997 / 19:19:00 / cg"
348
claus
parents: 345
diff changeset
   868
!
claus
parents: 345
diff changeset
   869
606
7a9ab63a6757 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   870
removeFirst
3695
9ebf6de8a764 added #removeAllIfAbsent:
Claus Gittinger <cg@exept.de>
parents: 3368
diff changeset
   871
    "remove the first element from the collection; return the element.
16304
2d8de035fd7a class: OrderedCollection
Claus Gittinger <cg@exept.de>
parents: 15757
diff changeset
   872
     If there is no element in the receiver collection, raise an error.
2d8de035fd7a class: OrderedCollection
Claus Gittinger <cg@exept.de>
parents: 15757
diff changeset
   873
     Destructive: modifies the receiver"
202
40ca7cc6fb9c *** empty log message ***
claus
parents: 159
diff changeset
   874
20341
72ed68b0d0ec little code cleanup
Claus Gittinger <cg@exept.de>
parents: 20026
diff changeset
   875
    |anObject
3968
a526029723ac checkin from browser
Claus Gittinger <cg@exept.de>
parents: 3695
diff changeset
   876
     fI "{ Class: SmallInteger }" |
13
62303f84ff5f *** empty log message ***
claus
parents: 10
diff changeset
   877
2362
23574f29c8af checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2361
diff changeset
   878
    fI := firstIndex.
23574f29c8af checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2361
diff changeset
   879
23574f29c8af checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2361
diff changeset
   880
    fI > lastIndex ifTrue:[
20341
72ed68b0d0ec little code cleanup
Claus Gittinger <cg@exept.de>
parents: 20026
diff changeset
   881
	"error if collection is empty"
72ed68b0d0ec little code cleanup
Claus Gittinger <cg@exept.de>
parents: 20026
diff changeset
   882
	^ self emptyCollectionError.
606
7a9ab63a6757 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   883
    ].
2354
652d17daeeb5 faster remove: if its the first or last element
Claus Gittinger <cg@exept.de>
parents: 2348
diff changeset
   884
3107
ce4b0a4b3b3a checkin from browser
Claus Gittinger <cg@exept.de>
parents: 3095
diff changeset
   885
    anObject := contentsArray basicAt:fI.
1496
bea70dc24829 commentary
Claus Gittinger <cg@exept.de>
parents: 1422
diff changeset
   886
bea70dc24829 commentary
Claus Gittinger <cg@exept.de>
parents: 1422
diff changeset
   887
    "/ nil it out, to allow GC to reclaim it.
3107
ce4b0a4b3b3a checkin from browser
Claus Gittinger <cg@exept.de>
parents: 3095
diff changeset
   888
    contentsArray basicAt:fI put:nil.
1496
bea70dc24829 commentary
Claus Gittinger <cg@exept.de>
parents: 1422
diff changeset
   889
2362
23574f29c8af checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2361
diff changeset
   890
    fI := fI + 1.
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   891
2362
23574f29c8af checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2361
diff changeset
   892
    fI > lastIndex ifTrue:[
20341
72ed68b0d0ec little code cleanup
Claus Gittinger <cg@exept.de>
parents: 20026
diff changeset
   893
	"reset to avoid ever growing"
72ed68b0d0ec little code cleanup
Claus Gittinger <cg@exept.de>
parents: 20026
diff changeset
   894
	fI := 1.
72ed68b0d0ec little code cleanup
Claus Gittinger <cg@exept.de>
parents: 20026
diff changeset
   895
	lastIndex := 0
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   896
    ].
2362
23574f29c8af checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2361
diff changeset
   897
    firstIndex := fI.
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   898
    ^ anObject
13
62303f84ff5f *** empty log message ***
claus
parents: 10
diff changeset
   899
62303f84ff5f *** empty log message ***
claus
parents: 10
diff changeset
   900
    "
606
7a9ab63a6757 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   901
     (OrderedCollection withAll:#(1 2 3 4 5)) removeFirst; yourself
7a9ab63a6757 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   902
     OrderedCollection new removeFirst
7a9ab63a6757 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   903
     (SortedCollection withAll:#(5 4 3 2 1)) removeFirst; yourself
93
e31220cb391f *** empty log message ***
claus
parents: 88
diff changeset
   904
    "
2354
652d17daeeb5 faster remove: if its the first or last element
Claus Gittinger <cg@exept.de>
parents: 2348
diff changeset
   905
3968
a526029723ac checkin from browser
Claus Gittinger <cg@exept.de>
parents: 3695
diff changeset
   906
    "Modified: / 5.2.1999 / 23:22:58 / cg"
606
7a9ab63a6757 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   907
!
7a9ab63a6757 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   908
7a9ab63a6757 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   909
removeFirst:n
20341
72ed68b0d0ec little code cleanup
Claus Gittinger <cg@exept.de>
parents: 20026
diff changeset
   910
    "remove the first n elements from the collection;
16304
2d8de035fd7a class: OrderedCollection
Claus Gittinger <cg@exept.de>
parents: 15757
diff changeset
   911
     Return a collection containing the removed elements.
2d8de035fd7a class: OrderedCollection
Claus Gittinger <cg@exept.de>
parents: 15757
diff changeset
   912
     Destructive: modifies the receiver"
606
7a9ab63a6757 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   913
2362
23574f29c8af checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2361
diff changeset
   914
    |mySize ret newFirstIndex|
606
7a9ab63a6757 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   915
7a9ab63a6757 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   916
    mySize := self size.
7a9ab63a6757 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   917
    mySize < n ifTrue:[
20341
72ed68b0d0ec little code cleanup
Claus Gittinger <cg@exept.de>
parents: 20026
diff changeset
   918
	"error if collection has not enough elements"
72ed68b0d0ec little code cleanup
Claus Gittinger <cg@exept.de>
parents: 20026
diff changeset
   919
	^ self notEnoughElementsError.
606
7a9ab63a6757 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   920
    ].
7a9ab63a6757 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   921
7a9ab63a6757 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   922
    ret := Array new:n.
7a9ab63a6757 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   923
    ret replaceFrom:1 to:n with:contentsArray startingAt:firstIndex.
1496
bea70dc24829 commentary
Claus Gittinger <cg@exept.de>
parents: 1422
diff changeset
   924
606
7a9ab63a6757 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   925
    "/
7a9ab63a6757 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   926
    "/ nil-out contents array, to not keep elements from being GC'd
7a9ab63a6757 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   927
    "/
2362
23574f29c8af checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2361
diff changeset
   928
    newFirstIndex := firstIndex + n.
23574f29c8af checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2361
diff changeset
   929
    contentsArray from:firstIndex to:newFirstIndex - 1 put:nil.
606
7a9ab63a6757 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   930
2362
23574f29c8af checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2361
diff changeset
   931
    newFirstIndex > lastIndex ifTrue:[
20341
72ed68b0d0ec little code cleanup
Claus Gittinger <cg@exept.de>
parents: 20026
diff changeset
   932
	"reset to avoid ever growing"
72ed68b0d0ec little code cleanup
Claus Gittinger <cg@exept.de>
parents: 20026
diff changeset
   933
	newFirstIndex := 1.
72ed68b0d0ec little code cleanup
Claus Gittinger <cg@exept.de>
parents: 20026
diff changeset
   934
	lastIndex := 0
606
7a9ab63a6757 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   935
    ].
2362
23574f29c8af checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2361
diff changeset
   936
    firstIndex := newFirstIndex.
606
7a9ab63a6757 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   937
    ^ ret
93
e31220cb391f *** empty log message ***
claus
parents: 88
diff changeset
   938
e31220cb391f *** empty log message ***
claus
parents: 88
diff changeset
   939
    "
20341
72ed68b0d0ec little code cleanup
Claus Gittinger <cg@exept.de>
parents: 20026
diff changeset
   940
     (OrderedCollection withAll:#(1 2 3 4 5)) removeFirst:2; yourself
72ed68b0d0ec little code cleanup
Claus Gittinger <cg@exept.de>
parents: 20026
diff changeset
   941
     (OrderedCollection withAll:#(1 2 3 4 5)) removeFirst:0; yourself
72ed68b0d0ec little code cleanup
Claus Gittinger <cg@exept.de>
parents: 20026
diff changeset
   942
     OrderedCollection new removeFirst:2
72ed68b0d0ec little code cleanup
Claus Gittinger <cg@exept.de>
parents: 20026
diff changeset
   943
     (OrderedCollection withAll:#(1 2 3 4 5)) removeFirst:6
72ed68b0d0ec little code cleanup
Claus Gittinger <cg@exept.de>
parents: 20026
diff changeset
   944
     (SortedCollection withAll:#(5 4 3 2 1)) removeFirst:2; yourself
13
62303f84ff5f *** empty log message ***
claus
parents: 10
diff changeset
   945
    "
1161
aad722dea51a return values compatible to ST-80; added comments; fixed & tuned #makeRoomAtIndex:
Claus Gittinger <cg@exept.de>
parents: 1157
diff changeset
   946
2362
23574f29c8af checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2361
diff changeset
   947
    "Modified: 8.2.1997 / 19:20:18 / cg"
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   948
!
a27a279701f8 Initial revision
claus
parents:
diff changeset
   949
3695
9ebf6de8a764 added #removeAllIfAbsent:
Claus Gittinger <cg@exept.de>
parents: 3368
diff changeset
   950
removeFirstIfAbsent:exceptionBlock
9ebf6de8a764 added #removeAllIfAbsent:
Claus Gittinger <cg@exept.de>
parents: 3368
diff changeset
   951
    "remove the first element from the collection; return the element.
9ebf6de8a764 added #removeAllIfAbsent:
Claus Gittinger <cg@exept.de>
parents: 3368
diff changeset
   952
     If there is no element in the receiver collection, return the value from
16304
2d8de035fd7a class: OrderedCollection
Claus Gittinger <cg@exept.de>
parents: 15757
diff changeset
   953
     exceptionBlock.
2d8de035fd7a class: OrderedCollection
Claus Gittinger <cg@exept.de>
parents: 15757
diff changeset
   954
     Destructive: modifies the receiver"
3695
9ebf6de8a764 added #removeAllIfAbsent:
Claus Gittinger <cg@exept.de>
parents: 3368
diff changeset
   955
9ebf6de8a764 added #removeAllIfAbsent:
Claus Gittinger <cg@exept.de>
parents: 3368
diff changeset
   956
    |anObject fI "{ Class: SmallInteger }" |
9ebf6de8a764 added #removeAllIfAbsent:
Claus Gittinger <cg@exept.de>
parents: 3368
diff changeset
   957
9ebf6de8a764 added #removeAllIfAbsent:
Claus Gittinger <cg@exept.de>
parents: 3368
diff changeset
   958
    fI := firstIndex.
9ebf6de8a764 added #removeAllIfAbsent:
Claus Gittinger <cg@exept.de>
parents: 3368
diff changeset
   959
9ebf6de8a764 added #removeAllIfAbsent:
Claus Gittinger <cg@exept.de>
parents: 3368
diff changeset
   960
    fI > lastIndex ifTrue:[
20341
72ed68b0d0ec little code cleanup
Claus Gittinger <cg@exept.de>
parents: 20026
diff changeset
   961
	"error if collection is empty"
72ed68b0d0ec little code cleanup
Claus Gittinger <cg@exept.de>
parents: 20026
diff changeset
   962
	^ exceptionBlock value.
3695
9ebf6de8a764 added #removeAllIfAbsent:
Claus Gittinger <cg@exept.de>
parents: 3368
diff changeset
   963
    ].
9ebf6de8a764 added #removeAllIfAbsent:
Claus Gittinger <cg@exept.de>
parents: 3368
diff changeset
   964
9ebf6de8a764 added #removeAllIfAbsent:
Claus Gittinger <cg@exept.de>
parents: 3368
diff changeset
   965
    anObject := contentsArray basicAt:fI.
9ebf6de8a764 added #removeAllIfAbsent:
Claus Gittinger <cg@exept.de>
parents: 3368
diff changeset
   966
9ebf6de8a764 added #removeAllIfAbsent:
Claus Gittinger <cg@exept.de>
parents: 3368
diff changeset
   967
    "/ nil it out, to allow GC to reclaim it.
9ebf6de8a764 added #removeAllIfAbsent:
Claus Gittinger <cg@exept.de>
parents: 3368
diff changeset
   968
    contentsArray basicAt:fI put:nil.
9ebf6de8a764 added #removeAllIfAbsent:
Claus Gittinger <cg@exept.de>
parents: 3368
diff changeset
   969
9ebf6de8a764 added #removeAllIfAbsent:
Claus Gittinger <cg@exept.de>
parents: 3368
diff changeset
   970
    fI := fI + 1.
9ebf6de8a764 added #removeAllIfAbsent:
Claus Gittinger <cg@exept.de>
parents: 3368
diff changeset
   971
9ebf6de8a764 added #removeAllIfAbsent:
Claus Gittinger <cg@exept.de>
parents: 3368
diff changeset
   972
    fI > lastIndex ifTrue:[
20341
72ed68b0d0ec little code cleanup
Claus Gittinger <cg@exept.de>
parents: 20026
diff changeset
   973
	"reset to avoid ever growing"
72ed68b0d0ec little code cleanup
Claus Gittinger <cg@exept.de>
parents: 20026
diff changeset
   974
	fI := 1.
72ed68b0d0ec little code cleanup
Claus Gittinger <cg@exept.de>
parents: 20026
diff changeset
   975
	lastIndex := 0
3695
9ebf6de8a764 added #removeAllIfAbsent:
Claus Gittinger <cg@exept.de>
parents: 3368
diff changeset
   976
    ].
9ebf6de8a764 added #removeAllIfAbsent:
Claus Gittinger <cg@exept.de>
parents: 3368
diff changeset
   977
    firstIndex := fI.
9ebf6de8a764 added #removeAllIfAbsent:
Claus Gittinger <cg@exept.de>
parents: 3368
diff changeset
   978
    ^ anObject
9ebf6de8a764 added #removeAllIfAbsent:
Claus Gittinger <cg@exept.de>
parents: 3368
diff changeset
   979
9ebf6de8a764 added #removeAllIfAbsent:
Claus Gittinger <cg@exept.de>
parents: 3368
diff changeset
   980
    "
9ebf6de8a764 added #removeAllIfAbsent:
Claus Gittinger <cg@exept.de>
parents: 3368
diff changeset
   981
     (OrderedCollection withAll:#(1 2 3 4 5)) removeFirst; yourself
9ebf6de8a764 added #removeAllIfAbsent:
Claus Gittinger <cg@exept.de>
parents: 3368
diff changeset
   982
     OrderedCollection new removeFirst
9ebf6de8a764 added #removeAllIfAbsent:
Claus Gittinger <cg@exept.de>
parents: 3368
diff changeset
   983
     (SortedCollection withAll:#(5 4 3 2 1)) removeFirst; yourself
9ebf6de8a764 added #removeAllIfAbsent:
Claus Gittinger <cg@exept.de>
parents: 3368
diff changeset
   984
    "
9ebf6de8a764 added #removeAllIfAbsent:
Claus Gittinger <cg@exept.de>
parents: 3368
diff changeset
   985
9ebf6de8a764 added #removeAllIfAbsent:
Claus Gittinger <cg@exept.de>
parents: 3368
diff changeset
   986
    "Modified: / 12.11.1997 / 17:58:43 / cg"
9ebf6de8a764 added #removeAllIfAbsent:
Claus Gittinger <cg@exept.de>
parents: 3368
diff changeset
   987
    "Created: / 30.7.1998 / 13:19:42 / cg"
9ebf6de8a764 added #removeAllIfAbsent:
Claus Gittinger <cg@exept.de>
parents: 3368
diff changeset
   988
!
9ebf6de8a764 added #removeAllIfAbsent:
Claus Gittinger <cg@exept.de>
parents: 3368
diff changeset
   989
2549
9ca8a3fcdaa7 fixed #addAll:beforeIndex:
Claus Gittinger <cg@exept.de>
parents: 2364
diff changeset
   990
removeFrom:startIndex to:stopIndex
9ca8a3fcdaa7 fixed #addAll:beforeIndex:
Claus Gittinger <cg@exept.de>
parents: 2364
diff changeset
   991
    "added for ST-80 compatibility.
9ca8a3fcdaa7 fixed #addAll:beforeIndex:
Claus Gittinger <cg@exept.de>
parents: 2364
diff changeset
   992
     Same as removeFromIndex:toIndex:."
9ca8a3fcdaa7 fixed #addAll:beforeIndex:
Claus Gittinger <cg@exept.de>
parents: 2364
diff changeset
   993
9ca8a3fcdaa7 fixed #addAll:beforeIndex:
Claus Gittinger <cg@exept.de>
parents: 2364
diff changeset
   994
    ^ self removeFromIndex:startIndex toIndex:stopIndex
9ca8a3fcdaa7 fixed #addAll:beforeIndex:
Claus Gittinger <cg@exept.de>
parents: 2364
diff changeset
   995
9ca8a3fcdaa7 fixed #addAll:beforeIndex:
Claus Gittinger <cg@exept.de>
parents: 2364
diff changeset
   996
    "Created: 15.4.1997 / 12:39:00 / cg"
9ca8a3fcdaa7 fixed #addAll:beforeIndex:
Claus Gittinger <cg@exept.de>
parents: 2364
diff changeset
   997
!
9ca8a3fcdaa7 fixed #addAll:beforeIndex:
Claus Gittinger <cg@exept.de>
parents: 2364
diff changeset
   998
606
7a9ab63a6757 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   999
removeFromIndex:startIndex toIndex:stopIndex
7a9ab63a6757 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1000
    "remove the elements stored under startIndex up to and including
7a9ab63a6757 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1001
     the elements under stopIndex.
16304
2d8de035fd7a class: OrderedCollection
Claus Gittinger <cg@exept.de>
parents: 15757
diff changeset
  1002
     Destructive: modifies the receiver
606
7a9ab63a6757 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1003
     Return the receiver.
7a9ab63a6757 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1004
     Returning the receiver here is a historic leftover - it may change.
14917
e61f35bf3521 class: OrderedCollection
Claus Gittinger <cg@exept.de>
parents: 14616
diff changeset
  1005
     Please use yourself in a cascade, if you need the receiver's value
606
7a9ab63a6757 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1006
     when using this method."
7a9ab63a6757 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1007
3968
a526029723ac checkin from browser
Claus Gittinger <cg@exept.de>
parents: 3695
diff changeset
  1008
    |nDeleted "{ Class: SmallInteger }"
20341
72ed68b0d0ec little code cleanup
Claus Gittinger <cg@exept.de>
parents: 20026
diff changeset
  1009
     fI "{ Class: SmallInteger }"
72ed68b0d0ec little code cleanup
Claus Gittinger <cg@exept.de>
parents: 20026
diff changeset
  1010
     lI "{ Class: SmallInteger }"
2364
788423a8d67f checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2362
diff changeset
  1011
     newLastIndex sz|
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1012
2364
788423a8d67f checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2362
diff changeset
  1013
    sz := self size.
788423a8d67f checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2362
diff changeset
  1014
788423a8d67f checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2362
diff changeset
  1015
    (startIndex < 1 or:[stopIndex > sz]) ifTrue:[
20341
72ed68b0d0ec little code cleanup
Claus Gittinger <cg@exept.de>
parents: 20026
diff changeset
  1016
	^ self notEnoughElementsError
606
7a9ab63a6757 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1017
    ].
2355
9476ba4d810d faster #removeFromIndex:toIndex.
Claus Gittinger <cg@exept.de>
parents: 2354
diff changeset
  1018
2362
23574f29c8af checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2361
diff changeset
  1019
    nDeleted := stopIndex - startIndex + 1.
23574f29c8af checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2361
diff changeset
  1020
    nDeleted < 0 ifTrue:[
20341
72ed68b0d0ec little code cleanup
Claus Gittinger <cg@exept.de>
parents: 20026
diff changeset
  1021
	"/ mhmh - what should be done here ?
72ed68b0d0ec little code cleanup
Claus Gittinger <cg@exept.de>
parents: 20026
diff changeset
  1022
	^ self error:'bad index range'
2355
9476ba4d810d faster #removeFromIndex:toIndex.
Claus Gittinger <cg@exept.de>
parents: 2354
diff changeset
  1023
    ].
2362
23574f29c8af checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2361
diff changeset
  1024
    nDeleted == 0 ifTrue:[^ self].
2355
9476ba4d810d faster #removeFromIndex:toIndex.
Claus Gittinger <cg@exept.de>
parents: 2354
diff changeset
  1025
3968
a526029723ac checkin from browser
Claus Gittinger <cg@exept.de>
parents: 3695
diff changeset
  1026
    fI := firstIndex.
a526029723ac checkin from browser
Claus Gittinger <cg@exept.de>
parents: 3695
diff changeset
  1027
    lI := lastIndex.
a526029723ac checkin from browser
Claus Gittinger <cg@exept.de>
parents: 3695
diff changeset
  1028
2362
23574f29c8af checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2361
diff changeset
  1029
    "/
2355
9476ba4d810d faster #removeFromIndex:toIndex.
Claus Gittinger <cg@exept.de>
parents: 2354
diff changeset
  1030
    "/ can be done faster, when removing the first elements
2362
23574f29c8af checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2361
diff changeset
  1031
    "/
2364
788423a8d67f checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2362
diff changeset
  1032
    startIndex == 1 ifTrue:[
20341
72ed68b0d0ec little code cleanup
Claus Gittinger <cg@exept.de>
parents: 20026
diff changeset
  1033
	"/ nil out (helps GC)
72ed68b0d0ec little code cleanup
Claus Gittinger <cg@exept.de>
parents: 20026
diff changeset
  1034
	contentsArray
72ed68b0d0ec little code cleanup
Claus Gittinger <cg@exept.de>
parents: 20026
diff changeset
  1035
	    from:fI
72ed68b0d0ec little code cleanup
Claus Gittinger <cg@exept.de>
parents: 20026
diff changeset
  1036
	    to:fI + nDeleted - 1
72ed68b0d0ec little code cleanup
Claus Gittinger <cg@exept.de>
parents: 20026
diff changeset
  1037
	    put:nil.
72ed68b0d0ec little code cleanup
Claus Gittinger <cg@exept.de>
parents: 20026
diff changeset
  1038
	firstIndex := fI := fI + nDeleted
2355
9476ba4d810d faster #removeFromIndex:toIndex.
Claus Gittinger <cg@exept.de>
parents: 2354
diff changeset
  1039
    ] ifFalse:[
20341
72ed68b0d0ec little code cleanup
Claus Gittinger <cg@exept.de>
parents: 20026
diff changeset
  1040
	"/
72ed68b0d0ec little code cleanup
Claus Gittinger <cg@exept.de>
parents: 20026
diff changeset
  1041
	"/ can be done faster, when removing the last elements
72ed68b0d0ec little code cleanup
Claus Gittinger <cg@exept.de>
parents: 20026
diff changeset
  1042
	"/
72ed68b0d0ec little code cleanup
Claus Gittinger <cg@exept.de>
parents: 20026
diff changeset
  1043
	stopIndex == sz ifTrue:[
72ed68b0d0ec little code cleanup
Claus Gittinger <cg@exept.de>
parents: 20026
diff changeset
  1044
	    "/ nil out (helps GC)
72ed68b0d0ec little code cleanup
Claus Gittinger <cg@exept.de>
parents: 20026
diff changeset
  1045
	    contentsArray
72ed68b0d0ec little code cleanup
Claus Gittinger <cg@exept.de>
parents: 20026
diff changeset
  1046
		from:lI - nDeleted + 1
72ed68b0d0ec little code cleanup
Claus Gittinger <cg@exept.de>
parents: 20026
diff changeset
  1047
		to:lI
72ed68b0d0ec little code cleanup
Claus Gittinger <cg@exept.de>
parents: 20026
diff changeset
  1048
		put:nil.
72ed68b0d0ec little code cleanup
Claus Gittinger <cg@exept.de>
parents: 20026
diff changeset
  1049
	    lastIndex := lI := lI - nDeleted
72ed68b0d0ec little code cleanup
Claus Gittinger <cg@exept.de>
parents: 20026
diff changeset
  1050
	] ifFalse:[
72ed68b0d0ec little code cleanup
Claus Gittinger <cg@exept.de>
parents: 20026
diff changeset
  1051
	    "/
72ed68b0d0ec little code cleanup
Claus Gittinger <cg@exept.de>
parents: 20026
diff changeset
  1052
	    "/ must shuffle
72ed68b0d0ec little code cleanup
Claus Gittinger <cg@exept.de>
parents: 20026
diff changeset
  1053
	    "/ TODO:
72ed68b0d0ec little code cleanup
Claus Gittinger <cg@exept.de>
parents: 20026
diff changeset
  1054
	    "/    for big collections, try to copy the smallest
72ed68b0d0ec little code cleanup
Claus Gittinger <cg@exept.de>
parents: 20026
diff changeset
  1055
	    "/    possible number of elements
606
7a9ab63a6757 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1056
20341
72ed68b0d0ec little code cleanup
Claus Gittinger <cg@exept.de>
parents: 20026
diff changeset
  1057
	    newLastIndex := lI - nDeleted.
2362
23574f29c8af checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2361
diff changeset
  1058
20341
72ed68b0d0ec little code cleanup
Claus Gittinger <cg@exept.de>
parents: 20026
diff changeset
  1059
	    contentsArray
72ed68b0d0ec little code cleanup
Claus Gittinger <cg@exept.de>
parents: 20026
diff changeset
  1060
		replaceFrom:(fI + startIndex - 1)
72ed68b0d0ec little code cleanup
Claus Gittinger <cg@exept.de>
parents: 20026
diff changeset
  1061
		to:newLastIndex
72ed68b0d0ec little code cleanup
Claus Gittinger <cg@exept.de>
parents: 20026
diff changeset
  1062
		with:contentsArray
72ed68b0d0ec little code cleanup
Claus Gittinger <cg@exept.de>
parents: 20026
diff changeset
  1063
		startingAt:(fI + stopIndex).
2355
9476ba4d810d faster #removeFromIndex:toIndex.
Claus Gittinger <cg@exept.de>
parents: 2354
diff changeset
  1064
20341
72ed68b0d0ec little code cleanup
Claus Gittinger <cg@exept.de>
parents: 20026
diff changeset
  1065
	    "/ nil out rest (helps GC)
72ed68b0d0ec little code cleanup
Claus Gittinger <cg@exept.de>
parents: 20026
diff changeset
  1066
	    contentsArray
72ed68b0d0ec little code cleanup
Claus Gittinger <cg@exept.de>
parents: 20026
diff changeset
  1067
		from:(newLastIndex + 1)
72ed68b0d0ec little code cleanup
Claus Gittinger <cg@exept.de>
parents: 20026
diff changeset
  1068
		to:lI
72ed68b0d0ec little code cleanup
Claus Gittinger <cg@exept.de>
parents: 20026
diff changeset
  1069
		put:nil.
2355
9476ba4d810d faster #removeFromIndex:toIndex.
Claus Gittinger <cg@exept.de>
parents: 2354
diff changeset
  1070
20341
72ed68b0d0ec little code cleanup
Claus Gittinger <cg@exept.de>
parents: 20026
diff changeset
  1071
	    lastIndex := lI := newLastIndex.
72ed68b0d0ec little code cleanup
Claus Gittinger <cg@exept.de>
parents: 20026
diff changeset
  1072
	]
2355
9476ba4d810d faster #removeFromIndex:toIndex.
Claus Gittinger <cg@exept.de>
parents: 2354
diff changeset
  1073
    ].
9476ba4d810d faster #removeFromIndex:toIndex.
Claus Gittinger <cg@exept.de>
parents: 2354
diff changeset
  1074
3968
a526029723ac checkin from browser
Claus Gittinger <cg@exept.de>
parents: 3695
diff changeset
  1075
    fI > lI ifTrue:[
20341
72ed68b0d0ec little code cleanup
Claus Gittinger <cg@exept.de>
parents: 20026
diff changeset
  1076
	"reset to avoid ever growing"
72ed68b0d0ec little code cleanup
Claus Gittinger <cg@exept.de>
parents: 20026
diff changeset
  1077
	firstIndex := 1.
72ed68b0d0ec little code cleanup
Claus Gittinger <cg@exept.de>
parents: 20026
diff changeset
  1078
	lastIndex := 0
606
7a9ab63a6757 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1079
    ]
13
62303f84ff5f *** empty log message ***
claus
parents: 10
diff changeset
  1080
62303f84ff5f *** empty log message ***
claus
parents: 10
diff changeset
  1081
    "
606
7a9ab63a6757 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1082
     #(1 2 3 4 5 6 7 8 9) asOrderedCollection removeFromIndex:3 toIndex:6
2355
9476ba4d810d faster #removeFromIndex:toIndex.
Claus Gittinger <cg@exept.de>
parents: 2354
diff changeset
  1083
     #(1 2 3 4 5 6 7 8 9) asOrderedCollection removeFromIndex:6 toIndex:8
9476ba4d810d faster #removeFromIndex:toIndex.
Claus Gittinger <cg@exept.de>
parents: 2354
diff changeset
  1084
     #(1 2 3 4 5 6 7 8 9) asOrderedCollection removeFromIndex:1 toIndex:3
9476ba4d810d faster #removeFromIndex:toIndex.
Claus Gittinger <cg@exept.de>
parents: 2354
diff changeset
  1085
     #(1 2 3 4 5 6 7 8 9) asOrderedCollection removeFromIndex:6 toIndex:9
606
7a9ab63a6757 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1086
     #(1 2 3 4 5) asOrderedCollection removeFromIndex:3 toIndex:6
217
a0400fdbc933 *** empty log message ***
claus
parents: 202
diff changeset
  1087
    "
2355
9476ba4d810d faster #removeFromIndex:toIndex.
Claus Gittinger <cg@exept.de>
parents: 2354
diff changeset
  1088
3968
a526029723ac checkin from browser
Claus Gittinger <cg@exept.de>
parents: 3695
diff changeset
  1089
    "Modified: / 5.2.1999 / 23:22:07 / cg"
217
a0400fdbc933 *** empty log message ***
claus
parents: 202
diff changeset
  1090
!
a0400fdbc933 *** empty log message ***
claus
parents: 202
diff changeset
  1091
2348
523e9d6e0049 added #removeIdentical:ifAbsent:
Claus Gittinger <cg@exept.de>
parents: 2222
diff changeset
  1092
removeIdentical:anObject ifAbsent:exceptionBlock
523e9d6e0049 added #removeIdentical:ifAbsent:
Claus Gittinger <cg@exept.de>
parents: 2222
diff changeset
  1093
    "remove the first element which is identical to anObject;
20341
72ed68b0d0ec little code cleanup
Claus Gittinger <cg@exept.de>
parents: 20026
diff changeset
  1094
     if found, remove and return it;
2348
523e9d6e0049 added #removeIdentical:ifAbsent:
Claus Gittinger <cg@exept.de>
parents: 2222
diff changeset
  1095
     if not, return the value from evaluating exceptionBlock.
16304
2d8de035fd7a class: OrderedCollection
Claus Gittinger <cg@exept.de>
parents: 15757
diff changeset
  1096
     Destructive: modifies the receiver.
2361
dd95b53674e9 oops - removeIdentical was wrong
Claus Gittinger <cg@exept.de>
parents: 2355
diff changeset
  1097
     Uses identity compare (==) to search for the element."
2354
652d17daeeb5 faster remove: if its the first or last element
Claus Gittinger <cg@exept.de>
parents: 2348
diff changeset
  1098
652d17daeeb5 faster remove: if its the first or last element
Claus Gittinger <cg@exept.de>
parents: 2348
diff changeset
  1099
    |index|
2348
523e9d6e0049 added #removeIdentical:ifAbsent:
Claus Gittinger <cg@exept.de>
parents: 2222
diff changeset
  1100
2354
652d17daeeb5 faster remove: if its the first or last element
Claus Gittinger <cg@exept.de>
parents: 2348
diff changeset
  1101
    index := contentsArray identityIndexOf:anObject startingAt:firstIndex endingAt:lastIndex.
652d17daeeb5 faster remove: if its the first or last element
Claus Gittinger <cg@exept.de>
parents: 2348
diff changeset
  1102
    index ~~ 0 ifTrue:[
20341
72ed68b0d0ec little code cleanup
Claus Gittinger <cg@exept.de>
parents: 20026
diff changeset
  1103
	index == firstIndex ifTrue:[
72ed68b0d0ec little code cleanup
Claus Gittinger <cg@exept.de>
parents: 20026
diff changeset
  1104
	    contentsArray basicAt:firstIndex put:nil.
72ed68b0d0ec little code cleanup
Claus Gittinger <cg@exept.de>
parents: 20026
diff changeset
  1105
	    firstIndex := firstIndex + 1.
72ed68b0d0ec little code cleanup
Claus Gittinger <cg@exept.de>
parents: 20026
diff changeset
  1106
	    firstIndex > lastIndex ifTrue:[
72ed68b0d0ec little code cleanup
Claus Gittinger <cg@exept.de>
parents: 20026
diff changeset
  1107
		"reset to avoid ever growing"
72ed68b0d0ec little code cleanup
Claus Gittinger <cg@exept.de>
parents: 20026
diff changeset
  1108
		firstIndex := 1.
72ed68b0d0ec little code cleanup
Claus Gittinger <cg@exept.de>
parents: 20026
diff changeset
  1109
		lastIndex := 0
72ed68b0d0ec little code cleanup
Claus Gittinger <cg@exept.de>
parents: 20026
diff changeset
  1110
	    ].
72ed68b0d0ec little code cleanup
Claus Gittinger <cg@exept.de>
parents: 20026
diff changeset
  1111
	] ifFalse:[
72ed68b0d0ec little code cleanup
Claus Gittinger <cg@exept.de>
parents: 20026
diff changeset
  1112
	    index == lastIndex ifTrue:[
72ed68b0d0ec little code cleanup
Claus Gittinger <cg@exept.de>
parents: 20026
diff changeset
  1113
		contentsArray basicAt:lastIndex put:nil.
72ed68b0d0ec little code cleanup
Claus Gittinger <cg@exept.de>
parents: 20026
diff changeset
  1114
		lastIndex := lastIndex - 1.
72ed68b0d0ec little code cleanup
Claus Gittinger <cg@exept.de>
parents: 20026
diff changeset
  1115
		firstIndex > lastIndex ifTrue:[
72ed68b0d0ec little code cleanup
Claus Gittinger <cg@exept.de>
parents: 20026
diff changeset
  1116
		    "reset to avoid ever growing"
72ed68b0d0ec little code cleanup
Claus Gittinger <cg@exept.de>
parents: 20026
diff changeset
  1117
		    firstIndex := 1.
72ed68b0d0ec little code cleanup
Claus Gittinger <cg@exept.de>
parents: 20026
diff changeset
  1118
		    lastIndex := 0
72ed68b0d0ec little code cleanup
Claus Gittinger <cg@exept.de>
parents: 20026
diff changeset
  1119
		].
72ed68b0d0ec little code cleanup
Claus Gittinger <cg@exept.de>
parents: 20026
diff changeset
  1120
	    ] ifFalse:[
72ed68b0d0ec little code cleanup
Claus Gittinger <cg@exept.de>
parents: 20026
diff changeset
  1121
		index := index - firstIndex + 1.
72ed68b0d0ec little code cleanup
Claus Gittinger <cg@exept.de>
parents: 20026
diff changeset
  1122
		self removeFromIndex:index toIndex:index.
72ed68b0d0ec little code cleanup
Claus Gittinger <cg@exept.de>
parents: 20026
diff changeset
  1123
	    ]
72ed68b0d0ec little code cleanup
Claus Gittinger <cg@exept.de>
parents: 20026
diff changeset
  1124
	].
72ed68b0d0ec little code cleanup
Claus Gittinger <cg@exept.de>
parents: 20026
diff changeset
  1125
	^ anObject
2348
523e9d6e0049 added #removeIdentical:ifAbsent:
Claus Gittinger <cg@exept.de>
parents: 2222
diff changeset
  1126
    ].
523e9d6e0049 added #removeIdentical:ifAbsent:
Claus Gittinger <cg@exept.de>
parents: 2222
diff changeset
  1127
    ^ exceptionBlock value
523e9d6e0049 added #removeIdentical:ifAbsent:
Claus Gittinger <cg@exept.de>
parents: 2222
diff changeset
  1128
523e9d6e0049 added #removeIdentical:ifAbsent:
Claus Gittinger <cg@exept.de>
parents: 2222
diff changeset
  1129
    "
20341
72ed68b0d0ec little code cleanup
Claus Gittinger <cg@exept.de>
parents: 20026
diff changeset
  1130
     #(1.0 2.0 3.0 4.0 5.0) asOrderedCollection remove:4 ifAbsent:'oops'
72ed68b0d0ec little code cleanup
Claus Gittinger <cg@exept.de>
parents: 20026
diff changeset
  1131
     #(1.0 2.0 3.0 4.0 5.0) asOrderedCollection remove:4 ifAbsent:'oops'; yourself
72ed68b0d0ec little code cleanup
Claus Gittinger <cg@exept.de>
parents: 20026
diff changeset
  1132
     #(1.0 2.0 3.0 4.0 5.0) asOrderedCollection removeIdentical:4 ifAbsent:'oops'
72ed68b0d0ec little code cleanup
Claus Gittinger <cg@exept.de>
parents: 20026
diff changeset
  1133
     #(fee foo bar baz) asOrderedCollection removeIdentical:#fee; yourself
72ed68b0d0ec little code cleanup
Claus Gittinger <cg@exept.de>
parents: 20026
diff changeset
  1134
     #(fee foo bar baz) asOrderedCollection removeIdentical:#foo; yourself
72ed68b0d0ec little code cleanup
Claus Gittinger <cg@exept.de>
parents: 20026
diff changeset
  1135
     #(fee foo bar baz) asOrderedCollection removeIdentical:#baz; yourself
72ed68b0d0ec little code cleanup
Claus Gittinger <cg@exept.de>
parents: 20026
diff changeset
  1136
     #(fee) asOrderedCollection removeIdentical:#fee; yourself
72ed68b0d0ec little code cleanup
Claus Gittinger <cg@exept.de>
parents: 20026
diff changeset
  1137
     #(fee) asOrderedCollection removeIdentical:#foo; yourself
2348
523e9d6e0049 added #removeIdentical:ifAbsent:
Claus Gittinger <cg@exept.de>
parents: 2222
diff changeset
  1138
    "
523e9d6e0049 added #removeIdentical:ifAbsent:
Claus Gittinger <cg@exept.de>
parents: 2222
diff changeset
  1139
2361
dd95b53674e9 oops - removeIdentical was wrong
Claus Gittinger <cg@exept.de>
parents: 2355
diff changeset
  1140
    "Modified: 8.2.1997 / 18:57:43 / cg"
2348
523e9d6e0049 added #removeIdentical:ifAbsent:
Claus Gittinger <cg@exept.de>
parents: 2222
diff changeset
  1141
!
523e9d6e0049 added #removeIdentical:ifAbsent:
Claus Gittinger <cg@exept.de>
parents: 2222
diff changeset
  1142
16304
2d8de035fd7a class: OrderedCollection
Claus Gittinger <cg@exept.de>
parents: 15757
diff changeset
  1143
removeIndices:aSortedCollectionOfIndices
20341
72ed68b0d0ec little code cleanup
Claus Gittinger <cg@exept.de>
parents: 20026
diff changeset
  1144
    "remove all elements stored in any of aSortedCollectionOfIndices,
16304
2d8de035fd7a class: OrderedCollection
Claus Gittinger <cg@exept.de>
parents: 15757
diff changeset
  1145
     which must be sorted and sequenceable.
2d8de035fd7a class: OrderedCollection
Claus Gittinger <cg@exept.de>
parents: 15757
diff changeset
  1146
     Destructive: modifies the receiver.
2d8de035fd7a class: OrderedCollection
Claus Gittinger <cg@exept.de>
parents: 15757
diff changeset
  1147
     Returns a collection of removed elements.
2d8de035fd7a class: OrderedCollection
Claus Gittinger <cg@exept.de>
parents: 15757
diff changeset
  1148
20341
72ed68b0d0ec little code cleanup
Claus Gittinger <cg@exept.de>
parents: 20026
diff changeset
  1149
     Performance:
72ed68b0d0ec little code cleanup
Claus Gittinger <cg@exept.de>
parents: 20026
diff changeset
  1150
	this is an O(N) algorithm (N being the size of the receiver).
18184
b72a856332b8 class: OrderedCollection
Claus Gittinger <cg@exept.de>
parents: 18183
diff changeset
  1151
b72a856332b8 class: OrderedCollection
Claus Gittinger <cg@exept.de>
parents: 18183
diff changeset
  1152
     This could be done much better, especially if the removed indices are
b72a856332b8 class: OrderedCollection
Claus Gittinger <cg@exept.de>
parents: 18183
diff changeset
  1153
     at either end of the receiver. However, as it is currently not heavily used,
b72a856332b8 class: OrderedCollection
Claus Gittinger <cg@exept.de>
parents: 18183
diff changeset
  1154
     I leave that as an exercise to the brave reader..."
16304
2d8de035fd7a class: OrderedCollection
Claus Gittinger <cg@exept.de>
parents: 15757
diff changeset
  1155
2d8de035fd7a class: OrderedCollection
Claus Gittinger <cg@exept.de>
parents: 15757
diff changeset
  1156
    |removed element dstIndex indexIndex nextIndex numIndices|
2d8de035fd7a class: OrderedCollection
Claus Gittinger <cg@exept.de>
parents: 15757
diff changeset
  1157
2d8de035fd7a class: OrderedCollection
Claus Gittinger <cg@exept.de>
parents: 15757
diff changeset
  1158
    removed := OrderedCollection new.
2d8de035fd7a class: OrderedCollection
Claus Gittinger <cg@exept.de>
parents: 15757
diff changeset
  1159
2d8de035fd7a class: OrderedCollection
Claus Gittinger <cg@exept.de>
parents: 15757
diff changeset
  1160
    dstIndex := firstIndex.
2d8de035fd7a class: OrderedCollection
Claus Gittinger <cg@exept.de>
parents: 15757
diff changeset
  1161
    numIndices := aSortedCollectionOfIndices size.
2d8de035fd7a class: OrderedCollection
Claus Gittinger <cg@exept.de>
parents: 15757
diff changeset
  1162
    indexIndex := 1.
2d8de035fd7a class: OrderedCollection
Claus Gittinger <cg@exept.de>
parents: 15757
diff changeset
  1163
    nextIndex := aSortedCollectionOfIndices at:1.
2d8de035fd7a class: OrderedCollection
Claus Gittinger <cg@exept.de>
parents: 15757
diff changeset
  1164
    firstIndex to: lastIndex do:[:srcIndex |
20341
72ed68b0d0ec little code cleanup
Claus Gittinger <cg@exept.de>
parents: 20026
diff changeset
  1165
	element := contentsArray at:srcIndex.
72ed68b0d0ec little code cleanup
Claus Gittinger <cg@exept.de>
parents: 20026
diff changeset
  1166
	srcIndex == nextIndex ifTrue:[
72ed68b0d0ec little code cleanup
Claus Gittinger <cg@exept.de>
parents: 20026
diff changeset
  1167
	    removed add:element.
72ed68b0d0ec little code cleanup
Claus Gittinger <cg@exept.de>
parents: 20026
diff changeset
  1168
	    indexIndex := indexIndex + 1.
72ed68b0d0ec little code cleanup
Claus Gittinger <cg@exept.de>
parents: 20026
diff changeset
  1169
	    indexIndex > numIndices ifTrue:[
72ed68b0d0ec little code cleanup
Claus Gittinger <cg@exept.de>
parents: 20026
diff changeset
  1170
		nextIndex := nil.
72ed68b0d0ec little code cleanup
Claus Gittinger <cg@exept.de>
parents: 20026
diff changeset
  1171
	    ] ifFalse:[
72ed68b0d0ec little code cleanup
Claus Gittinger <cg@exept.de>
parents: 20026
diff changeset
  1172
		nextIndex := aSortedCollectionOfIndices at:indexIndex.
72ed68b0d0ec little code cleanup
Claus Gittinger <cg@exept.de>
parents: 20026
diff changeset
  1173
	    ].
72ed68b0d0ec little code cleanup
Claus Gittinger <cg@exept.de>
parents: 20026
diff changeset
  1174
	] ifFalse:[
72ed68b0d0ec little code cleanup
Claus Gittinger <cg@exept.de>
parents: 20026
diff changeset
  1175
	    contentsArray at:dstIndex put:element.
72ed68b0d0ec little code cleanup
Claus Gittinger <cg@exept.de>
parents: 20026
diff changeset
  1176
	    dstIndex := dstIndex + 1.
72ed68b0d0ec little code cleanup
Claus Gittinger <cg@exept.de>
parents: 20026
diff changeset
  1177
	].
16304
2d8de035fd7a class: OrderedCollection
Claus Gittinger <cg@exept.de>
parents: 15757
diff changeset
  1178
    ].
2d8de035fd7a class: OrderedCollection
Claus Gittinger <cg@exept.de>
parents: 15757
diff changeset
  1179
    contentsArray from:dstIndex to:lastIndex put:nil.
2d8de035fd7a class: OrderedCollection
Claus Gittinger <cg@exept.de>
parents: 15757
diff changeset
  1180
    lastIndex := dstIndex - 1.
2d8de035fd7a class: OrderedCollection
Claus Gittinger <cg@exept.de>
parents: 15757
diff changeset
  1181
    ^ removed
2d8de035fd7a class: OrderedCollection
Claus Gittinger <cg@exept.de>
parents: 15757
diff changeset
  1182
2d8de035fd7a class: OrderedCollection
Claus Gittinger <cg@exept.de>
parents: 15757
diff changeset
  1183
    "
2d8de035fd7a class: OrderedCollection
Claus Gittinger <cg@exept.de>
parents: 15757
diff changeset
  1184
     |coll|
2d8de035fd7a class: OrderedCollection
Claus Gittinger <cg@exept.de>
parents: 15757
diff changeset
  1185
2d8de035fd7a class: OrderedCollection
Claus Gittinger <cg@exept.de>
parents: 15757
diff changeset
  1186
     coll := OrderedCollection withAll:(1 to:10).
2d8de035fd7a class: OrderedCollection
Claus Gittinger <cg@exept.de>
parents: 15757
diff changeset
  1187
     Transcript showCR:(coll removeIndices:#(1 5 7)).
2d8de035fd7a class: OrderedCollection
Claus Gittinger <cg@exept.de>
parents: 15757
diff changeset
  1188
     Transcript showCR:coll
2d8de035fd7a class: OrderedCollection
Claus Gittinger <cg@exept.de>
parents: 15757
diff changeset
  1189
    "
2d8de035fd7a class: OrderedCollection
Claus Gittinger <cg@exept.de>
parents: 15757
diff changeset
  1190
!
2d8de035fd7a class: OrderedCollection
Claus Gittinger <cg@exept.de>
parents: 15757
diff changeset
  1191
606
7a9ab63a6757 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1192
removeLast
16304
2d8de035fd7a class: OrderedCollection
Claus Gittinger <cg@exept.de>
parents: 15757
diff changeset
  1193
    "remove the last element from the collection.
2d8de035fd7a class: OrderedCollection
Claus Gittinger <cg@exept.de>
parents: 15757
diff changeset
  1194
     Return the removed element.
2d8de035fd7a class: OrderedCollection
Claus Gittinger <cg@exept.de>
parents: 15757
diff changeset
  1195
     Destructive: modifies the receiver"
606
7a9ab63a6757 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1196
3107
ce4b0a4b3b3a checkin from browser
Claus Gittinger <cg@exept.de>
parents: 3095
diff changeset
  1197
    |anObject
ce4b0a4b3b3a checkin from browser
Claus Gittinger <cg@exept.de>
parents: 3095
diff changeset
  1198
     idx "{ Class: SmallInteger }" |
217
a0400fdbc933 *** empty log message ***
claus
parents: 202
diff changeset
  1199
3107
ce4b0a4b3b3a checkin from browser
Claus Gittinger <cg@exept.de>
parents: 3095
diff changeset
  1200
    idx := lastIndex.
ce4b0a4b3b3a checkin from browser
Claus Gittinger <cg@exept.de>
parents: 3095
diff changeset
  1201
    firstIndex > idx ifTrue:[
20341
72ed68b0d0ec little code cleanup
Claus Gittinger <cg@exept.de>
parents: 20026
diff changeset
  1202
	"error if collection is empty"
72ed68b0d0ec little code cleanup
Claus Gittinger <cg@exept.de>
parents: 20026
diff changeset
  1203
	^ self emptyCollectionError.
606
7a9ab63a6757 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1204
    ].
3107
ce4b0a4b3b3a checkin from browser
Claus Gittinger <cg@exept.de>
parents: 3095
diff changeset
  1205
    anObject := contentsArray basicAt:idx.
1496
bea70dc24829 commentary
Claus Gittinger <cg@exept.de>
parents: 1422
diff changeset
  1206
bea70dc24829 commentary
Claus Gittinger <cg@exept.de>
parents: 1422
diff changeset
  1207
    "/ nil it (helps GC)
3107
ce4b0a4b3b3a checkin from browser
Claus Gittinger <cg@exept.de>
parents: 3095
diff changeset
  1208
    contentsArray basicAt:idx put:nil.
ce4b0a4b3b3a checkin from browser
Claus Gittinger <cg@exept.de>
parents: 3095
diff changeset
  1209
    lastIndex := idx := idx - 1.
606
7a9ab63a6757 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1210
3107
ce4b0a4b3b3a checkin from browser
Claus Gittinger <cg@exept.de>
parents: 3095
diff changeset
  1211
    firstIndex > idx ifTrue:[
20341
72ed68b0d0ec little code cleanup
Claus Gittinger <cg@exept.de>
parents: 20026
diff changeset
  1212
	"reset to avoid ever growing"
72ed68b0d0ec little code cleanup
Claus Gittinger <cg@exept.de>
parents: 20026
diff changeset
  1213
	firstIndex := 1.
72ed68b0d0ec little code cleanup
Claus Gittinger <cg@exept.de>
parents: 20026
diff changeset
  1214
	lastIndex := 0
606
7a9ab63a6757 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1215
    ].
7a9ab63a6757 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1216
    ^ anObject
217
a0400fdbc933 *** empty log message ***
claus
parents: 202
diff changeset
  1217
a0400fdbc933 *** empty log message ***
claus
parents: 202
diff changeset
  1218
    "
606
7a9ab63a6757 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1219
     (OrderedCollection withAll:#(1 2 3 4 5)) removeLast; yourself
7a9ab63a6757 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1220
     OrderedCollection new removeLast
7a9ab63a6757 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1221
     (SortedCollection withAll:#(5 4 3 2 1)) removeLast; yourself
217
a0400fdbc933 *** empty log message ***
claus
parents: 202
diff changeset
  1222
    "
3107
ce4b0a4b3b3a checkin from browser
Claus Gittinger <cg@exept.de>
parents: 3095
diff changeset
  1223
ce4b0a4b3b3a checkin from browser
Claus Gittinger <cg@exept.de>
parents: 3095
diff changeset
  1224
    "Modified: / 12.11.1997 / 17:58:57 / cg"
13
62303f84ff5f *** empty log message ***
claus
parents: 10
diff changeset
  1225
!
62303f84ff5f *** empty log message ***
claus
parents: 10
diff changeset
  1226
606
7a9ab63a6757 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1227
removeLast:n
20341
72ed68b0d0ec little code cleanup
Claus Gittinger <cg@exept.de>
parents: 20026
diff changeset
  1228
    "remove the last n elements from the receiver collection.
16304
2d8de035fd7a class: OrderedCollection
Claus Gittinger <cg@exept.de>
parents: 15757
diff changeset
  1229
     Destructive: modifies the receiver.
11330
4a1580833cb5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11275
diff changeset
  1230
     Return a collection of removed elements."
606
7a9ab63a6757 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1231
7a9ab63a6757 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1232
    |mySize ret|
7a9ab63a6757 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1233
7a9ab63a6757 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1234
    mySize := self size.
7a9ab63a6757 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1235
    mySize < n ifTrue:[
20341
72ed68b0d0ec little code cleanup
Claus Gittinger <cg@exept.de>
parents: 20026
diff changeset
  1236
	"error if collection has not enough elements"
72ed68b0d0ec little code cleanup
Claus Gittinger <cg@exept.de>
parents: 20026
diff changeset
  1237
	^ self notEnoughElementsError.
606
7a9ab63a6757 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1238
    ].
13
62303f84ff5f *** empty log message ***
claus
parents: 10
diff changeset
  1239
606
7a9ab63a6757 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1240
    ret := Array new:n.
7a9ab63a6757 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1241
    ret replaceFrom:1 to:n with:contentsArray startingAt:lastIndex - n + 1.
1496
bea70dc24829 commentary
Claus Gittinger <cg@exept.de>
parents: 1422
diff changeset
  1242
606
7a9ab63a6757 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1243
    "/
7a9ab63a6757 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1244
    "/ nil-out contents array, to not keep elements from being GC'd
7a9ab63a6757 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1245
    "/
7a9ab63a6757 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1246
    contentsArray from:lastIndex - n + 1 to:lastIndex put:nil.
7a9ab63a6757 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1247
    lastIndex := lastIndex - n.
13
62303f84ff5f *** empty log message ***
claus
parents: 10
diff changeset
  1248
606
7a9ab63a6757 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1249
    firstIndex > lastIndex ifTrue:[
20341
72ed68b0d0ec little code cleanup
Claus Gittinger <cg@exept.de>
parents: 20026
diff changeset
  1250
	"reset to avoid ever growing"
72ed68b0d0ec little code cleanup
Claus Gittinger <cg@exept.de>
parents: 20026
diff changeset
  1251
	firstIndex := 1.
72ed68b0d0ec little code cleanup
Claus Gittinger <cg@exept.de>
parents: 20026
diff changeset
  1252
	lastIndex := 0
13
62303f84ff5f *** empty log message ***
claus
parents: 10
diff changeset
  1253
    ].
606
7a9ab63a6757 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1254
    ^ ret
13
62303f84ff5f *** empty log message ***
claus
parents: 10
diff changeset
  1255
62303f84ff5f *** empty log message ***
claus
parents: 10
diff changeset
  1256
    "
20341
72ed68b0d0ec little code cleanup
Claus Gittinger <cg@exept.de>
parents: 20026
diff changeset
  1257
     (OrderedCollection withAll:#(1 2 3 4 5)) removeLast:2; yourself
72ed68b0d0ec little code cleanup
Claus Gittinger <cg@exept.de>
parents: 20026
diff changeset
  1258
     (OrderedCollection withAll:#(1 2 3 4 5)) removeLast:0; yourself
72ed68b0d0ec little code cleanup
Claus Gittinger <cg@exept.de>
parents: 20026
diff changeset
  1259
     (OrderedCollection withAll:#(1 2 3 4 5)) removeLast:6; yourself
72ed68b0d0ec little code cleanup
Claus Gittinger <cg@exept.de>
parents: 20026
diff changeset
  1260
     (SortedCollection withAll:#(5 4 3 2 1)) removeLast:2; yourself
72ed68b0d0ec little code cleanup
Claus Gittinger <cg@exept.de>
parents: 20026
diff changeset
  1261
     (SortedCollection withAll:#(5 4 3 2 1)) removeLast:0; yourself
72ed68b0d0ec little code cleanup
Claus Gittinger <cg@exept.de>
parents: 20026
diff changeset
  1262
     (SortedCollection withAll:#(5 4 3 2 1)) removeLast:0
13
62303f84ff5f *** empty log message ***
claus
parents: 10
diff changeset
  1263
    "
1161
aad722dea51a return values compatible to ST-80; added comments; fixed & tuned #makeRoomAtIndex:
Claus Gittinger <cg@exept.de>
parents: 1157
diff changeset
  1264
aad722dea51a return values compatible to ST-80; added comments; fixed & tuned #makeRoomAtIndex:
Claus Gittinger <cg@exept.de>
parents: 1157
diff changeset
  1265
    "Modified: 12.4.1996 / 13:39:12 / cg"
4862
5df99a53c364 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4427
diff changeset
  1266
!
5df99a53c364 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4427
diff changeset
  1267
5df99a53c364 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4427
diff changeset
  1268
reset
5df99a53c364 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4427
diff changeset
  1269
    "logically remove all elements from the collection.
16305
964f7ffb315d class: OrderedCollection
Claus Gittinger <cg@exept.de>
parents: 16304
diff changeset
  1270
     That's almost the same as #removeAll, but keeps the contentsArray.
4862
5df99a53c364 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4427
diff changeset
  1271
     Returns the receiver."
5df99a53c364 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4427
diff changeset
  1272
5df99a53c364 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4427
diff changeset
  1273
    firstIndex := contentsArray size // 3 max: 1.
5df99a53c364 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4427
diff changeset
  1274
    lastIndex := firstIndex - 1
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1275
! !
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1276
606
7a9ab63a6757 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1277
!OrderedCollection methodsFor:'converting'!
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1278
20341
72ed68b0d0ec little code cleanup
Claus Gittinger <cg@exept.de>
parents: 20026
diff changeset
  1279
asArray
1170
4250fe63479b added #asArray; commentary
Claus Gittinger <cg@exept.de>
parents: 1161
diff changeset
  1280
    "return the receiver as an array."
4250fe63479b added #asArray; commentary
Claus Gittinger <cg@exept.de>
parents: 1161
diff changeset
  1281
4153
3481f2a3429c much better #asArray
Claus Gittinger <cg@exept.de>
parents: 4064
diff changeset
  1282
    ^ contentsArray copyFrom:firstIndex to:lastIndex
1170
4250fe63479b added #asArray; commentary
Claus Gittinger <cg@exept.de>
parents: 1161
diff changeset
  1283
4153
3481f2a3429c much better #asArray
Claus Gittinger <cg@exept.de>
parents: 4064
diff changeset
  1284
"/    |newArray sz|
3481f2a3429c much better #asArray
Claus Gittinger <cg@exept.de>
parents: 4064
diff changeset
  1285
"/
3481f2a3429c much better #asArray
Claus Gittinger <cg@exept.de>
parents: 4064
diff changeset
  1286
"/    sz := self size.
3481f2a3429c much better #asArray
Claus Gittinger <cg@exept.de>
parents: 4064
diff changeset
  1287
"/    newArray := Array new:sz.
3481f2a3429c much better #asArray
Claus Gittinger <cg@exept.de>
parents: 4064
diff changeset
  1288
"/    newArray replaceFrom:1 to:sz with:contentsArray startingAt:firstIndex.
3481f2a3429c much better #asArray
Claus Gittinger <cg@exept.de>
parents: 4064
diff changeset
  1289
"/    ^ newArray
3481f2a3429c much better #asArray
Claus Gittinger <cg@exept.de>
parents: 4064
diff changeset
  1290
3481f2a3429c much better #asArray
Claus Gittinger <cg@exept.de>
parents: 4064
diff changeset
  1291
    "
3481f2a3429c much better #asArray
Claus Gittinger <cg@exept.de>
parents: 4064
diff changeset
  1292
     OrderedCollection new asArray
20341
72ed68b0d0ec little code cleanup
Claus Gittinger <cg@exept.de>
parents: 20026
diff changeset
  1293
     OrderedCollection new add:1;add:2;asArray
72ed68b0d0ec little code cleanup
Claus Gittinger <cg@exept.de>
parents: 20026
diff changeset
  1294
     OrderedCollection new add:1;removeFirst;asArray
4153
3481f2a3429c much better #asArray
Claus Gittinger <cg@exept.de>
parents: 4064
diff changeset
  1295
    "
1170
4250fe63479b added #asArray; commentary
Claus Gittinger <cg@exept.de>
parents: 1161
diff changeset
  1296
4250fe63479b added #asArray; commentary
Claus Gittinger <cg@exept.de>
parents: 1161
diff changeset
  1297
    "
4250fe63479b added #asArray; commentary
Claus Gittinger <cg@exept.de>
parents: 1161
diff changeset
  1298
     |o rnd|
4250fe63479b added #asArray; commentary
Claus Gittinger <cg@exept.de>
parents: 1161
diff changeset
  1299
4250fe63479b added #asArray; commentary
Claus Gittinger <cg@exept.de>
parents: 1161
diff changeset
  1300
     o := OrderedCollection new.
4250fe63479b added #asArray; commentary
Claus Gittinger <cg@exept.de>
parents: 1161
diff changeset
  1301
     rnd := Random new.
4250fe63479b added #asArray; commentary
Claus Gittinger <cg@exept.de>
parents: 1161
diff changeset
  1302
     10000 timesRepeat:[
20341
72ed68b0d0ec little code cleanup
Claus Gittinger <cg@exept.de>
parents: 20026
diff changeset
  1303
	 o add:rnd next.
1170
4250fe63479b added #asArray; commentary
Claus Gittinger <cg@exept.de>
parents: 1161
diff changeset
  1304
     ].
20341
72ed68b0d0ec little code cleanup
Claus Gittinger <cg@exept.de>
parents: 20026
diff changeset
  1305
     Time millisecondsToRun:[o asArray]
1170
4250fe63479b added #asArray; commentary
Claus Gittinger <cg@exept.de>
parents: 1161
diff changeset
  1306
    "
4250fe63479b added #asArray; commentary
Claus Gittinger <cg@exept.de>
parents: 1161
diff changeset
  1307
4250fe63479b added #asArray; commentary
Claus Gittinger <cg@exept.de>
parents: 1161
diff changeset
  1308
    "Modified: 13.4.1996 / 12:10:56 / cg"
4250fe63479b added #asArray; commentary
Claus Gittinger <cg@exept.de>
parents: 1161
diff changeset
  1309
!
4250fe63479b added #asArray; commentary
Claus Gittinger <cg@exept.de>
parents: 1161
diff changeset
  1310
20341
72ed68b0d0ec little code cleanup
Claus Gittinger <cg@exept.de>
parents: 20026
diff changeset
  1311
asNewOrderedCollection
14999
e6ad9751587b class: OrderedCollection
Stefan Vogel <sv@exept.de>
parents: 14919
diff changeset
  1312
    "return the receiver as an ordered collection.
e6ad9751587b class: OrderedCollection
Stefan Vogel <sv@exept.de>
parents: 14919
diff changeset
  1313
     Make sure to return a unique new OrderedCollection"
e6ad9751587b class: OrderedCollection
Stefan Vogel <sv@exept.de>
parents: 14919
diff changeset
  1314
e6ad9751587b class: OrderedCollection
Stefan Vogel <sv@exept.de>
parents: 14919
diff changeset
  1315
    "could be an instance of a subclass..."
e6ad9751587b class: OrderedCollection
Stefan Vogel <sv@exept.de>
parents: 14919
diff changeset
  1316
    self class == OrderedCollection ifTrue:[
20341
72ed68b0d0ec little code cleanup
Claus Gittinger <cg@exept.de>
parents: 20026
diff changeset
  1317
	^ self copy
14999
e6ad9751587b class: OrderedCollection
Stefan Vogel <sv@exept.de>
parents: 14919
diff changeset
  1318
    ].
e6ad9751587b class: OrderedCollection
Stefan Vogel <sv@exept.de>
parents: 14919
diff changeset
  1319
    ^ super asOrderedCollection
e6ad9751587b class: OrderedCollection
Stefan Vogel <sv@exept.de>
parents: 14919
diff changeset
  1320
20341
72ed68b0d0ec little code cleanup
Claus Gittinger <cg@exept.de>
parents: 20026
diff changeset
  1321
    "
72ed68b0d0ec little code cleanup
Claus Gittinger <cg@exept.de>
parents: 20026
diff changeset
  1322
	|s|
72ed68b0d0ec little code cleanup
Claus Gittinger <cg@exept.de>
parents: 20026
diff changeset
  1323
	s := #(1 2 3 4) asOrderedCollection.
72ed68b0d0ec little code cleanup
Claus Gittinger <cg@exept.de>
parents: 20026
diff changeset
  1324
	self assert:(s ~~ s asNewOrderedCollection).
72ed68b0d0ec little code cleanup
Claus Gittinger <cg@exept.de>
parents: 20026
diff changeset
  1325
	self assert:(s = s asNewOrderedCollection).
14999
e6ad9751587b class: OrderedCollection
Stefan Vogel <sv@exept.de>
parents: 14919
diff changeset
  1326
     "
e6ad9751587b class: OrderedCollection
Stefan Vogel <sv@exept.de>
parents: 14919
diff changeset
  1327
!
e6ad9751587b class: OrderedCollection
Stefan Vogel <sv@exept.de>
parents: 14919
diff changeset
  1328
20341
72ed68b0d0ec little code cleanup
Claus Gittinger <cg@exept.de>
parents: 20026
diff changeset
  1329
asOrderedCollection
15062
755e0e15b7fa class: OrderedCollection
Claus Gittinger <cg@exept.de>
parents: 14999
diff changeset
  1330
    "return the receiver as an ordered collection.
755e0e15b7fa class: OrderedCollection
Claus Gittinger <cg@exept.de>
parents: 14999
diff changeset
  1331
     Notice: this returns the receiver. Use asNewOrderedCollection, if you intent to
755e0e15b7fa class: OrderedCollection
Claus Gittinger <cg@exept.de>
parents: 14999
diff changeset
  1332
     modify the returned collection."
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1333
606
7a9ab63a6757 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1334
    "could be an instance of a subclass..."
7a9ab63a6757 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1335
    self class == OrderedCollection ifTrue:[
20341
72ed68b0d0ec little code cleanup
Claus Gittinger <cg@exept.de>
parents: 20026
diff changeset
  1336
	^ self
606
7a9ab63a6757 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1337
    ].
7a9ab63a6757 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1338
    ^ super asOrderedCollection
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1339
! !
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1340
606
7a9ab63a6757 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1341
!OrderedCollection methodsFor:'copying'!
13
62303f84ff5f *** empty log message ***
claus
parents: 10
diff changeset
  1342
606
7a9ab63a6757 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1343
, aCollection
14071
8e39d6128e1e comment/format in: #,
Claus Gittinger <cg@exept.de>
parents: 12036
diff changeset
  1344
    "return a new collection formed from concatenating the receiver with the argument"
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1345
606
7a9ab63a6757 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1346
    |newCollection|
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1347
606
7a9ab63a6757 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1348
    newCollection := self copyEmpty:(self size + aCollection size).
7a9ab63a6757 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1349
    ^ newCollection
20341
72ed68b0d0ec little code cleanup
Claus Gittinger <cg@exept.de>
parents: 20026
diff changeset
  1350
	addAll:self;
72ed68b0d0ec little code cleanup
Claus Gittinger <cg@exept.de>
parents: 20026
diff changeset
  1351
	addAll:aCollection;
72ed68b0d0ec little code cleanup
Claus Gittinger <cg@exept.de>
parents: 20026
diff changeset
  1352
	yourself.
42
e33491f6f260 *** empty log message ***
claus
parents: 40
diff changeset
  1353
253
30daee717a53 *** empty log message ***
claus
parents: 229
diff changeset
  1354
    "
606
7a9ab63a6757 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1355
     #(1 2 3) asOrderedCollection , #(4 5 6) asOrderedCollection
20026
c4063e226888 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 19991
diff changeset
  1356
     #(1 3 5) asSortedCollection , #(6 4 2) asSortedCollection
c4063e226888 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 19991
diff changeset
  1357
     #(1 3 5) asSortedCollection , #(6 4 2) asOrderedCollection
c4063e226888 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 19991
diff changeset
  1358
     #(1 3 5) asSortedCollection , (#(6 4 2) asSortedCollection:[:a :b| a > b])
253
30daee717a53 *** empty log message ***
claus
parents: 229
diff changeset
  1359
    "
14071
8e39d6128e1e comment/format in: #,
Claus Gittinger <cg@exept.de>
parents: 12036
diff changeset
  1360
8e39d6128e1e comment/format in: #,
Claus Gittinger <cg@exept.de>
parents: 12036
diff changeset
  1361
    "Modified (comment): / 01-04-2012 / 13:17:30 / cg"
42
e33491f6f260 *** empty log message ***
claus
parents: 40
diff changeset
  1362
!
e33491f6f260 *** empty log message ***
claus
parents: 40
diff changeset
  1363
606
7a9ab63a6757 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1364
copy
7a9ab63a6757 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1365
    "return a new OrderedCollection containing the elements of the receiver."
7a9ab63a6757 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1366
7a9ab63a6757 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1367
    "redefinition is a consequence of the implementation with a
7a9ab63a6757 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1368
     separate array - otherwise we get a shallow copy of the
7a9ab63a6757 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1369
     contents array, which is not what we want here"
7a9ab63a6757 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1370
7a9ab63a6757 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1371
    ^ self copyFrom:1 to:self size
7a9ab63a6757 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1372
!
7a9ab63a6757 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1373
7a9ab63a6757 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1374
postCopy
7a9ab63a6757 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1375
    "have to copy the contentsArray too"
7a9ab63a6757 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1376
7a9ab63a6757 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1377
    contentsArray := contentsArray shallowCopy
7a9ab63a6757 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1378
! !
7a9ab63a6757 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1379
7a9ab63a6757 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1380
!OrderedCollection methodsFor:'enumerating'!
7a9ab63a6757 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1381
7a9ab63a6757 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1382
collect:aBlock
7a9ab63a6757 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1383
    "evaluate the argument, aBlock for every element in the collection
7a9ab63a6757 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1384
     and return a collection of the results"
7a9ab63a6757 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1385
7a9ab63a6757 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1386
    |newCollection
7a9ab63a6757 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1387
     start  "{ Class:SmallInteger }"
7a9ab63a6757 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1388
     stop   "{ Class:SmallInteger }" |
7a9ab63a6757 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1389
7a9ab63a6757 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1390
    newCollection := self copyEmpty:(self size).
7a9ab63a6757 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1391
    stop := lastIndex.
7a9ab63a6757 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1392
    start := firstIndex.
7a9ab63a6757 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1393
    start to:stop do:[:index |
7a9ab63a6757 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1394
	newCollection add:(aBlock value:(contentsArray at:index)).
7a9ab63a6757 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1395
    ].
7a9ab63a6757 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1396
    ^ newCollection
7a9ab63a6757 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1397
253
30daee717a53 *** empty log message ***
claus
parents: 229
diff changeset
  1398
    "
20341
72ed68b0d0ec little code cleanup
Claus Gittinger <cg@exept.de>
parents: 20026
diff changeset
  1399
     #(1 2 3 4) asOrderedCollection collect:[:i | i * i]
72ed68b0d0ec little code cleanup
Claus Gittinger <cg@exept.de>
parents: 20026
diff changeset
  1400
     #(1 2 3 4) asOrderedCollection collect:[:i | i even]
606
7a9ab63a6757 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1401
    "
7a9ab63a6757 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1402
!
7a9ab63a6757 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1403
5508
caabcccaf926 added #collect:thenSelect:
Claus Gittinger <cg@exept.de>
parents: 5502
diff changeset
  1404
collect:collectBlock thenSelect:selectBlock
20341
72ed68b0d0ec little code cleanup
Claus Gittinger <cg@exept.de>
parents: 20026
diff changeset
  1405
    "combination of collect followed by select;
7164
5cdefa506c0e comment
Claus Gittinger <cg@exept.de>
parents: 6756
diff changeset
  1406
     redefined to avoid the creation of an intermediate (garbage) collection."
5508
caabcccaf926 added #collect:thenSelect:
Claus Gittinger <cg@exept.de>
parents: 5502
diff changeset
  1407
caabcccaf926 added #collect:thenSelect:
Claus Gittinger <cg@exept.de>
parents: 5502
diff changeset
  1408
    |newCollection newElement
caabcccaf926 added #collect:thenSelect:
Claus Gittinger <cg@exept.de>
parents: 5502
diff changeset
  1409
     start  "{ Class:SmallInteger }"
caabcccaf926 added #collect:thenSelect:
Claus Gittinger <cg@exept.de>
parents: 5502
diff changeset
  1410
     stop   "{ Class:SmallInteger }" |
caabcccaf926 added #collect:thenSelect:
Claus Gittinger <cg@exept.de>
parents: 5502
diff changeset
  1411
7166
Claus Gittinger <cg@exept.de>
parents: 7165
diff changeset
  1412
    newCollection := self copyEmpty.
5508
caabcccaf926 added #collect:thenSelect:
Claus Gittinger <cg@exept.de>
parents: 5502
diff changeset
  1413
    stop := lastIndex.
caabcccaf926 added #collect:thenSelect:
Claus Gittinger <cg@exept.de>
parents: 5502
diff changeset
  1414
    start := firstIndex.
caabcccaf926 added #collect:thenSelect:
Claus Gittinger <cg@exept.de>
parents: 5502
diff changeset
  1415
    start to:stop do:[:index |
20341
72ed68b0d0ec little code cleanup
Claus Gittinger <cg@exept.de>
parents: 20026
diff changeset
  1416
	newElement := collectBlock value:(contentsArray at:index).
72ed68b0d0ec little code cleanup
Claus Gittinger <cg@exept.de>
parents: 20026
diff changeset
  1417
	(selectBlock value:newElement) ifTrue:[
72ed68b0d0ec little code cleanup
Claus Gittinger <cg@exept.de>
parents: 20026
diff changeset
  1418
	    newCollection add:newElement.
72ed68b0d0ec little code cleanup
Claus Gittinger <cg@exept.de>
parents: 20026
diff changeset
  1419
	]
5508
caabcccaf926 added #collect:thenSelect:
Claus Gittinger <cg@exept.de>
parents: 5502
diff changeset
  1420
    ].
caabcccaf926 added #collect:thenSelect:
Claus Gittinger <cg@exept.de>
parents: 5502
diff changeset
  1421
    ^ newCollection
caabcccaf926 added #collect:thenSelect:
Claus Gittinger <cg@exept.de>
parents: 5502
diff changeset
  1422
caabcccaf926 added #collect:thenSelect:
Claus Gittinger <cg@exept.de>
parents: 5502
diff changeset
  1423
    "
caabcccaf926 added #collect:thenSelect:
Claus Gittinger <cg@exept.de>
parents: 5502
diff changeset
  1424
     #(1 2 3 4) asOrderedCollection collect:[:i | i * i] thenSelect:[:each | each > 5]
20341
72ed68b0d0ec little code cleanup
Claus Gittinger <cg@exept.de>
parents: 20026
diff changeset
  1425
     ( #(1 2 3 4) asOrderedCollection collect:[:i | i * i]) select:[:each | each > 5]
5508
caabcccaf926 added #collect:thenSelect:
Claus Gittinger <cg@exept.de>
parents: 5502
diff changeset
  1426
7165
Claus Gittinger <cg@exept.de>
parents: 7164
diff changeset
  1427
     |coll|
20341
72ed68b0d0ec little code cleanup
Claus Gittinger <cg@exept.de>
parents: 20026
diff changeset
  1428
     coll := #(1 2 3 4) asOrderedCollection.
5508
caabcccaf926 added #collect:thenSelect:
Claus Gittinger <cg@exept.de>
parents: 5502
diff changeset
  1429
     Time millisecondsToRun:[
20341
72ed68b0d0ec little code cleanup
Claus Gittinger <cg@exept.de>
parents: 20026
diff changeset
  1430
	100000 timesRepeat:[
72ed68b0d0ec little code cleanup
Claus Gittinger <cg@exept.de>
parents: 20026
diff changeset
  1431
	    coll collect:[:i | i * i] thenSelect:[:each | each > 5]
72ed68b0d0ec little code cleanup
Claus Gittinger <cg@exept.de>
parents: 20026
diff changeset
  1432
	]
72ed68b0d0ec little code cleanup
Claus Gittinger <cg@exept.de>
parents: 20026
diff changeset
  1433
     ]
5508
caabcccaf926 added #collect:thenSelect:
Claus Gittinger <cg@exept.de>
parents: 5502
diff changeset
  1434
7165
Claus Gittinger <cg@exept.de>
parents: 7164
diff changeset
  1435
     |coll|
20341
72ed68b0d0ec little code cleanup
Claus Gittinger <cg@exept.de>
parents: 20026
diff changeset
  1436
     coll := #(1 2 3 4) asOrderedCollection.
5508
caabcccaf926 added #collect:thenSelect:
Claus Gittinger <cg@exept.de>
parents: 5502
diff changeset
  1437
     Time millisecondsToRun:[
20341
72ed68b0d0ec little code cleanup
Claus Gittinger <cg@exept.de>
parents: 20026
diff changeset
  1438
	100000 timesRepeat:[
72ed68b0d0ec little code cleanup
Claus Gittinger <cg@exept.de>
parents: 20026
diff changeset
  1439
	    ( coll collect:[:i | i * i]) select:[:each | each > 5]
72ed68b0d0ec little code cleanup
Claus Gittinger <cg@exept.de>
parents: 20026
diff changeset
  1440
	]
72ed68b0d0ec little code cleanup
Claus Gittinger <cg@exept.de>
parents: 20026
diff changeset
  1441
     ]
5508
caabcccaf926 added #collect:thenSelect:
Claus Gittinger <cg@exept.de>
parents: 5502
diff changeset
  1442
    "
caabcccaf926 added #collect:thenSelect:
Claus Gittinger <cg@exept.de>
parents: 5502
diff changeset
  1443
!
caabcccaf926 added #collect:thenSelect:
Claus Gittinger <cg@exept.de>
parents: 5502
diff changeset
  1444
606
7a9ab63a6757 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1445
do:aBlock
7a9ab63a6757 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1446
    "evaluate the argument, aBlock for every element in the collection."
7a9ab63a6757 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1447
7a9ab63a6757 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1448
    contentsArray from:firstIndex to:lastIndex do:aBlock
7a9ab63a6757 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1449
!
7a9ab63a6757 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1450
7a9ab63a6757 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1451
keysAndValuesDo:aTwoArgBlock
7a9ab63a6757 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1452
    "evaluate the argument, aBlock for every element in the collection,
7a9ab63a6757 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1453
     passing both index and element as arguments."
7a9ab63a6757 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1454
7a9ab63a6757 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1455
    |start  "{ Class:SmallInteger }"
20341
72ed68b0d0ec little code cleanup
Claus Gittinger <cg@exept.de>
parents: 20026
diff changeset
  1456
     stop   "{ Class:SmallInteger }"
1090
def6e50a2d13 oops - keysAndValuesDo was wrong, iff elements have been removed upFront recently
ca
parents: 1071
diff changeset
  1457
     idx    "{ Class:SmallInteger }" |
606
7a9ab63a6757 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1458
7a9ab63a6757 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1459
    stop := lastIndex.
7a9ab63a6757 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1460
    start := firstIndex.
1090
def6e50a2d13 oops - keysAndValuesDo was wrong, iff elements have been removed upFront recently
ca
parents: 1071
diff changeset
  1461
    idx := 1.
606
7a9ab63a6757 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1462
    start to:stop do:[:index |
20341
72ed68b0d0ec little code cleanup
Claus Gittinger <cg@exept.de>
parents: 20026
diff changeset
  1463
	aTwoArgBlock value:idx value:(contentsArray at:index).
72ed68b0d0ec little code cleanup
Claus Gittinger <cg@exept.de>
parents: 20026
diff changeset
  1464
	idx := idx + 1.
606
7a9ab63a6757 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1465
    ]
7a9ab63a6757 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1466
7a9ab63a6757 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1467
    "
7a9ab63a6757 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1468
     #(10 20 30 40) asOrderedCollection keysAndValuesDo:[:index :value |
20341
72ed68b0d0ec little code cleanup
Claus Gittinger <cg@exept.de>
parents: 20026
diff changeset
  1469
	Transcript show:index; show:' '; showCR:value
72ed68b0d0ec little code cleanup
Claus Gittinger <cg@exept.de>
parents: 20026
diff changeset
  1470
     ]
606
7a9ab63a6757 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1471
    "
1090
def6e50a2d13 oops - keysAndValuesDo was wrong, iff elements have been removed upFront recently
ca
parents: 1071
diff changeset
  1472
    "
def6e50a2d13 oops - keysAndValuesDo was wrong, iff elements have been removed upFront recently
ca
parents: 1071
diff changeset
  1473
     |oc|
def6e50a2d13 oops - keysAndValuesDo was wrong, iff elements have been removed upFront recently
ca
parents: 1071
diff changeset
  1474
def6e50a2d13 oops - keysAndValuesDo was wrong, iff elements have been removed upFront recently
ca
parents: 1071
diff changeset
  1475
     oc := #(10 20 30 40 50 60 70 80) asOrderedCollection.
def6e50a2d13 oops - keysAndValuesDo was wrong, iff elements have been removed upFront recently
ca
parents: 1071
diff changeset
  1476
     oc removeFirst; removeFirst.
def6e50a2d13 oops - keysAndValuesDo was wrong, iff elements have been removed upFront recently
ca
parents: 1071
diff changeset
  1477
     oc keysAndValuesDo:[:index :value |
20341
72ed68b0d0ec little code cleanup
Claus Gittinger <cg@exept.de>
parents: 20026
diff changeset
  1478
	Transcript show:index; show:' '; showCR:value
72ed68b0d0ec little code cleanup
Claus Gittinger <cg@exept.de>
parents: 20026
diff changeset
  1479
     ]
1090
def6e50a2d13 oops - keysAndValuesDo was wrong, iff elements have been removed upFront recently
ca
parents: 1071
diff changeset
  1480
    "
def6e50a2d13 oops - keysAndValuesDo was wrong, iff elements have been removed upFront recently
ca
parents: 1071
diff changeset
  1481
606
7a9ab63a6757 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1482
!
7a9ab63a6757 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1483
679
d3165edbb098 *** empty log message ***
chrisy
parents: 629
diff changeset
  1484
keysAndValuesReverseDo:aTwoArgBlock
d3165edbb098 *** empty log message ***
chrisy
parents: 629
diff changeset
  1485
    "evaluate the argument, aBlock for every element in the collection,
d3165edbb098 *** empty log message ***
chrisy
parents: 629
diff changeset
  1486
     passing both index and element as arguments."
d3165edbb098 *** empty log message ***
chrisy
parents: 629
diff changeset
  1487
d3165edbb098 *** empty log message ***
chrisy
parents: 629
diff changeset
  1488
    |start  "{ Class:SmallInteger }"
20341
72ed68b0d0ec little code cleanup
Claus Gittinger <cg@exept.de>
parents: 20026
diff changeset
  1489
     stop   "{ Class:SmallInteger }"
1090
def6e50a2d13 oops - keysAndValuesDo was wrong, iff elements have been removed upFront recently
ca
parents: 1071
diff changeset
  1490
     idx    "{ Class:SmallInteger }"|
679
d3165edbb098 *** empty log message ***
chrisy
parents: 629
diff changeset
  1491
d3165edbb098 *** empty log message ***
chrisy
parents: 629
diff changeset
  1492
    stop := lastIndex.
d3165edbb098 *** empty log message ***
chrisy
parents: 629
diff changeset
  1493
    start := firstIndex.
1090
def6e50a2d13 oops - keysAndValuesDo was wrong, iff elements have been removed upFront recently
ca
parents: 1071
diff changeset
  1494
    idx := (stop - start + 1).
679
d3165edbb098 *** empty log message ***
chrisy
parents: 629
diff changeset
  1495
    stop to:start by: -1 do:[:index |
20341
72ed68b0d0ec little code cleanup
Claus Gittinger <cg@exept.de>
parents: 20026
diff changeset
  1496
	aTwoArgBlock value:idx value:(contentsArray at:index).
72ed68b0d0ec little code cleanup
Claus Gittinger <cg@exept.de>
parents: 20026
diff changeset
  1497
	idx := idx - 1.
679
d3165edbb098 *** empty log message ***
chrisy
parents: 629
diff changeset
  1498
    ]
d3165edbb098 *** empty log message ***
chrisy
parents: 629
diff changeset
  1499
d3165edbb098 *** empty log message ***
chrisy
parents: 629
diff changeset
  1500
    "
d3165edbb098 *** empty log message ***
chrisy
parents: 629
diff changeset
  1501
     #(10 20 30 40) asOrderedCollection keysAndValuesReverseDo:[:index :value |
20341
72ed68b0d0ec little code cleanup
Claus Gittinger <cg@exept.de>
parents: 20026
diff changeset
  1502
	Transcript show:index; show:' '; showCR:value
72ed68b0d0ec little code cleanup
Claus Gittinger <cg@exept.de>
parents: 20026
diff changeset
  1503
     ]
1090
def6e50a2d13 oops - keysAndValuesDo was wrong, iff elements have been removed upFront recently
ca
parents: 1071
diff changeset
  1504
    "
def6e50a2d13 oops - keysAndValuesDo was wrong, iff elements have been removed upFront recently
ca
parents: 1071
diff changeset
  1505
def6e50a2d13 oops - keysAndValuesDo was wrong, iff elements have been removed upFront recently
ca
parents: 1071
diff changeset
  1506
    "
def6e50a2d13 oops - keysAndValuesDo was wrong, iff elements have been removed upFront recently
ca
parents: 1071
diff changeset
  1507
     |oc|
def6e50a2d13 oops - keysAndValuesDo was wrong, iff elements have been removed upFront recently
ca
parents: 1071
diff changeset
  1508
def6e50a2d13 oops - keysAndValuesDo was wrong, iff elements have been removed upFront recently
ca
parents: 1071
diff changeset
  1509
     oc := #(10 20 30 40 50 60 70 80) asOrderedCollection.
def6e50a2d13 oops - keysAndValuesDo was wrong, iff elements have been removed upFront recently
ca
parents: 1071
diff changeset
  1510
     oc removeFirst; removeFirst.
def6e50a2d13 oops - keysAndValuesDo was wrong, iff elements have been removed upFront recently
ca
parents: 1071
diff changeset
  1511
     oc keysAndValuesReverseDo:[:index :value |
20341
72ed68b0d0ec little code cleanup
Claus Gittinger <cg@exept.de>
parents: 20026
diff changeset
  1512
	Transcript show:index; show:' '; showCR:value
72ed68b0d0ec little code cleanup
Claus Gittinger <cg@exept.de>
parents: 20026
diff changeset
  1513
     ]
679
d3165edbb098 *** empty log message ***
chrisy
parents: 629
diff changeset
  1514
    "
1071
5875a6eedd28 added #includesIdentical:
Claus Gittinger <cg@exept.de>
parents: 679
diff changeset
  1515
!
5875a6eedd28 added #includesIdentical:
Claus Gittinger <cg@exept.de>
parents: 679
diff changeset
  1516
5875a6eedd28 added #includesIdentical:
Claus Gittinger <cg@exept.de>
parents: 679
diff changeset
  1517
reverseDo:aBlock
5875a6eedd28 added #includesIdentical:
Claus Gittinger <cg@exept.de>
parents: 679
diff changeset
  1518
    "evaluate the argument, aBlock for every element in the collection
5875a6eedd28 added #includesIdentical:
Claus Gittinger <cg@exept.de>
parents: 679
diff changeset
  1519
     procesing elements in reverse direction (i.e. starting with the last)"
5875a6eedd28 added #includesIdentical:
Claus Gittinger <cg@exept.de>
parents: 679
diff changeset
  1520
5875a6eedd28 added #includesIdentical:
Claus Gittinger <cg@exept.de>
parents: 679
diff changeset
  1521
    contentsArray from:firstIndex to:lastIndex reverseDo:aBlock
7165
Claus Gittinger <cg@exept.de>
parents: 7164
diff changeset
  1522
!
Claus Gittinger <cg@exept.de>
parents: 7164
diff changeset
  1523
Claus Gittinger <cg@exept.de>
parents: 7164
diff changeset
  1524
select:selectBlock thenCollect:collectBlock
20341
72ed68b0d0ec little code cleanup
Claus Gittinger <cg@exept.de>
parents: 20026
diff changeset
  1525
    "combination of select followed by collect;
7165
Claus Gittinger <cg@exept.de>
parents: 7164
diff changeset
  1526
     redefined to avoid the creation of an intermediate (garbage) collection."
Claus Gittinger <cg@exept.de>
parents: 7164
diff changeset
  1527
Claus Gittinger <cg@exept.de>
parents: 7164
diff changeset
  1528
    |newCollection element
Claus Gittinger <cg@exept.de>
parents: 7164
diff changeset
  1529
     start  "{ Class:SmallInteger }"
Claus Gittinger <cg@exept.de>
parents: 7164
diff changeset
  1530
     stop   "{ Class:SmallInteger }" |
Claus Gittinger <cg@exept.de>
parents: 7164
diff changeset
  1531
7166
Claus Gittinger <cg@exept.de>
parents: 7165
diff changeset
  1532
    newCollection := self copyEmpty.
7165
Claus Gittinger <cg@exept.de>
parents: 7164
diff changeset
  1533
    stop := lastIndex.
Claus Gittinger <cg@exept.de>
parents: 7164
diff changeset
  1534
    start := firstIndex.
Claus Gittinger <cg@exept.de>
parents: 7164
diff changeset
  1535
    start to:stop do:[:index |
20341
72ed68b0d0ec little code cleanup
Claus Gittinger <cg@exept.de>
parents: 20026
diff changeset
  1536
	element := contentsArray at:index.
72ed68b0d0ec little code cleanup
Claus Gittinger <cg@exept.de>
parents: 20026
diff changeset
  1537
	(selectBlock value:element) ifTrue:[
72ed68b0d0ec little code cleanup
Claus Gittinger <cg@exept.de>
parents: 20026
diff changeset
  1538
	    newCollection add:(collectBlock value:element).
72ed68b0d0ec little code cleanup
Claus Gittinger <cg@exept.de>
parents: 20026
diff changeset
  1539
	]
7165
Claus Gittinger <cg@exept.de>
parents: 7164
diff changeset
  1540
    ].
Claus Gittinger <cg@exept.de>
parents: 7164
diff changeset
  1541
    ^ newCollection
Claus Gittinger <cg@exept.de>
parents: 7164
diff changeset
  1542
Claus Gittinger <cg@exept.de>
parents: 7164
diff changeset
  1543
    "
20341
72ed68b0d0ec little code cleanup
Claus Gittinger <cg@exept.de>
parents: 20026
diff changeset
  1544
     #(1 2 3 4 5 6 7 8) asOrderedCollection
72ed68b0d0ec little code cleanup
Claus Gittinger <cg@exept.de>
parents: 20026
diff changeset
  1545
	select:[:each | each > 5] thenCollect:[:i | i * i]
72ed68b0d0ec little code cleanup
Claus Gittinger <cg@exept.de>
parents: 20026
diff changeset
  1546
     ( #(1 2 3 4 5 6 7 8) asOrderedCollection
72ed68b0d0ec little code cleanup
Claus Gittinger <cg@exept.de>
parents: 20026
diff changeset
  1547
	select:[:each | each > 5]) collect:[:i | i * i]
7165
Claus Gittinger <cg@exept.de>
parents: 7164
diff changeset
  1548
Claus Gittinger <cg@exept.de>
parents: 7164
diff changeset
  1549
     |coll|
20341
72ed68b0d0ec little code cleanup
Claus Gittinger <cg@exept.de>
parents: 20026
diff changeset
  1550
     coll := #(1 2 3 4 5 6 7 8) asOrderedCollection.
7165
Claus Gittinger <cg@exept.de>
parents: 7164
diff changeset
  1551
     Time millisecondsToRun:[
20341
72ed68b0d0ec little code cleanup
Claus Gittinger <cg@exept.de>
parents: 20026
diff changeset
  1552
	100000 timesRepeat:[
72ed68b0d0ec little code cleanup
Claus Gittinger <cg@exept.de>
parents: 20026
diff changeset
  1553
	    coll select:[:each | each > 5] thenCollect:[:i | i * i]
72ed68b0d0ec little code cleanup
Claus Gittinger <cg@exept.de>
parents: 20026
diff changeset
  1554
	]
72ed68b0d0ec little code cleanup
Claus Gittinger <cg@exept.de>
parents: 20026
diff changeset
  1555
     ]
7165
Claus Gittinger <cg@exept.de>
parents: 7164
diff changeset
  1556
Claus Gittinger <cg@exept.de>
parents: 7164
diff changeset
  1557
     |coll|
20341
72ed68b0d0ec little code cleanup
Claus Gittinger <cg@exept.de>
parents: 20026
diff changeset
  1558
     coll := #(1 2 3 4 5 6 7 8) asOrderedCollection.
7165
Claus Gittinger <cg@exept.de>
parents: 7164
diff changeset
  1559
     Time millisecondsToRun:[
20341
72ed68b0d0ec little code cleanup
Claus Gittinger <cg@exept.de>
parents: 20026
diff changeset
  1560
	100000 timesRepeat:[
72ed68b0d0ec little code cleanup
Claus Gittinger <cg@exept.de>
parents: 20026
diff changeset
  1561
	    ( coll select:[:each | each > 5]) collect:[:i | i * i]
72ed68b0d0ec little code cleanup
Claus Gittinger <cg@exept.de>
parents: 20026
diff changeset
  1562
	]
72ed68b0d0ec little code cleanup
Claus Gittinger <cg@exept.de>
parents: 20026
diff changeset
  1563
     ]
7165
Claus Gittinger <cg@exept.de>
parents: 7164
diff changeset
  1564
    "
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1565
! !
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1566
56
be0ed17e6f85 *** empty log message ***
claus
parents: 42
diff changeset
  1567
!OrderedCollection methodsFor:'filling & replacing'!
13
62303f84ff5f *** empty log message ***
claus
parents: 10
diff changeset
  1568
62303f84ff5f *** empty log message ***
claus
parents: 10
diff changeset
  1569
replaceFrom:start to:stop with:aCollection startingAt:repStart
1170
4250fe63479b added #asArray; commentary
Claus Gittinger <cg@exept.de>
parents: 1161
diff changeset
  1570
    "replace elements in the receiver between index start and stop,
4250fe63479b added #asArray; commentary
Claus Gittinger <cg@exept.de>
parents: 1161
diff changeset
  1571
     with elements  taken from replacementCollection starting at repStart.
3236
b5f80b416cff check for valid subscript in #add:beforeIndex:
Claus Gittinger <cg@exept.de>
parents: 3109
diff changeset
  1572
     Return the receiver.
b5f80b416cff check for valid subscript in #add:beforeIndex:
Claus Gittinger <cg@exept.de>
parents: 3109
diff changeset
  1573
     Redefined here; can be done faster as the inherited operation."
13
62303f84ff5f *** empty log message ***
claus
parents: 10
diff changeset
  1574
62303f84ff5f *** empty log message ***
claus
parents: 10
diff changeset
  1575
    |end|
62303f84ff5f *** empty log message ***
claus
parents: 10
diff changeset
  1576
62303f84ff5f *** empty log message ***
claus
parents: 10
diff changeset
  1577
    end := stop + firstIndex - 1.
62303f84ff5f *** empty log message ***
claus
parents: 10
diff changeset
  1578
    ((start >= 1) and:[end <= lastIndex]) ifTrue:[
20341
72ed68b0d0ec little code cleanup
Claus Gittinger <cg@exept.de>
parents: 20026
diff changeset
  1579
	aCollection class == self class ifTrue:[
72ed68b0d0ec little code cleanup
Claus Gittinger <cg@exept.de>
parents: 20026
diff changeset
  1580
	    contentsArray
72ed68b0d0ec little code cleanup
Claus Gittinger <cg@exept.de>
parents: 20026
diff changeset
  1581
		replaceFrom:(start + firstIndex - 1)
72ed68b0d0ec little code cleanup
Claus Gittinger <cg@exept.de>
parents: 20026
diff changeset
  1582
		to:end
72ed68b0d0ec little code cleanup
Claus Gittinger <cg@exept.de>
parents: 20026
diff changeset
  1583
		with:aCollection contentsArray
72ed68b0d0ec little code cleanup
Claus Gittinger <cg@exept.de>
parents: 20026
diff changeset
  1584
		startingAt:(repStart + aCollection firstIndex - 1).
72ed68b0d0ec little code cleanup
Claus Gittinger <cg@exept.de>
parents: 20026
diff changeset
  1585
	] ifFalse:[
72ed68b0d0ec little code cleanup
Claus Gittinger <cg@exept.de>
parents: 20026
diff changeset
  1586
	    contentsArray
72ed68b0d0ec little code cleanup
Claus Gittinger <cg@exept.de>
parents: 20026
diff changeset
  1587
		replaceFrom:(start + firstIndex - 1)
72ed68b0d0ec little code cleanup
Claus Gittinger <cg@exept.de>
parents: 20026
diff changeset
  1588
		to:end
72ed68b0d0ec little code cleanup
Claus Gittinger <cg@exept.de>
parents: 20026
diff changeset
  1589
		with:aCollection
72ed68b0d0ec little code cleanup
Claus Gittinger <cg@exept.de>
parents: 20026
diff changeset
  1590
		startingAt:repStart.
72ed68b0d0ec little code cleanup
Claus Gittinger <cg@exept.de>
parents: 20026
diff changeset
  1591
	].
72ed68b0d0ec little code cleanup
Claus Gittinger <cg@exept.de>
parents: 20026
diff changeset
  1592
	^ self
13
62303f84ff5f *** empty log message ***
claus
parents: 10
diff changeset
  1593
    ].
62303f84ff5f *** empty log message ***
claus
parents: 10
diff changeset
  1594
    ^ super replaceFrom:start to:stop with:aCollection startingAt:repStart
293
31df3850e98c *** empty log message ***
claus
parents: 282
diff changeset
  1595
31df3850e98c *** empty log message ***
claus
parents: 282
diff changeset
  1596
    "
15757
f7e84eeeaaa9 class: OrderedCollection
Claus Gittinger <cg@exept.de>
parents: 15749
diff changeset
  1597
     |c1 c2|
f7e84eeeaaa9 class: OrderedCollection
Claus Gittinger <cg@exept.de>
parents: 15749
diff changeset
  1598
f7e84eeeaaa9 class: OrderedCollection
Claus Gittinger <cg@exept.de>
parents: 15749
diff changeset
  1599
     c1 := #(1 2 3 4 5 6) asOrderedCollection.
f7e84eeeaaa9 class: OrderedCollection
Claus Gittinger <cg@exept.de>
parents: 15749
diff changeset
  1600
     c2 := #(a b c d e f) asOrderedCollection.
f7e84eeeaaa9 class: OrderedCollection
Claus Gittinger <cg@exept.de>
parents: 15749
diff changeset
  1601
     c2 replaceFrom:3 to:6 with:c1.
20341
72ed68b0d0ec little code cleanup
Claus Gittinger <cg@exept.de>
parents: 20026
diff changeset
  1602
     c2
15757
f7e84eeeaaa9 class: OrderedCollection
Claus Gittinger <cg@exept.de>
parents: 15749
diff changeset
  1603
    "
f7e84eeeaaa9 class: OrderedCollection
Claus Gittinger <cg@exept.de>
parents: 15749
diff changeset
  1604
    "
f7e84eeeaaa9 class: OrderedCollection
Claus Gittinger <cg@exept.de>
parents: 15749
diff changeset
  1605
     |c1 c2|
f7e84eeeaaa9 class: OrderedCollection
Claus Gittinger <cg@exept.de>
parents: 15749
diff changeset
  1606
f7e84eeeaaa9 class: OrderedCollection
Claus Gittinger <cg@exept.de>
parents: 15749
diff changeset
  1607
     c1 := #(1 2 3 4 5 6) asOrderedCollection.
f7e84eeeaaa9 class: OrderedCollection
Claus Gittinger <cg@exept.de>
parents: 15749
diff changeset
  1608
     c2 := #(a b c d e f) asOrderedCollection.
f7e84eeeaaa9 class: OrderedCollection
Claus Gittinger <cg@exept.de>
parents: 15749
diff changeset
  1609
     c2 replaceFrom:3 to:6 with:c1 startingAt:2.
20341
72ed68b0d0ec little code cleanup
Claus Gittinger <cg@exept.de>
parents: 20026
diff changeset
  1610
     c2
15757
f7e84eeeaaa9 class: OrderedCollection
Claus Gittinger <cg@exept.de>
parents: 15749
diff changeset
  1611
    "
f7e84eeeaaa9 class: OrderedCollection
Claus Gittinger <cg@exept.de>
parents: 15749
diff changeset
  1612
    "
293
31df3850e98c *** empty log message ***
claus
parents: 282
diff changeset
  1613
     |c|
31df3850e98c *** empty log message ***
claus
parents: 282
diff changeset
  1614
31df3850e98c *** empty log message ***
claus
parents: 282
diff changeset
  1615
     c := #(1 2 3 4 5 6) asOrderedCollection.
31df3850e98c *** empty log message ***
claus
parents: 282
diff changeset
  1616
     c replaceFrom:3 to:6 with:c startingAt:2.
20341
72ed68b0d0ec little code cleanup
Claus Gittinger <cg@exept.de>
parents: 20026
diff changeset
  1617
     c
293
31df3850e98c *** empty log message ***
claus
parents: 282
diff changeset
  1618
    "
31df3850e98c *** empty log message ***
claus
parents: 282
diff changeset
  1619
    "
31df3850e98c *** empty log message ***
claus
parents: 282
diff changeset
  1620
     |c|
31df3850e98c *** empty log message ***
claus
parents: 282
diff changeset
  1621
31df3850e98c *** empty log message ***
claus
parents: 282
diff changeset
  1622
     c := #(1 2 3 4 5 6) asOrderedCollection.
31df3850e98c *** empty log message ***
claus
parents: 282
diff changeset
  1623
     c replaceFrom:3 to:5 with:c startingAt:4.
20341
72ed68b0d0ec little code cleanup
Claus Gittinger <cg@exept.de>
parents: 20026
diff changeset
  1624
     c
293
31df3850e98c *** empty log message ***
claus
parents: 282
diff changeset
  1625
    "
1170
4250fe63479b added #asArray; commentary
Claus Gittinger <cg@exept.de>
parents: 1161
diff changeset
  1626
3236
b5f80b416cff check for valid subscript in #add:beforeIndex:
Claus Gittinger <cg@exept.de>
parents: 3109
diff changeset
  1627
    "Modified: / 28.1.1998 / 16:49:31 / cg"
13
62303f84ff5f *** empty log message ***
claus
parents: 10
diff changeset
  1628
! !
62303f84ff5f *** empty log message ***
claus
parents: 10
diff changeset
  1629
606
7a9ab63a6757 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1630
!OrderedCollection methodsFor:'grow & shrink'!
77
6c38ca59927f *** empty log message ***
claus
parents: 68
diff changeset
  1631
18379
e36a3b641b80 class: OrderedCollection
Claus Gittinger <cg@exept.de>
parents: 18184
diff changeset
  1632
ensureSizeAtLeast:minSize
e36a3b641b80 class: OrderedCollection
Claus Gittinger <cg@exept.de>
parents: 18184
diff changeset
  1633
    "ensure that the size is at least minSize.
e36a3b641b80 class: OrderedCollection
Claus Gittinger <cg@exept.de>
parents: 18184
diff changeset
  1634
     If the receiver's size is smaller, grow the receiver to minSize,
e36a3b641b80 class: OrderedCollection
Claus Gittinger <cg@exept.de>
parents: 18184
diff changeset
  1635
     filling new slots with nil.
20341
72ed68b0d0ec little code cleanup
Claus Gittinger <cg@exept.de>
parents: 20026
diff changeset
  1636
     Otherwise, if the size is already >= minSize, leave the receiver unchanged."
18379
e36a3b641b80 class: OrderedCollection
Claus Gittinger <cg@exept.de>
parents: 18184
diff changeset
  1637
e36a3b641b80 class: OrderedCollection
Claus Gittinger <cg@exept.de>
parents: 18184
diff changeset
  1638
    (self size < minSize) ifTrue:[
20341
72ed68b0d0ec little code cleanup
Claus Gittinger <cg@exept.de>
parents: 20026
diff changeset
  1639
	self grow:minSize
18379
e36a3b641b80 class: OrderedCollection
Claus Gittinger <cg@exept.de>
parents: 18184
diff changeset
  1640
    ].
e36a3b641b80 class: OrderedCollection
Claus Gittinger <cg@exept.de>
parents: 18184
diff changeset
  1641
e36a3b641b80 class: OrderedCollection
Claus Gittinger <cg@exept.de>
parents: 18184
diff changeset
  1642
    "
e36a3b641b80 class: OrderedCollection
Claus Gittinger <cg@exept.de>
parents: 18184
diff changeset
  1643
     |oc|
e36a3b641b80 class: OrderedCollection
Claus Gittinger <cg@exept.de>
parents: 18184
diff changeset
  1644
e36a3b641b80 class: OrderedCollection
Claus Gittinger <cg@exept.de>
parents: 18184
diff changeset
  1645
     oc := OrderedCollection new.
e36a3b641b80 class: OrderedCollection
Claus Gittinger <cg@exept.de>
parents: 18184
diff changeset
  1646
     oc ensureSizeAtLeast:10.
e36a3b641b80 class: OrderedCollection
Claus Gittinger <cg@exept.de>
parents: 18184
diff changeset
  1647
     oc at:10 put:10.
e36a3b641b80 class: OrderedCollection
Claus Gittinger <cg@exept.de>
parents: 18184
diff changeset
  1648
     oc add:11.
e36a3b641b80 class: OrderedCollection
Claus Gittinger <cg@exept.de>
parents: 18184
diff changeset
  1649
     oc at:11.
e36a3b641b80 class: OrderedCollection
Claus Gittinger <cg@exept.de>
parents: 18184
diff changeset
  1650
     oc ensureSizeAtLeast:20.
e36a3b641b80 class: OrderedCollection
Claus Gittinger <cg@exept.de>
parents: 18184
diff changeset
  1651
     oc at:20 put:20.
e36a3b641b80 class: OrderedCollection
Claus Gittinger <cg@exept.de>
parents: 18184
diff changeset
  1652
     oc.
e36a3b641b80 class: OrderedCollection
Claus Gittinger <cg@exept.de>
parents: 18184
diff changeset
  1653
    "
e36a3b641b80 class: OrderedCollection
Claus Gittinger <cg@exept.de>
parents: 18184
diff changeset
  1654
!
e36a3b641b80 class: OrderedCollection
Claus Gittinger <cg@exept.de>
parents: 18184
diff changeset
  1655
606
7a9ab63a6757 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1656
grow:newSize
20341
72ed68b0d0ec little code cleanup
Claus Gittinger <cg@exept.de>
parents: 20026
diff changeset
  1657
    "grow the receiver to newSize.
72ed68b0d0ec little code cleanup
Claus Gittinger <cg@exept.de>
parents: 20026
diff changeset
  1658
     This only logically changes the receiver's size;
72ed68b0d0ec little code cleanup
Claus Gittinger <cg@exept.de>
parents: 20026
diff changeset
  1659
     the underlying contentsArray is kept
19836
f6f451ada167 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 19831
diff changeset
  1660
     (except if growing to a zero size, or too small for newSize)"
77
6c38ca59927f *** empty log message ***
claus
parents: 68
diff changeset
  1661
606
7a9ab63a6757 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1662
    |oldSize newContents oldLast newLast|
77
6c38ca59927f *** empty log message ***
claus
parents: 68
diff changeset
  1663
606
7a9ab63a6757 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1664
    oldSize := lastIndex - firstIndex + 1.
7a9ab63a6757 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1665
    newSize ~~ oldSize ifTrue:[
20341
72ed68b0d0ec little code cleanup
Claus Gittinger <cg@exept.de>
parents: 20026
diff changeset
  1666
	newLast := firstIndex + newSize - 1.
72ed68b0d0ec little code cleanup
Claus Gittinger <cg@exept.de>
parents: 20026
diff changeset
  1667
	newSize < oldSize ifTrue:[
72ed68b0d0ec little code cleanup
Claus Gittinger <cg@exept.de>
parents: 20026
diff changeset
  1668
	    newSize == 0 ifTrue:[
72ed68b0d0ec little code cleanup
Claus Gittinger <cg@exept.de>
parents: 20026
diff changeset
  1669
		self initContents:0.
72ed68b0d0ec little code cleanup
Claus Gittinger <cg@exept.de>
parents: 20026
diff changeset
  1670
		^ self.
72ed68b0d0ec little code cleanup
Claus Gittinger <cg@exept.de>
parents: 20026
diff changeset
  1671
	    ].
72ed68b0d0ec little code cleanup
Claus Gittinger <cg@exept.de>
parents: 20026
diff changeset
  1672
	    oldLast := lastIndex.
72ed68b0d0ec little code cleanup
Claus Gittinger <cg@exept.de>
parents: 20026
diff changeset
  1673
	    lastIndex := newLast.
72ed68b0d0ec little code cleanup
Claus Gittinger <cg@exept.de>
parents: 20026
diff changeset
  1674
	    "
72ed68b0d0ec little code cleanup
Claus Gittinger <cg@exept.de>
parents: 20026
diff changeset
  1675
	     nil out rest, to give GC a chance to reclaim things
72ed68b0d0ec little code cleanup
Claus Gittinger <cg@exept.de>
parents: 20026
diff changeset
  1676
	    "
72ed68b0d0ec little code cleanup
Claus Gittinger <cg@exept.de>
parents: 20026
diff changeset
  1677
	    contentsArray from:lastIndex + 1 to:oldLast put:nil.
72ed68b0d0ec little code cleanup
Claus Gittinger <cg@exept.de>
parents: 20026
diff changeset
  1678
	] ifFalse:[
72ed68b0d0ec little code cleanup
Claus Gittinger <cg@exept.de>
parents: 20026
diff changeset
  1679
	    newLast <= contentsArray size ifTrue:[
72ed68b0d0ec little code cleanup
Claus Gittinger <cg@exept.de>
parents: 20026
diff changeset
  1680
		lastIndex := newLast.
72ed68b0d0ec little code cleanup
Claus Gittinger <cg@exept.de>
parents: 20026
diff changeset
  1681
		^ self
72ed68b0d0ec little code cleanup
Claus Gittinger <cg@exept.de>
parents: 20026
diff changeset
  1682
	    ].
77
6c38ca59927f *** empty log message ***
claus
parents: 68
diff changeset
  1683
20341
72ed68b0d0ec little code cleanup
Claus Gittinger <cg@exept.de>
parents: 20026
diff changeset
  1684
	    newContents := Array basicNew:newSize.
72ed68b0d0ec little code cleanup
Claus Gittinger <cg@exept.de>
parents: 20026
diff changeset
  1685
	    newContents replaceFrom:1 to:oldSize with:contentsArray startingAt:firstIndex.
72ed68b0d0ec little code cleanup
Claus Gittinger <cg@exept.de>
parents: 20026
diff changeset
  1686
	    contentsArray := newContents.
72ed68b0d0ec little code cleanup
Claus Gittinger <cg@exept.de>
parents: 20026
diff changeset
  1687
	    firstIndex := 1.
72ed68b0d0ec little code cleanup
Claus Gittinger <cg@exept.de>
parents: 20026
diff changeset
  1688
	    lastIndex := newSize
72ed68b0d0ec little code cleanup
Claus Gittinger <cg@exept.de>
parents: 20026
diff changeset
  1689
	]
606
7a9ab63a6757 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1690
    ]
7a9ab63a6757 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1691
! !
77
6c38ca59927f *** empty log message ***
claus
parents: 68
diff changeset
  1692
6c38ca59927f *** empty log message ***
claus
parents: 68
diff changeset
  1693
20026
c4063e226888 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 19991
diff changeset
  1694
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1695
!OrderedCollection methodsFor:'private'!
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1696
606
7a9ab63a6757 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1697
initContents:size
7a9ab63a6757 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1698
    "setup the receiver-collection to hold size entries"
33
50cf0f6bc0ad *** empty log message ***
claus
parents: 13
diff changeset
  1699
18879
5d1bbfc1761d #FEATURE
Stefan Vogel <sv@exept.de>
parents: 18811
diff changeset
  1700
    size == 0 ifTrue:[
20341
72ed68b0d0ec little code cleanup
Claus Gittinger <cg@exept.de>
parents: 20026
diff changeset
  1701
	contentsArray := #().   "save memory by using a shared instance"
18879
5d1bbfc1761d #FEATURE
Stefan Vogel <sv@exept.de>
parents: 18811
diff changeset
  1702
    ] ifFalse:[
20341
72ed68b0d0ec little code cleanup
Claus Gittinger <cg@exept.de>
parents: 20026
diff changeset
  1703
	contentsArray := Array basicNew:size.
18879
5d1bbfc1761d #FEATURE
Stefan Vogel <sv@exept.de>
parents: 18811
diff changeset
  1704
    ].
606
7a9ab63a6757 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1705
    firstIndex := 1.
20341
72ed68b0d0ec little code cleanup
Claus Gittinger <cg@exept.de>
parents: 20026
diff changeset
  1706
    lastIndex := 0
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1707
!
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1708
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1709
makeRoomAtFront
282
94f5c3a6230d *** empty log message ***
claus
parents: 253
diff changeset
  1710
    "grow/shift the contents for more room at the beginning.
94f5c3a6230d *** empty log message ***
claus
parents: 253
diff changeset
  1711
     Does not change the logical size.
18183
3178ced76cfa class: OrderedCollection
Claus Gittinger <cg@exept.de>
parents: 18182
diff changeset
  1712
     i.e. the contents array is changed from:
20341
72ed68b0d0ec little code cleanup
Claus Gittinger <cg@exept.de>
parents: 20026
diff changeset
  1713
	#(1 2 3 4 5 6) -> #(nil 1 2 3 4 5 6)
18183
3178ced76cfa class: OrderedCollection
Claus Gittinger <cg@exept.de>
parents: 18182
diff changeset
  1714
     and the start/stopIndices are adjusted as required"
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1715
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1716
    |newContents
33
50cf0f6bc0ad *** empty log message ***
claus
parents: 13
diff changeset
  1717
     oldSize    "{ Class:SmallInteger }"
20341
72ed68b0d0ec little code cleanup
Claus Gittinger <cg@exept.de>
parents: 20026
diff changeset
  1718
     newSize    "{ Class:SmallInteger }"
33
50cf0f6bc0ad *** empty log message ***
claus
parents: 13
diff changeset
  1719
     startIndex "{ Class:SmallInteger }"
50cf0f6bc0ad *** empty log message ***
claus
parents: 13
diff changeset
  1720
     sz         "{ Class:SmallInteger }"|
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1721
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1722
    oldSize := contentsArray size.
506
984b32fe635a fixed makeRoomAtFront if underlying arrays size is <= 3
Claus Gittinger <cg@exept.de>
parents: 407
diff changeset
  1723
    sz := lastIndex - firstIndex + 1.
984b32fe635a fixed makeRoomAtFront if underlying arrays size is <= 3
Claus Gittinger <cg@exept.de>
parents: 407
diff changeset
  1724
20341
72ed68b0d0ec little code cleanup
Claus Gittinger <cg@exept.de>
parents: 20026
diff changeset
  1725
    ((oldSize == 0) or:[sz == 0]) ifTrue:[
72ed68b0d0ec little code cleanup
Claus Gittinger <cg@exept.de>
parents: 20026
diff changeset
  1726
	contentsArray := Array basicNew:MinContentsArraySize.
72ed68b0d0ec little code cleanup
Claus Gittinger <cg@exept.de>
parents: 20026
diff changeset
  1727
	firstIndex := 2. lastIndex := 1.
72ed68b0d0ec little code cleanup
Claus Gittinger <cg@exept.de>
parents: 20026
diff changeset
  1728
	^ self
93
e31220cb391f *** empty log message ***
claus
parents: 88
diff changeset
  1729
    ].
e31220cb391f *** empty log message ***
claus
parents: 88
diff changeset
  1730
329
claus
parents: 293
diff changeset
  1731
    "
20341
72ed68b0d0ec little code cleanup
Claus Gittinger <cg@exept.de>
parents: 20026
diff changeset
  1732
     if there is lots of room at the end (> 50%),
329
claus
parents: 293
diff changeset
  1733
     shift instead of growing. This helps collections
claus
parents: 293
diff changeset
  1734
     which get elements removed at the end and added at front.
claus
parents: 293
diff changeset
  1735
    "
33
50cf0f6bc0ad *** empty log message ***
claus
parents: 13
diff changeset
  1736
    oldSize > (sz * 2) ifTrue:[
20341
72ed68b0d0ec little code cleanup
Claus Gittinger <cg@exept.de>
parents: 20026
diff changeset
  1737
	startIndex := oldSize // 4.
72ed68b0d0ec little code cleanup
Claus Gittinger <cg@exept.de>
parents: 20026
diff changeset
  1738
	startIndex > 1 ifTrue:[
72ed68b0d0ec little code cleanup
Claus Gittinger <cg@exept.de>
parents: 20026
diff changeset
  1739
	    contentsArray
72ed68b0d0ec little code cleanup
Claus Gittinger <cg@exept.de>
parents: 20026
diff changeset
  1740
		replaceFrom:startIndex to:(startIndex + sz - 1)
72ed68b0d0ec little code cleanup
Claus Gittinger <cg@exept.de>
parents: 20026
diff changeset
  1741
		with:contentsArray startingAt:1.
72ed68b0d0ec little code cleanup
Claus Gittinger <cg@exept.de>
parents: 20026
diff changeset
  1742
	    contentsArray from:1 to:(startIndex - 1) put:nil.
72ed68b0d0ec little code cleanup
Claus Gittinger <cg@exept.de>
parents: 20026
diff changeset
  1743
	    firstIndex := startIndex.
72ed68b0d0ec little code cleanup
Claus Gittinger <cg@exept.de>
parents: 20026
diff changeset
  1744
	    lastIndex := startIndex + sz - 1.
72ed68b0d0ec little code cleanup
Claus Gittinger <cg@exept.de>
parents: 20026
diff changeset
  1745
	    ^ self
72ed68b0d0ec little code cleanup
Claus Gittinger <cg@exept.de>
parents: 20026
diff changeset
  1746
	]
33
50cf0f6bc0ad *** empty log message ***
claus
parents: 13
diff changeset
  1747
    ].
2
claus
parents: 1
diff changeset
  1748
    newSize := oldSize * 2.
253
30daee717a53 *** empty log message ***
claus
parents: 229
diff changeset
  1749
    newContents := Array basicNew:newSize.
77
6c38ca59927f *** empty log message ***
claus
parents: 68
diff changeset
  1750
    newContents
20341
72ed68b0d0ec little code cleanup
Claus Gittinger <cg@exept.de>
parents: 20026
diff changeset
  1751
	replaceFrom:(oldSize + 1) to:newSize
72ed68b0d0ec little code cleanup
Claus Gittinger <cg@exept.de>
parents: 20026
diff changeset
  1752
	with:contentsArray startingAt:1.
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1753
    contentsArray := newContents.
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1754
    firstIndex := firstIndex + oldSize.
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1755
    lastIndex := lastIndex + oldSize
506
984b32fe635a fixed makeRoomAtFront if underlying arrays size is <= 3
Claus Gittinger <cg@exept.de>
parents: 407
diff changeset
  1756
11275
2883195d540e makeRoomAtIndex: there is no need to do an early reallocation
Claus Gittinger <cg@exept.de>
parents: 11271
diff changeset
  1757
    "Created: / 08-11-1995 / 12:47:49 / cg"
2883195d540e makeRoomAtIndex: there is no need to do an early reallocation
Claus Gittinger <cg@exept.de>
parents: 11271
diff changeset
  1758
    "Modified: / 22-10-2008 / 17:10:13 / cg"
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1759
!
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1760
1161
aad722dea51a return values compatible to ST-80; added comments; fixed & tuned #makeRoomAtIndex:
Claus Gittinger <cg@exept.de>
parents: 1157
diff changeset
  1761
makeRoomAtIndex:whereToMakeEmptySlot
20341
72ed68b0d0ec little code cleanup
Claus Gittinger <cg@exept.de>
parents: 20026
diff changeset
  1762
    "grow the contents for inserting at whereToMakeEmptySlot.
1161
aad722dea51a return values compatible to ST-80; added comments; fixed & tuned #makeRoomAtIndex:
Claus Gittinger <cg@exept.de>
parents: 1157
diff changeset
  1763
     The whereToMakeEmptySlot argument must be a physical index within the contentsArray.
aad722dea51a return values compatible to ST-80; added comments; fixed & tuned #makeRoomAtIndex:
Claus Gittinger <cg@exept.de>
parents: 1157
diff changeset
  1764
     If there is (plenty of) room at either end, elements are shifted inplace to create
aad722dea51a return values compatible to ST-80; added comments; fixed & tuned #makeRoomAtIndex:
Claus Gittinger <cg@exept.de>
parents: 1157
diff changeset
  1765
     an empty slot; otherwise, a new contentsArray is allocated.
aad722dea51a return values compatible to ST-80; added comments; fixed & tuned #makeRoomAtIndex:
Claus Gittinger <cg@exept.de>
parents: 1157
diff changeset
  1766
     Since this changes the logical size, the modified index is returned.
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1767
     i.e.
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1768
     #(1 2 3 4 5 6) asOrderedCollection makeRoomAtIndex:3 -> #(1 2 nil 3 4 5 6)
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1769
     #(1 2 3 4 5 6) asOrderedCollection makeRoomAtIndex:1 -> #(nil 1 2 3 4 5 6)
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1770
     #(1 2 3 4 5 6) asOrderedCollection makeRoomAtIndex:7 -> #(1 2 3 4 5 6 nil)"
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1771
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1772
    |newContents
20341
72ed68b0d0ec little code cleanup
Claus Gittinger <cg@exept.de>
parents: 20026
diff changeset
  1773
     newSize         "{ Class:SmallInteger }"
72ed68b0d0ec little code cleanup
Claus Gittinger <cg@exept.de>
parents: 20026
diff changeset
  1774
     oldSize         "{ Class:SmallInteger }"
1161
aad722dea51a return values compatible to ST-80; added comments; fixed & tuned #makeRoomAtIndex:
Claus Gittinger <cg@exept.de>
parents: 1157
diff changeset
  1775
     first           "{ Class:SmallInteger }"
aad722dea51a return values compatible to ST-80; added comments; fixed & tuned #makeRoomAtIndex:
Claus Gittinger <cg@exept.de>
parents: 1157
diff changeset
  1776
     last            "{ Class:SmallInteger }"
aad722dea51a return values compatible to ST-80; added comments; fixed & tuned #makeRoomAtIndex:
Claus Gittinger <cg@exept.de>
parents: 1157
diff changeset
  1777
     index           "{ Class:SmallInteger }"
aad722dea51a return values compatible to ST-80; added comments; fixed & tuned #makeRoomAtIndex:
Claus Gittinger <cg@exept.de>
parents: 1157
diff changeset
  1778
     shiftLeft shiftRight|
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1779
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1780
    oldSize := contentsArray size.
1161
aad722dea51a return values compatible to ST-80; added comments; fixed & tuned #makeRoomAtIndex:
Claus Gittinger <cg@exept.de>
parents: 1157
diff changeset
  1781
    index := whereToMakeEmptySlot.
aad722dea51a return values compatible to ST-80; added comments; fixed & tuned #makeRoomAtIndex:
Claus Gittinger <cg@exept.de>
parents: 1157
diff changeset
  1782
    first := firstIndex.
aad722dea51a return values compatible to ST-80; added comments; fixed & tuned #makeRoomAtIndex:
Claus Gittinger <cg@exept.de>
parents: 1157
diff changeset
  1783
    last := lastIndex.
aad722dea51a return values compatible to ST-80; added comments; fixed & tuned #makeRoomAtIndex:
Claus Gittinger <cg@exept.de>
parents: 1157
diff changeset
  1784
19791
610d2bf9af00 #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 19098
diff changeset
  1785
    (first > 1) ifTrue:[
20341
72ed68b0d0ec little code cleanup
Claus Gittinger <cg@exept.de>
parents: 20026
diff changeset
  1786
	"there is room at the beginning"
1161
aad722dea51a return values compatible to ST-80; added comments; fixed & tuned #makeRoomAtIndex:
Claus Gittinger <cg@exept.de>
parents: 1157
diff changeset
  1787
20341
72ed68b0d0ec little code cleanup
Claus Gittinger <cg@exept.de>
parents: 20026
diff changeset
  1788
	shiftLeft := true.
33
50cf0f6bc0ad *** empty log message ***
claus
parents: 13
diff changeset
  1789
20341
72ed68b0d0ec little code cleanup
Claus Gittinger <cg@exept.de>
parents: 20026
diff changeset
  1790
	index == first ifFalse:[
72ed68b0d0ec little code cleanup
Claus Gittinger <cg@exept.de>
parents: 20026
diff changeset
  1791
	    "/ so, we'd have to copy all elements before that index
72ed68b0d0ec little code cleanup
Claus Gittinger <cg@exept.de>
parents: 20026
diff changeset
  1792
	    "/ one slot towards the containers beginning ...
72ed68b0d0ec little code cleanup
Claus Gittinger <cg@exept.de>
parents: 20026
diff changeset
  1793
	    "/ if there is also space at the end, AND the number of
72ed68b0d0ec little code cleanup
Claus Gittinger <cg@exept.de>
parents: 20026
diff changeset
  1794
	    "/ elements after the index is smaller than the number before,
72ed68b0d0ec little code cleanup
Claus Gittinger <cg@exept.de>
parents: 20026
diff changeset
  1795
	    "/ copy the remaining elements. To copy the least possible number.
1161
aad722dea51a return values compatible to ST-80; added comments; fixed & tuned #makeRoomAtIndex:
Claus Gittinger <cg@exept.de>
parents: 1157
diff changeset
  1796
20341
72ed68b0d0ec little code cleanup
Claus Gittinger <cg@exept.de>
parents: 20026
diff changeset
  1797
	    (last - index) < (index - first) ifTrue:[
72ed68b0d0ec little code cleanup
Claus Gittinger <cg@exept.de>
parents: 20026
diff changeset
  1798
		last < oldSize ifTrue:[
72ed68b0d0ec little code cleanup
Claus Gittinger <cg@exept.de>
parents: 20026
diff changeset
  1799
		    shiftLeft := false.
72ed68b0d0ec little code cleanup
Claus Gittinger <cg@exept.de>
parents: 20026
diff changeset
  1800
		    shiftRight := true.
72ed68b0d0ec little code cleanup
Claus Gittinger <cg@exept.de>
parents: 20026
diff changeset
  1801
		]
72ed68b0d0ec little code cleanup
Claus Gittinger <cg@exept.de>
parents: 20026
diff changeset
  1802
	    ]
72ed68b0d0ec little code cleanup
Claus Gittinger <cg@exept.de>
parents: 20026
diff changeset
  1803
	]
1161
aad722dea51a return values compatible to ST-80; added comments; fixed & tuned #makeRoomAtIndex:
Claus Gittinger <cg@exept.de>
parents: 1157
diff changeset
  1804
    ] ifFalse:[
20341
72ed68b0d0ec little code cleanup
Claus Gittinger <cg@exept.de>
parents: 20026
diff changeset
  1805
	last < oldSize ifTrue:[
72ed68b0d0ec little code cleanup
Claus Gittinger <cg@exept.de>
parents: 20026
diff changeset
  1806
	    shiftRight := true
72ed68b0d0ec little code cleanup
Claus Gittinger <cg@exept.de>
parents: 20026
diff changeset
  1807
	]
33
50cf0f6bc0ad *** empty log message ***
claus
parents: 13
diff changeset
  1808
    ].
1161
aad722dea51a return values compatible to ST-80; added comments; fixed & tuned #makeRoomAtIndex:
Claus Gittinger <cg@exept.de>
parents: 1157
diff changeset
  1809
aad722dea51a return values compatible to ST-80; added comments; fixed & tuned #makeRoomAtIndex:
Claus Gittinger <cg@exept.de>
parents: 1157
diff changeset
  1810
    shiftLeft == true ifTrue:[
20341
72ed68b0d0ec little code cleanup
Claus Gittinger <cg@exept.de>
parents: 20026
diff changeset
  1811
	"there is room at the beginning"
33
50cf0f6bc0ad *** empty log message ***
claus
parents: 13
diff changeset
  1812
20341
72ed68b0d0ec little code cleanup
Claus Gittinger <cg@exept.de>
parents: 20026
diff changeset
  1813
	index == first ifFalse:[
72ed68b0d0ec little code cleanup
Claus Gittinger <cg@exept.de>
parents: 20026
diff changeset
  1814
	    contentsArray
72ed68b0d0ec little code cleanup
Claus Gittinger <cg@exept.de>
parents: 20026
diff changeset
  1815
		replaceFrom:(first - 1) to:(index - 2)
72ed68b0d0ec little code cleanup
Claus Gittinger <cg@exept.de>
parents: 20026
diff changeset
  1816
		with:contentsArray startingAt:first.
72ed68b0d0ec little code cleanup
Claus Gittinger <cg@exept.de>
parents: 20026
diff changeset
  1817
	    contentsArray at:index-1 put:nil.
72ed68b0d0ec little code cleanup
Claus Gittinger <cg@exept.de>
parents: 20026
diff changeset
  1818
	].
72ed68b0d0ec little code cleanup
Claus Gittinger <cg@exept.de>
parents: 20026
diff changeset
  1819
	firstIndex := first - 1.
72ed68b0d0ec little code cleanup
Claus Gittinger <cg@exept.de>
parents: 20026
diff changeset
  1820
	^ index - 1
1161
aad722dea51a return values compatible to ST-80; added comments; fixed & tuned #makeRoomAtIndex:
Claus Gittinger <cg@exept.de>
parents: 1157
diff changeset
  1821
    ].
aad722dea51a return values compatible to ST-80; added comments; fixed & tuned #makeRoomAtIndex:
Claus Gittinger <cg@exept.de>
parents: 1157
diff changeset
  1822
aad722dea51a return values compatible to ST-80; added comments; fixed & tuned #makeRoomAtIndex:
Claus Gittinger <cg@exept.de>
parents: 1157
diff changeset
  1823
    shiftRight == true ifTrue:[
20341
72ed68b0d0ec little code cleanup
Claus Gittinger <cg@exept.de>
parents: 20026
diff changeset
  1824
	"there is room at the end"
1161
aad722dea51a return values compatible to ST-80; added comments; fixed & tuned #makeRoomAtIndex:
Claus Gittinger <cg@exept.de>
parents: 1157
diff changeset
  1825
20341
72ed68b0d0ec little code cleanup
Claus Gittinger <cg@exept.de>
parents: 20026
diff changeset
  1826
	last := last + 1.
72ed68b0d0ec little code cleanup
Claus Gittinger <cg@exept.de>
parents: 20026
diff changeset
  1827
	index == last ifFalse:[
72ed68b0d0ec little code cleanup
Claus Gittinger <cg@exept.de>
parents: 20026
diff changeset
  1828
	    contentsArray
72ed68b0d0ec little code cleanup
Claus Gittinger <cg@exept.de>
parents: 20026
diff changeset
  1829
		replaceFrom:(index + 1) to:last
72ed68b0d0ec little code cleanup
Claus Gittinger <cg@exept.de>
parents: 20026
diff changeset
  1830
		with:contentsArray startingAt:index.
72ed68b0d0ec little code cleanup
Claus Gittinger <cg@exept.de>
parents: 20026
diff changeset
  1831
	    contentsArray at:index put:nil
72ed68b0d0ec little code cleanup
Claus Gittinger <cg@exept.de>
parents: 20026
diff changeset
  1832
	].
72ed68b0d0ec little code cleanup
Claus Gittinger <cg@exept.de>
parents: 20026
diff changeset
  1833
	lastIndex := last.
72ed68b0d0ec little code cleanup
Claus Gittinger <cg@exept.de>
parents: 20026
diff changeset
  1834
	^ index
33
50cf0f6bc0ad *** empty log message ***
claus
parents: 13
diff changeset
  1835
    ].
50cf0f6bc0ad *** empty log message ***
claus
parents: 13
diff changeset
  1836
19791
610d2bf9af00 #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 19098
diff changeset
  1837
    "/ no space at either end
610d2bf9af00 #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 19098
diff changeset
  1838
    oldSize < MinContentsArraySize ifTrue:[
20341
72ed68b0d0ec little code cleanup
Claus Gittinger <cg@exept.de>
parents: 20026
diff changeset
  1839
	newSize := MinContentsArraySize
18879
5d1bbfc1761d #FEATURE
Stefan Vogel <sv@exept.de>
parents: 18811
diff changeset
  1840
    ] ifFalse:[
20341
72ed68b0d0ec little code cleanup
Claus Gittinger <cg@exept.de>
parents: 20026
diff changeset
  1841
	newSize := oldSize * 2.
18879
5d1bbfc1761d #FEATURE
Stefan Vogel <sv@exept.de>
parents: 18811
diff changeset
  1842
    ].
253
30daee717a53 *** empty log message ***
claus
parents: 229
diff changeset
  1843
    newContents := Array basicNew:newSize.
11271
5b75b4a7fb35 tuned makeRoomAtIndex:
Claus Gittinger <cg@exept.de>
parents: 11269
diff changeset
  1844
    index == first ifTrue:[
20341
72ed68b0d0ec little code cleanup
Claus Gittinger <cg@exept.de>
parents: 20026
diff changeset
  1845
	"/ if there is a lot at the end (> 50), make all new space at the beginning.
72ed68b0d0ec little code cleanup
Claus Gittinger <cg@exept.de>
parents: 20026
diff changeset
  1846
	"/ otherwise make 3/4 of the new space to the beginning, 1/4 to the end
72ed68b0d0ec little code cleanup
Claus Gittinger <cg@exept.de>
parents: 20026
diff changeset
  1847
	oldSize ~~ 0 ifTrue:[
72ed68b0d0ec little code cleanup
Claus Gittinger <cg@exept.de>
parents: 20026
diff changeset
  1848
	    (last < (oldSize - 50)) ifTrue:[
72ed68b0d0ec little code cleanup
Claus Gittinger <cg@exept.de>
parents: 20026
diff changeset
  1849
		lastIndex := newSize - (oldSize-last).
72ed68b0d0ec little code cleanup
Claus Gittinger <cg@exept.de>
parents: 20026
diff changeset
  1850
		firstIndex := lastIndex - (last - first).
72ed68b0d0ec little code cleanup
Claus Gittinger <cg@exept.de>
parents: 20026
diff changeset
  1851
	    ] ifFalse:[
72ed68b0d0ec little code cleanup
Claus Gittinger <cg@exept.de>
parents: 20026
diff changeset
  1852
		firstIndex := oldSize * 3 // 4.
72ed68b0d0ec little code cleanup
Claus Gittinger <cg@exept.de>
parents: 20026
diff changeset
  1853
		firstIndex < 2 ifTrue:[firstIndex := 2]. "/ pathological case (was explicitly allocated with size<MinSize
72ed68b0d0ec little code cleanup
Claus Gittinger <cg@exept.de>
parents: 20026
diff changeset
  1854
		lastIndex := firstIndex + (last - first).
72ed68b0d0ec little code cleanup
Claus Gittinger <cg@exept.de>
parents: 20026
diff changeset
  1855
	    ].
72ed68b0d0ec little code cleanup
Claus Gittinger <cg@exept.de>
parents: 20026
diff changeset
  1856
	    newContents
72ed68b0d0ec little code cleanup
Claus Gittinger <cg@exept.de>
parents: 20026
diff changeset
  1857
		replaceFrom:firstIndex to:lastIndex
72ed68b0d0ec little code cleanup
Claus Gittinger <cg@exept.de>
parents: 20026
diff changeset
  1858
		with:contentsArray startingAt:first.
72ed68b0d0ec little code cleanup
Claus Gittinger <cg@exept.de>
parents: 20026
diff changeset
  1859
	].
72ed68b0d0ec little code cleanup
Claus Gittinger <cg@exept.de>
parents: 20026
diff changeset
  1860
	contentsArray := newContents.
72ed68b0d0ec little code cleanup
Claus Gittinger <cg@exept.de>
parents: 20026
diff changeset
  1861
	firstIndex := firstIndex - 1.
11271
5b75b4a7fb35 tuned makeRoomAtIndex:
Claus Gittinger <cg@exept.de>
parents: 11269
diff changeset
  1862
20341
72ed68b0d0ec little code cleanup
Claus Gittinger <cg@exept.de>
parents: 20026
diff changeset
  1863
	^ firstIndex.
11271
5b75b4a7fb35 tuned makeRoomAtIndex:
Claus Gittinger <cg@exept.de>
parents: 11269
diff changeset
  1864
    ] ifFalse:[
20341
72ed68b0d0ec little code cleanup
Claus Gittinger <cg@exept.de>
parents: 20026
diff changeset
  1865
	oldSize ~~ 0 ifTrue:[
72ed68b0d0ec little code cleanup
Claus Gittinger <cg@exept.de>
parents: 20026
diff changeset
  1866
	    newContents
72ed68b0d0ec little code cleanup
Claus Gittinger <cg@exept.de>
parents: 20026
diff changeset
  1867
		replaceFrom:1 to:(index - first)
72ed68b0d0ec little code cleanup
Claus Gittinger <cg@exept.de>
parents: 20026
diff changeset
  1868
		with:contentsArray startingAt:first.
11271
5b75b4a7fb35 tuned makeRoomAtIndex:
Claus Gittinger <cg@exept.de>
parents: 11269
diff changeset
  1869
20341
72ed68b0d0ec little code cleanup
Claus Gittinger <cg@exept.de>
parents: 20026
diff changeset
  1870
	    index <= last ifTrue:[
72ed68b0d0ec little code cleanup
Claus Gittinger <cg@exept.de>
parents: 20026
diff changeset
  1871
		newContents
72ed68b0d0ec little code cleanup
Claus Gittinger <cg@exept.de>
parents: 20026
diff changeset
  1872
		    replaceFrom:(index - first + 2) to:(last - first + 2)
72ed68b0d0ec little code cleanup
Claus Gittinger <cg@exept.de>
parents: 20026
diff changeset
  1873
		    with:contentsArray startingAt:index.
72ed68b0d0ec little code cleanup
Claus Gittinger <cg@exept.de>
parents: 20026
diff changeset
  1874
	    ].
72ed68b0d0ec little code cleanup
Claus Gittinger <cg@exept.de>
parents: 20026
diff changeset
  1875
	].
72ed68b0d0ec little code cleanup
Claus Gittinger <cg@exept.de>
parents: 20026
diff changeset
  1876
	contentsArray := newContents.
72ed68b0d0ec little code cleanup
Claus Gittinger <cg@exept.de>
parents: 20026
diff changeset
  1877
	firstIndex := 1.
72ed68b0d0ec little code cleanup
Claus Gittinger <cg@exept.de>
parents: 20026
diff changeset
  1878
	lastIndex := last - first + 2.
11271
5b75b4a7fb35 tuned makeRoomAtIndex:
Claus Gittinger <cg@exept.de>
parents: 11269
diff changeset
  1879
20341
72ed68b0d0ec little code cleanup
Claus Gittinger <cg@exept.de>
parents: 20026
diff changeset
  1880
	"/ return the modified index
72ed68b0d0ec little code cleanup
Claus Gittinger <cg@exept.de>
parents: 20026
diff changeset
  1881
	^ index - (first - firstIndex).
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1882
    ].
1161
aad722dea51a return values compatible to ST-80; added comments; fixed & tuned #makeRoomAtIndex:
Claus Gittinger <cg@exept.de>
parents: 1157
diff changeset
  1883
11275
2883195d540e makeRoomAtIndex: there is no need to do an early reallocation
Claus Gittinger <cg@exept.de>
parents: 11271
diff changeset
  1884
    "Modified: / 22-10-2008 / 17:11:06 / cg"
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1885
!
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1886
2222
e6fa084818ec added #addAll:beforeIndex:
Claus Gittinger <cg@exept.de>
parents: 2166
diff changeset
  1887
makeRoomAtIndex:whereToMakeEmptySlots for:howMany
20341
72ed68b0d0ec little code cleanup
Claus Gittinger <cg@exept.de>
parents: 20026
diff changeset
  1888
    "grow the contents for inserting at whereToMakeEmptySlot.
2222
e6fa084818ec added #addAll:beforeIndex:
Claus Gittinger <cg@exept.de>
parents: 2166
diff changeset
  1889
     The whereToMakeEmptySlot argument must be a physical index within the contentsArray.
e6fa084818ec added #addAll:beforeIndex:
Claus Gittinger <cg@exept.de>
parents: 2166
diff changeset
  1890
     If there is (plenty of) room at either end, elements are shifted inplace to create
e6fa084818ec added #addAll:beforeIndex:
Claus Gittinger <cg@exept.de>
parents: 2166
diff changeset
  1891
     an empty slot; otherwise, a new contentsArray is allocated.
e6fa084818ec added #addAll:beforeIndex:
Claus Gittinger <cg@exept.de>
parents: 2166
diff changeset
  1892
     Since this changes the logical size, the modified index is returned.
e6fa084818ec added #addAll:beforeIndex:
Claus Gittinger <cg@exept.de>
parents: 2166
diff changeset
  1893
     i.e.
e6fa084818ec added #addAll:beforeIndex:
Claus Gittinger <cg@exept.de>
parents: 2166
diff changeset
  1894
     #(1 2 3 4 5 6) asOrderedCollection makeRoomAtIndex:3 for:2 -> #(1 2 nil nil 3 4 5 6)
e6fa084818ec added #addAll:beforeIndex:
Claus Gittinger <cg@exept.de>
parents: 2166
diff changeset
  1895
     #(1 2 3 4 5 6) asOrderedCollection makeRoomAtIndex:1 for:2 -> #(nil nil 1 2 3 4 5 6)
e6fa084818ec added #addAll:beforeIndex:
Claus Gittinger <cg@exept.de>
parents: 2166
diff changeset
  1896
     #(1 2 3 4 5 6) asOrderedCollection makeRoomAtIndex:7 for:2 -> #(1 2 3 4 5 6 nil nil)"
e6fa084818ec added #addAll:beforeIndex:
Claus Gittinger <cg@exept.de>
parents: 2166
diff changeset
  1897
e6fa084818ec added #addAll:beforeIndex:
Claus Gittinger <cg@exept.de>
parents: 2166
diff changeset
  1898
    |newContents
20341
72ed68b0d0ec little code cleanup
Claus Gittinger <cg@exept.de>
parents: 20026
diff changeset
  1899
     newSize         "{ Class:SmallInteger }"
72ed68b0d0ec little code cleanup
Claus Gittinger <cg@exept.de>
parents: 20026
diff changeset
  1900
     oldSize         "{ Class:SmallInteger }"
2222
e6fa084818ec added #addAll:beforeIndex:
Claus Gittinger <cg@exept.de>
parents: 2166
diff changeset
  1901
     oneFourthOfSize "{ Class:SmallInteger }"
e6fa084818ec added #addAll:beforeIndex:
Claus Gittinger <cg@exept.de>
parents: 2166
diff changeset
  1902
     first           "{ Class:SmallInteger }"
e6fa084818ec added #addAll:beforeIndex:
Claus Gittinger <cg@exept.de>
parents: 2166
diff changeset
  1903
     last            "{ Class:SmallInteger }"
e6fa084818ec added #addAll:beforeIndex:
Claus Gittinger <cg@exept.de>
parents: 2166
diff changeset
  1904
     index           "{ Class:SmallInteger }"
e6fa084818ec added #addAll:beforeIndex:
Claus Gittinger <cg@exept.de>
parents: 2166
diff changeset
  1905
     shiftLeft shiftRight|
e6fa084818ec added #addAll:beforeIndex:
Claus Gittinger <cg@exept.de>
parents: 2166
diff changeset
  1906
e6fa084818ec added #addAll:beforeIndex:
Claus Gittinger <cg@exept.de>
parents: 2166
diff changeset
  1907
    oldSize := contentsArray size.
19792
4625cef49989 #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 19791
diff changeset
  1908
    oneFourthOfSize := (oldSize // 4).
4625cef49989 #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 19791
diff changeset
  1909
    oneFourthOfSize == 0 ifTrue:[oneFourthOfSize := 1].
2222
e6fa084818ec added #addAll:beforeIndex:
Claus Gittinger <cg@exept.de>
parents: 2166
diff changeset
  1910
    index := whereToMakeEmptySlots.
e6fa084818ec added #addAll:beforeIndex:
Claus Gittinger <cg@exept.de>
parents: 2166
diff changeset
  1911
    first := firstIndex.
e6fa084818ec added #addAll:beforeIndex:
Claus Gittinger <cg@exept.de>
parents: 2166
diff changeset
  1912
    last := lastIndex.
e6fa084818ec added #addAll:beforeIndex:
Claus Gittinger <cg@exept.de>
parents: 2166
diff changeset
  1913
2549
9ca8a3fcdaa7 fixed #addAll:beforeIndex:
Claus Gittinger <cg@exept.de>
parents: 2364
diff changeset
  1914
    shiftLeft := shiftRight := false.
2222
e6fa084818ec added #addAll:beforeIndex:
Claus Gittinger <cg@exept.de>
parents: 2166
diff changeset
  1915
    ((first > howMany) and:[first > oneFourthOfSize]) ifTrue:[
20341
72ed68b0d0ec little code cleanup
Claus Gittinger <cg@exept.de>
parents: 20026
diff changeset
  1916
	"there is room (>25%) at the beginning"
72ed68b0d0ec little code cleanup
Claus Gittinger <cg@exept.de>
parents: 20026
diff changeset
  1917
	shiftLeft := true.
2222
e6fa084818ec added #addAll:beforeIndex:
Claus Gittinger <cg@exept.de>
parents: 2166
diff changeset
  1918
    ] ifFalse:[
20341
72ed68b0d0ec little code cleanup
Claus Gittinger <cg@exept.de>
parents: 20026
diff changeset
  1919
	((last + howMany) <= oldSize
72ed68b0d0ec little code cleanup
Claus Gittinger <cg@exept.de>
parents: 20026
diff changeset
  1920
	and:[last < (oneFourthOfSize * 3)]) ifTrue:[
72ed68b0d0ec little code cleanup
Claus Gittinger <cg@exept.de>
parents: 20026
diff changeset
  1921
	    shiftRight := true
72ed68b0d0ec little code cleanup
Claus Gittinger <cg@exept.de>
parents: 20026
diff changeset
  1922
	]
2222
e6fa084818ec added #addAll:beforeIndex:
Claus Gittinger <cg@exept.de>
parents: 2166
diff changeset
  1923
    ].
e6fa084818ec added #addAll:beforeIndex:
Claus Gittinger <cg@exept.de>
parents: 2166
diff changeset
  1924
e6fa084818ec added #addAll:beforeIndex:
Claus Gittinger <cg@exept.de>
parents: 2166
diff changeset
  1925
    shiftLeft == true ifTrue:[
20341
72ed68b0d0ec little code cleanup
Claus Gittinger <cg@exept.de>
parents: 20026
diff changeset
  1926
	"there is room at the beginning"
2222
e6fa084818ec added #addAll:beforeIndex:
Claus Gittinger <cg@exept.de>
parents: 2166
diff changeset
  1927
20341
72ed68b0d0ec little code cleanup
Claus Gittinger <cg@exept.de>
parents: 20026
diff changeset
  1928
	index == first ifFalse:[
72ed68b0d0ec little code cleanup
Claus Gittinger <cg@exept.de>
parents: 20026
diff changeset
  1929
	    contentsArray
72ed68b0d0ec little code cleanup
Claus Gittinger <cg@exept.de>
parents: 20026
diff changeset
  1930
		replaceFrom:(first - howMany)
72ed68b0d0ec little code cleanup
Claus Gittinger <cg@exept.de>
parents: 20026
diff changeset
  1931
		to:(index - howMany - 1)
72ed68b0d0ec little code cleanup
Claus Gittinger <cg@exept.de>
parents: 20026
diff changeset
  1932
		with:contentsArray
72ed68b0d0ec little code cleanup
Claus Gittinger <cg@exept.de>
parents: 20026
diff changeset
  1933
		startingAt:first.
72ed68b0d0ec little code cleanup
Claus Gittinger <cg@exept.de>
parents: 20026
diff changeset
  1934
	    contentsArray from:index-howMany to:index-1 put:nil.
72ed68b0d0ec little code cleanup
Claus Gittinger <cg@exept.de>
parents: 20026
diff changeset
  1935
	].
72ed68b0d0ec little code cleanup
Claus Gittinger <cg@exept.de>
parents: 20026
diff changeset
  1936
	firstIndex := first - howMany.
72ed68b0d0ec little code cleanup
Claus Gittinger <cg@exept.de>
parents: 20026
diff changeset
  1937
	^ index - howMany
2222
e6fa084818ec added #addAll:beforeIndex:
Claus Gittinger <cg@exept.de>
parents: 2166
diff changeset
  1938
    ].
e6fa084818ec added #addAll:beforeIndex:
Claus Gittinger <cg@exept.de>
parents: 2166
diff changeset
  1939
e6fa084818ec added #addAll:beforeIndex:
Claus Gittinger <cg@exept.de>
parents: 2166
diff changeset
  1940
    shiftRight == true ifTrue:[
20341
72ed68b0d0ec little code cleanup
Claus Gittinger <cg@exept.de>
parents: 20026
diff changeset
  1941
	"there is room at the end"
2222
e6fa084818ec added #addAll:beforeIndex:
Claus Gittinger <cg@exept.de>
parents: 2166
diff changeset
  1942
20341
72ed68b0d0ec little code cleanup
Claus Gittinger <cg@exept.de>
parents: 20026
diff changeset
  1943
	last := last + howMany.
72ed68b0d0ec little code cleanup
Claus Gittinger <cg@exept.de>
parents: 20026
diff changeset
  1944
	index == last ifFalse:[
72ed68b0d0ec little code cleanup
Claus Gittinger <cg@exept.de>
parents: 20026
diff changeset
  1945
	    contentsArray
72ed68b0d0ec little code cleanup
Claus Gittinger <cg@exept.de>
parents: 20026
diff changeset
  1946
		replaceFrom:(index + howMany)
72ed68b0d0ec little code cleanup
Claus Gittinger <cg@exept.de>
parents: 20026
diff changeset
  1947
		to:last
72ed68b0d0ec little code cleanup
Claus Gittinger <cg@exept.de>
parents: 20026
diff changeset
  1948
		with:contentsArray
72ed68b0d0ec little code cleanup
Claus Gittinger <cg@exept.de>
parents: 20026
diff changeset
  1949
		startingAt:index.
72ed68b0d0ec little code cleanup
Claus Gittinger <cg@exept.de>
parents: 20026
diff changeset
  1950
	    contentsArray from:index to:index+howMany-1 put:nil
72ed68b0d0ec little code cleanup
Claus Gittinger <cg@exept.de>
parents: 20026
diff changeset
  1951
	].
72ed68b0d0ec little code cleanup
Claus Gittinger <cg@exept.de>
parents: 20026
diff changeset
  1952
	lastIndex := last.
72ed68b0d0ec little code cleanup
Claus Gittinger <cg@exept.de>
parents: 20026
diff changeset
  1953
	^ index
2222
e6fa084818ec added #addAll:beforeIndex:
Claus Gittinger <cg@exept.de>
parents: 2166
diff changeset
  1954
    ].
20341
72ed68b0d0ec little code cleanup
Claus Gittinger <cg@exept.de>
parents: 20026
diff changeset
  1955
72ed68b0d0ec little code cleanup
Claus Gittinger <cg@exept.de>
parents: 20026
diff changeset
  1956
    newSize := (oldSize+howMany) nextPowerOf2.
72ed68b0d0ec little code cleanup
Claus Gittinger <cg@exept.de>
parents: 20026
diff changeset
  1957
    "/ newSize := (oldSize * 2).
72ed68b0d0ec little code cleanup
Claus Gittinger <cg@exept.de>
parents: 20026
diff changeset
  1958
    "/ [newSize < (oldSize+howMany)] whileTrue:[
72ed68b0d0ec little code cleanup
Claus Gittinger <cg@exept.de>
parents: 20026
diff changeset
  1959
    "/    newSize := (newSize * 2) max:howMany
72ed68b0d0ec little code cleanup
Claus Gittinger <cg@exept.de>
parents: 20026
diff changeset
  1960
    "/ ].
2222
e6fa084818ec added #addAll:beforeIndex:
Claus Gittinger <cg@exept.de>
parents: 2166
diff changeset
  1961
e6fa084818ec added #addAll:beforeIndex:
Claus Gittinger <cg@exept.de>
parents: 2166
diff changeset
  1962
    newContents := Array basicNew:newSize.
18879
5d1bbfc1761d #FEATURE
Stefan Vogel <sv@exept.de>
parents: 18811
diff changeset
  1963
    oldSize ~~ 0 ifTrue:[
20341
72ed68b0d0ec little code cleanup
Claus Gittinger <cg@exept.de>
parents: 20026
diff changeset
  1964
	index > first ifTrue:[
72ed68b0d0ec little code cleanup
Claus Gittinger <cg@exept.de>
parents: 20026
diff changeset
  1965
	    newContents
72ed68b0d0ec little code cleanup
Claus Gittinger <cg@exept.de>
parents: 20026
diff changeset
  1966
		replaceFrom:1
72ed68b0d0ec little code cleanup
Claus Gittinger <cg@exept.de>
parents: 20026
diff changeset
  1967
		to:(index - first)
72ed68b0d0ec little code cleanup
Claus Gittinger <cg@exept.de>
parents: 20026
diff changeset
  1968
		with:contentsArray
72ed68b0d0ec little code cleanup
Claus Gittinger <cg@exept.de>
parents: 20026
diff changeset
  1969
		startingAt:first.
72ed68b0d0ec little code cleanup
Claus Gittinger <cg@exept.de>
parents: 20026
diff changeset
  1970
	].
72ed68b0d0ec little code cleanup
Claus Gittinger <cg@exept.de>
parents: 20026
diff changeset
  1971
	index <= last ifTrue:[
72ed68b0d0ec little code cleanup
Claus Gittinger <cg@exept.de>
parents: 20026
diff changeset
  1972
	    newContents
72ed68b0d0ec little code cleanup
Claus Gittinger <cg@exept.de>
parents: 20026
diff changeset
  1973
		replaceFrom:(index - first + howMany + 1)
72ed68b0d0ec little code cleanup
Claus Gittinger <cg@exept.de>
parents: 20026
diff changeset
  1974
		to:(last - first + howMany + 1)
72ed68b0d0ec little code cleanup
Claus Gittinger <cg@exept.de>
parents: 20026
diff changeset
  1975
		with:contentsArray
72ed68b0d0ec little code cleanup
Claus Gittinger <cg@exept.de>
parents: 20026
diff changeset
  1976
		startingAt:(index).
72ed68b0d0ec little code cleanup
Claus Gittinger <cg@exept.de>
parents: 20026
diff changeset
  1977
	].
2222
e6fa084818ec added #addAll:beforeIndex:
Claus Gittinger <cg@exept.de>
parents: 2166
diff changeset
  1978
    ].
e6fa084818ec added #addAll:beforeIndex:
Claus Gittinger <cg@exept.de>
parents: 2166
diff changeset
  1979
    contentsArray := newContents.
e6fa084818ec added #addAll:beforeIndex:
Claus Gittinger <cg@exept.de>
parents: 2166
diff changeset
  1980
    firstIndex := 1.
e6fa084818ec added #addAll:beforeIndex:
Claus Gittinger <cg@exept.de>
parents: 2166
diff changeset
  1981
    lastIndex := last - first + howMany + 1.
e6fa084818ec added #addAll:beforeIndex:
Claus Gittinger <cg@exept.de>
parents: 2166
diff changeset
  1982
e6fa084818ec added #addAll:beforeIndex:
Claus Gittinger <cg@exept.de>
parents: 2166
diff changeset
  1983
    "/ return the modified index
e6fa084818ec added #addAll:beforeIndex:
Claus Gittinger <cg@exept.de>
parents: 2166
diff changeset
  1984
    ^ index - (first - firstIndex).
e6fa084818ec added #addAll:beforeIndex:
Claus Gittinger <cg@exept.de>
parents: 2166
diff changeset
  1985
2549
9ca8a3fcdaa7 fixed #addAll:beforeIndex:
Claus Gittinger <cg@exept.de>
parents: 2364
diff changeset
  1986
    "Modified: 15.4.1997 / 12:34:16 / cg"
2222
e6fa084818ec added #addAll:beforeIndex:
Claus Gittinger <cg@exept.de>
parents: 2166
diff changeset
  1987
!
e6fa084818ec added #addAll:beforeIndex:
Claus Gittinger <cg@exept.de>
parents: 2166
diff changeset
  1988
606
7a9ab63a6757 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1989
makeRoomAtLast
7a9ab63a6757 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1990
    "grow/shift the contents for more room at the end.
7a9ab63a6757 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1991
     Does not change the logical size.
7a9ab63a6757 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1992
     i.e.
7a9ab63a6757 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1993
     #(1 2 3 4 5 6) -> #(1 2 3 4 5 6 nil)"
7a9ab63a6757 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1994
20341
72ed68b0d0ec little code cleanup
Claus Gittinger <cg@exept.de>
parents: 20026
diff changeset
  1995
    |newContents
606
7a9ab63a6757 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1996
     oldSize    "{ Class:SmallInteger }"
20341
72ed68b0d0ec little code cleanup
Claus Gittinger <cg@exept.de>
parents: 20026
diff changeset
  1997
     newSize    "{ Class:SmallInteger }"
606
7a9ab63a6757 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1998
     startIndex "{ Class:SmallInteger }"
7a9ab63a6757 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1999
     sz         "{ Class:SmallInteger }"|
7a9ab63a6757 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  2000
7a9ab63a6757 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  2001
    oldSize := contentsArray size.
7a9ab63a6757 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  2002
    sz := lastIndex - firstIndex + 1.
7a9ab63a6757 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  2003
7a9ab63a6757 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  2004
    "
20341
72ed68b0d0ec little code cleanup
Claus Gittinger <cg@exept.de>
parents: 20026
diff changeset
  2005
     if there is lots of room at the beginning (> 50%),
606
7a9ab63a6757 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  2006
     shift instead of growing. This helps collections which get
7a9ab63a6757 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  2007
     elements removed at front and added at the end.
7a9ab63a6757 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  2008
    "
7a9ab63a6757 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  2009
    oldSize > (sz * 2) ifTrue:[
20341
72ed68b0d0ec little code cleanup
Claus Gittinger <cg@exept.de>
parents: 20026
diff changeset
  2010
	startIndex := firstIndex // 4.
72ed68b0d0ec little code cleanup
Claus Gittinger <cg@exept.de>
parents: 20026
diff changeset
  2011
	startIndex == 0 ifTrue:[
72ed68b0d0ec little code cleanup
Claus Gittinger <cg@exept.de>
parents: 20026
diff changeset
  2012
	    startIndex := 1
72ed68b0d0ec little code cleanup
Claus Gittinger <cg@exept.de>
parents: 20026
diff changeset
  2013
	].
72ed68b0d0ec little code cleanup
Claus Gittinger <cg@exept.de>
parents: 20026
diff changeset
  2014
	contentsArray
72ed68b0d0ec little code cleanup
Claus Gittinger <cg@exept.de>
parents: 20026
diff changeset
  2015
	    replaceFrom:startIndex to:startIndex + sz - 1
72ed68b0d0ec little code cleanup
Claus Gittinger <cg@exept.de>
parents: 20026
diff changeset
  2016
	    with:contentsArray startingAt:firstIndex.
72ed68b0d0ec little code cleanup
Claus Gittinger <cg@exept.de>
parents: 20026
diff changeset
  2017
	contentsArray from:startIndex + sz to:lastIndex put:nil.
72ed68b0d0ec little code cleanup
Claus Gittinger <cg@exept.de>
parents: 20026
diff changeset
  2018
	firstIndex := startIndex.
72ed68b0d0ec little code cleanup
Claus Gittinger <cg@exept.de>
parents: 20026
diff changeset
  2019
	lastIndex := startIndex + sz - 1.
72ed68b0d0ec little code cleanup
Claus Gittinger <cg@exept.de>
parents: 20026
diff changeset
  2020
	^ self
606
7a9ab63a6757 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  2021
    ].
18879
5d1bbfc1761d #FEATURE
Stefan Vogel <sv@exept.de>
parents: 18811
diff changeset
  2022
    oldSize == 0 ifTrue:[
20341
72ed68b0d0ec little code cleanup
Claus Gittinger <cg@exept.de>
parents: 20026
diff changeset
  2023
	newSize := MinContentsArraySize
18879
5d1bbfc1761d #FEATURE
Stefan Vogel <sv@exept.de>
parents: 18811
diff changeset
  2024
    ] ifFalse:[
20341
72ed68b0d0ec little code cleanup
Claus Gittinger <cg@exept.de>
parents: 20026
diff changeset
  2025
	newSize := oldSize * 2.
18879
5d1bbfc1761d #FEATURE
Stefan Vogel <sv@exept.de>
parents: 18811
diff changeset
  2026
    ].
606
7a9ab63a6757 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  2027
    newContents := Array basicNew:newSize.
18879
5d1bbfc1761d #FEATURE
Stefan Vogel <sv@exept.de>
parents: 18811
diff changeset
  2028
    oldSize ~~ 0 ifTrue:[
20341
72ed68b0d0ec little code cleanup
Claus Gittinger <cg@exept.de>
parents: 20026
diff changeset
  2029
	newContents
72ed68b0d0ec little code cleanup
Claus Gittinger <cg@exept.de>
parents: 20026
diff changeset
  2030
	    replaceFrom:1 to:oldSize
72ed68b0d0ec little code cleanup
Claus Gittinger <cg@exept.de>
parents: 20026
diff changeset
  2031
	    with:contentsArray startingAt:1.
18879
5d1bbfc1761d #FEATURE
Stefan Vogel <sv@exept.de>
parents: 18811
diff changeset
  2032
    ].
606
7a9ab63a6757 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  2033
    contentsArray := newContents
11269
f45a4a2cd7ab *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 10839
diff changeset
  2034
f45a4a2cd7ab *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 10839
diff changeset
  2035
    "Modified: / 22-10-2008 / 11:50:28 / cg"
606
7a9ab63a6757 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  2036
!
7a9ab63a6757 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  2037
7a9ab63a6757 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  2038
setFirstIndex:newFirstIndex lastIndex:newLastIndex
7a9ab63a6757 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  2039
    "set first and last index"
7a9ab63a6757 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  2040
7a9ab63a6757 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  2041
    firstIndex := newFirstIndex.
7a9ab63a6757 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  2042
    lastIndex := newLastIndex.
6088
db3fc1ec9c1a added #setIndices for VW compatibility
Claus Gittinger <cg@exept.de>
parents: 5874
diff changeset
  2043
!
db3fc1ec9c1a added #setIndices for VW compatibility
Claus Gittinger <cg@exept.de>
parents: 5874
diff changeset
  2044
db3fc1ec9c1a added #setIndices for VW compatibility
Claus Gittinger <cg@exept.de>
parents: 5874
diff changeset
  2045
setIndices
db3fc1ec9c1a added #setIndices for VW compatibility
Claus Gittinger <cg@exept.de>
parents: 5874
diff changeset
  2046
    "added for VW compatibility: set the indices for an empty collection"
db3fc1ec9c1a added #setIndices for VW compatibility
Claus Gittinger <cg@exept.de>
parents: 5874
diff changeset
  2047
db3fc1ec9c1a added #setIndices for VW compatibility
Claus Gittinger <cg@exept.de>
parents: 5874
diff changeset
  2048
    firstIndex := 1.
db3fc1ec9c1a added #setIndices for VW compatibility
Claus Gittinger <cg@exept.de>
parents: 5874
diff changeset
  2049
    lastIndex := 0.
606
7a9ab63a6757 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  2050
! !
7a9ab63a6757 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  2051
7260
edfa8d6a6046 method category rename
Claus Gittinger <cg@exept.de>
parents: 7166
diff changeset
  2052
!OrderedCollection methodsFor:'private-accessing'!
606
7a9ab63a6757 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  2053
7a9ab63a6757 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  2054
contentsArray
4153
3481f2a3429c much better #asArray
Claus Gittinger <cg@exept.de>
parents: 4064
diff changeset
  2055
    "return the orderedCollections underlying contentsArray.
3481f2a3429c much better #asArray
Claus Gittinger <cg@exept.de>
parents: 4064
diff changeset
  2056
     The actual elements are found here starting at firstIndex,
3481f2a3429c much better #asArray
Claus Gittinger <cg@exept.de>
parents: 4064
diff changeset
  2057
     and ending at lastIndex."
3481f2a3429c much better #asArray
Claus Gittinger <cg@exept.de>
parents: 4064
diff changeset
  2058
606
7a9ab63a6757 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  2059
    ^ contentsArray
7a9ab63a6757 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  2060
!
7a9ab63a6757 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  2061
7a9ab63a6757 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  2062
firstIndex
4153
3481f2a3429c much better #asArray
Claus Gittinger <cg@exept.de>
parents: 4064
diff changeset
  2063
    "return the index of my first element in my underlying contentsArray.
3481f2a3429c much better #asArray
Claus Gittinger <cg@exept.de>
parents: 4064
diff changeset
  2064
     The actual elements are found starting this index,
3481f2a3429c much better #asArray
Claus Gittinger <cg@exept.de>
parents: 4064
diff changeset
  2065
     and ending at lastIndex."
3481f2a3429c much better #asArray
Claus Gittinger <cg@exept.de>
parents: 4064
diff changeset
  2066
606
7a9ab63a6757 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  2067
    ^ firstIndex
7a9ab63a6757 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  2068
! !
7a9ab63a6757 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  2069
7a9ab63a6757 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  2070
!OrderedCollection methodsFor:'queries'!
7a9ab63a6757 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  2071
7a9ab63a6757 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  2072
capacity
20354
a671aac9c70d #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20341
diff changeset
  2073
    "return the number of elements, that the receiver is prepared to take
a671aac9c70d #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20341
diff changeset
  2074
     without growing. 
a671aac9c70d #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20341
diff changeset
  2075
     Notice, that OCs do automatically resize as required, 
a671aac9c70d #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20341
diff changeset
  2076
     so knowing the capacity is of no real use.
606
7a9ab63a6757 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  2077
     Not used by the system; added for ST-80 compatibility."
7a9ab63a6757 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  2078
7a9ab63a6757 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  2079
    ^ contentsArray size
7a9ab63a6757 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  2080
!
7a9ab63a6757 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  2081
7a9ab63a6757 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  2082
size
7a9ab63a6757 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  2083
    "return the number of elements in the collection"
7a9ab63a6757 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  2084
7a9ab63a6757 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  2085
    ^ lastIndex - firstIndex + 1
7a9ab63a6757 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  2086
! !
7a9ab63a6757 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  2087
3095
cdb753308f6e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2549
diff changeset
  2088
!OrderedCollection methodsFor:'searching'!
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  2089
a27a279701f8 Initial revision
claus
parents:
diff changeset
  2090
identityIndexOf:anObject
33
50cf0f6bc0ad *** empty log message ***
claus
parents: 13
diff changeset
  2091
    "return the index of anObject or 0 if not found. Compare using =="
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  2092
1157
c52d548036e2 faster search (limit to active range)
Claus Gittinger <cg@exept.de>
parents: 1106
diff changeset
  2093
    |index|
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  2094
20341
72ed68b0d0ec little code cleanup
Claus Gittinger <cg@exept.de>
parents: 20026
diff changeset
  2095
    index := contentsArray
72ed68b0d0ec little code cleanup
Claus Gittinger <cg@exept.de>
parents: 20026
diff changeset
  2096
		identityIndexOf:anObject
72ed68b0d0ec little code cleanup
Claus Gittinger <cg@exept.de>
parents: 20026
diff changeset
  2097
		startingAt:firstIndex
72ed68b0d0ec little code cleanup
Claus Gittinger <cg@exept.de>
parents: 20026
diff changeset
  2098
		endingAt:lastIndex.
1157
c52d548036e2 faster search (limit to active range)
Claus Gittinger <cg@exept.de>
parents: 1106
diff changeset
  2099
    index == 0 ifTrue:[^ 0].
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  2100
    ^ index - firstIndex + 1
1157
c52d548036e2 faster search (limit to active range)
Claus Gittinger <cg@exept.de>
parents: 1106
diff changeset
  2101
c52d548036e2 faster search (limit to active range)
Claus Gittinger <cg@exept.de>
parents: 1106
diff changeset
  2102
    "Modified: 12.4.1996 / 17:58:25 / cg"
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  2103
!
a27a279701f8 Initial revision
claus
parents:
diff changeset
  2104
a27a279701f8 Initial revision
claus
parents:
diff changeset
  2105
identityIndexOf:anObject startingAt:startIndex
33
50cf0f6bc0ad *** empty log message ***
claus
parents: 13
diff changeset
  2106
    "return the index of anObject, starting search at startIndex.
50cf0f6bc0ad *** empty log message ***
claus
parents: 13
diff changeset
  2107
     Compare using ==; return 0 if not found in the collection"
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  2108
1157
c52d548036e2 faster search (limit to active range)
Claus Gittinger <cg@exept.de>
parents: 1106
diff changeset
  2109
    |index|
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  2110
20341
72ed68b0d0ec little code cleanup
Claus Gittinger <cg@exept.de>
parents: 20026
diff changeset
  2111
    index := contentsArray
72ed68b0d0ec little code cleanup
Claus Gittinger <cg@exept.de>
parents: 20026
diff changeset
  2112
		identityIndexOf:anObject
72ed68b0d0ec little code cleanup
Claus Gittinger <cg@exept.de>
parents: 20026
diff changeset
  2113
		startingAt:(startIndex + firstIndex - 1)
72ed68b0d0ec little code cleanup
Claus Gittinger <cg@exept.de>
parents: 20026
diff changeset
  2114
		endingAt:lastIndex.
1157
c52d548036e2 faster search (limit to active range)
Claus Gittinger <cg@exept.de>
parents: 1106
diff changeset
  2115
    index == 0 ifTrue:[^ 0].
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  2116
    ^ index - firstIndex + 1
1157
c52d548036e2 faster search (limit to active range)
Claus Gittinger <cg@exept.de>
parents: 1106
diff changeset
  2117
c52d548036e2 faster search (limit to active range)
Claus Gittinger <cg@exept.de>
parents: 1106
diff changeset
  2118
    "Modified: 12.4.1996 / 17:58:19 / cg"
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  2119
!
a27a279701f8 Initial revision
claus
parents:
diff changeset
  2120
a27a279701f8 Initial revision
claus
parents:
diff changeset
  2121
indexOf:anObject
33
50cf0f6bc0ad *** empty log message ***
claus
parents: 13
diff changeset
  2122
    "return the index of anObject or 0 if not found in the collection.
50cf0f6bc0ad *** empty log message ***
claus
parents: 13
diff changeset
  2123
     Compare using ="
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  2124
1157
c52d548036e2 faster search (limit to active range)
Claus Gittinger <cg@exept.de>
parents: 1106
diff changeset
  2125
    |index|
c52d548036e2 faster search (limit to active range)
Claus Gittinger <cg@exept.de>
parents: 1106
diff changeset
  2126
20341
72ed68b0d0ec little code cleanup
Claus Gittinger <cg@exept.de>
parents: 20026
diff changeset
  2127
    index := contentsArray
72ed68b0d0ec little code cleanup
Claus Gittinger <cg@exept.de>
parents: 20026
diff changeset
  2128
		indexOf:anObject
72ed68b0d0ec little code cleanup
Claus Gittinger <cg@exept.de>
parents: 20026
diff changeset
  2129
		startingAt:firstIndex
72ed68b0d0ec little code cleanup
Claus Gittinger <cg@exept.de>
parents: 20026
diff changeset
  2130
		endingAt:lastIndex.
1157
c52d548036e2 faster search (limit to active range)
Claus Gittinger <cg@exept.de>
parents: 1106
diff changeset
  2131
    index == 0 ifTrue:[^ 0].
c52d548036e2 faster search (limit to active range)
Claus Gittinger <cg@exept.de>
parents: 1106
diff changeset
  2132
    ^ index - firstIndex + 1
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  2133
1157
c52d548036e2 faster search (limit to active range)
Claus Gittinger <cg@exept.de>
parents: 1106
diff changeset
  2134
    "
c52d548036e2 faster search (limit to active range)
Claus Gittinger <cg@exept.de>
parents: 1106
diff changeset
  2135
     |c|
c52d548036e2 faster search (limit to active range)
Claus Gittinger <cg@exept.de>
parents: 1106
diff changeset
  2136
c52d548036e2 faster search (limit to active range)
Claus Gittinger <cg@exept.de>
parents: 1106
diff changeset
  2137
     c := OrderedCollection new:10000.
12035
b927a2b293f8 changed:
Claus Gittinger <cg@exept.de>
parents: 11330
diff changeset
  2138
     c add:10; add:20; add:30.
20341
72ed68b0d0ec little code cleanup
Claus Gittinger <cg@exept.de>
parents: 20026
diff changeset
  2139
     c indexOf:99
1157
c52d548036e2 faster search (limit to active range)
Claus Gittinger <cg@exept.de>
parents: 1106
diff changeset
  2140
    "
c52d548036e2 faster search (limit to active range)
Claus Gittinger <cg@exept.de>
parents: 1106
diff changeset
  2141
12035
b927a2b293f8 changed:
Claus Gittinger <cg@exept.de>
parents: 11330
diff changeset
  2142
    "
b927a2b293f8 changed:
Claus Gittinger <cg@exept.de>
parents: 11330
diff changeset
  2143
     |c|
b927a2b293f8 changed:
Claus Gittinger <cg@exept.de>
parents: 11330
diff changeset
  2144
b927a2b293f8 changed:
Claus Gittinger <cg@exept.de>
parents: 11330
diff changeset
  2145
     c := OrderedCollection new:10000.
b927a2b293f8 changed:
Claus Gittinger <cg@exept.de>
parents: 11330
diff changeset
  2146
     c add:10; add:20; add:30.
20341
72ed68b0d0ec little code cleanup
Claus Gittinger <cg@exept.de>
parents: 20026
diff changeset
  2147
     c indexOf:30
12035
b927a2b293f8 changed:
Claus Gittinger <cg@exept.de>
parents: 11330
diff changeset
  2148
    "
b927a2b293f8 changed:
Claus Gittinger <cg@exept.de>
parents: 11330
diff changeset
  2149
1157
c52d548036e2 faster search (limit to active range)
Claus Gittinger <cg@exept.de>
parents: 1106
diff changeset
  2150
    "Modified: 12.4.1996 / 17:57:54 / cg"
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  2151
!
a27a279701f8 Initial revision
claus
parents:
diff changeset
  2152
12036
4ce4157ce6a9 added: #indexOf:ifAbsent:
Claus Gittinger <cg@exept.de>
parents: 12035
diff changeset
  2153
indexOf:anObject ifAbsent:exceptionValue
4ce4157ce6a9 added: #indexOf:ifAbsent:
Claus Gittinger <cg@exept.de>
parents: 12035
diff changeset
  2154
    "return the index of anObject or 0 if not found in the collection.
4ce4157ce6a9 added: #indexOf:ifAbsent:
Claus Gittinger <cg@exept.de>
parents: 12035
diff changeset
  2155
     Compare using =
4ce4157ce6a9 added: #indexOf:ifAbsent:
Claus Gittinger <cg@exept.de>
parents: 12035
diff changeset
  2156
     If the receiver does not contain anElement,
4ce4157ce6a9 added: #indexOf:ifAbsent:
Claus Gittinger <cg@exept.de>
parents: 12035
diff changeset
  2157
     return the result of evaluating the argument, exceptionBlock."
4ce4157ce6a9 added: #indexOf:ifAbsent:
Claus Gittinger <cg@exept.de>
parents: 12035
diff changeset
  2158
4ce4157ce6a9 added: #indexOf:ifAbsent:
Claus Gittinger <cg@exept.de>
parents: 12035
diff changeset
  2159
    |index|
4ce4157ce6a9 added: #indexOf:ifAbsent:
Claus Gittinger <cg@exept.de>
parents: 12035
diff changeset
  2160
20341
72ed68b0d0ec little code cleanup
Claus Gittinger <cg@exept.de>
parents: 20026
diff changeset
  2161
    index := contentsArray
72ed68b0d0ec little code cleanup
Claus Gittinger <cg@exept.de>
parents: 20026
diff changeset
  2162
		indexOf:anObject
72ed68b0d0ec little code cleanup
Claus Gittinger <cg@exept.de>
parents: 20026
diff changeset
  2163
		startingAt:firstIndex
72ed68b0d0ec little code cleanup
Claus Gittinger <cg@exept.de>
parents: 20026
diff changeset
  2164
		endingAt:lastIndex.
12036
4ce4157ce6a9 added: #indexOf:ifAbsent:
Claus Gittinger <cg@exept.de>
parents: 12035
diff changeset
  2165
    index == 0 ifTrue:[^ exceptionValue value].
4ce4157ce6a9 added: #indexOf:ifAbsent:
Claus Gittinger <cg@exept.de>
parents: 12035
diff changeset
  2166
    ^ index - firstIndex + 1
4ce4157ce6a9 added: #indexOf:ifAbsent:
Claus Gittinger <cg@exept.de>
parents: 12035
diff changeset
  2167
4ce4157ce6a9 added: #indexOf:ifAbsent:
Claus Gittinger <cg@exept.de>
parents: 12035
diff changeset
  2168
    "
4ce4157ce6a9 added: #indexOf:ifAbsent:
Claus Gittinger <cg@exept.de>
parents: 12035
diff changeset
  2169
     |c|
4ce4157ce6a9 added: #indexOf:ifAbsent:
Claus Gittinger <cg@exept.de>
parents: 12035
diff changeset
  2170
4ce4157ce6a9 added: #indexOf:ifAbsent:
Claus Gittinger <cg@exept.de>
parents: 12035
diff changeset
  2171
     c := OrderedCollection new:10000.
4ce4157ce6a9 added: #indexOf:ifAbsent:
Claus Gittinger <cg@exept.de>
parents: 12035
diff changeset
  2172
     c add:10; add:20; add:30.
20341
72ed68b0d0ec little code cleanup
Claus Gittinger <cg@exept.de>
parents: 20026
diff changeset
  2173
     c indexOf:99 ifAbsent:'nope'
12036
4ce4157ce6a9 added: #indexOf:ifAbsent:
Claus Gittinger <cg@exept.de>
parents: 12035
diff changeset
  2174
    "
4ce4157ce6a9 added: #indexOf:ifAbsent:
Claus Gittinger <cg@exept.de>
parents: 12035
diff changeset
  2175
4ce4157ce6a9 added: #indexOf:ifAbsent:
Claus Gittinger <cg@exept.de>
parents: 12035
diff changeset
  2176
    "
4ce4157ce6a9 added: #indexOf:ifAbsent:
Claus Gittinger <cg@exept.de>
parents: 12035
diff changeset
  2177
     |c|
4ce4157ce6a9 added: #indexOf:ifAbsent:
Claus Gittinger <cg@exept.de>
parents: 12035
diff changeset
  2178
4ce4157ce6a9 added: #indexOf:ifAbsent:
Claus Gittinger <cg@exept.de>
parents: 12035
diff changeset
  2179
     c := OrderedCollection new:10000.
4ce4157ce6a9 added: #indexOf:ifAbsent:
Claus Gittinger <cg@exept.de>
parents: 12035
diff changeset
  2180
     c add:10; add:20; add:30.
20341
72ed68b0d0ec little code cleanup
Claus Gittinger <cg@exept.de>
parents: 20026
diff changeset
  2181
     c indexOf:30 ifAbsent:'nope'
12036
4ce4157ce6a9 added: #indexOf:ifAbsent:
Claus Gittinger <cg@exept.de>
parents: 12035
diff changeset
  2182
    "
4ce4157ce6a9 added: #indexOf:ifAbsent:
Claus Gittinger <cg@exept.de>
parents: 12035
diff changeset
  2183
!
4ce4157ce6a9 added: #indexOf:ifAbsent:
Claus Gittinger <cg@exept.de>
parents: 12035
diff changeset
  2184
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  2185
indexOf:anObject startingAt:startIndex
33
50cf0f6bc0ad *** empty log message ***
claus
parents: 13
diff changeset
  2186
    "return the index of anObject, starting search at startIndex.
50cf0f6bc0ad *** empty log message ***
claus
parents: 13
diff changeset
  2187
     Compare using =; return 0 if not found in the collection"
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  2188
1157
c52d548036e2 faster search (limit to active range)
Claus Gittinger <cg@exept.de>
parents: 1106
diff changeset
  2189
    |index|
c52d548036e2 faster search (limit to active range)
Claus Gittinger <cg@exept.de>
parents: 1106
diff changeset
  2190
20341
72ed68b0d0ec little code cleanup
Claus Gittinger <cg@exept.de>
parents: 20026
diff changeset
  2191
    index := contentsArray
72ed68b0d0ec little code cleanup
Claus Gittinger <cg@exept.de>
parents: 20026
diff changeset
  2192
		indexOf:anObject
72ed68b0d0ec little code cleanup
Claus Gittinger <cg@exept.de>
parents: 20026
diff changeset
  2193
		startingAt:(startIndex + firstIndex - 1)
72ed68b0d0ec little code cleanup
Claus Gittinger <cg@exept.de>
parents: 20026
diff changeset
  2194
		endingAt:lastIndex.
1157
c52d548036e2 faster search (limit to active range)
Claus Gittinger <cg@exept.de>
parents: 1106
diff changeset
  2195
    index == 0 ifTrue:[^ 0].
c52d548036e2 faster search (limit to active range)
Claus Gittinger <cg@exept.de>
parents: 1106
diff changeset
  2196
    ^ index - firstIndex + 1
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  2197
1157
c52d548036e2 faster search (limit to active range)
Claus Gittinger <cg@exept.de>
parents: 1106
diff changeset
  2198
    "
c52d548036e2 faster search (limit to active range)
Claus Gittinger <cg@exept.de>
parents: 1106
diff changeset
  2199
     |c|
c52d548036e2 faster search (limit to active range)
Claus Gittinger <cg@exept.de>
parents: 1106
diff changeset
  2200
c52d548036e2 faster search (limit to active range)
Claus Gittinger <cg@exept.de>
parents: 1106
diff changeset
  2201
     c := OrderedCollection new:10000.
c52d548036e2 faster search (limit to active range)
Claus Gittinger <cg@exept.de>
parents: 1106
diff changeset
  2202
     c add:1; add:2; add:3.
20341
72ed68b0d0ec little code cleanup
Claus Gittinger <cg@exept.de>
parents: 20026
diff changeset
  2203
     c indexOf:4 startingAt:5
1157
c52d548036e2 faster search (limit to active range)
Claus Gittinger <cg@exept.de>
parents: 1106
diff changeset
  2204
    "
c52d548036e2 faster search (limit to active range)
Claus Gittinger <cg@exept.de>
parents: 1106
diff changeset
  2205
c52d548036e2 faster search (limit to active range)
Claus Gittinger <cg@exept.de>
parents: 1106
diff changeset
  2206
    "Modified: 12.4.1996 / 17:58:53 / cg"
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  2207
! !
a27a279701f8 Initial revision
claus
parents:
diff changeset
  2208
3095
cdb753308f6e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2549
diff changeset
  2209
!OrderedCollection methodsFor:'testing'!
cdb753308f6e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2549
diff changeset
  2210
cdb753308f6e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2549
diff changeset
  2211
includes:anObject
cdb753308f6e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2549
diff changeset
  2212
    "return true if anObject is in the collection. Compare using ="
cdb753308f6e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2549
diff changeset
  2213
20341
72ed68b0d0ec little code cleanup
Claus Gittinger <cg@exept.de>
parents: 20026
diff changeset
  2214
    ^ (contentsArray
72ed68b0d0ec little code cleanup
Claus Gittinger <cg@exept.de>
parents: 20026
diff changeset
  2215
		indexOf:anObject
72ed68b0d0ec little code cleanup
Claus Gittinger <cg@exept.de>
parents: 20026
diff changeset
  2216
		startingAt:firstIndex
72ed68b0d0ec little code cleanup
Claus Gittinger <cg@exept.de>
parents: 20026
diff changeset
  2217
		endingAt:lastIndex) ~~ 0
3095
cdb753308f6e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2549
diff changeset
  2218
cdb753308f6e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2549
diff changeset
  2219
    "Modified: 12.4.1996 / 17:57:27 / cg"
cdb753308f6e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2549
diff changeset
  2220
!
cdb753308f6e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2549
diff changeset
  2221
cdb753308f6e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2549
diff changeset
  2222
includesIdentical:anObject
cdb753308f6e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2549
diff changeset
  2223
    "return true if anObject is in the collection. Compare using =="
cdb753308f6e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2549
diff changeset
  2224
20341
72ed68b0d0ec little code cleanup
Claus Gittinger <cg@exept.de>
parents: 20026
diff changeset
  2225
    ^ (contentsArray
72ed68b0d0ec little code cleanup
Claus Gittinger <cg@exept.de>
parents: 20026
diff changeset
  2226
		identityIndexOf:anObject
72ed68b0d0ec little code cleanup
Claus Gittinger <cg@exept.de>
parents: 20026
diff changeset
  2227
		startingAt:firstIndex
72ed68b0d0ec little code cleanup
Claus Gittinger <cg@exept.de>
parents: 20026
diff changeset
  2228
		endingAt:lastIndex) ~~ 0
3095
cdb753308f6e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2549
diff changeset
  2229
cdb753308f6e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2549
diff changeset
  2230
    "Modified: 12.4.1996 / 17:57:09 / cg"
5401
81ea19e6843c test for class
ps
parents: 4862
diff changeset
  2231
!
81ea19e6843c test for class
ps
parents: 4862
diff changeset
  2232
5556
1056cc5d6ce0 category change
Claus Gittinger <cg@exept.de>
parents: 5508
diff changeset
  2233
isEmpty
1056cc5d6ce0 category change
Claus Gittinger <cg@exept.de>
parents: 5508
diff changeset
  2234
    "return true, if the receiver has no elements"
1056cc5d6ce0 category change
Claus Gittinger <cg@exept.de>
parents: 5508
diff changeset
  2235
1056cc5d6ce0 category change
Claus Gittinger <cg@exept.de>
parents: 5508
diff changeset
  2236
    ^ lastIndex < firstIndex
1056cc5d6ce0 category change
Claus Gittinger <cg@exept.de>
parents: 5508
diff changeset
  2237
!
1056cc5d6ce0 category change
Claus Gittinger <cg@exept.de>
parents: 5508
diff changeset
  2238
17705
76b6ce4a59cd class: OrderedCollection
Claus Gittinger <cg@exept.de>
parents: 17167
diff changeset
  2239
isEmptyOrNil
76b6ce4a59cd class: OrderedCollection
Claus Gittinger <cg@exept.de>
parents: 17167
diff changeset
  2240
    "return true, if the receiver has no elements"
76b6ce4a59cd class: OrderedCollection
Claus Gittinger <cg@exept.de>
parents: 17167
diff changeset
  2241
76b6ce4a59cd class: OrderedCollection
Claus Gittinger <cg@exept.de>
parents: 17167
diff changeset
  2242
    ^ lastIndex < firstIndex
76b6ce4a59cd class: OrderedCollection
Claus Gittinger <cg@exept.de>
parents: 17167
diff changeset
  2243
!
76b6ce4a59cd class: OrderedCollection
Claus Gittinger <cg@exept.de>
parents: 17167
diff changeset
  2244
5556
1056cc5d6ce0 category change
Claus Gittinger <cg@exept.de>
parents: 5508
diff changeset
  2245
isFixedSize
1056cc5d6ce0 category change
Claus Gittinger <cg@exept.de>
parents: 5508
diff changeset
  2246
    "return true if the receiver cannot grow - this will vanish once
1056cc5d6ce0 category change
Claus Gittinger <cg@exept.de>
parents: 5508
diff changeset
  2247
     Arrays and Strings learn how to grow ..."
1056cc5d6ce0 category change
Claus Gittinger <cg@exept.de>
parents: 5508
diff changeset
  2248
1056cc5d6ce0 category change
Claus Gittinger <cg@exept.de>
parents: 5508
diff changeset
  2249
    ^ false
1056cc5d6ce0 category change
Claus Gittinger <cg@exept.de>
parents: 5508
diff changeset
  2250
!
1056cc5d6ce0 category change
Claus Gittinger <cg@exept.de>
parents: 5508
diff changeset
  2251
5401
81ea19e6843c test for class
ps
parents: 4862
diff changeset
  2252
isOrderedCollection
81ea19e6843c test for class
ps
parents: 4862
diff changeset
  2253
    "return true, if the receiver is some kind of ordered collection (or list etc);
81ea19e6843c test for class
ps
parents: 4862
diff changeset
  2254
     true is returned here - the method is only redefined in Object."
81ea19e6843c test for class
ps
parents: 4862
diff changeset
  2255
81ea19e6843c test for class
ps
parents: 4862
diff changeset
  2256
    ^ true
81ea19e6843c test for class
ps
parents: 4862
diff changeset
  2257
81ea19e6843c test for class
ps
parents: 4862
diff changeset
  2258
5556
1056cc5d6ce0 category change
Claus Gittinger <cg@exept.de>
parents: 5508
diff changeset
  2259
!
1056cc5d6ce0 category change
Claus Gittinger <cg@exept.de>
parents: 5508
diff changeset
  2260
1056cc5d6ce0 category change
Claus Gittinger <cg@exept.de>
parents: 5508
diff changeset
  2261
notEmpty
1056cc5d6ce0 category change
Claus Gittinger <cg@exept.de>
parents: 5508
diff changeset
  2262
    "return true, if the receiver has any elements"
1056cc5d6ce0 category change
Claus Gittinger <cg@exept.de>
parents: 5508
diff changeset
  2263
1056cc5d6ce0 category change
Claus Gittinger <cg@exept.de>
parents: 5508
diff changeset
  2264
    ^ lastIndex >= firstIndex
3095
cdb753308f6e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2549
diff changeset
  2265
! !
cdb753308f6e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2549
diff changeset
  2266
15660
3143ca7c443a class: OrderedCollection
Claus Gittinger <cg@exept.de>
parents: 15442
diff changeset
  2267
!OrderedCollection methodsFor:'tuning'!
3143ca7c443a class: OrderedCollection
Claus Gittinger <cg@exept.de>
parents: 15442
diff changeset
  2268
20341
72ed68b0d0ec little code cleanup
Claus Gittinger <cg@exept.de>
parents: 20026
diff changeset
  2269
quickSortFrom:inBegin to:inEnd
15660
3143ca7c443a class: OrderedCollection
Claus Gittinger <cg@exept.de>
parents: 15442
diff changeset
  2270
    self class == OrderedCollection ifTrue:[
20341
72ed68b0d0ec little code cleanup
Claus Gittinger <cg@exept.de>
parents: 20026
diff changeset
  2271
	"/ because array-at/at:put: is much faster, this speeds up sorting by
72ed68b0d0ec little code cleanup
Claus Gittinger <cg@exept.de>
parents: 20026
diff changeset
  2272
	"/ up to 30%
72ed68b0d0ec little code cleanup
Claus Gittinger <cg@exept.de>
parents: 20026
diff changeset
  2273
	contentsArray
72ed68b0d0ec little code cleanup
Claus Gittinger <cg@exept.de>
parents: 20026
diff changeset
  2274
	    quickSortFrom:(firstIndex + inBegin - 1)
72ed68b0d0ec little code cleanup
Claus Gittinger <cg@exept.de>
parents: 20026
diff changeset
  2275
	    to:(firstIndex + inEnd - 1)
15660
3143ca7c443a class: OrderedCollection
Claus Gittinger <cg@exept.de>
parents: 15442
diff changeset
  2276
    ] ifFalse:[
20341
72ed68b0d0ec little code cleanup
Claus Gittinger <cg@exept.de>
parents: 20026
diff changeset
  2277
	super quickSortFrom:inBegin to:inEnd
15660
3143ca7c443a class: OrderedCollection
Claus Gittinger <cg@exept.de>
parents: 15442
diff changeset
  2278
    ].
3143ca7c443a class: OrderedCollection
Claus Gittinger <cg@exept.de>
parents: 15442
diff changeset
  2279
!
3143ca7c443a class: OrderedCollection
Claus Gittinger <cg@exept.de>
parents: 15442
diff changeset
  2280
3143ca7c443a class: OrderedCollection
Claus Gittinger <cg@exept.de>
parents: 15442
diff changeset
  2281
quickSortFrom:inBegin to:inEnd sortBlock:sortBlock
3143ca7c443a class: OrderedCollection
Claus Gittinger <cg@exept.de>
parents: 15442
diff changeset
  2282
    self class == OrderedCollection ifTrue:[
20341
72ed68b0d0ec little code cleanup
Claus Gittinger <cg@exept.de>
parents: 20026
diff changeset
  2283
	"/ because array-at/at:put: is much faster, this speeds up sorting by
72ed68b0d0ec little code cleanup
Claus Gittinger <cg@exept.de>
parents: 20026
diff changeset
  2284
	"/ up to 30%
72ed68b0d0ec little code cleanup
Claus Gittinger <cg@exept.de>
parents: 20026
diff changeset
  2285
	contentsArray
72ed68b0d0ec little code cleanup
Claus Gittinger <cg@exept.de>
parents: 20026
diff changeset
  2286
	    quickSortFrom:(firstIndex + inBegin - 1)
72ed68b0d0ec little code cleanup
Claus Gittinger <cg@exept.de>
parents: 20026
diff changeset
  2287
	    to:(firstIndex + inEnd - 1)
72ed68b0d0ec little code cleanup
Claus Gittinger <cg@exept.de>
parents: 20026
diff changeset
  2288
	    sortBlock:sortBlock
15660
3143ca7c443a class: OrderedCollection
Claus Gittinger <cg@exept.de>
parents: 15442
diff changeset
  2289
    ] ifFalse:[
20341
72ed68b0d0ec little code cleanup
Claus Gittinger <cg@exept.de>
parents: 20026
diff changeset
  2290
	super quickSortFrom:inBegin to:inEnd sortBlock:sortBlock
15660
3143ca7c443a class: OrderedCollection
Claus Gittinger <cg@exept.de>
parents: 15442
diff changeset
  2291
    ]
3143ca7c443a class: OrderedCollection
Claus Gittinger <cg@exept.de>
parents: 15442
diff changeset
  2292
! !
3143ca7c443a class: OrderedCollection
Claus Gittinger <cg@exept.de>
parents: 15442
diff changeset
  2293
629
2ceefe9b5a19 version at the end
Claus Gittinger <cg@exept.de>
parents: 606
diff changeset
  2294
!OrderedCollection class methodsFor:'documentation'!
2ceefe9b5a19 version at the end
Claus Gittinger <cg@exept.de>
parents: 606
diff changeset
  2295
2ceefe9b5a19 version at the end
Claus Gittinger <cg@exept.de>
parents: 606
diff changeset
  2296
version
18811
54e839ea9d44 #BUGFIX
Claus Gittinger <cg@exept.de>
parents: 18379
diff changeset
  2297
    ^ '$Header$'
16305
964f7ffb315d class: OrderedCollection
Claus Gittinger <cg@exept.de>
parents: 16304
diff changeset
  2298
!
964f7ffb315d class: OrderedCollection
Claus Gittinger <cg@exept.de>
parents: 16304
diff changeset
  2299
964f7ffb315d class: OrderedCollection
Claus Gittinger <cg@exept.de>
parents: 16304
diff changeset
  2300
version_CVS
18811
54e839ea9d44 #BUGFIX
Claus Gittinger <cg@exept.de>
parents: 18379
diff changeset
  2301
    ^ '$Header$'
629
2ceefe9b5a19 version at the end
Claus Gittinger <cg@exept.de>
parents: 606
diff changeset
  2302
! !
14616
e763997b09d1 class: OrderedCollection
Claus Gittinger <cg@exept.de>
parents: 14071
diff changeset
  2303
18879
5d1bbfc1761d #FEATURE
Stefan Vogel <sv@exept.de>
parents: 18811
diff changeset
  2304
5d1bbfc1761d #FEATURE
Stefan Vogel <sv@exept.de>
parents: 18811
diff changeset
  2305
OrderedCollection initialize!