[Q]uestions regarding collections

Raymond Tiefenthal r.tiefenthal at gmx.de
Sat Aug 18 19:59:35 UTC 2001


Hi,

I'm a weekend hacker and curious about a few things:

1. Searching in collections
Both, # indexOf: and # lastIndexOf: take an element as argument and return
an index.
Both, # findFirst: and # findLast: take a block as argument and return an
index too.
# detect: takes a block and returns an element.
I wondered why there isn't a # detectLast: counterpart. I would expect it in
SequenceableCollection and since # detect: in class Collection depends on
the order of # do:, I would expect it to depend on # reverseDo:.

2. Could you explain why I would want to use class Array instead of a
OrderedCollection for instance. I understand that ByteArray, IntegerArray
etc. don't have objects as elements and therefore are less costly in terms
of memory and speed. But Array has normal objects as elements. When should
do I want to use Array?

3. I was asking myself, why SortedCollection doesn't overwrite # indexOf:
for instance, in order to perform a binary search.

4. How to figure the memory usage of an object?

Btw., Recently I had fun, messing with prime number search and I figured
that my "sieve of erasthostenes" algorithm (tight loop, only adding and
memory assignments) was only 10x slower in Squeak then it was in C. I would
have guessed something like 50x or 100x :) for some reason. Accoding to
moores law, thats only 3-4 years worth of cpu power, hehe.






More information about the Squeak-dev mailing list