<commit_before>%%% The MIT License
%%%
%%% Copyright (C) 2011-2014 by <NAME> <<EMAIL>>
%%%
%%% Permission is hereby granted, free of charge, to any person obtaining a copy
%%% of this software and associated documentation files (the "Software"), to deal
%%% in the Software without restriction, including without limitation the rights
%%% to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
%%% copies of the Software, and to permit persons to whom the Software is
%%% furnished to do so, subject to the following conditions:
%%%
%%% The above copyright notice and this permission notice shall be included in
%%% all copies or substantial portions of the Software.
%%%
%%% THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
%%% IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
%%% FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
%%% AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
%%% LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
%%% OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
%%% THE SOFTWARE.

-module(lets).

-include("lets.hrl").

%% External exports
-export([all/0
         , tid/1
         , new/2
         , destroy/2
         , repair/2
         , delete/1
         , delete/2
         , delete_all_objects/1
         , first/1
         , foldl/3
         , foldr/3
         , info/1
         , info/2
         , insert/2
         , insert_new/2
         , last/1
         , lookup/2
         , lookup_element/3
         , match/2
         , match/3
         , match/1
         , match_delete/2
         , match_object/2
         , match_object/3
         , match_object/1
         , member/2
         , next/2
         , prev/2
         , select/2
         , select/3
         , select/1
         , select_count/2
         , select_delete/2
         , select_reverse/2
         , select_reverse/3
         , select_reverse/1
         , tab2list/1
        ]).

%% DEBUG -compile(export_all).

-export_type([lets_tab/0, lets_tid/0, name/0, key/0, object/0, match_pattern/0, match_spec/0, cont/0]).

%%%----------------------------------------------------------------------
%%% Types/Specs/Records
%%%----------------------------------------------------------------------

-type lets_tid()      :: gen_ets_ns:gen_tid().
-type lets_tab()      :: gen_ets_ns:gen_tab().

-type opts()          :: [ets_opt() | impl_opt() | db_opts() | db_read_opts() | db_write_opts()].
-type ets_opt()       :: set | ordered_set | named_table | {keypos,pos_integer()} | public | protected | private | compressed | async.
-type impl_opt()      :: drv | nif | hyper | ets.

-type db_opts()       :: {db, [{path,file:filename()} | create_if_missing | {create_if_missing,boolean()} | error_if_exists | {error_if_exists,boolean()} | paranoid_checks | {paranoid_checks,boolean()} | {write_buffer_size,pos_integer()} | {max_open_files,pos_integer()} | {block_cache_size,pos_integer()} | {block_size,pos_integer()} | {block_restart_interval,pos_integer()} | {filter_policy,no | {bloom,pos_integer()}}]}.
-type db_read_opts()  :: {db_read, [verify_checksums | {verify_checksums,boolean()} | fill_cache | {fill_cache,boolean()}]}.
-type db_write_opts() :: {db_write, [sync | {sync,boolean()}]}.

-type key()           :: gen_ets_ns:key().
-type object()        :: gen_ets_ns:object().

-type name()          :: gen_ets_ns:gen_name().
-type item()          :: owner | name | named_table | type | keypos | protection | compressed | async | memory | size.
-type pos()           :: pos_integer().
-type match_pattern() :: gen_ets_ns:match_pattern().
-type match_spec()    :: gen_ets_ns:match_spec().
-type match()         :: term().
-type limit()         :: pos_integer().
-opaque cont()        :: {cont, lets_tid(), term()}.

-define(NS, lets_reg).

%%%----------------------------------------------------------------------
%%% API
%%%----------------------------------------------------------------------

%% @doc Returns a list of all tables at the node.
%% @end
%% @see ets:all/0

-spec all() -> [lets_tab()].
all() ->
    gen_ets_ns:all(?NS).

%% @doc Returns a table\'s identifier.
%% @end

-spec tid(lets_tab()) -> lets_tid().
tid(Tab) ->
    gen_ets_ns:tid(?NS, Tab).

