author | Claus Gittinger <cg@exept.de> |
Wed, 07 Sep 2011 10:55:54 +0200 | |
changeset 13642 | 37eba7280fcf |
parent 13163 | e4845fce0ada |
child 13727 | 05c6543b983b |
permissions | -rw-r--r-- |
1 | 1 |
" |
5 | 2 |
COPYRIGHT (c) 1989 by Claus Gittinger |
159 | 3 |
All Rights Reserved |
1 | 4 |
|
5 |
This software is furnished under a license and may be used |
|
6 |
only in accordance with the terms of that license and with the |
|
7 |
inclusion of the above copyright notice. This software may not |
|
8 |
be provided or otherwise made available to, or used by, any |
|
9 |
other person. No title to or ownership of the software is |
|
10 |
hereby transferred. |
|
11 |
" |
|
5519
925d9a1eda2c
fixed emptyCollection error signaling
Claus Gittinger <cg@exept.de>
parents:
5244
diff
changeset
|
12 |
"{ Package: 'stx:libbasic' }" |
925d9a1eda2c
fixed emptyCollection error signaling
Claus Gittinger <cg@exept.de>
parents:
5244
diff
changeset
|
13 |
|
1 | 14 |
SequenceableCollection subclass:#LinkedList |
1110 | 15 |
instanceVariableNames:'firstLink lastLink numberOfNodes' |
16 |
classVariableNames:'' |
|
17 |
poolDictionaries:'' |
|
1364 | 18 |
category:'Collections-Linked' |
1 | 19 |
! |
20 |
||
88 | 21 |
!LinkedList class methodsFor:'documentation'! |
22 |
||
23 |
copyright |
|
24 |
" |
|
25 |
COPYRIGHT (c) 1989 by Claus Gittinger |
|
159 | 26 |
All Rights Reserved |
1 | 27 |
|
88 | 28 |
This software is furnished under a license and may be used |
29 |
only in accordance with the terms of that license and with the |
|
30 |
inclusion of the above copyright notice. This software may not |
|
31 |
be provided or otherwise made available to, or used by, any |
|
32 |
other person. No title to or ownership of the software is |
|
33 |
hereby transferred. |
|
34 |
" |
|
35 |
! |
|
1 | 36 |
|
88 | 37 |
documentation |
38 |
" |
|
39 |
this class implements an anchor to a list of Links. |
|
10647 | 40 |
The data itself is held in the link elements. |
243 | 41 |
See (the abstract) Link, ValueLink and (possibly other) classes, |
42 |
which can be used as elements of a linkedList. |
|
43 |
||
360 | 44 |
LinkedList does not care for storage; all it does is handling |
45 |
chained link elements, which must respond to #nextLink/#nextLink:. |
|
46 |
(i.e. any object which can do this, can be used as elements of a linked |
|
10647 | 47 |
list). |
2146 | 48 |
An abstract superclass for linkElements is Link; a concrete class is |
49 |
ValueLink, which holds a reference to some object. |
|
50 |
||
51 |
[warning:] |
|
10647 | 52 |
Be careful when subclassing Link, since there is a big drawback, |
53 |
which may be overlooked by beginners: |
|
54 |
a Link element can only be in one LinkedList |
|
55 |
- adding the same element to another LinkedList |
|
56 |
will remove it from the first as a side effect. |
|
57 |
Therefore, NEVER simply add something to a linkedList (except for |
|
58 |
valueLinks) unless you know what you do. |
|
59 |
The ST-80 implementors probably wanted this behavior, to move |
|
60 |
processes from the waitingList to runLists and vice versa; |
|
61 |
however, literature seems to not point this out enough. |
|
360 | 62 |
|
243 | 63 |
Although LinkedList is a subclass of SequenceableCollection (and therefore |
64 |
supports indexed access via at:), you should be careful in using it or |
|
10647 | 65 |
other methods based upon at:. |
360 | 66 |
The reason is that #at: walks the linkedlist to find the indexed element |
10647 | 67 |
and is therefore slow. |
68 |
This means that some linear-in-time algorithms inherited from |
|
360 | 69 |
SequenceableCollection become square in runtime. |
243 | 70 |
In general, if you need access via a numeric index, you better use Array, |
71 |
OrderedCollection or similar. |
|
360 | 72 |
|
73 |
For the above reasons, the system does not make heavily use of LinkedLists; |
|
74 |
the only good application is where elements must be repeatedly be removed |
|
75 |
at the front and added at the end. |
|
76 |
(the schedulers process handling code does this to manage process lists.) |
|
1290 | 77 |
|
4063 | 78 |
[memory requirements:] |
10647 | 79 |
(OBJ-HEADER + (3 * ptr-size)) * size |
80 |
+ any additional instvars due to subclassing |
|
4063 | 81 |
|
1290 | 82 |
[author:] |
10647 | 83 |
Claus Gittinger |
2146 | 84 |
|
85 |
[see also:] |
|
10647 | 86 |
Link ValueLink Process |
360 | 87 |
" |
88 |
! |
|
89 |
||
10647 | 90 |
examples |
360 | 91 |
" |
10647 | 92 |
[exBegin] |
360 | 93 |
|l| |
94 |
||
95 |
l := LinkedList new. |
|
96 |
l addLast:(ValueLink new value:'one'). |
|
97 |
l addLast:(ValueLink new value:'two'). |
|
98 |
l addLast:(ValueLink new value:'three'). |
|
99 |
l addLast:(ValueLink new value:'four'). |
|
100 |
l inspect |
|
10647 | 101 |
[exEnd] |
360 | 102 |
|
103 |
||
10647 | 104 |
[exBegin] |
360 | 105 |
|l| |
106 |
||
107 |
l := LinkedList new. |
|
108 |
l addLast:(ValueLink new value:'one'). |
|
109 |
l addLast:(ValueLink new value:'two'). |
|
110 |
l addLast:(ValueLink new value:'three'). |
|
111 |
l addLast:(ValueLink new value:'four'). |
|
112 |
(l at:3) value inspect. 'slow operation for large lists'. |
|
10647 | 113 |
[exEnd] |
360 | 114 |
|
115 |
||
10647 | 116 |
[exBegin] |
360 | 117 |
|l link| |
118 |
||
119 |
l := LinkedList new. |
|
120 |
l addLast:(ValueLink new value:'one'). |
|
121 |
l addLast:(ValueLink new value:'two'). |
|
122 |
l addLast:(ValueLink new value:'three'). |
|
123 |
l addLast:(ValueLink new value:'four'). |
|
124 |
link := l removeFirst. |
|
125 |
l addLast:link. |
|
10647 | 126 |
l inspect. |
127 |
[exEnd] |
|
88 | 128 |
" |
129 |
! ! |
|
1 | 130 |
|
131 |
!LinkedList class methodsFor:'instance creation'! |
|
132 |
||
133 |
new |
|
134 |
"create and return a new LinkedList" |
|
135 |
||
4300 | 136 |
^ self basicNew initialize |
1 | 137 |
! ! |
138 |
||
139 |
!LinkedList methodsFor:'accessing'! |
|
140 |
||
159 | 141 |
at:index |
142 |
"return the n'th element - use of this method should be avoided, |
|
143 |
since it is slow to walk through the list - think about using |
|
9118 | 144 |
another collection if you need indexed access. |
241 | 145 |
Notice, that many methods in SeqColl are based on at:-access, |
146 |
so other inherited methods may be very slow (showing square runtime)." |
|
159 | 147 |
|
9117 | 148 |
^ self at:index ifAbsent:[ self subscriptBoundsError:index] |
149 |
! |
|
150 |
||
151 |
at:index ifAbsent:exceptionBlock |
|
152 |
"return the n'th element - use of this method should be avoided, |
|
153 |
since it is slow to walk through the list - think about using |
|
9118 | 154 |
another collection if you need indexed access. |
9117 | 155 |
Notice, that many methods in SeqColl are based on at:-access, |
156 |
so other inherited methods may be very slow (showing square runtime)." |
|
157 |
||
159 | 158 |
|theLink |
159 |
runIndex "{Class: SmallInteger}"| |
|
160 |
||
161 |
theLink := firstLink. |
|
162 |
runIndex := 1. |
|
243 | 163 |
[runIndex == index] whileFalse:[ |
10647 | 164 |
theLink isNil ifTrue:[^ exceptionBlock value]. |
165 |
theLink := theLink nextLink. |
|
166 |
runIndex := runIndex + 1. |
|
159 | 167 |
]. |
168 |
^ theLink |
|
606 | 169 |
! |
170 |
||
171 |
first |
|
172 |
"return the first node in the list" |
|
173 |
||
5519
925d9a1eda2c
fixed emptyCollection error signaling
Claus Gittinger <cg@exept.de>
parents:
5244
diff
changeset
|
174 |
firstLink isNil ifTrue:[^ self emptyCollectionError]. |
606 | 175 |
^ firstLink |
176 |
! |
|
177 |
||
10647 | 178 |
firstIfEmpty:exceptionalValue |
179 |
"return the first node in the list or exceptionlValue, if empty" |
|
180 |
||
181 |
firstLink isNil ifTrue:[^ exceptionalValue value]. |
|
182 |
^ firstLink |
|
183 |
! |
|
184 |
||
606 | 185 |
last |
186 |
"return last node in the list" |
|
187 |
||
188 |
lastLink isNil ifTrue:[self emptyCollectionError]. |
|
189 |
^ lastLink |
|
190 |
! ! |
|
191 |
||
192 |
!LinkedList methodsFor:'adding & removing'! |
|
193 |
||
194 |
add:aLink |
|
195 |
"adds aLink to the end of the sequence. Returns aLink" |
|
196 |
||
197 |
aLink nextLink:nil. |
|
198 |
lastLink isNil ifTrue:[ |
|
199 |
firstLink := aLink |
|
200 |
] ifFalse: [ |
|
201 |
lastLink nextLink:aLink |
|
202 |
]. |
|
203 |
lastLink := aLink. |
|
204 |
numberOfNodes := numberOfNodes + 1. |
|
205 |
^ aLink |
|
206 |
! |
|
207 |
||
208 |
add:linkToAdd after:aLink |
|
209 |
"adds linkToAdd after another link, aLink. If aLink is nil, |
|
210 |
linkToAdd is inserted at the beginning. Returns linkToAdd." |
|
211 |
||
212 |
|this| |
|
213 |
||
214 |
aLink isNil ifTrue:[^ self addFirst:linkToAdd ]. |
|
215 |
||
216 |
this := firstLink. |
|
217 |
[this notNil and:[this ~~ aLink]] whileTrue:[ |
|
218 |
this := this nextLink |
|
219 |
]. |
|
220 |
this isNil ifTrue:[^ self add:linkToAdd ]. |
|
221 |
linkToAdd nextLink:(this nextLink). |
|
222 |
this nextLink:linkToAdd. |
|
10647 | 223 |
numberOfNodes := numberOfNodes + 1. |
606 | 224 |
^ linkToAdd |
225 |
! |
|
226 |
||
227 |
addFirst:aLink |
|
228 |
"adds aLink to the beginning of the sequence. Returns aLink" |
|
229 |
||
230 |
firstLink isNil ifTrue:[ |
|
10647 | 231 |
lastLink := aLink. |
606 | 232 |
]. |
10647 | 233 |
aLink nextLink:firstLink. |
234 |
firstLink := aLink. |
|
606 | 235 |
numberOfNodes := numberOfNodes + 1. |
236 |
^ aLink |
|
237 |
! |
|
238 |
||
239 |
remove:aLink ifAbsent:exceptionBlock |
|
10647 | 240 |
"remove the argument, aLink from the sequence and return it; |
2350 | 241 |
if absent, evaluate the exceptionBlock. |
13153
572dc11e2e96
added: #removeIdentical:ifAbsent:
Claus Gittinger <cg@exept.de>
parents:
13150
diff
changeset
|
242 |
Actually this is really a #removeIdentical (but for compatibility...)" |
606 | 243 |
|
13153
572dc11e2e96
added: #removeIdentical:ifAbsent:
Claus Gittinger <cg@exept.de>
parents:
13150
diff
changeset
|
244 |
^ self removeIdentical:aLink ifAbsent:exceptionBlock |
2349 | 245 |
|
13153
572dc11e2e96
added: #removeIdentical:ifAbsent:
Claus Gittinger <cg@exept.de>
parents:
13150
diff
changeset
|
246 |
"Modified: / 30-11-2010 / 13:38:45 / cg" |
606 | 247 |
! |
248 |
||
1110 | 249 |
removeAll |
1164 | 250 |
"remove all elements from the sequence. Returns the receiver." |
1110 | 251 |
|
252 |
firstLink := lastLink := nil. |
|
253 |
numberOfNodes := 0 |
|
254 |
||
255 |
"Created: 21.3.1996 / 15:24:38 / cg" |
|
1164 | 256 |
"Modified: 12.4.1996 / 13:34:53 / cg" |
1110 | 257 |
! |
258 |
||
606 | 259 |
removeFirst |
260 |
"remove and return the first node from the sequence" |
|
261 |
||
262 |
|link| |
|
263 |
||
264 |
firstLink isNil ifTrue:[ |
|
10647 | 265 |
^ self emptyCollectionError |
5519
925d9a1eda2c
fixed emptyCollection error signaling
Claus Gittinger <cg@exept.de>
parents:
5244
diff
changeset
|
266 |
]. |
925d9a1eda2c
fixed emptyCollection error signaling
Claus Gittinger <cg@exept.de>
parents:
5244
diff
changeset
|
267 |
link := firstLink. |
10647 | 268 |
firstLink := firstLink nextLink. |
269 |
firstLink isNil ifTrue:[ |
|
270 |
lastLink := nil |
|
606 | 271 |
]. |
5519
925d9a1eda2c
fixed emptyCollection error signaling
Claus Gittinger <cg@exept.de>
parents:
5244
diff
changeset
|
272 |
link nextLink:nil. |
925d9a1eda2c
fixed emptyCollection error signaling
Claus Gittinger <cg@exept.de>
parents:
5244
diff
changeset
|
273 |
numberOfNodes := numberOfNodes - 1. |
606 | 274 |
^ link |
13153
572dc11e2e96
added: #removeIdentical:ifAbsent:
Claus Gittinger <cg@exept.de>
parents:
13150
diff
changeset
|
275 |
! |
572dc11e2e96
added: #removeIdentical:ifAbsent:
Claus Gittinger <cg@exept.de>
parents:
13150
diff
changeset
|
276 |
|
572dc11e2e96
added: #removeIdentical:ifAbsent:
Claus Gittinger <cg@exept.de>
parents:
13150
diff
changeset
|
277 |
removeIdentical:aLink ifAbsent:exceptionBlock |
572dc11e2e96
added: #removeIdentical:ifAbsent:
Claus Gittinger <cg@exept.de>
parents:
13150
diff
changeset
|
278 |
"remove the argument, aLink from the sequence and return it; |
13163
e4845fce0ada
changed comment: #removeIdentical:ifAbsent:
Stefan Vogel <sv@exept.de>
parents:
13153
diff
changeset
|
279 |
if absent, evaluate the exceptionBlock." |
13153
572dc11e2e96
added: #removeIdentical:ifAbsent:
Claus Gittinger <cg@exept.de>
parents:
13150
diff
changeset
|
280 |
|
572dc11e2e96
added: #removeIdentical:ifAbsent:
Claus Gittinger <cg@exept.de>
parents:
13150
diff
changeset
|
281 |
|prevNode nextNode thisNode| |
572dc11e2e96
added: #removeIdentical:ifAbsent:
Claus Gittinger <cg@exept.de>
parents:
13150
diff
changeset
|
282 |
|
572dc11e2e96
added: #removeIdentical:ifAbsent:
Claus Gittinger <cg@exept.de>
parents:
13150
diff
changeset
|
283 |
thisNode := firstLink. |
572dc11e2e96
added: #removeIdentical:ifAbsent:
Claus Gittinger <cg@exept.de>
parents:
13150
diff
changeset
|
284 |
[thisNode notNil] whileTrue:[ |
572dc11e2e96
added: #removeIdentical:ifAbsent:
Claus Gittinger <cg@exept.de>
parents:
13150
diff
changeset
|
285 |
nextNode := thisNode nextLink. |
572dc11e2e96
added: #removeIdentical:ifAbsent:
Claus Gittinger <cg@exept.de>
parents:
13150
diff
changeset
|
286 |
(thisNode == aLink) ifTrue:[ |
572dc11e2e96
added: #removeIdentical:ifAbsent:
Claus Gittinger <cg@exept.de>
parents:
13150
diff
changeset
|
287 |
prevNode isNil ifTrue:[ |
572dc11e2e96
added: #removeIdentical:ifAbsent:
Claus Gittinger <cg@exept.de>
parents:
13150
diff
changeset
|
288 |
firstLink := nextNode |
572dc11e2e96
added: #removeIdentical:ifAbsent:
Claus Gittinger <cg@exept.de>
parents:
13150
diff
changeset
|
289 |
] ifFalse:[ |
572dc11e2e96
added: #removeIdentical:ifAbsent:
Claus Gittinger <cg@exept.de>
parents:
13150
diff
changeset
|
290 |
prevNode nextLink:nextNode |
572dc11e2e96
added: #removeIdentical:ifAbsent:
Claus Gittinger <cg@exept.de>
parents:
13150
diff
changeset
|
291 |
]. |
572dc11e2e96
added: #removeIdentical:ifAbsent:
Claus Gittinger <cg@exept.de>
parents:
13150
diff
changeset
|
292 |
nextNode isNil ifTrue:[ |
572dc11e2e96
added: #removeIdentical:ifAbsent:
Claus Gittinger <cg@exept.de>
parents:
13150
diff
changeset
|
293 |
lastLink := prevNode |
572dc11e2e96
added: #removeIdentical:ifAbsent:
Claus Gittinger <cg@exept.de>
parents:
13150
diff
changeset
|
294 |
]. |
572dc11e2e96
added: #removeIdentical:ifAbsent:
Claus Gittinger <cg@exept.de>
parents:
13150
diff
changeset
|
295 |
numberOfNodes := numberOfNodes - 1. |
572dc11e2e96
added: #removeIdentical:ifAbsent:
Claus Gittinger <cg@exept.de>
parents:
13150
diff
changeset
|
296 |
thisNode nextLink:nil. |
572dc11e2e96
added: #removeIdentical:ifAbsent:
Claus Gittinger <cg@exept.de>
parents:
13150
diff
changeset
|
297 |
^ aLink |
572dc11e2e96
added: #removeIdentical:ifAbsent:
Claus Gittinger <cg@exept.de>
parents:
13150
diff
changeset
|
298 |
]. |
572dc11e2e96
added: #removeIdentical:ifAbsent:
Claus Gittinger <cg@exept.de>
parents:
13150
diff
changeset
|
299 |
prevNode := thisNode. |
572dc11e2e96
added: #removeIdentical:ifAbsent:
Claus Gittinger <cg@exept.de>
parents:
13150
diff
changeset
|
300 |
thisNode := nextNode |
572dc11e2e96
added: #removeIdentical:ifAbsent:
Claus Gittinger <cg@exept.de>
parents:
13150
diff
changeset
|
301 |
]. |
572dc11e2e96
added: #removeIdentical:ifAbsent:
Claus Gittinger <cg@exept.de>
parents:
13150
diff
changeset
|
302 |
^ exceptionBlock value |
572dc11e2e96
added: #removeIdentical:ifAbsent:
Claus Gittinger <cg@exept.de>
parents:
13150
diff
changeset
|
303 |
|
572dc11e2e96
added: #removeIdentical:ifAbsent:
Claus Gittinger <cg@exept.de>
parents:
13150
diff
changeset
|
304 |
"Created: / 30-11-2010 / 13:38:25 / cg" |
606 | 305 |
! ! |
306 |
||
307 |
!LinkedList methodsFor:'enumerating'! |
|
308 |
||
309 |
do:aBlock |
|
310 |
"evaluate the argument, aBlock with 1 arg for every element in the list" |
|
311 |
||
312 |
|thisNode| |
|
313 |
||
314 |
thisNode := firstLink. |
|
315 |
[thisNode notNil] whileTrue:[ |
|
316 |
aBlock value:thisNode. |
|
317 |
thisNode := thisNode nextLink |
|
318 |
] |
|
319 |
! ! |
|
320 |
||
5244 | 321 |
!LinkedList methodsFor:'initialization'! |
606 | 322 |
|
323 |
initialize |
|
324 |
numberOfNodes := 0 |
|
93 | 325 |
! ! |
326 |
||
327 |
!LinkedList methodsFor:'queries'! |
|
328 |
||
606 | 329 |
size |
330 |
"return the size of the LinkedList i.e. the number of nodes" |
|
331 |
||
332 |
^ numberOfNodes |
|
1 | 333 |
! ! |
334 |
||
335 |
!LinkedList methodsFor:'testing'! |
|
336 |
||
10647 | 337 |
identityIndexOf:aLink startingAt:start |
243 | 338 |
"search the collection for aLink, starting the search at index start; |
339 |
if found, return the index otherwise return 0. Here, index is defined |
|
340 |
as the link-nodes position in the list. |
|
10647 | 341 |
The comparison is done using == |
13150
e20625aa25a7
comment changed: #identityIndexOf:startingAt:
Stefan Vogel <sv@exept.de>
parents:
10647
diff
changeset
|
342 |
(i.e. identity test - not equality test)." |
243 | 343 |
|
344 |
|theNode idx "{ Class: SmallInteger }"| |
|
345 |
||
346 |
theNode := firstLink. |
|
347 |
idx := 1. |
|
348 |
[idx < start] whileTrue:[ |
|
13150
e20625aa25a7
comment changed: #identityIndexOf:startingAt:
Stefan Vogel <sv@exept.de>
parents:
10647
diff
changeset
|
349 |
theNode isNil ifTrue:[^ 0]. "reached the end" |
e20625aa25a7
comment changed: #identityIndexOf:startingAt:
Stefan Vogel <sv@exept.de>
parents:
10647
diff
changeset
|
350 |
theNode := theNode nextLink. |
e20625aa25a7
comment changed: #identityIndexOf:startingAt:
Stefan Vogel <sv@exept.de>
parents:
10647
diff
changeset
|
351 |
idx := idx + 1. |
243 | 352 |
]. |
353 |
[theNode notNil] whileTrue:[ |
|
13150
e20625aa25a7
comment changed: #identityIndexOf:startingAt:
Stefan Vogel <sv@exept.de>
parents:
10647
diff
changeset
|
354 |
(aLink == theNode) ifTrue:[^ idx]. |
e20625aa25a7
comment changed: #identityIndexOf:startingAt:
Stefan Vogel <sv@exept.de>
parents:
10647
diff
changeset
|
355 |
theNode := theNode nextLink. |
e20625aa25a7
comment changed: #identityIndexOf:startingAt:
Stefan Vogel <sv@exept.de>
parents:
10647
diff
changeset
|
356 |
idx := idx + 1. |
243 | 357 |
]. "reached the end" |
358 |
^ 0 |
|
359 |
||
360 |
" |
|
361 |
|l| |
|
362 |
||
363 |
l := LinkedList new. |
|
10647 | 364 |
l indexOf:'hello' |
243 | 365 |
" |
366 |
||
367 |
" |
|
368 |
|l v| |
|
369 |
||
370 |
l := LinkedList new. |
|
371 |
l add:(ValueLink new value:'one'). |
|
372 |
l add:(ValueLink new value:'two'). |
|
373 |
l add:(v := ValueLink new value:'hello'). |
|
10647 | 374 |
l identityIndexOf:v |
243 | 375 |
" |
1 | 376 |
! |
377 |
||
10647 | 378 |
indexOf:aLink startingAt:start |
606 | 379 |
"search the collection for aLink, starting the search at index start; |
380 |
if found, return the index otherwise return 0. Here, index is defined |
|
381 |
as the link-nodes position in the list. |
|
382 |
The comparison is done using = (i.e. equality test - not identity test)." |
|
1 | 383 |
|
606 | 384 |
|theNode idx "{ Class: SmallInteger }"| |
1 | 385 |
|
606 | 386 |
theNode := firstLink. |
387 |
idx := 1. |
|
388 |
[idx < start] whileTrue:[ |
|
389 |
theNode isNil ifTrue:[^ 0]. "reached the end" |
|
390 |
theNode := theNode nextLink. |
|
391 |
idx := idx + 1. |
|
392 |
]. |
|
393 |
[theNode notNil] whileTrue:[ |
|
394 |
(aLink = theNode) ifTrue:[^ idx]. |
|
395 |
theNode := theNode nextLink. |
|
396 |
idx := idx + 1. |
|
397 |
]. "reached the end" |
|
398 |
^ 0 |
|
1 | 399 |
|
606 | 400 |
" |
401 |
|l| |
|
402 |
||
403 |
l := LinkedList new. |
|
10647 | 404 |
l indexOf:'hello' |
606 | 405 |
" |
406 |
||
407 |
" |
|
408 |
|l v| |
|
409 |
||
410 |
l := LinkedList new. |
|
411 |
l add:(ValueLink new value:'one'). |
|
412 |
l add:(ValueLink new value:'two'). |
|
413 |
l add:(v := ValueLink new value:'hello'). |
|
10647 | 414 |
l indexOf:v |
606 | 415 |
" |
5556 | 416 |
! |
417 |
||
418 |
isEmpty |
|
419 |
"return true, if the collection is empty" |
|
420 |
||
421 |
^ firstLink isNil |
|
422 |
! |
|
423 |
||
424 |
notEmpty |
|
425 |
"return true, if the collection is not empty" |
|
426 |
||
427 |
^ firstLink notNil |
|
1 | 428 |
! ! |
429 |
||
629 | 430 |
!LinkedList class methodsFor:'documentation'! |
431 |
||
432 |
version |
|
13163
e4845fce0ada
changed comment: #removeIdentical:ifAbsent:
Stefan Vogel <sv@exept.de>
parents:
13153
diff
changeset
|
433 |
^ '$Header: /cvs/stx/stx/libbasic/LinkedList.st,v 1.40 2010-12-08 15:06:55 stefan Exp $' |
13150
e20625aa25a7
comment changed: #identityIndexOf:startingAt:
Stefan Vogel <sv@exept.de>
parents:
10647
diff
changeset
|
434 |
! |
e20625aa25a7
comment changed: #identityIndexOf:startingAt:
Stefan Vogel <sv@exept.de>
parents:
10647
diff
changeset
|
435 |
|
e20625aa25a7
comment changed: #identityIndexOf:startingAt:
Stefan Vogel <sv@exept.de>
parents:
10647
diff
changeset
|
436 |
version_CVS |
13163
e4845fce0ada
changed comment: #removeIdentical:ifAbsent:
Stefan Vogel <sv@exept.de>
parents:
13153
diff
changeset
|
437 |
^ '$Header: /cvs/stx/stx/libbasic/LinkedList.st,v 1.40 2010-12-08 15:06:55 stefan Exp $' |
629 | 438 |
! ! |