style(emqx_inflight): elvis: User UPPER_CASE macro
This commit is contained in:
parent
7e3b7bb0fe
commit
4c5273c1d1
|
@ -45,83 +45,83 @@
|
||||||
|
|
||||||
-opaque(inflight() :: {inflight, max_size(), gb_trees:tree()}).
|
-opaque(inflight() :: {inflight, max_size(), gb_trees:tree()}).
|
||||||
|
|
||||||
-define(Inflight(Tree), {inflight, _MaxSize, Tree}).
|
-define(INFLIGHT(Tree), {inflight, _MaxSize, Tree}).
|
||||||
|
|
||||||
-define(Inflight(MaxSize, Tree), {inflight, MaxSize, (Tree)}).
|
-define(INFLIGHT(MaxSize, Tree), {inflight, MaxSize, (Tree)}).
|
||||||
|
|
||||||
-spec(new() -> inflight()).
|
-spec(new() -> inflight()).
|
||||||
new() -> new(0).
|
new() -> new(0).
|
||||||
|
|
||||||
-spec(new(non_neg_integer()) -> inflight()).
|
-spec(new(non_neg_integer()) -> inflight()).
|
||||||
new(MaxSize) when MaxSize >= 0 ->
|
new(MaxSize) when MaxSize >= 0 ->
|
||||||
?Inflight(MaxSize, gb_trees:empty()).
|
?INFLIGHT(MaxSize, gb_trees:empty()).
|
||||||
|
|
||||||
-spec(contain(key(), inflight()) -> boolean()).
|
-spec(contain(key(), inflight()) -> boolean()).
|
||||||
contain(Key, ?Inflight(Tree)) ->
|
contain(Key, ?INFLIGHT(Tree)) ->
|
||||||
gb_trees:is_defined(Key, Tree).
|
gb_trees:is_defined(Key, Tree).
|
||||||
|
|
||||||
-spec(lookup(key(), inflight()) -> {value, term()} | none).
|
-spec(lookup(key(), inflight()) -> {value, term()} | none).
|
||||||
lookup(Key, ?Inflight(Tree)) ->
|
lookup(Key, ?INFLIGHT(Tree)) ->
|
||||||
gb_trees:lookup(Key, Tree).
|
gb_trees:lookup(Key, Tree).
|
||||||
|
|
||||||
-spec(insert(key(), Val :: term(), inflight()) -> inflight()).
|
-spec(insert(key(), Val :: term(), inflight()) -> inflight()).
|
||||||
insert(Key, Val, ?Inflight(MaxSize, Tree)) ->
|
insert(Key, Val, ?INFLIGHT(MaxSize, Tree)) ->
|
||||||
?Inflight(MaxSize, gb_trees:insert(Key, Val, Tree)).
|
?INFLIGHT(MaxSize, gb_trees:insert(Key, Val, Tree)).
|
||||||
|
|
||||||
-spec(delete(key(), inflight()) -> inflight()).
|
-spec(delete(key(), inflight()) -> inflight()).
|
||||||
delete(Key, ?Inflight(MaxSize, Tree)) ->
|
delete(Key, ?INFLIGHT(MaxSize, Tree)) ->
|
||||||
?Inflight(MaxSize, gb_trees:delete(Key, Tree)).
|
?INFLIGHT(MaxSize, gb_trees:delete(Key, Tree)).
|
||||||
|
|
||||||
-spec(update(key(), Val :: term(), inflight()) -> inflight()).
|
-spec(update(key(), Val :: term(), inflight()) -> inflight()).
|
||||||
update(Key, Val, ?Inflight(MaxSize, Tree)) ->
|
update(Key, Val, ?INFLIGHT(MaxSize, Tree)) ->
|
||||||
?Inflight(MaxSize, gb_trees:update(Key, Val, Tree)).
|
?INFLIGHT(MaxSize, gb_trees:update(Key, Val, Tree)).
|
||||||
|
|
||||||
-spec(resize(integer(), inflight()) -> inflight()).
|
-spec(resize(integer(), inflight()) -> inflight()).
|
||||||
resize(MaxSize, ?Inflight(Tree)) ->
|
resize(MaxSize, ?INFLIGHT(Tree)) ->
|
||||||
?Inflight(MaxSize, Tree).
|
?INFLIGHT(MaxSize, Tree).
|
||||||
|
|
||||||
-spec(is_full(inflight()) -> boolean()).
|
-spec(is_full(inflight()) -> boolean()).
|
||||||
is_full(?Inflight(0, _Tree)) ->
|
is_full(?INFLIGHT(0, _Tree)) ->
|
||||||
false;
|
false;
|
||||||
is_full(?Inflight(MaxSize, Tree)) ->
|
is_full(?INFLIGHT(MaxSize, Tree)) ->
|
||||||
MaxSize =< gb_trees:size(Tree).
|
MaxSize =< gb_trees:size(Tree).
|
||||||
|
|
||||||
-spec(is_empty(inflight()) -> boolean()).
|
-spec(is_empty(inflight()) -> boolean()).
|
||||||
is_empty(?Inflight(Tree)) ->
|
is_empty(?INFLIGHT(Tree)) ->
|
||||||
gb_trees:is_empty(Tree).
|
gb_trees:is_empty(Tree).
|
||||||
|
|
||||||
-spec(smallest(inflight()) -> {key(), term()}).
|
-spec(smallest(inflight()) -> {key(), term()}).
|
||||||
smallest(?Inflight(Tree)) ->
|
smallest(?INFLIGHT(Tree)) ->
|
||||||
gb_trees:smallest(Tree).
|
gb_trees:smallest(Tree).
|
||||||
|
|
||||||
-spec(largest(inflight()) -> {key(), term()}).
|
-spec(largest(inflight()) -> {key(), term()}).
|
||||||
largest(?Inflight(Tree)) ->
|
largest(?INFLIGHT(Tree)) ->
|
||||||
gb_trees:largest(Tree).
|
gb_trees:largest(Tree).
|
||||||
|
|
||||||
-spec(values(inflight()) -> list()).
|
-spec(values(inflight()) -> list()).
|
||||||
values(?Inflight(Tree)) ->
|
values(?INFLIGHT(Tree)) ->
|
||||||
gb_trees:values(Tree).
|
gb_trees:values(Tree).
|
||||||
|
|
||||||
-spec(to_list(inflight()) -> list({key(), term()})).
|
-spec(to_list(inflight()) -> list({key(), term()})).
|
||||||
to_list(?Inflight(Tree)) ->
|
to_list(?INFLIGHT(Tree)) ->
|
||||||
gb_trees:to_list(Tree).
|
gb_trees:to_list(Tree).
|
||||||
|
|
||||||
-spec(to_list(fun(), inflight()) -> list({key(), term()})).
|
-spec(to_list(fun(), inflight()) -> list({key(), term()})).
|
||||||
to_list(SortFun, ?Inflight(Tree)) ->
|
to_list(SortFun, ?INFLIGHT(Tree)) ->
|
||||||
lists:sort(SortFun, gb_trees:to_list(Tree)).
|
lists:sort(SortFun, gb_trees:to_list(Tree)).
|
||||||
|
|
||||||
-spec(window(inflight()) -> list()).
|
-spec(window(inflight()) -> list()).
|
||||||
window(Inflight = ?Inflight(Tree)) ->
|
window(Inflight = ?INFLIGHT(Tree)) ->
|
||||||
case gb_trees:is_empty(Tree) of
|
case gb_trees:is_empty(Tree) of
|
||||||
true -> [];
|
true -> [];
|
||||||
false -> [Key || {Key, _Val} <- [smallest(Inflight), largest(Inflight)]]
|
false -> [Key || {Key, _Val} <- [smallest(Inflight), largest(Inflight)]]
|
||||||
end.
|
end.
|
||||||
|
|
||||||
-spec(size(inflight()) -> non_neg_integer()).
|
-spec(size(inflight()) -> non_neg_integer()).
|
||||||
size(?Inflight(Tree)) ->
|
size(?INFLIGHT(Tree)) ->
|
||||||
gb_trees:size(Tree).
|
gb_trees:size(Tree).
|
||||||
|
|
||||||
-spec(max_size(inflight()) -> non_neg_integer()).
|
-spec(max_size(inflight()) -> non_neg_integer()).
|
||||||
max_size(?Inflight(MaxSize, _Tree)) ->
|
max_size(?INFLIGHT(MaxSize, _Tree)) ->
|
||||||
MaxSize.
|
MaxSize.
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue