Add valid_size/1
This commit is contained in:
parent
fd4fbf7ea8
commit
7912742a84
1 changed files with 11 additions and 2 deletions
|
@ -66,7 +66,8 @@
|
||||||
get_segment/2,
|
get_segment/2,
|
||||||
tictac_hash/3,
|
tictac_hash/3,
|
||||||
export_tree/1,
|
export_tree/1,
|
||||||
import_tree/1
|
import_tree/1,
|
||||||
|
valid_size/1
|
||||||
]).
|
]).
|
||||||
|
|
||||||
|
|
||||||
|
@ -80,6 +81,7 @@
|
||||||
-define(LARGE, {10, 1024, 1024 * 1024}).
|
-define(LARGE, {10, 1024, 1024 * 1024}).
|
||||||
-define(XLARGE, {11, 2048, 2048 * 2048}).
|
-define(XLARGE, {11, 2048, 2048 * 2048}).
|
||||||
-define(EMPTY, <<0:8/integer>>).
|
-define(EMPTY, <<0:8/integer>>).
|
||||||
|
-define(VALID_SIZES, [xxsmall, xsmall, small, medium, large, xlarge]).
|
||||||
|
|
||||||
-record(tictactree, {treeID :: any(),
|
-record(tictactree, {treeID :: any(),
|
||||||
size :: xxsmall|xsmall|small|medium|large|xlarge,
|
size :: xxsmall|xsmall|small|medium|large|xlarge,
|
||||||
|
@ -96,6 +98,12 @@
|
||||||
%%% External functions
|
%%% External functions
|
||||||
%%%============================================================================
|
%%%============================================================================
|
||||||
|
|
||||||
|
-spec valid_size(any()) -> boolean().
|
||||||
|
%% @doc
|
||||||
|
%% For validation of input
|
||||||
|
valid_size(Size) ->
|
||||||
|
lists:member(Size, ?VALID_SIZES).
|
||||||
|
|
||||||
-spec new_tree(any()) -> tictactree().
|
-spec new_tree(any()) -> tictactree().
|
||||||
%% @doc
|
%% @doc
|
||||||
%% Create a new tree, zeroed out.
|
%% Create a new tree, zeroed out.
|
||||||
|
@ -142,7 +150,7 @@ import_tree(ExportedTree) ->
|
||||||
L1Bin = base64:decode(L1Base64),
|
L1Bin = base64:decode(L1Base64),
|
||||||
Sizes =
|
Sizes =
|
||||||
lists:map(fun(SizeTag) -> {SizeTag, element(2, get_size(SizeTag))} end,
|
lists:map(fun(SizeTag) -> {SizeTag, element(2, get_size(SizeTag))} end,
|
||||||
[xxsmall, xsmall, small, medium, large, xlarge]),
|
?VALID_SIZES),
|
||||||
Width = byte_size(L1Bin) div ?HASH_SIZE,
|
Width = byte_size(L1Bin) div ?HASH_SIZE,
|
||||||
{Size, Width} = lists:keyfind(Width, 2, Sizes),
|
{Size, Width} = lists:keyfind(Width, 2, Sizes),
|
||||||
{BitWidth, Width, SegmentCount} = get_size(Size),
|
{BitWidth, Width, SegmentCount} = get_size(Size),
|
||||||
|
@ -414,6 +422,7 @@ simple_bysize_test_allsizes() ->
|
||||||
simple_test_withsize(xlarge).
|
simple_test_withsize(xlarge).
|
||||||
|
|
||||||
simple_test_withsize(Size) ->
|
simple_test_withsize(Size) ->
|
||||||
|
?assertMatch(true, valid_size(Size)),
|
||||||
BinFun = fun(K, V) -> {term_to_binary(K), term_to_binary(V)} end,
|
BinFun = fun(K, V) -> {term_to_binary(K), term_to_binary(V)} end,
|
||||||
|
|
||||||
K1 = {o, "B1", "K1", null},
|
K1 = {o, "B1", "K1", null},
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue