Skip to content

Commit ed133c8

Browse files
authored
Merge pull request #52 from Shpaky/v2.2.0
'reset' command processing to accordance with protocol was corrected
2 parents 97478dd + 715497e commit ed133c8

4 files changed

Lines changed: 36 additions & 6 deletions

File tree

lfu.app

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{application,lfu,[
22
{description,"Least Frequently Used Algorithm"},
3-
{vsn,"2.1.4"},
3+
{vsn,"2.2.0"},
44
{modules,[
55
lfu_app,lfu_sup,lfu,
66
lfu_score_sups_sup,lfu_protocol,

priv/lfu.rel

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,5 +9,5 @@
99
{crypto,"4.8"},
1010
{public_key,"1.9"},
1111
{asn1,"5.0.14"},
12-
{lfu, "2.1.4"}]
12+
{lfu, "2.2.0"}]
1313
}.

priv/lfu.tar.gz

703 KB
Binary file not shown.

src/lfu.erl

Lines changed: 34 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -109,8 +109,8 @@ fetch(T) ->
109109
clean(T) ->
110110
gen_statem:call(?MODULE,{clean,T}).
111111

112-
reset(T) ->
113-
gen_statem:cast(?MODULE,{reset,T}).
112+
reset(D) ->
113+
gen_statem:cast(?MODULE,{reset,D}).
114114

115115
score(R,C) ->
116116
gen_statem:cast(?MODULE,{{score,R},C}).
@@ -334,8 +334,8 @@ common({call,From},{fetch,T},[O,Q]) ->
334334
{next_state,offset,[O,Q,#{from => From, tid => T, ets => external, order => fetch}],[{next_event,internal,{score,{previous,{?SCORE_OFFSET,O}}}}]};
335335
common({call,From},{clean,T},[O,Q]) ->
336336
{next_state,offset,[O,Q,#{from => From, tid => T, ets => external, order => clean}],[{next_event,internal,{score,{previous,{?SCORE_OFFSET,O}}}}]};
337-
common(cast,{reset,T},[O,Q]) ->
338-
NQ = resetting(T,Q),
337+
common(cast,{reset,D},[O,Q]) ->
338+
NQ = resetting(D,Q),
339339
{keep_state,[O,NQ]};
340340
common(cast,{{score,_R},_S},_StateData) ->
341341
keep_state_and_data;
@@ -743,6 +743,36 @@ scoring(L,U,R) ->
743743
L1 + L2
744744
end.
745745

746+
resetting({_,KL},Q) ->
747+
put(reset,0),
748+
lists:foreach(
749+
fun(K) ->
750+
ets:delete(?ETS_KEYS_TABLE_NAME,K),
751+
C = erase(K),
752+
if
753+
(C-1) div ?MAX_LIMIT == 0 ->
754+
N = list_to_atom("o0" ++ integer_to_list((C-1) div ?MIN_LIMIT)),
755+
case whereis(N) of
756+
undefined ->
757+
lfu_exact_score_sup:start([(C-1) div ?MIN_LIMIT,0]),
758+
lfu_exact_score:reset(N,K);
759+
_ ->
760+
lfu_exact_score:reset(N,K)
761+
end;
762+
true ->
763+
N = list_to_atom("o" ++ integer_to_list((C-1) div ?MAX_LIMIT)),
764+
case whereis(N) of
765+
undefined ->
766+
lfu_quick_score_sup:start([(C-1) div ?MAX_LIMIT,0]),
767+
lfu_quick_score:reset(N,K);
768+
true ->
769+
lfu_quick_score:reset(N,K)
770+
end
771+
end,
772+
put(reset,get(reset)+1)
773+
end,
774+
KL),
775+
Q - erase(reset);
746776
resetting(T,Q) ->
747777
put(reset,0),
748778
ets:info(T) =/= undefined andalso

0 commit comments

Comments
 (0)