hashtree 0.0.3 → 0.0.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/lib/hashtree/version.rb +1 -1
- data/lib/hashtree.rb +4 -4
- metadata +1 -1
data/lib/hashtree/version.rb
CHANGED
data/lib/hashtree.rb
CHANGED
@@ -101,7 +101,7 @@ class HashTree
|
|
101
101
|
def get_branch_id(key)
|
102
102
|
id = @index[key]
|
103
103
|
if id
|
104
|
-
branch_id = id[0..
|
104
|
+
branch_id = id[0..31]
|
105
105
|
else
|
106
106
|
nil
|
107
107
|
end
|
@@ -109,7 +109,7 @@ class HashTree
|
|
109
109
|
|
110
110
|
# Private API
|
111
111
|
def translate_id(id)
|
112
|
-
branch_id, leaf_id = id[0..
|
112
|
+
branch_id, leaf_id = id[0..31], id[33..64]
|
113
113
|
return branch_id, leaf_id
|
114
114
|
end
|
115
115
|
|
@@ -128,13 +128,13 @@ class HashTree
|
|
128
128
|
def create(key, value)
|
129
129
|
free_branch_id = @branches[:free].keys.sample
|
130
130
|
if free_branch_id
|
131
|
-
leaf_id = Digest::
|
131
|
+
leaf_id = Digest::SHA2.hexdigest(SecureRandom.uuid)[0..31]
|
132
132
|
@index[key] = free_branch_id + leaf_id
|
133
133
|
branch = @branches[free_branch_id]
|
134
134
|
branch[leaf_id] = value
|
135
135
|
@branches[:free].delete(branch_id) if branch.size >= @settings[:max_branch_size]
|
136
136
|
else
|
137
|
-
id = Digest::
|
137
|
+
id = Digest::SHA2.hexdigest(SecureRandom.uuid)
|
138
138
|
@index[key] = id
|
139
139
|
branch_id, leaf_id = translate_id(id)
|
140
140
|
branch = { leaf_id => value }
|