-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsorter.erl
More file actions
48 lines (39 loc) · 1.62 KB
/
sorter.erl
File metadata and controls
48 lines (39 loc) · 1.62 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
%%%----------------------------------------------------
%%% 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(sorter).
-compile(export_all).
-define(DEBUGFILE, "debug.txt").
% This is the aggregrator
init(Data) ->
Dict = dict:new(),
Dict.
terminate() ->
ok.
%Data is the data structure which stores the list [{Event1, Freq1}, {Event, Freq2}....]
%We use a dict
%EventData is of the format: [Word, Freq]
handle_event(EventData, Data) ->
NewData = dict:store(lists:nth(1, EventData), lists:nth(2, EventData), Data),
NewData.
%Whenever output is called, sort the Data dict and output partial sorted list
%serialization/deserialization required ?
output(Data) ->
%turn dict to a list of tuples
TupleList = dict:to_list(Data),
OutputData = lists:reverse(lists:keysort(2, TupleList)),
{ok, Fdd} = file:open(?DEBUGFILE, [append]),
io:fwrite(Fdd, "~p~n", ["Output from sorter: "]),
io:fwrite(Fdd, "~p~n", [OutputData]),
file:close(Fdd),
{"123","wordfreqmergesort",OutputData}.