in reply to Re^2: Fastest way to lookup a point in a set
in thread Fastest way to lookup a point in a set

> they turned out to be slower than join.

Interesting, I think that's because you address the points separately in multi (2 lookups) while join can optimize over an array (one list returned)

Maybe try to see how it compares with join over 2 elements.

I wouldn't be surprised if the result is equally fast. Multi dimensional hashes are an old (Perl 4) but somehow obscure feature. They probably never optimized it over the equivalence to join.

Cheers Rolf
(addicted to the Perl Programming Language and ☆☆☆☆ :)
Je suis Charlie!

  • Comment on Re^3: Fastest way to lookup a point in a set

Replies are listed 'Best First'.
Re^4: Fastest way to lookup a point in a set
by swl (Prior) on Aug 07, 2017 at 09:19 UTC

    There is also the issue of locales and the radix char when non-integer values are used with multidimensional hash keys.

    If one has coordinates

    [5, 5.5] [5.5, 5 ]
    then using the multidimensional hash approach in a locale where both $; and the radix char are a comma would result in ambiguous keys:
    {5,5,5} {5,5,5}

    I know the original post specifies signed ints, so I'm just being more generic here. I also haven't checked if there is locale specific behaviour of $;

      From the docs: The default subscript separator is "\034", the same as SUBSEP in awk

      It's not "," , that's just the placeholder in Perl's syntax.

      I don't know and can't think of any number format or localization which uses chr(28) .

      Printable characters start from chr(32) onwards.

      update

      to avoid confusion

      hex, oct, dez

      perl -e "print 0x1c,034,28" 282828

      Cheers Rolf
      (addicted to the Perl Programming Language and ☆☆☆☆ :)
      Je suis Charlie!

        Thanks for clarifying.

        Here are some more examples for those reading later and who haven't previously had to work with non-printing characters in this way (e.g. me a few hours ago):

        # default $; does not print perl -e 'print join $;, 1..5' 12345 # but $; is still in the string perl -e '@x = split ($;, join ($;, 1..5)); print join ":", @x' 1:2:3:4:5

        That still does leave the issue of debugging using print statements, as [5,55] and [55,5] will both print as 555 on a terminal. The point is effectively moot, though, as the other posts have shown multidimensional indexing is slower and should probably not be used in this case.