Does MagmaCollection preserve order, so that standard collection methods will always go through objects in the order of original insertion?
While doing some tests for that I ran into "Instances of MagmaCollection are not indexable" while using at: at: index "Primitive. Assumes receiver is indexable. Answer the value of an indexable element in the receiver. Fail if the argument index is not an Integer or is out of bounds. Essential. See Object documentation whatIsAPrimitive."
<primitive: 60> index isInteger ifTrue: [self class isVariable ifTrue: [self errorSubscriptBounds: index] ifFalse: [self errorNotIndexable]]. index isNumber ifTrue: [^self at: index asInteger] ifFalse: [self errorNonIntegerIndex]
The test was |c| c := MagmaCollection new. c add: 1; add: 2; add: 3. c do: [:x | Transcript show: x]. Transcript cr. c remove: 2. c do: [:x | Transcript show: x]. Transcript cr. c add: 4. c do: [:x | Transcript show: x]. Transcript cr. Transcript show: (c at: 2); cr.
and the error was in the last line. BTW, 4 did appear after 3 in the printout, not in the hole created from removing 2. So it looks as if insertion order is preserved. I did NOT have a magma session open when I ran the test.
I was expecting at: to work since http://wiki.squeak.org/squeak/2639 says that MagmaCollection "Provides size and absolute position access (at: anInteger) making it suitable for scrolling lists".
Finally, is it advisable to use the standard collection methods if the MagmaCollection is large, or is it better to use a reader? By "better" I am mostly thinking of whether the entire collection is forced into memory or not. Since the standard collection methods return a "self species", which is a Bag, I'm guessing it's better to use a reader.
Thanks. Ross Boylan
Hi Ross,
Does MagmaCollection preserve order, so that standard collection methods will always go through objects in the order of original insertion?
No. The order of enumeration in a MagmaCollection is based on the age of the objects; e.g., the order they were ever persisted in the db (whether part of that MagmaCollection or not).
While doing some tests for that I ran into "Instances of MagmaCollection are not indexable" while using at:
Yep. They are not indexable.
I was expecting at: to work since http://wiki.squeak.org/squeak/2639 says that MagmaCollection "Provides size and absolute position access (at: anInteger) making it suitable for scrolling lists".
It does. What you want to do is described starting under the "Indexes" section.
Finally, is it advisable to use the standard collection methods if the MagmaCollection is large, or is it better to use a reader?
A Reader. A Reader utilizes the indexing to quickly chop a MagmaCollection down into a subset accessible by #at:. Only from there, and only if absolutely necessary, would you use the standard collectoin methods.
By "better" I am mostly thinking of whether the entire collection is forced into memory or not.
Don't use the standard Collection api on a large MagmaCollection except for a batch operation. For on-line operation, just on a MagmaCollectionReader which was obtained from sending a constricting #where: query.
- Chris
magma@lists.squeakfoundation.org