Skip to content

Instantly share code, notes, and snippets.

@maruks
Created November 17, 2015 09:57
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save maruks/b36b422fa145ffa47d0a to your computer and use it in GitHub Desktop.
Save maruks/b36b422fa145ffa47d0a to your computer and use it in GitHub Desktop.
-module('shake').
-import(lists,[reverse/1]).
-define(FILENAME,"/Users/maris/Documents/pg1000.txt").
%% API exports
-compile(export_all).
insert(Children, [X | Xs]) ->
I = maps:get(X, Children, #{}),
maps:put(X, insert(I, Xs), Children);
insert( Children, []) -> Children.
create_trie(Lines) ->
lists:foldl(fun(T, Acc) -> insert(Acc, T) end, #{}, Lines ).
complete( Children, [X]) ->
K = maps:is_key(X, Children),
if K ->
Cs = maps:get(X, Children),
maps:keys(Cs);
true ->
[]
end;
complete( Children, [X | Xs]) ->
K = maps:is_key(X, Children),
if K ->
Cs = maps:get(X, Children),
complete(Cs, Xs);
true ->
[]
end.
foo() ->
{ok, File} = file:open(?FILENAME, [read]),
read(File).
read(File) ->
case file:read_line(File) of
{ok, Line} -> [ string:strip(Line) | read(File)];
eof -> []
end.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment