From 2f9afa14695063d5e15366c5d213b7abd9df1b72 Mon Sep 17 00:00:00 2001 From: Martin Sumner Date: Tue, 26 Sep 2017 16:32:59 +0100 Subject: [PATCH] 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. --- src/leveled_codec.erl | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/leveled_codec.erl b/src/leveled_codec.erl index 9ed2a2c..1f6d6cc 100644 --- a/src/leveled_codec.erl +++ b/src/leveled_codec.erl @@ -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;