Просмотр исходного кода

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

master V0.0.1
SisMaker 4 лет назад
Родитель
Сommit
cb9cedebf2
2 измененных файлов: 34 добавлений и 17 удалений
  1. +19
    -9
      src/eAcs.erl
  2. +15
    -8
      src/genAcs.erl

+ 19
- 9
src/eAcs.erl Просмотреть файл

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

+ 15
- 8
src/genAcs.erl Просмотреть файл

@ -183,19 +183,26 @@ genGoto(Goto, StrAcc) ->
doGenGoto([], StrAcc) ->
<<StrAcc/binary, "goto(_) -> undefined.\n\n">>;
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;
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, StrAcc)
NewStrAcc = <<StrAcc/binary, "goto(", (integer_to_binary(K))/binary, ") -> ", (iolist_to_binary(io_lib:format(<<"~w">>, [V])))/binary, ";\n">>,
doGenGoto(SortKvs, NewStrAcc)
end.
genFailOut([], _Fail, _Output, StrAcc) ->

Загрузка…
Отмена
Сохранить