diff options
| author | kjnilsson <knilsson@pivotal.io> | 2019-11-04 16:53:14 +0000 |
|---|---|---|
| committer | kjnilsson <knilsson@pivotal.io> | 2019-11-04 16:53:14 +0000 |
| commit | a808e1be8adc801e97b4fe2dd88d94f221e983e4 (patch) | |
| tree | dcd52eb63aa33b0e7962452cc0238eb8e6409e05 /deps/rabbitmq_management_agent | |
| parent | 2826927541cca8038064ae202371b09f12c8ffda (diff) | |
| download | rabbitmq-server-git-a808e1be8adc801e97b4fe2dd88d94f221e983e4.tar.gz | |
Replace use of orddict with map
There is only a single point in the code we need the ordering at which
point we can explicitly sort the result.
Diffstat (limited to 'deps/rabbitmq_management_agent')
| -rw-r--r-- | deps/rabbitmq_management_agent/src/exometer_slide.erl | 34 |
1 files changed, 19 insertions, 15 deletions
diff --git a/deps/rabbitmq_management_agent/src/exometer_slide.erl b/deps/rabbitmq_management_agent/src/exometer_slide.erl index 5af252803c..ac13d4cc02 100644 --- a/deps/rabbitmq_management_agent/src/exometer_slide.erl +++ b/deps/rabbitmq_management_agent/src/exometer_slide.erl @@ -376,14 +376,17 @@ maybe_add_last_sample(_Now, #slide{buf1 = Buf1, n = N}) -> create_normalized_lookup(Start, Interval, RoundFun, Samples) -> - lists:foldl(fun({TS, Value}, Dict) when TS - Start >= 0 -> - NewTS = map_timestamp(TS, Start, Interval, RoundFun), - orddict:update(NewTS, fun({T, V}) when T > TS -> - {T, V}; - (_) -> {TS, Value} - end, {TS, Value}, Dict); - (_, Dict) -> Dict end, orddict:new(), - Samples). + lists:foldl(fun({TS, Value}, Acc) when TS - Start >= 0 -> + NewTS = map_timestamp(TS, Start, Interval, RoundFun), + maps:update_with(NewTS, + fun({T, V}) when T > TS -> + {T, V}; + (_) -> + {TS, Value} + end, {TS, Value}, Acc); + (_, Acc) -> + Acc + end, #{}, Samples). -spec to_normalized_list(timestamp(), timestamp(), integer(), slide(), no_pad | tuple()) -> [tuple()]. @@ -423,7 +426,7 @@ to_normalized_list(Now, Start, Interval, #slide{first = FirstTS0, {_, Res1} = lists:foldl( fun(T, {Last, Acc}) -> - case orddict:find(T, Lookup) of + case maps:find(T, Lookup) of {ok, {_, V}} -> {V, [{T, V} | Acc]}; error when Last =:= undefined -> @@ -431,7 +434,8 @@ to_normalized_list(Now, Start, Interval, #slide{first = FirstTS0, error -> % this pads the last value into the future {Last, [{T, Last} | Acc]} end - end, {undefined, []}, lists:seq(Start, NowRound, Interval)), + end, {undefined, []}, + lists:seq(Start, NowRound, Interval)), Res1 ++ Pad. @@ -452,9 +456,9 @@ sum([#slide{size = Size, interval = Interval} | _] = Slides, Pad) -> sum(Now, Start, Interval, [Slide | _ ] = All, Pad) -> - Fun = fun({TS, Value}, Dict) -> - orddict:update(TS, fun(V) -> add_to_total(V, Value) end, - Value, Dict) + Fun = fun({TS, Value}, Acc) -> + maps:update_with(TS, fun(V) -> add_to_total(V, Value) end, + Value, Acc) end, {Total, Dict} = lists:foldl(fun(#slide{total = T} = S, {Tot, Acc}) -> @@ -463,9 +467,9 @@ sum(Now, Start, Interval, [Slide | _ ] = All, Pad) -> Total = add_to_total(T, Tot), Folded = lists:foldl(Fun, Acc, Samples), {Total, Folded} - end, {undefined, orddict:new()}, All), + end, {undefined, #{}}, All), - {First, Buffer} = case orddict:to_list(Dict) of + {First, Buffer} = case lists:sort(maps:to_list(Dict)) of [] -> F = case [TS || #slide{first = TS} <- All, is_integer(TS)] of |
