Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Removed (most) compilation warnings #6

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion rebar.config
Original file line number Diff line number Diff line change
Expand Up @@ -19,4 +19,3 @@
{edoc_opts, [{doclet, edown_doclet},
{src_path, ["src/"]},
{subpackages, true}]}.

8 changes: 4 additions & 4 deletions src/uca/ux_uca_alt.erl
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,13 @@
-spec get_alternate_function(#uca_options{}, fun()) -> fun().
get_alternate_function(#uca_options{alternate='shifted', strength=4}, D) ->
R = D({reassign_function, 4}),
Common = R(get_common_value),
Common = R(get_common_value),
shifted_weight(Common);

get_alternate_function(C=#uca_options{alternate=Alt}, _D) ->
get_alternate_function(#uca_options{alternate=Alt}, _D) ->
get_function(Alt).


-spec get_function(Alt :: ux_uca:uca_alternate()) -> fun().
get_function(non_ignorable) ->
fun non_ignorable_weight/1;
Expand Down Expand Up @@ -141,5 +141,5 @@ shift_trimmed_weight2([_|_] = Value) ->

%% @private
%% Return: [_, _, _, _]
set_l4_to_value([Var, L1, L2, L3, _L4], NewL4) ->
set_l4_to_value([_Var, L1, L2, L3, _L4], NewL4) ->
[L1, L2, L3, NewL4].
116 changes: 58 additions & 58 deletions src/uca/ux_uca_compress.erl
Original file line number Diff line number Diff line change
Expand Up @@ -17,95 +17,95 @@ reassign_fun(Lvl, Min, OldMax) ->
MinTop = NewMin + BottomSize,
GapSize = MaxBottom - MinTop,
true = (GapSize > 0),

Bound = MaxBottom + (GapSize div 2),
?DBG(
"~w:reassign_fun: Level ~w.~n"
" COMMON is ~w. ~n"
" MIN is ~w. ~n"
" MAX is ~w. ~n"
" BOUND is ~w. ~n"
" GAP_SIZE is ~w. ~n"
" TOP_SIZE is ~w. ~n"
" BOT_SIZE is ~w. ~n"
" MAX_BOT is ~w. ~n"
" MIN_TOP is ~w. ~n"
" OLD_MAX is ~w. ~n"
,
" COMMON is ~w. ~n"
" MIN is ~w. ~n"
" MAX is ~w. ~n"
" BOUND is ~w. ~n"
" GAP_SIZE is ~w. ~n"
" TOP_SIZE is ~w. ~n"
" BOT_SIZE is ~w. ~n"
" MAX_BOT is ~w. ~n"
" MIN_TOP is ~w. ~n"
" OLD_MAX is ~w. ~n"
,
[?MODULE, Lvl,
Common, Min, Max, Bound,
Common, Min, Max, Bound,
GapSize, TopSize, BottomSize,
MaxBottom, MinTop, OldMax]),

%% Reassign the weights in the collation element table at level n to create
%% a gap of size GAP above COMMON. Typically for secondaries or tertiaries
%% this is done after the values have been reduced to a byte range by the
%% above methods. Here is a mapping that moves weights up or down to create
%% a gap of size GAP above COMMON. Typically for secondaries or tertiaries
%% this is done after the values have been reduced to a byte range by the
%% above methods. Here is a mapping that moves weights up or down to create
%% a gap in a byte range.
%% w -> w + 01 - MIN, for MIN <= w < COMMON
%% w -> w + FF - MAX, for COMMON < w <= MAX
RaFn = fun(W) when W < Common -> W + NewMin - Min;
(W) when W > Common -> W + NewMax - Max
end,

%% If a synthetic high weight would be less than BOUND, use a
%% sequence of high weights of the form (BOUND)..(BOUND)(MAXBOTTOM -
%% If a synthetic high weight would be less than BOUND, use a
%% sequence of high weights of the form (BOUND)..(BOUND)(MAXBOTTOM -
%% remainder).
SynFn = fun(high, SynWeight, List) when SynWeight < Bound ->
SynFn = fun(high, SynWeight, List) when SynWeight < Bound ->
{Remainder, NewList} = do_seq(Bound, SynWeight, List),
[(MaxBottom - Remainder) | NewList];

%% If a synthetic low weight would not be less than BOUND, use a sequence
%% of low weights of the form (BOUND-1)..(BOUND-1)(MINTOP + remainder) to
%% If a synthetic low weight would not be less than BOUND, use a sequence
%% of low weights of the form (BOUND-1)..(BOUND-1)(MINTOP + remainder) to
%% express the length of the sequence.
(low, SynWeight, List) ->
(low, SynWeight, List) ->
{Remainder, NewList} = do_seq(Bound - 1, SynWeight, List),
[(MinTop + Remainder) | NewList]
end,
%% When generating a sort key, look for maximal sequences of m COMMON values

%% When generating a sort key, look for maximal sequences of m COMMON values
%% in a row. Let W be the weight right after the sequence.

Capacity = Max - Min,
%% Capacity = Max - Min,
Result = [],

Len = get_bits_len(Max),
fun({to_binary, W}) -> <<<<X:Len>> || X <- W>>;
(get_common_value)
(get_common_value)
-> Common; % for ux_uca_alt
(Weights) -> do_reassign(Common, SynFn, RaFn, Weights, Result)
end.

do_seq(Val, Rem, List) when Rem >= Val ->
do_seq(Val, Rem - Val, [Val|List]);
do_seq(Val, Rem, List) ->
do_seq(_Val, Rem, List) ->
{Rem, List}.


get_bits_len(Max) ->
if
Max =< 16#FF -> 8;
Max =< 16#FFFF -> 16;
Max =< 16#FFFFFF -> 24
Max =< 16#FFFFFF -> 24
end.

%% @param W:[int()] List of weights on this lvl.
%% @param R:[int()] Reversed list of resulted weights.
%% @param Cnt:int() Count of repeated Commons.
%% The last step is a bit too simple, because the synthetic weights must
%% not collide with other values having long strings of COMMON weights.
%% This is done by using a sequence of synthetic weights, absorbing as
%% much length into each one as possible.
%% A value BOUND is defined between MINTOP and MAXBOTTOM.
%% The exact value for BOUND can be chosen based on the expected
%% frequency of synthetic low weights versus high weights for the
%% The last step is a bit too simple, because the synthetic weights must
%% not collide with other values having long strings of COMMON weights.
%% This is done by using a sequence of synthetic weights, absorbing as
%% much length into each one as possible.
%% A value BOUND is defined between MINTOP and MAXBOTTOM.
%% The exact value for BOUND can be chosen based on the expected
%% frequency of synthetic low weights versus high weights for the
%% particular collation element table.


%% When generating a sort key, look for maximal sequences of
%% m (Cnt) COMMON values in a row.
do_reassign(Common, SynFn, RaFn, [W|WT], R)
when (W =:= Common) ->
%% When generating a sort key, look for maximal sequences of
%% m (Cnt) COMMON values in a row.
do_reassign(Common, SynFn, RaFn, [W|WT], R)
when (W =:= Common) ->
{Cnt, NewWT} = do_common(W, WT, 1),
Type = syn_weight_type(NewWT, Common),
NewR = SynFn(Type, Cnt, R),
Expand All @@ -115,18 +115,18 @@ do_reassign(Common, SynFn, RaFn, [W|WT], R) ->
do_reassign(Common, SynFn, RaFn, WT, [NewW|R]);
do_reassign(_Common, _SynFn, _RaFn, []=_W, R) ->
lists:reverse(R).


%% The parameter is the tail of the string after the sequence.
%%
%% Let W be the weight right after the sequence.
%% If W < COMMON (or there is no W), replace the sequence by a synthetic
%% Let W be the weight right after the sequence.
%% If W < COMMON (or there is no W), replace the sequence by a synthetic
%% low weight equal to (MINTOP + m).
%% If W > COMMON, replace the sequence by a synthetic high weight equal
%% If W > COMMON, replace the sequence by a synthetic high weight equal
%% to (MAXBOTTOM - m).
syn_weight_type([W|_], Common) when W > Common ->
syn_weight_type([W|_], Common) when W > Common ->
high;
syn_weight_type(_Str, _Common) ->
syn_weight_type(_Str, _Common) ->
low.


Expand All @@ -136,11 +136,11 @@ do_common(W, [WH|WT], Cnt) when WH=:=W ->
do_common(_W, WT, Cnt) ->
{Cnt, WT}.

get_common_value(_L = 2, Max) ->
get_common_value(_L = 2, Max) ->
{32, Max};
get_common_value(_L = 3, Max) ->
get_common_value(_L = 3, Max) ->
{2, Max};
get_common_value(_L = 4, Max) ->
get_common_value(_L = 4, Max) ->
{Max+1, Max}.
%get_common_value(_L = 4) -> 16#FFFF.

Expand All @@ -164,9 +164,9 @@ cmp(X, Y) when X < Y -> '<';
cmp(X, X) -> '=';
cmp(_, _) -> '>'.

-define(_assertLower(X, Y),
{unicode:characters_to_list(io_lib:format("Is ~w < ~w?", [X, Y])),
?_assertEqual([X, '<', Y], [X, cmp(X, Y), Y])}).
-define(_assertLower(X, Y),
{unicode:characters_to_list(io_lib:format("Is ~w < ~w?", [X, Y])),
?_assertEqual([X, '<', Y], [X, cmp(X, Y), Y])}).


binarize(Fn) ->
Expand All @@ -187,20 +187,20 @@ lvl4_test_() ->
%% DATA1:
%% Error (key): [8427,820] greater [820,1425]
%% Key1: <<0,0,158,131,0,224>>
%% Key2: <<0,0,158,0,225>>
%% Key2: <<0,0,158,0,225>>
%% Arr1: [[non_variable,0,97,2,8427],[non_variable,0,124,2,820]]
%% Arr2: [[non_variable,0,124,2,820],[non_variable,0,0,0,1425]]
%% Error in the compression algorithm.
%% Unzip Key1: [0,97,124,0,2,2]
%% Unzip Key2: [0,124,0,2]
%% Unzip Key2: [0,124,0,2]
%% sort_key and compare returns different results.
%% Data1: 20EB 0334
%% Data2: 0334 0591
%%
%% Result (it is from eunit's output):
%% ux_uca_compress:162: lvl4_test_ (Is <<131,158>> < <<158>>?)...[0.001 s] ok


%% ux_uca_compress:reassign_fun: Level 2.
%% COMMON is 32.
%% MIN is 0.
Expand All @@ -212,7 +212,7 @@ lvl4_test_() ->
%% MAX_BOT is 66.
%% MIN_TOP is 33.
%% OLD_MAX is 221.
%%
%%
%% =INFO REPORT==== 19-Jun-2012::13:41:39 ===
%% ux_uca_compress:reassign_fun: Level 3.
%% COMMON is 2.
Expand All @@ -225,7 +225,7 @@ lvl4_test_() ->
%% MAX_BOT is 226.
%% MIN_TOP is 3.
%% OLD_MAX is 31.
%%
%%
%% =INFO REPORT==== 19-Jun-2012::13:41:39 ===
%% ux_uca_compress:reassign_fun: Level 4.
%% COMMON is 65502.
Expand Down
11 changes: 6 additions & 5 deletions src/uca/ux_uca_decomp.erl
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,13 @@ compute(Char, List) ->
L3 = ux_unidata:tertiary_weight(Char),
L3Max = 16#001F,
cycle(1, List, F, L3, L3Max, []).


cycle(Pos, [H|T], Ducet, Value, Max, Acc) ->

%% Set the first two L3 values to be lookup (L3), where the lookup function
%% uses the table in Section 7.2, Tertiary Weight Table. Set the remaining
%% L3 values to MAX (which in the default table is 001F).
%% Set the first two L3 values to be lookup (L3), where the lookup function
%% uses the table in Section 7.2, Tertiary Weight Table. Set the remaining
%% L3 values to MAX (which in the default table is 001F).
NewL3 = if Pos>2 -> Max;
true -> Value end,

Expand All @@ -30,12 +30,13 @@ cycle(Pos, [H|T], Ducet, Value, Max, Acc) ->
NewAcc = fill_l3(Weight, NewL3, Acc),
cycle(Pos+1, T, Ducet, Value, Max, NewAcc);

cycle(_Pos, [], _Ducet, _Value, _Max, Acc) ->
cycle(_Pos, [], _Ducet, _Value, _Max, Acc) ->
ux_unidata_parser_allkeys:el_to_bin(lists:reverse(Acc)).


fill_l3([H|T], NewL3, Acc) ->
[Var, L1, L2, _L3, L4] = H,
NewH = [Var, L1, L2, NewL3, L4],
%% @TODO: Should the next line be: [NewH | fill_l3(T, NewL3, Acc)];
fill_l3(T, NewL3, Acc);
fill_l3([], _NewL3, Acc) -> Acc.
Loading