author | Stefan Vogel <sv@exept.de> |
Fri, 03 Apr 2020 18:50:48 +0200 | |
changeset 5471 | 0bee7a5e40e8 |
parent 4332 | e273ae4149cc |
permissions | -rw-r--r-- |
4332 | 1 |
" |
2 |
COPYRIGHT (c) 2015 by Claus Gittinger / eXept Software AG |
|
3 |
All Rights Reserved |
|
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 |
" |
|
3561 | 12 |
"{ Package: 'stx:libbasic2' }" |
13 |
||
14 |
"{ NameSpace: Smalltalk }" |
|
15 |
||
16 |
OrderedCollection subclass:#AutoResizingOrderedCollection |
|
17 |
instanceVariableNames:'' |
|
18 |
classVariableNames:'' |
|
19 |
poolDictionaries:'' |
|
20 |
category:'Collections-Sequenceable' |
|
21 |
! |
|
22 |
||
23 |
!AutoResizingOrderedCollection class methodsFor:'documentation'! |
|
24 |
||
4332 | 25 |
copyright |
26 |
" |
|
27 |
COPYRIGHT (c) 2015 by Claus Gittinger / eXept Software AG |
|
28 |
All Rights Reserved |
|
29 |
||
30 |
This software is furnished under a license and may be used |
|
31 |
only in accordance with the terms of that license and with the |
|
32 |
inclusion of the above copyright notice. This software may not |
|
33 |
be provided or otherwise made available to, or used by, any |
|
34 |
other person. No title to or ownership of the software is |
|
35 |
hereby transferred. |
|
36 |
" |
|
37 |
! |
|
38 |
||
3561 | 39 |
documentation |
40 |
" |
|
3635 | 41 |
I am an ordered collection which automatically resizes if elements |
3561 | 42 |
are added beyond the size. |
4134 | 43 |
I.e. if #at:put: is sent for indexes > the current size, the receiver grows to |
3561 | 44 |
the required index and missing fields are implicitly filled with nils. |
3698 | 45 |
Queries for non-existing elements are anwered with nil. |
4134 | 46 |
|
47 |
[see also:] |
|
48 |
OrderedCollection |
|
49 |
Array |
|
50 |
SparseArray |
|
3561 | 51 |
" |
52 |
! |
|
53 |
||
54 |
examples |
|
55 |
" |
|
56 |
|coll| |
|
57 |
||
58 |
coll := AutoResizingOrderedCollection new. |
|
59 |
coll at:4 put:'four'. |
|
60 |
coll at:8 put:'eight'. |
|
3571
968420ff1815
class: AutoResizingOrderedCollection
Claus Gittinger <cg@exept.de>
parents:
3570
diff
changeset
|
61 |
coll at:9 |
3561 | 62 |
" |
63 |
! ! |
|
64 |
||
3700
02b6eebda3de
class: AutoResizingOrderedCollection
Claus Gittinger <cg@exept.de>
parents:
3698
diff
changeset
|
65 |
!AutoResizingOrderedCollection class methodsFor:'instance creation'! |
02b6eebda3de
class: AutoResizingOrderedCollection
Claus Gittinger <cg@exept.de>
parents:
3698
diff
changeset
|
66 |
|
02b6eebda3de
class: AutoResizingOrderedCollection
Claus Gittinger <cg@exept.de>
parents:
3698
diff
changeset
|
67 |
newWithDefaultValue:defaultValue |
02b6eebda3de
class: AutoResizingOrderedCollection
Claus Gittinger <cg@exept.de>
parents:
3698
diff
changeset
|
68 |
^ AutoResizingOrderedCollectionWithDefault new setDefaultValue:defaultValue |
02b6eebda3de
class: AutoResizingOrderedCollection
Claus Gittinger <cg@exept.de>
parents:
3698
diff
changeset
|
69 |
! ! |
02b6eebda3de
class: AutoResizingOrderedCollection
Claus Gittinger <cg@exept.de>
parents:
3698
diff
changeset
|
70 |
|
3561 | 71 |
!AutoResizingOrderedCollection methodsFor:'accessing'! |
72 |
||
3570
5e8a9a8cbb3d
class: AutoResizingOrderedCollection
Claus Gittinger <cg@exept.de>
parents:
3561
diff
changeset
|
73 |
at:index |
5e8a9a8cbb3d
class: AutoResizingOrderedCollection
Claus Gittinger <cg@exept.de>
parents:
3561
diff
changeset
|
74 |
"fetch an object at index. |
5e8a9a8cbb3d
class: AutoResizingOrderedCollection
Claus Gittinger <cg@exept.de>
parents:
3561
diff
changeset
|
75 |
If index is beyond the actual size, return nil |
5e8a9a8cbb3d
class: AutoResizingOrderedCollection
Claus Gittinger <cg@exept.de>
parents:
3561
diff
changeset
|
76 |
(i.e. this is an alias for at:index ifAbsent:[nil])" |
5e8a9a8cbb3d
class: AutoResizingOrderedCollection
Claus Gittinger <cg@exept.de>
parents:
3561
diff
changeset
|
77 |
|
5e8a9a8cbb3d
class: AutoResizingOrderedCollection
Claus Gittinger <cg@exept.de>
parents:
3561
diff
changeset
|
78 |
index > self size ifTrue:[^ nil]. |
5e8a9a8cbb3d
class: AutoResizingOrderedCollection
Claus Gittinger <cg@exept.de>
parents:
3561
diff
changeset
|
79 |
^ super at:index |
5e8a9a8cbb3d
class: AutoResizingOrderedCollection
Claus Gittinger <cg@exept.de>
parents:
3561
diff
changeset
|
80 |
! |
5e8a9a8cbb3d
class: AutoResizingOrderedCollection
Claus Gittinger <cg@exept.de>
parents:
3561
diff
changeset
|
81 |
|
3561 | 82 |
at:index put:anObject |
3570
5e8a9a8cbb3d
class: AutoResizingOrderedCollection
Claus Gittinger <cg@exept.de>
parents:
3561
diff
changeset
|
83 |
"store an object at index. |
5e8a9a8cbb3d
class: AutoResizingOrderedCollection
Claus Gittinger <cg@exept.de>
parents:
3561
diff
changeset
|
84 |
If required, grow the receiver to ensure that index is valid" |
5e8a9a8cbb3d
class: AutoResizingOrderedCollection
Claus Gittinger <cg@exept.de>
parents:
3561
diff
changeset
|
85 |
|
3561 | 86 |
index > self size ifTrue:[ |
87 |
self grow:index. |
|
88 |
]. |
|
89 |
super at:index put:anObject |
|
90 |
! ! |
|
91 |
||
92 |
!AutoResizingOrderedCollection class methodsFor:'documentation'! |
|
93 |
||
94 |
version |
|
95 |
^ '$Header$' |
|
96 |
! |
|
97 |
||
98 |
version_CVS |
|
99 |
^ '$Header$' |
|
100 |
! ! |
|
101 |