summaryrefslogtreecommitdiff
path: root/src/partitions.erl
diff options
context:
space:
mode:
authorAdam Kocoloski <adam@cloudant.com>2010-06-10 09:45:28 -0400
committerAdam Kocoloski <adam@cloudant.com>2010-08-12 00:59:45 -0400
commit4928ce68b31b7fd5ce3fcf1d4ebc4a786fd045eb (patch)
tree8318184addde439d0bb30162b560df83249258eb /src/partitions.erl
parent67ddab6a918f1844ec5d15ac5613f70ef763c356 (diff)
remove hash_int(), just convert hash() to int inline
Diffstat (limited to 'src/partitions.erl')
-rw-r--r--src/partitions.erl13
1 files changed, 2 insertions, 11 deletions
diff --git a/src/partitions.erl b/src/partitions.erl
index cfc1d90b..0a20d195 100644
--- a/src/partitions.erl
+++ b/src/partitions.erl
@@ -45,7 +45,7 @@ install_fullmap(DbName, Fullmap, FullNodes, Options) ->
write_db_doc(Doc).
for_key(DbName, Key) ->
- HashKey = hash_int(hash(Key)),
+ <<HashKey:160/integer>> = hash(Key),
Head = #shard{
name = '_',
node = '_',
@@ -88,8 +88,7 @@ const(Const, Options) ->
%% @doc hash the dbname, and return the corresponding node for seeding a ring
seednode(DbName, Nodes) ->
- Hash = hash(DbName),
- HashInt = hash_int(Hash),
+ <<HashInt:160/integer>> = hash(DbName),
Size = partition_range(length(Nodes)),
Factor = (HashInt div Size),
lists:nth(Factor+1, Nodes).
@@ -139,14 +138,6 @@ partners(DbName, N, Node, Nodes, {Beg,End}) ->
name=shard_name(Beg,DbName)}
end, Partners).
-
-%% @doc turn hash into an integer
-hash_int(Hash) when is_binary(Hash) ->
- <<IndexAsInt:160/integer>> = Hash,
- IndexAsInt;
-hash_int(Hash) when is_integer(Hash) ->
- Hash.
-
%% @doc size of one partition in the ring
partition_range(Q) ->
trunc( ?RINGTOP / Q ). % SHA-1 space / Q