smalltalk: Collection class |
back |
| Collection | Ordered | Fixed Size | Duplicates | Keys | Element Class | Laufzeitvorteil ° |
| Bag | No | No | Yes | None | any | |
| IndexedCollection* | Yes | N.A. | N.A. | Integer | N.A. | |
| FixedSizeCollection* | Yes | Yes | N.A. | Integer | N.A. | |
| Array | Yes | Yes | Yes | Integer | any | Ja |
| ByteArray | Yes | Yes | Yes | Integer | SmallInteger | |
| Interval | Internal | Yes | No | Integer | Number | |
| String | Yes | Yes | Yes | Integer | Character | |
| Symbol | Yes | Yes | Yes | Integer | Character | |
| OrderedCollection | Yes | No | Yes | Integer | any | |
| SortedCollection | Internal | No | Yes | Integer | any | |
| Set | No | No | No | None | any | |
| Dictionary | No | No | No | Lookup | any | |
| IdentityDictionary | No | No | No | Lookup | any | Ja |
Notes:
* -- abstract classes, there are no instances
Internal -- ordered by the internal contents of the collection
N.A. -- not applicable (determined by subclasses)
Because the various collection classes have different attributes, being able to convert from one kind of collection to another
is useful. Smalltalk/V provides the following conversion protocol in class Collection.
Methods Comments
| asArray | Ordering is possibly arbitrary. (arbitrary=willkürlich °) |
| asBag | Duplicates are kept. |
| asSet | Duplicates are eliminated. |
| asOrderedCollection | Ordering is possibly arbitrary. |
| asSortedCollection | Each element is <= its successor. |
| asSortedCollection: sortBlock | Ordering is specified by sortBlock |
Thus any collection can be converted into an Array, a Bag, a Set, an OrderedCollection, or a SortedCollection.
Source: Smalltalk/V Tutorial and Programming Handbook, 1991
° -- Items added by mr, Jan. 13, 1999