Beefy Boxes and Bandwidth Generously Provided by pair Networks
We don't bite newbies here... much
 
PerlMonks  

Re: Unsigned 64-bit integer as Judy key

by bliako (Monsignor)
on Dec 07, 2022 at 08:27 UTC ( [id://11148645]=note: print w/replies, xml ) Need Help??


in reply to Unsigned 64-bit integer as Judy key

How was your perl compiled?: perl -V:ivsize

It could well be that this has nothing to do with Judy but that for your Perl, 1<<63 overflows and becomes negative which Judy then receives it and complains.

Also, from Judy source, Set() accepts a key as UWord_t which is T_UWORD which is:

T_UWORD /* Accept: - IV that's -1. - IV that's negative, coerce to 0 and warn. - IV/UV that fits in (unsigned long int) - IV/UV that requires more bits than fit in (unsigned long int). Truncate it and throw a warning. - Cast everything else to UV and apply the above rules */ ...

(edit: https://metacpan.org/release/JJORE/Judy-0.41/source/lib/Judy.xs and https://metacpan.org/release/JJORE/Judy-0.41/source/typemap)

edit: IV: integer value, UV: unsigned valued. In my system with ivsize=8, perl -e 'print 1<<63' outputs 9223372036854775808, do you get the same?

bw, bliako

Replies are listed 'Best First'.
Re^2: Unsigned 64-bit integer as Judy key
by Anonymous Monk on Dec 07, 2022 at 14:16 UTC

    Thanks everyone for answers.

    https://metacpan.org/release/JJORE/Judy-0.41/source/typemap

    oh, but that explains it all. The argument is treated by default and by design as signed IV. Which is a bug in Perl Judy distribution, as very strange as it is. I understand it is "0-dot-something" version, but it's strange and sad this wasn't noticed in 10 years. Conditionals starting from line #88 should first check if $arg is an UV.

    For example:

    >perl -MDevel::Peek -E "Dump 1<<63" SV = IV(0x3e42b48) at 0x3e42b58 REFCNT = 1 FLAGS = (PADTMP,IOK,READONLY,PROTECT,pIOK,IsUV) UV = 9223372036854775808

    How can I check for IsUV flag in XS? Can't find it in perlguts. Hopefully, this easy fix in typemap file won't break anything else.

      so I changed that line #88 to

      if ( !SvIsUV($arg) && SvIOK($arg) && SvIV($arg) < 0 ) {

      now Judy installs OK with its tests, and a test I posted in OP passes OK. Actually, it's all about 11148465 meditation; I knew Judy technology is amazing and just wanted to check this yet again. With latest llil2d.pl I get

      llil2d start get_properties : 10 secs sort + output : 21 secs total : 31 secs

      and 2263M of htop's RES, with my Judy script:

      my_test start get_properties: 16 secs sort + output: 21 secs total: 37 secs

      and 378M of htop's RES. And like I said (in my plan outline there) "words" are not stored in RAM (suppose they are long strings) but read again while writing output, hence relatively long time in 2nd row with almost instantaneous sort by Sort::Packed. I'll post to that thread later.

        I suspect that the changes doesn't make it stop considering 9223372036854775808 equal to -9223372036854775808.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://11148645]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others admiring the Monastery: (5)
As of 2024-04-19 14:42 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found