[squeak-dev] Question about the Heap class.

Brett Kosinski fancypantalons at gmail.com
Thu Apr 3 17:36:24 UTC 2008


This might just belong on the newbies list, but... I'm looking at
using a Heap for a primarily read-only, sorted set of some objects.
Now, just to prefix this, I'm assuming the Heap is largely equivalent
to the SortedCollection, in that it's intended to keep it's items in
sorted order as they're added, and that accessing those items using
the #at: selector will retrieve them in their sorted positions.

So, that said, I have the following little code snippet:

h := Heap new sortBlock: [ : a : b | a <= b ].  "Just to be explicit"
r := Random new.

1 to: 10 do: [ : i | h add: (r nextInt: 1000000) ].

h do: [ : i | Transcript show: i; cr ].

Here's some example output:

90436
692737
206478
849361
825757
704772
262508
999388
971421
956498

It ain't sorted.  So... thoughts? :)

Brett.



More information about the Squeak-dev mailing list