summaryrefslogtreecommitdiff
path: root/src/lqueue.erl
diff options
context:
space:
mode:
authorkjnilsson <knilsson@pivotal.io>2018-12-07 15:28:26 +0000
committerkjnilsson <knilsson@pivotal.io>2018-12-07 15:50:09 +0000
commit4fa8cc8678519bb2a618fff670b761858a2f3807 (patch)
treedd8b669f7c16fd0f56cf2c41dc23e37921da4caf /src/lqueue.erl
parentdef0a53d821e7c99a9b59c89e9bbcf1baf23f594 (diff)
downloadrabbitmq-server-git-4fa8cc8678519bb2a618fff670b761858a2f3807.tar.gz
Add rabbit_fifo snapshot property test
And fix various subtle bugs around snapshotting.
Diffstat (limited to 'src/lqueue.erl')
-rw-r--r--src/lqueue.erl8
1 files changed, 6 insertions, 2 deletions
diff --git a/src/lqueue.erl b/src/lqueue.erl
index 0652061075..1abe4e0b82 100644
--- a/src/lqueue.erl
+++ b/src/lqueue.erl
@@ -21,7 +21,7 @@
%% is an O(1) operation, in contrast with queue:len/1 which is O(n).
-export([new/0, is_empty/1, len/1, in/2, in_r/2, out/1, out_r/1, join/2,
- foldl/3, foldr/3, from_list/1, to_list/1, peek/1, peek_r/1]).
+ foldl/3, foldr/3, from_list/1, drop/1, to_list/1, peek/1, peek_r/1]).
-define(QUEUE, queue).
@@ -32,6 +32,7 @@
-type result() :: 'empty' | {'value', value()}.
-spec new() -> ?MODULE().
+-spec drop(?MODULE()) -> ?MODULE().
-spec is_empty(?MODULE()) -> boolean().
-spec len(?MODULE()) -> non_neg_integer().
-spec in(value(), ?MODULE()) -> ?MODULE().
@@ -48,6 +49,8 @@
new() -> {0, ?QUEUE:new()}.
+drop({L, Q}) -> {L - 1, ?QUEUE:drop(Q)}.
+
is_empty({0, _Q}) -> true;
is_empty(_) -> false.
@@ -81,7 +84,8 @@ foldr(Fun, Init, Q) ->
{{value, V}, Q1} -> foldr(Fun, Fun(V, Init), Q1)
end.
-len({L, _Q}) -> L.
+len({L, _}) -> L.
+
peek({ 0, _Q}) -> empty;
peek({_L, Q}) -> ?QUEUE:peek(Q).