Charles Greathouse on Wed, 07 Nov 2012 17:03:01 +0100


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

Re: sseraching in dynamic list


While you're reformatting, I would not use return() in the final line of a function: rather put the return value. So I would replace
return([setunion(m[1],[k]), m[2]]);
with
[setunion(m[1],[k]), m[2]]

I wouldn't write
error("e_MAPGET");
either; that makes it look like one of the PARI error classes, but if you were able to send a PARI error it would be something like e_DOMAIN. Error classes aren't named after functions.

Finally I would use my() rather than local(); lexical scoping is better than dynamic scoping for almost all purposes. See section 2.6, especially the final paragraph:

We strongly recommended to explicitly scope (lexically) all variables to the smallest possible
block. Should you forget this, in expressions involving such \rogue" variables, the value used will
be the one which happens to be on top of the value stack at the time of the call; which depends on
the whole calling context in a non-trivial way. This is in general not what you want.


Charles Greathouse
Analyst/Programmer
Case Western Reserve University


On Wed, Nov 7, 2012 at 9:26 AM, Mathieu Carbou <mathieu.carbou@gmail.com> wrote:
Hi,

Really thank you! It works fine. I reformated a little.

Mathieu.


On 06-Nov-2012 15:30, Max Alekseyev wrote:
> Mathieu,
> Please find my implementation of hashmap attached. I'd be glad you
> find it helpful.
> Regards,
> Max
>
> I've implemented hashmap
>
> On Sun, Nov 4, 2012 at 4:20 PM, Mathieu Carbou <mathieu.carbou@gmail.com> wrote:
>> Hello,
>>
>> I have a case where I need to put key-value items in a dynamic sorted
>> list and then search into:
>>
>> l=List()
>> listput([2,4])
>> listput([1,7])
>> listput([0,3])
>> listsort(l)
>> setsearch(l, ...)
>>
>> The issue is that only vecsearch takes a cmpf function, not setsearch.
>>
>> Is it possible to add it, or to indicate me a better way to do this  ?
>>
>> Actually I'd like to simulate a HashMap, where the key is unique and the
>> value can be anything. In my case, the sorting is not necessary, but
>> since PARI has no Map, I think I need to use the sort feature of lists
>> to be able to search back in them.
>>
>> Thank you.
>>
>> --
>>
>> Mathieu Carbou
>> Cell: 514-660-4287
>>
>>


--

Mathieu Carbou
Cell: 514-660-4287