Skip to content
Merged
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: 1 addition & 0 deletions tests/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -504,6 +504,7 @@ These are automatically skipped by the runner and show up as SKIP in output.
| `ets_stored_fun.erl` | A fun stored in ETS (at the top of a row, nested in a list, tuple and map, after `update_element/3`) or `persistent_term` by a process that then exits or collects garbage keeps its captured list, binaries, tuple, map, float, bignum and inner fun when looked up and called; a fun read by `tab2list/1` or `persistent_term:get/1` still works after the table or term is deleted; completion marker; also run on BEAM | ~16 |
| `ets_stored_bitstring.erl` | Non-byte-aligned heap/refc bitstrings, sub-byte values and extracted tails stored in ETS or `persistent_term` survive writer exit/GC; boxed `update_element/3` replacements and copying reads remain intact after table deletion or term erasure; completion marker; same fixture on BEAM | 4 lifetime scenarios |
| `ets_bitstring_keys.erl` | Partial-bitstring bag duplicate suppression; copied direct/list/tuple keys in hash-backed tables for lookup, membership, insert_new, boxed updates, counters, deletion and forward/backward traversal; copied values as persistent_term keys; significant bits and exact lengths remain distinct; completion marker; same fixture on BEAM | Table-driven |
| `ets_structural_keys.erl` | Separately built map, float and big integer keys in set, bag and duplicate_bag tables, including nested terms and maps built in reverse order; misses for distinct keys including equal-valued integers and floats; completion marker; same fixture on BEAM | 24 hits + 24 misses |
| `ets_named_table_return.erl` | ets:new/2 with `named_table` returns the name (Cowboy's `?MODULE = ets:new(?MODULE, [named_table, ...])`): every table type, apply, variable module and fun calls; a table without `named_table` does not take the name, and creating or deleting one leaves a named table with the same atom reachable; the name is released by ets:delete/1; a table created in another process is reached by its name; also run on BEAM | Table-driven |

### Stdlib
Expand Down
43 changes: 43 additions & 0 deletions tests/ets_structural_keys.erl
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
%% EXPECT: ets_structural_keys_ok
%% Hash-backed ETS tables use exact term identity, not allocation addresses.
%% Run the same assertions natively and on BEAM.
-module(ets_structural_keys).
-export([test/0]).

test() ->
N = id(3),
[check_table(Type, N) || Type <- [set, bag, duplicate_bag]],
io:format("ets_structural_keys_ok~n"),
ok.

id(X) -> X.

map_key(N, forward) ->
maps:from_list([{N, integer}, {N / 1, float}, {items, [N]}]);
map_key(N, reverse) ->
maps:from_list([{items, [N]}, {N / 1, float}, {N, integer}]).

float_key(N) -> N / 2.

bigint_key(N) -> (1 bsl 80) + N.

check_table(Type, N) ->
T = ets:new(structural_keys, [Type]),
Map = map_key(N, forward),
check_lookup(T, Map, map_key(N, reverse), Map#{N => changed}),
check_lookup(T, float_key(N), float_key(N), float_key(N + 1)),
check_lookup(T, bigint_key(N), bigint_key(N), -bigint_key(N)),
check_lookup(T, {wrapped, Map}, {wrapped, map_key(N, reverse)}, {wrapped, Map#{items => [N + 1]}}),
check_lookup(T, [float_key(N)], [float_key(N)], [float_key(N + 1)]),
check_lookup(T, #{value => -bigint_key(N)}, #{value => -bigint_key(N)}, #{value => -bigint_key(N + 1)}),
%% Numerically equal keys need not be exact matches, even inside a map.
check_lookup(T, N / 1, N / 1, N),
check_lookup(T, #{value => N / 1}, #{value => N / 1}, #{value => N}),
true = ets:delete(T).

check_lookup(T, Key, Equal, Different) ->
Row = {Key, stored},
true = ets:insert(T, Row),
[Row] = ets:lookup(T, Equal),
[] = ets:lookup(T, Different),
true = ets:delete(T, Key).
Loading