🐐 Hash tables

This commit is contained in:
2026-04-25 20:49:31 +02:00
parent c9fd245bb3
commit ff1c392dd6
3 changed files with 146 additions and 29 deletions

View File

@@ -189,3 +189,34 @@ class TestDictDisplay(unittest.TestCase):
@parameterized.expand(dict_display_tests)
def test_dict_display(self, source, nodes, value, output):
run_test(self, source, nodes, value, output)
class TestDictGrowth(unittest.TestCase):
def test_dict_growth_preserves_order_and_lookup(self):
# Inserts XX entries via PER; pushes the compiled dict through
# multiple rehashes (initial cap=4) and verifies that lookup, length,
# and insertion-order iteration all still hold afterwards.
source = (
"DESIGNA d VT TABVLA {}\n"
"PER i IN [I VSQVE XX] FAC {\n"
"DESIGNA d[i] VT i * II\n"
"}\n"
"DIC(d[X])\n"
"DIC(LONGITVDO(d))\n"
"DIC(CLAVES(d))"
)
nodes = Program([], [
Designa(ID("d"), DataDict([])),
PerStatement(
DataRangeArray(Numeral("I"), Numeral("XX")),
ID("i"),
[DesignaIndex(ID("d"), [ID("i")],
BinOp(ID("i"), Numeral("II"), "SYMBOL_TIMES"))],
),
ExpressionStatement(BuiltIn("DIC", [ArrayIndex(ID("d"), Numeral("X"))])),
ExpressionStatement(BuiltIn("DIC", [BuiltIn("LONGITVDO", [ID("d")])])),
ExpressionStatement(BuiltIn("DIC", [BuiltIn("CLAVES", [ID("d")])])),
])
keys_str = "[" + " ".join(int_to_num(i, False) for i in range(1, 21)) + "]"
output = f"XX\nXX\n{keys_str}\n"
run_test(self, source, nodes, ValStr(keys_str), output)