Skip to content

Commit

Permalink
otpbp_ets: add first_lookup/1, last_lookup/1, next_lookup/2, prev_loo…
Browse files Browse the repository at this point in the history
…kup/2
  • Loading branch information
Ledest committed Jan 10, 2024
1 parent 9fb8a74 commit 41bc95a
Show file tree
Hide file tree
Showing 3 changed files with 54 additions and 0 deletions.
4 changes: 4 additions & 0 deletions rebar.config.script
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,11 @@ Funs = [{application, get_supervisor, 1},
{erts_internal, binary_to_integer, 2},
{erts_internal, list_to_integer, 2},
{erts_internal, map_next, 3},
{ets, first_lookup, 1},
{ets, last_lookup, 1},
{ets, lookup_element, 4},
{ets, next_lookup, 2},
{ets, prev_lookup, 2},
{ets, whereis, 1},
{file, del_dir_r, 1},
{file, delete, 2},
Expand Down
48 changes: 48 additions & 0 deletions src/otpbp_ets.erl
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,22 @@
% OTP 26.0
-export([lookup_element/4]).
-endif.
-ifndef(HAVE_ets__first_lookup_1).
% OTP 27.0
-export([first_lookup/1]).
-endif.
-ifndef(HAVE_ets__last_lookup_1).
% OTP 27.0
-export([last_lookup/1]).
-endif.
-ifndef(HAVE_ets__next_lookup_2).
% OTP 27.0
-export([next_lookup/2]).
-endif.
-ifndef(HAVE_ets__prev_lookup_2).
% OTP 27.0
-export([prev_lookup/2]).
-endif.

-ifndef(HAVE_ets__whereis_1).
whereis(T) ->
Expand All @@ -32,3 +48,35 @@ lookup_element(Table, Key, Pos, Default) ->
_ -> Default
end.
-endif.

-ifndef(HAVE_ets__first_lookup_1).
first_lookup(Tab) ->
case ets:first(Tab) of
'$end_of_table' -> '$end_of_table';
Key -> ets:lookup(Tab, Key)
end.
-endif.

-ifndef(HAVE_ets__last_lookup_1).
last_lookup(Tab) ->
case ets:last(Tab) of
'$end_of_table' -> '$end_of_table';
Key -> ets:lookup(Tab, Key)
end.
-endif.

-ifndef(HAVE_ets__next_lookup_2).
next_lookup(Tab, Key) ->
case ets:next(Tab, Key) of
'$end_of_table' -> '$end_of_table';
KeyN -> ets:lookup(Tab, KeyN)
end.
-endif.

-ifndef(HAVE_ets__prev_lookup_2).
prev_lookup(Tab, Key) ->
case ets:prev(Tab, Key) of
'$end_of_table' -> '$end_of_table';
KeyN -> ets:lookup(Tab, KeyN)
end.
-endif.
2 changes: 2 additions & 0 deletions src/otpbp_pt.erl
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,9 @@
{{error_logger, limit_term, 1}, otpbp_error_logger},
{{erts_internal, [binary_to_integer, list_to_integer], 2}, otpbp_erts_internal},
{{erts_internal, map_next, 3}, otpbp_erts_internal},
{{ets, [first_lookup, last_lookup], 1}, otpbp_ets},
{{ets, lookup_element, 4}, otpbp_ets},
{{ets, [next_lookup, prev_lookup], 2}, otpbp_ets},
{{ets, whereis, 1}, otpbp_ets},
{{file, del_dir_r, 1}, otpbp_file},
{{file, [delete, read_file], 2}, otpbp_file},
Expand Down

0 comments on commit 41bc95a

Please sign in to comment.