[erlang-patches] [PATCH] - Add NIF function enif_phash2

Fredrik fredrik@REDACTED
Mon Feb 11 10:23:38 CET 2013


On 02/08/2013 09:19 PM, Paul Davis wrote:
> Fredrik,
>
> Rebased against master:
>
> git fetch git://github.com/davisp/otp.git enif_phash2
>
> https://github.com/davisp/otp/compare/master...enif_phash2
> https://github.com/davisp/otp/compare/master...enif_phash2.patch
>
> Sverker,
>
> I've updated the function ordering as per the comment in
> erl_nif_api_funcs.h. For use case, I'm implementing a couple data
> structures that use hash tables to speed up some hot loops. I can get
> away for awhile using erlang:phash2/2 in Erlang and passing that value
> into the NIF but this breaks down when I don't know a priori which
> terms (or subterms) I may need to hash in the NIF.
>
> A similar example would be trying to reimplement ets without this.
> Either I'd have to store enough information in the Erlang term
> representing the table to be able to know which elements of the tuple
> to hash or I'd have to ask the table what to hash before passing the
> term off to the NIF. There are definitely work arounds to not having
> access to phash2 but they aren't pretty.
>
> Thanks,
> Paul Davis
>
> On Fri, Feb 8, 2013 at 7:39 AM, Sverker Eriksson
> <sverker.eriksson@REDACTED>  wrote:
>> Fredrik wrote:
>>> On 02/08/2013 12:58 AM, Paul Davis wrote:
>>>> git fetch git://github.com/davisp/otp.git enif_phash2
>>>>
>>>> https://github.com/davisp/otp/compare/maint...enif_phash2
>>>> https://github.com/davisp/otp/compare/maint...enif_phash2.patch
>>>>
>>>> This patch exposes the phash2 function to NIFs. It is exactly equivalent
>>>> to:
>>>>
>>>> erlang:phash2(Term, 16#100000000)
>>>>
>>>> Thanks,
>>>> Paul Davis
>>>> _______________________________________________
>>>> erlang-patches mailing list
>>>> erlang-patches@REDACTED
>>>> http://erlang.org/mailman/listinfo/erlang-patches
>>> Please rebase this patch upon the current 'master' branch.
>>> Thanks,
>>>
>> Also read the comments in erl_nif_api_funcs.h of how to add new functions.
>> You do not have to increase ERL_NIF_MINOR_VERSION as I've already done that
>> for R16B.
>>
>> I guess you have a real use case for enif_phash2 and why erlang:phash2 is
>> not enough.
>>
>> /Sverker
Re-fetched. Currently cooking in the 'master-pu' branch.
Thanks,

-- 

BR Fredrik Gustafsson
Erlang OTP Team




More information about the erlang-patches mailing list