summaryrefslogtreecommitdiff
path: root/src/lqueue.erl
diff options
context:
space:
mode:
authorMatthew Sackman <matthew@rabbitmq.com>2011-10-02 14:53:31 +0100
committerMatthew Sackman <matthew@rabbitmq.com>2011-10-02 14:53:31 +0100
commit542644446675a7392ab30667b140ab3145bf95c2 (patch)
tree6238b9cc4550f1d8a0aa2a9de65d7ebf3d729488 /src/lqueue.erl
parentb6bea063ea878259f0e7eba95aeeed3cb8773da7 (diff)
downloadrabbitmq-server-git-542644446675a7392ab30667b140ab3145bf95c2.tar.gz
Avoid lots of combine_delta calls
Diffstat (limited to 'src/lqueue.erl')
-rw-r--r--src/lqueue.erl42
1 files changed, 31 insertions, 11 deletions
diff --git a/src/lqueue.erl b/src/lqueue.erl
index 8bbd52d9fc..ea54ffd4b9 100644
--- a/src/lqueue.erl
+++ b/src/lqueue.erl
@@ -1,17 +1,33 @@
+%% The contents of this file are subject to the Mozilla Public License
+%% Version 1.1 (the "License"); you may not use this file except in
+%% compliance with the License. You may obtain a copy of the License
+%% at http://www.mozilla.org/MPL/
+%%
+%% Software distributed under the License is distributed on an "AS IS"
+%% basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See
+%% the License for the specific language governing rights and
+%% limitations under the License.
+%%
+%% The Original Code is RabbitMQ.
+%%
+%% The Initial Developer of the Original Code is VMware, Inc.
+%% Copyright (c) 2011-2011 VMware, Inc. All rights reserved.
+%%
+
-module(lqueue).
--compile([export_all]).
+-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]).
-define(QUEUE, queue).
new() -> {0, ?QUEUE:new()}.
-is_empty({0, _Q}) ->
- true;
-is_empty(_) ->
- false.
+is_empty({0, _Q}) -> true;
+is_empty(_) -> false.
in(V, {L, Q}) -> {L+1, ?QUEUE:in(V, Q)}.
+
in_r(V, {L, Q}) -> {L+1, ?QUEUE:in_r(V, Q)}.
out({0, _Q} = Q) ->
@@ -29,16 +45,20 @@ out_r({L, Q}) ->
join({L1, Q1}, {L2, Q2}) ->
{L1 + L2, ?QUEUE:join(Q1, Q2)}.
-to_list({_L, Q}) ->
- ?QUEUE:to_list(Q).
+to_list({_L, Q}) -> ?QUEUE:to_list(Q).
-from_list(L) ->
- {length(L), ?QUEUE:from_list(L)}.
+from_list(L) -> {length(L), ?QUEUE:from_list(L)}.
-queue_fold(Fun, Init, Q) ->
+foldl(Fun, Init, Q) ->
case out(Q) of
{empty, _Q} -> Init;
- {{value, V}, Q1} -> queue_fold(Fun, Fun(V, Init), Q1)
+ {{value, V}, Q1} -> foldl(Fun, Fun(V, Init), Q1)
+ end.
+
+foldr(Fun, Init, Q) ->
+ case out_r(Q) of
+ {empty, _Q} -> Init;
+ {{value, V}, Q1} -> foldr(Fun, Fun(V, Init), Q1)
end.
len({L, _Q}) ->