Przeglądaj źródła

pf: 减少一点acsTree代码加载之后的内存

master V0.0.1
SisMaker 4 lat temu
rodzic
commit
cb9cedebf2
2 zmienionych plików z 34 dodań i 17 usunięć
  1. +19
    -9
      src/eAcs.erl
  2. +15
    -8
      src/genAcs.erl

+ 19
- 9
src/eAcs.erl Wyświetl plik

@ -27,8 +27,7 @@ doMatchMs(<>, State, Index, MatchList) ->
end. end.
matchWordMs(Word, State, Index, MatchList) -> matchWordMs(Word, State, Index, MatchList) ->
Node = acsTree:goto(State),
case Node of
case acsTree:goto(State) of
undefined -> undefined ->
case State of case State of
0 -> 0 ->
@ -37,8 +36,11 @@ matchWordMs(Word, State, Index, MatchList) ->
{NextState, _} = acsTree:failOut(State), {NextState, _} = acsTree:failOut(State),
matchWordMs(Word, NextState, Index, MatchList) matchWordMs(Word, NextState, Index, MatchList)
end; end;
_ ->
Node ->
case Node of case Node of
{Word, NextState} ->
NewMatchList = getOutputMs(NextState, Index, MatchList),
{NextState, NewMatchList};
#{Word := NextState} -> #{Word := NextState} ->
NewMatchList = getOutputMs(NextState, Index, MatchList), NewMatchList = getOutputMs(NextState, Index, MatchList),
{NextState, NewMatchList}; {NextState, NewMatchList};
@ -87,8 +89,7 @@ doMatchIs(<>, State) ->
end. end.
matchWordIs(Word, State) -> matchWordIs(Word, State) ->
Node = acsTree:goto(State),
case Node of
case acsTree:goto(State) of
undefined -> undefined ->
case State of case State of
0 -> 0 ->
@ -97,8 +98,15 @@ matchWordIs(Word, State) ->
{NextState, _} = acsTree:failOut(State), {NextState, _} = acsTree:failOut(State),
matchWordIs(Word, NextState) matchWordIs(Word, NextState)
end; end;
_ ->
Node ->
case Node of case Node of
{Word, NextState} ->
case getOutputIs(NextState) of
false ->
NextState;
_ ->
true
end;
#{Word := NextState} -> #{Word := NextState} ->
case getOutputIs(NextState) of case getOutputIs(NextState) of
false -> false ->
@ -264,8 +272,7 @@ doMatchRs(<>, TotalSize, CurIndex, State, MatchList) ->
end. end.
matchWordRs(Word, State, MatchCnt) -> matchWordRs(Word, State, MatchCnt) ->
Node = acsTree:goto(State),
case Node of
case acsTree:goto(State) of
undefined -> undefined ->
case State of case State of
0 -> 0 ->
@ -274,8 +281,11 @@ matchWordRs(Word, State, MatchCnt) ->
{NextState, _} = acsTree:failOut(State), {NextState, _} = acsTree:failOut(State),
matchWordRs(Word, NextState, MatchCnt) matchWordRs(Word, NextState, MatchCnt)
end; end;
_ ->
Node ->
case Node of case Node of
{Word, NextState} ->
NewMatchCnt = getOutputRs(NextState, MatchCnt),
{NextState, NewMatchCnt};
#{Word := NextState} -> #{Word := NextState} ->
NewMatchCnt = getOutputRs(NextState, MatchCnt), NewMatchCnt = getOutputRs(NextState, MatchCnt),
{NextState, NewMatchCnt}; {NextState, NewMatchCnt};

+ 15
- 8
src/genAcs.erl Wyświetl plik

@ -183,19 +183,26 @@ genGoto(Goto, StrAcc) ->
doGenGoto([], StrAcc) -> doGenGoto([], StrAcc) ->
<<StrAcc/binary, "goto(_) -> undefined.\n\n">>; <<StrAcc/binary, "goto(_) -> undefined.\n\n">>;
doGenGoto([{K, V}], StrAcc) -> doGenGoto([{K, V}], StrAcc) ->
case maps:size(V) > 0 of
true ->
<<StrAcc/binary, "goto(", (integer_to_binary(K))/binary, ") -> ", (iolist_to_binary(io_lib:format(<<"~w">>, [V])))/binary, ";\ngoto(_) -> undefined.\n\n">>;
case maps:size(V) of
0 ->
<<StrAcc/binary, "goto(_) -> undefined.\n\n">>;
1 ->
[TupleKV] = maps:to_list(V),
<<StrAcc/binary, "goto(", (integer_to_binary(K))/binary, ") -> ", (iolist_to_binary(io_lib:format(<<"~w">>, [TupleKV])))/binary, ";\ngoto(_) -> undefined.\n\n">>;
_ -> _ ->
<<StrAcc/binary, "goto(_) -> undefined.\n\n">>
<<StrAcc/binary, "goto(", (integer_to_binary(K))/binary, ") -> ", (iolist_to_binary(io_lib:format(<<"~w">>, [V])))/binary, ";\ngoto(_) -> undefined.\n\n">>
end; end;
doGenGoto([{K, V} | SortKvs], StrAcc) -> doGenGoto([{K, V} | SortKvs], StrAcc) ->
case maps:size(V) > 0 of
true ->
NewStrAcc = <<StrAcc/binary, "goto(", (integer_to_binary(K))/binary, ") -> ", (iolist_to_binary(io_lib:format(<<"~w">>, [V])))/binary, ";\n">>,
case maps:size(V) of
0 ->
doGenGoto(SortKvs, StrAcc);
1 ->
[TupleKV] = maps:to_list(V),
NewStrAcc = <<StrAcc/binary, "goto(", (integer_to_binary(K))/binary, ") -> ", (iolist_to_binary(io_lib:format(<<"~w">>, [TupleKV])))/binary, ";\n">>,
doGenGoto(SortKvs, NewStrAcc); doGenGoto(SortKvs, NewStrAcc);
_ -> _ ->
doGenGoto(SortKvs, StrAcc)
NewStrAcc = <<StrAcc/binary, "goto(", (integer_to_binary(K))/binary, ") -> ", (iolist_to_binary(io_lib:format(<<"~w">>, [V])))/binary, ";\n">>,
doGenGoto(SortKvs, NewStrAcc)
end. end.
genFailOut([], _Fail, _Output, StrAcc) -> genFailOut([], _Fail, _Output, StrAcc) ->

Ładowanie…
Anuluj
Zapisz