swarm-support
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Problems with maps


From: Marcus G. Daniels
Subject: Re: Problems with maps
Date: 14 Jun 1999 08:41:42 -0700
User-agent: Gnus/5.070084 (Pterodactyl Gnus v0.84) Emacs/20.3.10

>>>>> "PU" == Paulo Urbano <address@hidden> writes:

PU> I would like a map where the keys were integers and the values
PU> were floats!!

The problem is that some methods, like forEach: will not work on this
kind of Map, and serialization will break.

We have considered adding a `MemberType' protocol that would like
users specify a primitive type for collection types, i.e. disabling
methods like forEach: and adding extra cases for serializing the sundry
primitive types.

Besides being a hassle to implement, my problem with this is that
different languages provide different primitive types, and different
platforms represent these primitive types in different ways; on some
platforms you could hide a float bit pattern within an int variable, which
you could then hide in an id, on other platforms -- no way. 

In the long run, I think MemberType is the sort of feature that causes pain
for everyone.

Probably what you ran into was the problem of casting between float's and
id's.  To sidestep that, you have to do some abuse with pointers, e.g.

    int ival;
    float fval;

    fval = 3.5;
    memcpy (&ival, &fval, sizeof (ival));
    [m at: (id) 1 insert: (id) ival];

    ival = (int) [m at: (id) 0];
    memcpy (&fval, &ival, sizeof (ival));
    printf ("%f\n", fval);

I hope this is ugly enough (not to mention fragile), to convince you
to give up on the idea of using floats as Map values. 

I suggest you make a wrapper object.


                  ==================================
   Swarm-Support is for discussion of the technical details of the day
   to day usage of Swarm.  For list administration needs (esp.
   [un]subscribing), please send a message to <address@hidden>
   with "help" in the body of the message.



reply via email to

[Prev in Thread] Current Thread [Next in Thread]