%% @doc Creates a new table and returns a table identifier which can
%% be used in subsequent operations.  The table identifier can be sent
%% to other processes so that a table can be shared between different
%% processes within a node.
%%
%% Valid LETS properties for +Options+ are:
%%
%% - +set+ The table is a set table - one key, one object, no order
%%   among objects. This is the default table type.
%%
%% - +ordered_set+ The table is an ordered_set table - one key, one
%%   object, ordered in Erlang term order, which is the order implied
%%   by the +<+ and +>+ operators.
%%
%% - +named_table+ If this option is present, the name +Name+ is
%%   associated with the table identifier.
%%
%% - +{keypos,pos_integer()}+ Specfies which element in the stored
%%   tuples should be used as key. By default, it is the first
%%   element, i.e. +Pos=1+.
%%
%% - +public+ Any process may read or write to the table.
%%
%% - +protected+ The owner process can read and write to the table.
%%   Other processes can only read the table. This is the default
%%   setting for the access rights.
%%
%% - +private+ Only the owner process can read or write to the table.
%%
%% - +compressed+ If this option is present, the table data is stored
%%   in a compressed format.
%%
%% - +async+ If this option is present, the emulator\'s async thread
%%   pool is used when accessing the table data.  _only the drv
%%   implementation_
%%
%% - +drv+ If this option is present, the table data is stored with
%%   LevelDB backend via an Erlang Driver.  This is the default
%%   setting for the table implementation.
%%
%% - +nif+ If this option is present, the table data is stored with
%%   LevelDB backend via an Erlang NIF.
%%
%% - +hyper+ If this option is present, the HyperLeveDB version of the
%%   LevelDB implementation is used as the backend.  The original
%%   LevelDB implementation is the default backend.  _not applicable
%%   to the ets implementation_
%%
%% - +ets+ If this option is present, the table data is stored with
%%   ETS as the backend.
%%
%% - +{db, [db_opts()]}+ LevelDB database options.
%%
%% - +{db_read, [db_read_opts()]}+ LevelDB read options.
%%
%% - +{db_write, [db_write_opts()]}+ LevelDB write options.
%%
%% Valid LevelDB database properties for +db_opts()+ are:
%%
%% - +{path, file:filename()}+ Open the database with the specified
%%   path.  The default is +Name+.
%%
%% - +create_if_missing | {create_if_missing, boolean()}+ If +true+,
%%   the database is created if it is missing.  The default is<commit_msg>Correct db type definitions<commit_after>%%% The MIT License
%%%
%%% Copyright (C) 2011-2014 by <NAME> <<EMAIL>>
%%%
%%% Permission is hereby granted, free of charge, to any person obtaining a copy
%%% of this software and associated documentation files (the "Software"), to deal
%%% in the Software without restriction, including without limitation the rights
%%% to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
%%% copies of the Software, and to permit persons to whom the Software is
%%% furnished to do so, subject to the following conditions:
%%%
%%% The above copyright notice and this permission notice shall be included in
%%% all copies or substantial portions of the Software.
%%%
%%% THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
%%% IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
%%% FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
%%% AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
%%% LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
%%% OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
%%% THE SOFTWARE.

-module(lets).

-include("lets.hrl").

%% External exports
-export([all/0
         , tid/1
         , new/2
         , destroy/2
         , repair/2
         , delete/1
         , delete/2
         , delete_all_objects/1
         , first/1
         , foldl/3
         , foldr/3
         , info/1
         , info/2
         , insert/2
         , insert_new/2
         , last/1
         , lookup/2
         , lookup_element/3
         , match/2
         , match/3
         , match/1
         , match_delete/2
         , match_object/2
         , match_object/3
         , match_object/1
         , member/2
         , next/2
         , prev/2
         , select/2
         , select/3
         , select/1
         , select_count/2
         , select_delete/2
         , select_reverse/2
         , select_reverse/3
         , select_reverse/1
         , tab2list/1
        ]).

%% DEBUG -compile(export_all).

-export_type([lets_tab/0, lets_tid/0, name/0, key/0, object/0, match_pattern/0, match_spec/0, cont/0]).

%%%----------------------------------------------------------------------
%%% Types/Specs/Records
%%%----------------------------------------------------------------------

-type lets_tid()      :: gen_ets_ns:gen_tid().
-type lets_tab()      :: gen_ets_ns:gen_tab().

-type opts()          :: [ets_opt() | impl_opt() | {db, db_opts()} | {db_read, db_read_opts()} | {db_write, db_write_opts()}].
-type ets_opt()       :: set | ordered_set | named_table | {keypos,pos_integer()} | public | protected | private | compressed | async.
-type impl_opt()      :: drv | nif | hyper | ets.

