【发布时间】:2020-01-19 12:57:33
【问题描述】:
在下面的 select_highest_bids 函数中,使用 orddict:new() 代替 list 是否更好,如下所示?
OrderedBatches = lists:foldl(fun high_bid_filter/2, orddict:new(), Campaigns)
我们如何更改 high_bid_filter 以返回 orddict ?
select_highest_bids(Campaigns, BidRequest) ->
lists:map(fun({_, C}) -> C end,
lists:foldl(fun high_bid_filter/2, [], Campaigns),
high_bid_filter(Campaign = #campaign_response{bid = BR = #bid_response{ad_id = AdID, cpm_bid = Score}}, Campaigns) ->
case lists:keyfind(AdID, 1, Campaigns) of
false ->
[{AdID, Campaign}|Campaigns];
{AdID, _ = #campaign_response{bid = _ = #bid_response{cpm_bid = EB}}} when EB >= Score ->
Campaigns;
{AdID, _ = #campaign_response{bid = _ = #bid_response{cpm_bid = EB}}} when EB < Score ->
lists:keystore(AdID, 1, Campaigns, {AdID, Campaign})
end.
【问题讨论】:
标签: list dictionary erlang