MarkingKey

Niko Schwarz niko.schwarz at gmx.net
Tue Jun 11 11:52:45 UTC 2002


-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Am Dienstag, 11. Juni 2002 11:20 schrieb Hans-Martin Mosner:

> > I do not want one to toggle the flag, cos for that i have another method.
>
> ??? If you don't want a method to toggle the flag, then don't write one.
> Whhere is the problem? :-)

A method called smallest could have 2 meanings.
a) turn the object to be the smallest
b) tell if the object is the smallest.

in ruby, a would be "smallest!" and b) would be "smallest?"
is there smth like this in smalltalk? what do you do in such cases?

[what do you need sentinels for?]

Hmm, Insertion Sort would be a good example, as Insertion Sort is a part of 
many advanced sorting algorithms.

var a: array[0..N] of integer;

procedure init;
          var i:integer;
          begin
               a[0]:=0;
               for i:=1 to N do
                   a[i] := trunc(random * N)
          end;

procedure insertion;
          var i, j, v: integer;
          begin
          for i:=1 to N do
              begin
              v:=a[i]; j:=i;
              while v < a[j-1] do
                   begin a[j]:=a[j-1]; j:=j-1; end
              end;
              a[j]:=v
          end;

The trick is in the a[0]:=0

If I had not done that, I'd need to check for j<= 0, which would make the 
implementation significantly slower.

I don't think modifiying at: put: and so on is a serious option, as they're 
the very heart of these algorithms, modifying them would probably cost a lot 
of performance. Once for calculating index+1, and then the overhead of the 
method call would be serious, cos i found out that at: index is a primitive, 
which is inlined.

regards,

nick
- -- 
Everyone can be taught to sculpt: Michelangelo would have had to be
taught how ___not to.  So it is with the great programmers.
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.0.6 (GNU/Linux)
Comment: For info see http://www.gnupg.org

iD8DBQE9BeSQc9uyCiO8RNQRAr9YAJ4slSqIhQoAjocIEomI1Qr53Nv0KwCdHMwq
+VMyetcrkbpSHGoqULhi+hU=
=8a8e
-----END PGP SIGNATURE-----




More information about the Squeak-dev mailing list