iilyak commented on a change in pull request #3766:
URL: https://github.com/apache/couchdb/pull/3766#discussion_r727011634



##########
File path: src/smoosh/src/smoosh_priority_queue.erl
##########
@@ -73,14 +109,56 @@ info(#priority_queue{tree=Tree}=Q) ->
              [{min, Min}, {max, Max}]
      end].
 
+from_list(Capacity, List, Q) ->
+    lists:foldr(fun({TreeKey, {Key, Value}}, Queue) ->
+        insert(Key, Value, TreeKey, Capacity, Queue)
+    end, Q, List).
+
+to_list(#priority_queue{tree=Tree}) ->
+    gb_trees:to_list(Tree).
+
+file_name(#priority_queue{name=Name}) ->
+    filename:join(".", Name ++ ".queue").
+
 truncate(infinity, Q) ->
     Q;
 truncate(Capacity, Q) when Capacity > 0 ->
     truncate(Capacity, ?MODULE:size(Q), Q).
 
 truncate(Capacity, Size, Q) when Size =< Capacity ->
     Q;
-truncate(Capacity, Size, #priority_queue{dict=Dict, tree=Tree}) when Size > 0 
->
+truncate(Capacity, Size, #priority_queue{name=Name, map=Map, tree=Tree}) when 
Size > 0 ->
     {_, {Key, _}, Tree1} = gb_trees:take_smallest(Tree),
-    Q1 = #priority_queue{dict=dict:erase(Key, Dict), tree=Tree1},
+    Q1 = #priority_queue{name=Name, map=maps:remove(Key, Map), tree=Tree1},
     truncate(Capacity, ?MODULE:size(Q1), Q1).
+
+insert(Key, Value, TreeKey, Capacity, #priority_queue{name=Name, map=Map, 
tree=Tree} = Q) ->
+    Tree1 = case maps:find(Key, Map) of
+        [OldTreeKey] ->
+            gb_trees:delete_any(OldTreeKey, Tree);
+        _ ->
+            Tree
+    end,
+    Tree2 = gb_trees:enter(TreeKey, {Key, Value}, Tree1),
+    Map2 = maps:put(Key, {TreeKey, Value}, Map),
+    truncate(Capacity, Q#priority_queue{name=Name, map=Map2, tree=Tree2}).
+
+do_open(FilePath) ->
+    case file:read_file(FilePath) of
+        {ok, Content} ->

Review comment:
       I think you forgot about VSN byte in front of a binary.




-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


Reply via email to