diff options
| author | Matthias Radestock <matthias@lshift.net> | 2009-04-15 17:48:37 +0100 |
|---|---|---|
| committer | Matthias Radestock <matthias@lshift.net> | 2009-04-15 17:48:37 +0100 |
| commit | 77b03035b527000ab490c96659f91cfd8cd337b8 (patch) | |
| tree | 344f7226a472184367fc80d71a437e5fdfcc6e20 | |
| parent | 1f5f030b9394759f2a1f55e07d12eb89742cfc32 (diff) | |
| download | rabbitmq-server-git-77b03035b527000ab490c96659f91cfd8cd337b8.tar.gz | |
handle negative priorities
| -rw-r--r-- | src/priority_queue.erl | 2 | ||||
| -rw-r--r-- | src/rabbit_tests.erl | 4 |
2 files changed, 6 insertions, 0 deletions
diff --git a/src/priority_queue.erl b/src/priority_queue.erl index b872c8d539..88ad0c182d 100644 --- a/src/priority_queue.erl +++ b/src/priority_queue.erl @@ -111,6 +111,8 @@ in(X, 0, {queue, [_] = In, []}) -> {queue, [X], In}; in(X, 0, {queue, In, Out}) when is_list(In), is_list(Out) -> {queue, [X|In], Out}; +in(X, Priority, Q = {queue, [], []}) -> + in(X, Priority, {pqueue, []}); in(X, Priority, Q = {queue, _, _}) -> in(X, Priority, {pqueue, [{0, Q}]}); in(X, Priority, {pqueue, Queues}) -> diff --git a/src/rabbit_tests.erl b/src/rabbit_tests.erl index 946b8c3182..7d5fe2c1b8 100644 --- a/src/rabbit_tests.erl +++ b/src/rabbit_tests.erl @@ -83,6 +83,10 @@ test_priority_queue() -> {true, false, 2, [{2, bar}, {1, foo}], [bar, foo]} = test_priority_queue(Q3), + %% 1-element negative priority Q + Q4 = priority_queue:in(foo, -1, priority_queue:new()), + {true, false, 1, [{-1, foo}], [foo]} = test_priority_queue(Q4), + passed. priority_queue_in_all(Q, L) -> |
