Add support for performing a magic hash on a binary

Ignore unnecessray term_to_binary if already binary.  This will be useful when we use magic_hash in tictac_trees we wish to be exportable.
This commit is contained in:
Martin Sumner 2017-09-26 16:32:59 +01:00
parent f50a2a19d3
commit 2f9afa1469

View file

@ -87,10 +87,12 @@ magic_hash({?RIAK_TAG, Bucket, Key, _SubKey}) ->
magic_hash({Bucket, Key});
magic_hash({?STD_TAG, Bucket, Key, _SubKey}) ->
magic_hash({Bucket, Key});
magic_hash({binary, BinaryKey}) ->
H = 5381,
hash1(H, BinaryKey) band 16#FFFFFFFF;
magic_hash(AnyKey) ->
BK = term_to_binary(AnyKey),
H = 5381,
hash1(H, BK) band 16#FFFFFFFF.
magic_hash({binary, BK}).
hash1(H, <<>>) ->
H;