From 7c39eb85747ee579f8b7b936743bc2cc0afeb0d7 Mon Sep 17 00:00:00 2001 From: Nicholas Rutherford Date: Thu, 12 Jun 2014 15:16:19 +0200 Subject: [PATCH] convert tabs to spaces --- src/derflow.erl | 36 ++++++------- src/derflow_server.erl | 116 ++++++++++++++++++++-------------------- test/bounded_buffer.erl | 26 ++++----- test/prod_cons.erl | 18 +++---- test/prod_cons_lazy.erl | 18 +++---- 5 files changed, 107 insertions(+), 107 deletions(-) diff --git a/src/derflow.erl b/src/derflow.erl index 3b43065..c6f1971 100644 --- a/src/derflow.erl +++ b/src/derflow.erl @@ -2,17 +2,17 @@ -module(derflow). -behaviour(application). -export([start/2, - stop/1, - bind/2, - bind/3, - read/1, - declare/0, - thread/3, - get_stream/1, - byNeed/2, - byNeed/3, - waitNeeded/1, - async_print_stream/1]). + stop/1, + bind/2, + bind/3, + read/1, + declare/0, + thread/3, + get_stream/1, + byNeed/2, + byNeed/3, + waitNeeded/1, + async_print_stream/1]). start(normal, _Args) -> derflow_sup:start_link(). @@ -49,17 +49,17 @@ get_stream(Stream)-> async_print_stream(Stream)-> io:format("Stream: ~w~n", [Stream]), case read(Stream) of - {nil, _} -> {ok, stream_read}; - {Value, Next} -> - io:format("Value of stream: ~w~n",[Value]), - async_print_stream(Next) + {nil, _} -> {ok, stream_read}; + {Value, Next} -> + io:format("Value of stream: ~w~n",[Value]), + async_print_stream(Next) end. %Internal functions internal_get_stream(Head, Output) -> case read(Head) of - {nil, _} -> Output; - {Value, Next} -> - internal_get_stream(Next, lists:append(Output, [Value])) + {nil, _} -> Output; + {Value, Next} -> + internal_get_stream(Next, lists:append(Output, [Value])) end. diff --git a/src/derflow_server.erl b/src/derflow_server.erl index a268686..36004e3 100644 --- a/src/derflow_server.erl +++ b/src/derflow_server.erl @@ -13,9 +13,9 @@ start_link() -> gen_server:start_link({local, ?MODULE}, ?MODULE, [], []). init(_Args) -> - io:format("Init called~n"), - ets:new(dvstore, [set, named_table, public, {write_concurrency, true}]), - {ok, #state{clock=0}}. + io:format("Init called~n"), + ets:new(dvstore, [set, named_table, public, {write_concurrency, true}]), + {ok, #state{clock=0}}. declare() -> gen_server:call(?MODULE, {declare}). @@ -30,7 +30,7 @@ bind(Id, Value) -> waitNeeded(Id) -> gen_server:call(?MODULE, {waitNeeded, Id}). - + wait(X) -> gen_server:call(?MODULE, {wait, X}). @@ -38,10 +38,10 @@ read(X) -> gen_server:call(?MODULE, {read, X}). handle_call({declare}, _From, State) -> - Clock = State#state.clock +1, - V = #dv{value=empty, next=empty}, - ets:insert(dvstore, {Clock, V}), - {reply, {id, Clock}, State#state{clock=Clock}}; + Clock = State#state.clock +1, + V = #dv{value=empty, next=empty}, + ets:insert(dvstore, {Clock, V}), + {reply, {id, Clock}, State#state{clock=Clock}}; handle_call({next, Id}, _From, State)-> io:format("Requesting for next~w~n",[Id]), @@ -70,34 +70,34 @@ handle_call({waitNeeded, Id}, From, State) -> case V#dv.waitingThreads of [_H|_T] -> {reply, ok, State}; _ -> - ets:insert(dvstore, {Id, V#dv{lazy=true, creator=From}}), + ets:insert(dvstore, {Id, V#dv{lazy=true, creator=From}}), {noreply, State} end; %%%What if the Key does not exist in the map?%%% handle_call({read,X}, From, State) -> - [{_Key,V}] = ets:lookup(dvstore, X), + [{_Key,V}] = ets:lookup(dvstore, X), Value = V#dv.value, - Bounded = V#dv.bounded, - Creator = V#dv.creator, - Lazy = V#dv.lazy, - %%%Need to distinguish that value is not calculated or is the end of a list%%% - if Bounded == true -> - {reply, {Value, V#dv.next}, State}; - true -> - if Lazy == true -> - WT = lists:append(V#dv.waitingThreads, [From]), + Bounded = V#dv.bounded, + Creator = V#dv.creator, + Lazy = V#dv.lazy, + %%%Need to distinguish that value is not calculated or is the end of a list%%% + if Bounded == true -> + {reply, {Value, V#dv.next}, State}; + true -> + if Lazy == true -> + WT = lists:append(V#dv.waitingThreads, [From]), V1 = V#dv{waitingThreads=WT}, ets:insert(dvstore, {X, V1}), - gen_server:reply(Creator, ok), - {noreply, State}; - true -> - WT = lists:append(V#dv.waitingThreads, [From]), - V1 = V#dv{waitingThreads=WT}, - ets:insert(dvstore, {X, V1}), - {noreply, State} - end - end; + gen_server:reply(Creator, ok), + {noreply, State}; + true -> + WT = lists:append(V#dv.waitingThreads, [From]), + V1 = V#dv{waitingThreads=WT}, + ets:insert(dvstore, {X, V1}), + {noreply, State} + end + end; handle_call({wait, _X}, _From, State) -> %_V = wait_for_value(X, State#state.kv), @@ -108,43 +108,43 @@ handle_cast({_}, State) -> %putLazy(Value, Next, Key, From) -> -% %io:format("Put lazy ~w~n",[Key]), -% V1 = #dv{value= Value, next =Next, bounded= true, lazy = true, creator = From}, -% ets:insert(dvstore, {Key, V1}). +% %io:format("Put lazy ~w~n",[Key]), +% V1 = #dv{value= Value, next =Next, bounded= true, lazy = true, creator = From}, +% ets:insert(dvstore, {Key, V1}). %Bind the key with the result (either by assignment or calculating) %executeLazy(Key, V) -> -% %io:format("Execute lazy ~w~n",[Key]), -% Value= V#dv.value, -% case Value of {F, Arg} -> -% Result = F(Arg); -% _ -> -% Result = Value -% end, -% V1 = V#dv{value= Result, lazy = false, waitingThreads= []}, -% ets:insert(dvstore, {Key, V1}), -% Result. +% %io:format("Execute lazy ~w~n",[Key]), +% Value= V#dv.value, +% case Value of {F, Arg} -> +% Result = F(Arg); +% _ -> +% Result = Value +% end, +% V1 = V#dv{value= Result, lazy = false, waitingThreads= []}, +% ets:insert(dvstore, {Key, V1}), +% Result. put(Value, Next, Key) -> - [{_Key,V}] = ets:lookup(dvstore, Key), - Threads = V#dv.waitingThreads, - V1 = #dv{value= Value, next =Next, bounded= true,lazy=false}, - ets:insert(dvstore, {Key, V1}), - replyToAll(Threads, Value, Next). + [{_Key,V}] = ets:lookup(dvstore, Key), + Threads = V#dv.waitingThreads, + V1 = #dv{value= Value, next =Next, bounded= true,lazy=false}, + ets:insert(dvstore, {Key, V1}), + replyToAll(Threads, Value, Next). execute_and_put(F, Arg, Next, Key) -> - [{_Key,V}] = ets:lookup(dvstore, Key), - Threads = V#dv.waitingThreads, - Value = F(Arg), - V1 = #dv{value= Value, next =Next, bounded= true, lazy=false}, - ets:insert(dvstore, {Key, V1}), - replyToAll(Threads, Value, Next). + [{_Key,V}] = ets:lookup(dvstore, Key), + Threads = V#dv.waitingThreads, + Value = F(Arg), + V1 = #dv{value= Value, next =Next, bounded= true, lazy=false}, + ets:insert(dvstore, {Key, V1}), + replyToAll(Threads, Value, Next). replyToAll([], _Value, _Next) -> - ok; + ok; replyToAll([H|T], Value, Next) -> - gen_server:reply(H,{Value,Next}), - replyToAll(T, Value, Next). + gen_server:reply(H,{Value,Next}), + replyToAll(T, Value, Next). code_change(_, State, _) -> {ok, State}. @@ -158,9 +158,9 @@ terminate(normal, _State) -> %wait_for_value(X, KV)-> % IsKey = derflow_map:is_key(X, KV), % if IsKey == true -> -% derflow_map:get(X, KV); -% true -> -% waitTime(500), +% derflow_map:get(X, KV); +% true -> +% waitTime(500), % wait_for_value(X, KV) % end. % diff --git a/test/bounded_buffer.erl b/test/bounded_buffer.erl index f4d4a4e..6945fc9 100644 --- a/test/bounded_buffer.erl +++ b/test/bounded_buffer.erl @@ -16,8 +16,8 @@ test2() -> producer(Init, N, Output) -> if (N>0) -> derflow:waitNeeded(Output), - {id,Next} = derflow:bind(Output,Init), - io:format("Prod:Bound for ~w next ~w Produced~w ~n",[Output, Next, 11-N]), + {id,Next} = derflow:bind(Output,Init), + io:format("Prod:Bound for ~w next ~w Produced~w ~n",[Output, Next, 11-N]), producer(Init + 1, N-1, Next); true -> derflow:bind(Output, nil) @@ -29,8 +29,8 @@ loop(S1, S2, End) -> {id, S2Next} = derflow:bind(S2, Value1), io:format("Buff:Bound for consumer ~w-> ~w ~w~n",[S1,S2,Value1]), case derflow:read(End) of {nil, _} -> - loop(S1Next, S2Next, End); - {_V,EndNext} -> + loop(S1Next, S2Next, End); + {_V,EndNext} -> loop(S1Next, S2Next, EndNext) end. @@ -41,20 +41,20 @@ buffer(S1, Size, S2) -> drop_list(S, Size) -> if Size == 0 -> - S; + S; true -> - {_Value,Next}=derflow:read(S), - drop_list(Next, Size-1) + {_Value,Next}=derflow:read(S), + drop_list(Next, Size-1) end. consumer(S2,F) -> case derflow:read(S2) of - {nil, _} -> - io:format("Cons:Reading end~n"); - {Value, Next} -> - io:format("Cons:Id ~w Consume ~w, Get ~w, Next~w ~n",[S2,Value, F(Value),Next]), - %timer:sleep(1000), - consumer(Next, F) + {nil, _} -> + io:format("Cons:Reading end~n"); + {Value, Next} -> + io:format("Cons:Id ~w Consume ~w, Get ~w, Next~w ~n",[S2,Value, F(Value),Next]), + %timer:sleep(1000), + consumer(Next, F) end. diff --git a/test/prod_cons.erl b/test/prod_cons.erl index 29a14b9..fdec7d7 100644 --- a/test/prod_cons.erl +++ b/test/prod_cons.erl @@ -14,18 +14,18 @@ test1() -> producer(Init, N, Output) -> if (N>0) -> - timer:sleep(1000), - {id, Next} = derflow:bind(Output, Init), - producer(Init + 1, N-1, Next); + timer:sleep(1000), + {id, Next} = derflow:bind(Output, Init), + producer(Init + 1, N-1, Next); true -> - derflow:bind(Output, nil) + derflow:bind(Output, nil) end. consumer(S1, F, S2) -> case derflow:read(S1) of - {nil, _} -> - derflow:bind(S2, nil); - {Value, Next} -> - {id, NextOutput} = derflow:bind(S2, F, Value), - consumer(Next, F, NextOutput) + {nil, _} -> + derflow:bind(S2, nil); + {Value, Next} -> + {id, NextOutput} = derflow:bind(S2, F, Value), + consumer(Next, F, NextOutput) end. diff --git a/test/prod_cons_lazy.erl b/test/prod_cons_lazy.erl index 62f2c91..b83506e 100644 --- a/test/prod_cons_lazy.erl +++ b/test/prod_cons_lazy.erl @@ -14,18 +14,18 @@ test1() -> producer(Init, N, Output) -> if (N>0) -> - timer:sleep(1000), - {id, Next} = derflow:byNeed(Output, Init), - producer(Init + 1, N-1, Next); + timer:sleep(1000), + {id, Next} = derflow:byNeed(Output, Init), + producer(Init + 1, N-1, Next); true -> - derflow:bind(Output, nil) + derflow:bind(Output, nil) end. consumer(S1, F, S2) -> case derflow:read(S1) of - {nil, _} -> - derflow:bind(S2, nil); - {Value, Next} -> - {id, NextOutput} = derflow:byNeed(S2, F, Value), - consumer(Next, F, NextOutput) + {nil, _} -> + derflow:bind(S2, nil); + {Value, Next} -> + {id, NextOutput} = derflow:byNeed(S2, F, Value), + consumer(Next, F, NextOutput) end.