-type db_opts()       :: [{path,file:filename()} | create_if_missing | {create_if_missing,boolean()} | error_if_exists | {error_if_exists,boolean()} | paranoid_checks | {paranoid_checks,boolean()} | {write_buffer_size,pos_integer()} | {max_open_files,pos_integer()} | {block_cache_size,pos_integer()} | {block_size,pos_integer()} | {block_restart_interval,pos_integer()} | {filter_policy,no | {bloom,pos_integer()}}].
-type db_read_opts()  :: [verify_checksums | {verify_checksums,boolean()} | fill_cache | {fill_cache,boolean()}].
-type db_write_opts() :: [sync | {sync,boolean()}].

-type key()           :: gen_ets_ns:key().
-type object()        :: gen_ets_ns:object().

-type name()          :: gen_ets_ns:gen_name().
-type item()          :: owner | name | named_table | type | keypos | protection | compressed | async | memory | size.
-type pos()           :: pos_integer().
-type match_pattern() :: gen_ets_ns:match_pattern().
-type match_spec()    :: gen_ets_ns:match_spec().
-type match()         :: term().
-type limit()         :: pos_integer().
-opaque cont()        :: {cont, lets_tid(), term()}.

-define(NS, lets_reg).

%%%----------------------------------------------------------------------
%%% API
%%%----------------------------------------------------------------------

%% @doc Returns a list of all tables at the node.
%% @end
%% @see ets:all/0

-spec all() -> [lets_tab()].
all() ->
    gen_ets_ns:all(?NS).

%% @doc Returns a table\'s identifier.
%% @end

-spec tid(lets_tab()) -> lets_tid().
tid(Tab) ->
    gen_ets_ns:tid(?NS, Tab).

%% @doc Creates a new table and returns a table identifier which can
%% be used in subsequent operations.  The table identifier can be sent
%% to other processes so that a table can be shared between different
%% processes within a node.
%%
%% Valid LETS properties for +Options+ are:
%%
%% - +set+ The table is a set table - one key, one object, no order
%%   among objects. This is the default table type.
%%
%% - +ordered_set+ The table is an ordered_set table - one key, one
%%   object, ordered in Erlang term order, which is the order implied
%%   by the +<+ and +>+ operators.
%%
%% - +named_table+ If this option is present, the name +Name+ is
%%   associated with the table identifier.
%%
%% - +{keypos,pos_integer()}+ Specfies which element in the stored
%%   tuples should be used as key. By default, it is the first
%%   element, i.e. +Pos=1+.
%%
%% - +public+ Any process may read or write to the table.
%%
%% - +protected+ The owner process can read and write to the table.
%%   Other processes can only read the table. This is the default
%%   setting for the access rights.
%%
%% - +private+ Only the owner process can read or write to the table.
%%
%% - +compressed+ If this option is present, the table data is stored
%%   in a compressed format.
%%
%% - +async+ If this option is present, the emulator\'s async thread
%%   pool is used when accessing the table data.  _only the drv
%%   implementation_
%%
%% - +drv+ If this option is present, the table data is stored with
%%   LevelDB backend via an Erlang Driver.  This is the default
%%   setting for the table implementation.
%%
%% - +nif+ If this option is present, the table data is stored with
%%   LevelDB backend via an Erlang NIF.
%%
%% - +hyper+ If this option is present, the HyperLeveDB version of the
%%   LevelDB implementation is used as the backend.  The original
%%   LevelDB implementation is the default backend.  _not applicable
%%   to the ets implementation_
%%
%% - +ets+ If this option is present, the table data is stored with
%%   ETS as the backend.
%%
%% - +{db, db_opts()}+ LevelDB database options.
%%
%% - +{db_read, db_read_opts()}+ LevelDB read options.
%%
%% - +{db_write, db_write_opts()}+ LevelDB write options.
%%
%% Valid LevelDB database properties for +db_opts()+ are:
%%
%% - +{path, file:filename()}+ Open the database with the specified
%%   path.  The default is +Name+.
%%
%% - +create_if_missing | {create_if_missing, boolean()}+ If +true+,
%%   the database is created if it is missing.  The default is
{'fraction_non_alphanumeric': 0.16957533449680046, 'fraction_numerical': 0.008144269924374637, 'mean_word_length': 2.630675818373812, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 19, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3162417', 'n_tokens_mistral': 4116, 'n_tokens_neox': 4047, 'n_words': 1432}