-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmergesorter.erl
More file actions
50 lines (40 loc) · 1.56 KB
/
mergesorter.erl
File metadata and controls
50 lines (40 loc) · 1.56 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
%%%----------------------------------------------------
%%% Copyright AnalyzERL 2011
%%% All rights reserved. No part of this computer programs(s) may be
%%% used, reproduced,stored in any retrieval system, or transmitted,
%%% in any form or by any means, electronic, mechanical, photocopying,
%%% recording, or otherwise without prior written permission of
%%% the authors
%%%---------------------------------------------------------------------
%%%---------------------------------------------------------------------
%%% Revision History
%%%---------------------------------------------------------------------
%%% Revision 1.0 Author: Souvik Ray (rsouvik@gmail.com)
%%%---------------------------------------------------------------------
-module(mergesorter).
-compile(export_all).
% This is the aggregrator
init(Data) ->
%Data.
[{"empty",0}].
terminate() ->
ok.
%Each time a new partially sorted list comes in, it is mergesorted with the
%existing list and topN list is stored
handle_event(EventData, Data) ->
DataPruned = lists:reverse(lists:keysort(2,utils:pruneList(EventData,Data))),
if
length(DataPruned)==0 ->
NewData = lists:reverse(lists:keysort(2, EventData));
true ->
%NewData = lists:sublist(utils:mergesort(EventData, Data),1,10),
NewData = lists:sublist(utils:mergesort(EventData, DataPruned),1,10)
end,
NewData.
%Whenever output is called, sort the Data dict and output partial sorted list
%serialization/deserialization required ?
output(Data) ->
%{lists:sublist(Data,1,10)}.
{Data}.
printState(Data) ->
"".